mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2025-01-05 17:42:24 +08:00
327 lines
7.5 KiB
C++
327 lines
7.5 KiB
C++
/**
|
||
* Tencent is pleased to support the open source community by making Tars available.
|
||
*
|
||
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
|
||
*
|
||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||
* in compliance with the License. You may obtain a copy of the License at
|
||
*
|
||
* https://opensource.org/licenses/BSD-3-Clause
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software distributed
|
||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||
* specific language governing permissions and limitations under the License.
|
||
*/
|
||
#ifndef _TARS2OC_H
|
||
#define _TARS2OC_H
|
||
|
||
#include "parse.h"
|
||
|
||
#include <cassert>
|
||
#include <string>
|
||
|
||
using namespace tars;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>tars<72><73><EFBFBD><EFBFBD>h<EFBFBD><68>m<EFBFBD>ļ<EFBFBD>
|
||
*/
|
||
class Tars2OC
|
||
{
|
||
|
||
public:
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>
|
||
* @param file
|
||
*/
|
||
void createFile(const string &file);
|
||
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ŀ¼
|
||
*
|
||
*/
|
||
void setBaseDir(const std::string & sPath) { m_sBaseDir = sPath; }
|
||
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||
*
|
||
* @param bCheck
|
||
*/
|
||
void setArc(const bool bArc) { m_bARC = bArc; }
|
||
/**
|
||
* <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>ǰ
|
||
*/
|
||
void setNeedNS(bool bNeed) { m_bNeedNS = bNeed;}
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>
|
||
*/
|
||
void setNS(const string& sNS) {m_sNamespace = sNS;}
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
protected:
|
||
/**
|
||
* <20><>ȡö<C8A1>ٻ<EFBFBD><D9BB>߽ṹ<DFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<C7B0>ַ<EFBFBD><D6B7><EFBFBD>
|
||
* @param sTarsNS tars<72>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>
|
||
* @param bEnum <20>Ƿ<EFBFBD><C7B7><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<C7B0>ַ<EFBFBD><D6B7><EFBFBD>
|
||
*/
|
||
string getNamePrix(const string& sTarsNS) const;
|
||
|
||
/**
|
||
* <20><>ȡ<EFBFBD><C8A1><EFBFBD>Ϲ淶<CFB9>ij<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>
|
||
*/
|
||
string getPropertyName(const string& sId) const;
|
||
|
||
/**
|
||
*
|
||
* <20><>ȡ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>setter<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*/
|
||
string getSetterName(const string& sId) const;
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostr(const TypePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrBuiltin(const BuiltinPtr &pPtr) const;
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>vector<6F><72><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrVector(const VectorPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>map<61><70><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrMap(const MapPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD>ֽṹ<D6BD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrStruct(const StructPtr &pPtr) const;
|
||
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ö<EFBFBD>ٵķ<D9B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrEnum(const EnumPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>OBJC <20>汾2<E6B1BE><32><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string toTarsV2Procstr(const TypeIdPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>OBJC<4A>汾2<E6B1BE>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string toAddtionalClassName(const TypePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɽṹ<C9BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>synthesize<7A><65><EFBFBD><EFBFBD>
|
||
* @param vMember
|
||
*
|
||
* @return string
|
||
*/
|
||
string writesynthesize(const vector<TypeIdPtr>& vMember) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>Initialize<7A><65><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string writeInitialize(const StructPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>庯<EFBFBD><E5BAAF>init
|
||
* @param vMember
|
||
*
|
||
* @return string
|
||
*/
|
||
string writeInit(const vector<TypeIdPtr>& vMember) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param vMember
|
||
*
|
||
* @return string
|
||
*/
|
||
string writedealloc(const vector<TypeIdPtr>& vMember) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɽṹ<C9BD><E1B9B9><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string writeTarsType(const StructPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>ʾ<EFBFBD><CABE>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string toClassName(const TypePtr &pPtr) const;
|
||
protected:
|
||
/**
|
||
* <20><>ȡtars<72>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>require<72><65>optional
|
||
* @param pPtr
|
||
*
|
||
*/
|
||
string getReqOptionType(const TypeIdPtr &pPtr) const;
|
||
/**
|
||
* <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>retain<69><6E><EFBFBD>ͣ<EFBFBD>string<6E>Ͷ<EFBFBD><CDB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD><EFBFBD><EFBFBD>retain
|
||
* @param pPtr
|
||
*
|
||
*/
|
||
bool IsRetainType(const TypePtr &pPtr) const;
|
||
|
||
bool isNumberType(const TypePtr &pPtr) const;
|
||
/**
|
||
* <20><>ȡ<EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ı<CDB5>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD><C6BA><EFBFBD><EFBFBD>ͣ<EFBFBD>Ŀǰ<C4BF>ǽṹ<C7BD><E1B9B9><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @param pPtr
|
||
* @param namespaceId
|
||
*
|
||
* @return
|
||
*/
|
||
map<string,int> getReferences(const StructPtr &pPtr, const string& namespaceId="") const;
|
||
|
||
/**
|
||
* <20><>ȡ<EFBFBD><C8A1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
||
* <20><><EFBFBD><EFBFBD>, stHello hello;stHelloΪ<6F><CEAA><EFBFBD>ͱ<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||
*
|
||
* @param pPtr
|
||
* @param mRefs
|
||
*/
|
||
void toIncludeName(const TypePtr &pPtr,map<string,int>& mRefs) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɽṹ<C9BD><E1B9B9>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateH(const StructPtr &pPtr, const string& namespaceId) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɽṹ<C9BD><E1B9B9>m<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateM(const StructPtr &pPtr, const string& namespaceId) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ö<EFBFBD>ٵ<EFBFBD>m<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateM(const EnumPtr &pPtr, const string& namespaceId) const;
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateH(const ContainerPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ö<EFBFBD>ٵ<EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateH(const EnumPtr &pPtr, const string& namespaceId) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF><D5BC>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ʵ<EFBFBD><CAB5>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generate(const NamespacePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>m<EFBFBD>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateM(const NamespacePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF><D5BC>ͷ<EFBFBD>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
void generate(const ContextPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>m<EFBFBD>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
void generateM(const ContextPtr &pPtr) const;
|
||
|
||
private:
|
||
enum EM_TYPE
|
||
{
|
||
EM_STRUCT_TYPE = 1,
|
||
EM_ENUM_TYPE = 2
|
||
};
|
||
std::string m_sBaseDir;
|
||
|
||
//<modulename,EM_TYPE>, 2:enum,1,stuct;
|
||
mutable map<string,int> m_mIncludes;
|
||
/**
|
||
* <20>Ƿ<EFBFBD>֧<EFBFBD><D6A7>arc<72>汾
|
||
*
|
||
*/
|
||
bool m_bARC;
|
||
/**
|
||
* <20>Ƿ<EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>ǰ
|
||
*/
|
||
bool m_bNeedNS;
|
||
/**
|
||
*<2A>û<EFBFBD><C3BB>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>ǰ<C7B0><D7BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ<D6B5>գ<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>ȡtars<72>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ֵ
|
||
*/
|
||
string m_sNamespace;
|
||
};
|
||
|
||
#endif
|
||
|
||
|