mirror of
https://github.com/tars-node/tars2node.git
synced 2024-03-22 13:10:56 +08:00
version: 20190509
This commit is contained in:
parent
888a032269
commit
a5b3fdf39d
|
@ -7,7 +7,7 @@ set(CMAKE_VERBOSE_MAKEFILE off)
|
|||
# version
|
||||
set(TARS_VERSION "1.1.0")
|
||||
set(PARSER_VERSION "${TARS_VERSION}")
|
||||
set(GENERATOR_VERSION "20190326")
|
||||
set(GENERATOR_VERSION "20190509")
|
||||
|
||||
# namespace
|
||||
set(IDL_NAMESPACE Tars)
|
||||
|
|
|
@ -29,7 +29,7 @@ tars2node [OPTIONS] tarsfile
|
|||
| --server | 生成服务端的框架代码。|
|
||||
| --ts | 打开此选项将后将只生成 TypeScript (.ts) 代码。|
|
||||
| --dts | 生成时附加 TypeScript 描述文件(.d.ts)。|
|
||||
| --use-string-represent | 当需要保持 <long> 类型的精度时,打开此选项使用 \<string\> 存储 \<long\>。|
|
||||
| --long-type=[number|string|bigint] | 可选择使用 \<Number\|String\|BigInt\> 表达 \<long\> 类型,默认值为 \<Number\>。|
|
||||
| --string-binary-encoding | 遇到字符编码问题或需对原始数据进行存取时,打开此选项使用 \<buffer\> 存储 \<string\>。|
|
||||
| --enum-reverse-mappings | 输出代码 \<enum\> 支持枚举值到枚举名的反向映射 。|
|
||||
| --optimize=[0\|s] | 优化输出代码大小,默认为 0(也就是不优化)。|
|
||||
|
|
BIN
build/tars2node
BIN
build/tars2node
Binary file not shown.
|
@ -105,7 +105,7 @@ void CodeGenerator::createFile(const string &file, const bool bEntry)
|
|||
node.setTargetPath(_sToPath);
|
||||
node.setRecursive(_bRecursive);
|
||||
node.setUseSpecialPath(_bUseSpecialPath);
|
||||
node.setUseStringRepresent(_bUseStringRepresent);
|
||||
node.setLongType(_iLongType);
|
||||
node.setStringBinaryEncoding(_bStringBinaryEncoding);
|
||||
node.setMinimalMembers(_bMinimalMembers);
|
||||
node.setDependent(_depMembers);
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
_bServer(false),
|
||||
_bRecursive(false),
|
||||
_bUseSpecialPath(false),
|
||||
_bUseStringRepresent(false),
|
||||
_iLongType(Number),
|
||||
_bStringBinaryEncoding(false),
|
||||
_bEnumReverseMappings(false),
|
||||
_bMinimalMembers(false),
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
|
||||
void setUseSpecialPath(bool bEnable) { _bUseSpecialPath = bEnable; }
|
||||
|
||||
void setUseStringRepresent(bool bEnable) { _bUseStringRepresent = bEnable; }
|
||||
void setLongType(int iLongType) { _iLongType = iLongType; }
|
||||
|
||||
void setStringBinaryEncoding(bool bEnable) { _bStringBinaryEncoding = bEnable; }
|
||||
|
||||
|
@ -119,6 +119,8 @@ public:
|
|||
|
||||
enum OPTIMIZE_LEVEL {O0 = 0, Os};
|
||||
|
||||
enum LONG_TYPE {Number = 0, String, BigInt};
|
||||
|
||||
private:
|
||||
struct ImportFileType
|
||||
{
|
||||
|
@ -273,7 +275,7 @@ private:
|
|||
|
||||
bool isBinBuffer(const TypePtr & pPtr) const;
|
||||
|
||||
bool isRawOrString(const TypePtr & pPtr) const;
|
||||
string representArgument(const TypePtr& pPtr) const;
|
||||
|
||||
bool isDependent(const string & sNamespace, const string & sName) const;
|
||||
|
||||
|
@ -298,7 +300,7 @@ private:
|
|||
|
||||
bool _bUseSpecialPath;
|
||||
|
||||
bool _bUseStringRepresent;
|
||||
int _iLongType;
|
||||
|
||||
bool _bStringBinaryEncoding;
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ string CodeGenerator::generateJS(const StructPtr &pPtr, const string &sNamespace
|
|||
if (isSimple(member[i]->getTypePtr()))
|
||||
{
|
||||
s << getDefault(member[i], member[i]->def(), sNamespace)
|
||||
<< (isRawOrString(member[i]->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(member[i]->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -170,7 +170,7 @@ string CodeGenerator::generateJS(const StructPtr &pPtr, const string &sNamespace
|
|||
string sFuncName = toFunctionName(member[i], "write");
|
||||
|
||||
s << TAB << "os." << sFuncName << "(" << member[i]->getTag() << ", this." << member[i]->getId()
|
||||
<< (isRawOrString(member[i]->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(member[i]->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
DEL_TAB;
|
||||
s << TAB << "};" << endl;
|
||||
|
|
|
@ -101,7 +101,7 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
|
||||
str << TAB << "os." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "("
|
||||
<< (i + 1) << ", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
|
||||
// push the symbol into dependent list
|
||||
getDataType(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
|
@ -140,7 +140,7 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
if (isSimple(oPtr->getReturnPtr()->getTypePtr()))
|
||||
{
|
||||
str << getDefault(oPtr->getReturnPtr(), oPtr->getReturnPtr()->def(), nPtr->getId())
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
if (isSimple(vParamDecl[i]->getTypeIdPtr()->getTypePtr()))
|
||||
{
|
||||
str << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId())
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -221,7 +221,7 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
|
||||
str << TAB << PROTOCOL_VAR << "." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "(\""
|
||||
<< vParamDecl[i]->getTypeIdPtr()->getId() << "\", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
|
||||
// push the symbol into dependent list
|
||||
getDataType(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
|
@ -257,7 +257,7 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
}
|
||||
|
||||
str << ", " << getDefault(oPtr->getReturnPtr(), "", nPtr->getId(), true)
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr());
|
||||
|
||||
str << ")";
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
|
||||
str << TAB << "os." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "("
|
||||
<< (i + 1) << ", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
|
||||
// push the symbol into dependent list
|
||||
getDataType(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
|
@ -137,7 +137,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
if (isSimple(oPtr->getReturnPtr()->getTypePtr()))
|
||||
{
|
||||
str << getDefault(oPtr->getReturnPtr(), oPtr->getReturnPtr()->def(), nPtr->getId(), true, true)
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
if (isSimple(vParamDecl[i]->getTypeIdPtr()->getTypePtr()))
|
||||
{
|
||||
str << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId(), true, true)
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -221,7 +221,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
|
||||
str << TAB << PROTOCOL_VAR << "." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "(\""
|
||||
<< vParamDecl[i]->getTypeIdPtr()->getId() << "\", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
|
||||
// push the symbol into dependent list
|
||||
getDataType(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
|
@ -258,7 +258,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP
|
|||
}
|
||||
|
||||
str << ", " << getDefault(oPtr->getReturnPtr(), "", nPtr->getId(), true, true)
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr());
|
||||
|
||||
str << ")," << endl;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ string CodeGenerator::generateAsync(const NamespacePtr &nPtr, const InterfacePtr
|
|||
if (oPtr->getReturnPtr()->getTypePtr())
|
||||
{
|
||||
str << TAB << PROTOCOL_VAR << "." << toFunctionName(oPtr->getReturnPtr(), "write") << "(\"\", _ret"
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
for (size_t i = 0; i < vParamDecl.size(); i++)
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ string CodeGenerator::generateAsync(const NamespacePtr &nPtr, const InterfacePtr
|
|||
|
||||
str << TAB << PROTOCOL_VAR << "." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "(\""
|
||||
<< vParamDecl[i]->getTypeIdPtr()->getId() << "\", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
str << endl;
|
||||
str << TAB << "this.doResponse(" << PROTOCOL_VAR << ".encode());" << endl;
|
||||
|
@ -110,7 +110,7 @@ string CodeGenerator::generateAsync(const NamespacePtr &nPtr, const InterfacePtr
|
|||
if (oPtr->getReturnPtr()->getTypePtr())
|
||||
{
|
||||
str << TAB << "os." << toFunctionName(oPtr->getReturnPtr(), "write") << "(0, _ret"
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
for (size_t i = 0; i < vParamDecl.size(); i++)
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ string CodeGenerator::generateAsync(const NamespacePtr &nPtr, const InterfacePtr
|
|||
|
||||
str << TAB << "os." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "("
|
||||
<< (i + 1) << ", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
str << endl;
|
||||
str << TAB << "this.doResponse(os.getBinBuffer());" << endl;
|
||||
|
@ -172,7 +172,7 @@ string CodeGenerator::generateDispatch(const NamespacePtr &nPtr, const Interface
|
|||
if (vParamDecl[i]->isOut())
|
||||
{
|
||||
dstr << ", " << getDefault(vParamDecl[i]->getTypeIdPtr(), "", nPtr->getId(), true)
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
}
|
||||
|
||||
dstr << ");" << endl;
|
||||
|
@ -194,7 +194,7 @@ string CodeGenerator::generateDispatch(const NamespacePtr &nPtr, const Interface
|
|||
if (isSimple(vParamDecl[i]->getTypeIdPtr()->getTypePtr()))
|
||||
{
|
||||
dstr << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId())
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -58,7 +58,7 @@ string CodeGenerator::generateTSServerAsync(const NamespacePtr &nPtr, const Inte
|
|||
if (oPtr->getReturnPtr()->getTypePtr())
|
||||
{
|
||||
str << TAB << PROTOCOL_VAR << "." << toFunctionName(oPtr->getReturnPtr(), "write") << "(\"\", _ret"
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
for (size_t i = 0; i < vParamDecl.size(); i++)
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ string CodeGenerator::generateTSServerAsync(const NamespacePtr &nPtr, const Inte
|
|||
|
||||
str << TAB << PROTOCOL_VAR << "." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "(\""
|
||||
<< vParamDecl[i]->getTypeIdPtr()->getId() << "\", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
str << endl;
|
||||
str << TAB << "this.doResponse(" << PROTOCOL_VAR << ".encode());" << endl;
|
||||
|
@ -78,7 +78,7 @@ string CodeGenerator::generateTSServerAsync(const NamespacePtr &nPtr, const Inte
|
|||
if (oPtr->getReturnPtr()->getTypePtr())
|
||||
{
|
||||
str << TAB << "os." << toFunctionName(oPtr->getReturnPtr(), "write") << "(0, _ret"
|
||||
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(oPtr->getReturnPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
for (size_t i = 0; i < vParamDecl.size(); i++)
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ string CodeGenerator::generateTSServerAsync(const NamespacePtr &nPtr, const Inte
|
|||
|
||||
str << TAB << "os." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "("
|
||||
<< (i + 1) << ", " << vParamDecl[i]->getTypeIdPtr()->getId()
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
str << endl;
|
||||
str << TAB << "this.doResponse(os.getBinBuffer());" << endl;
|
||||
|
@ -142,7 +142,7 @@ string CodeGenerator::generateTSServerDispatch(const NamespacePtr &nPtr, const I
|
|||
if (vParamDecl[i]->isOut())
|
||||
{
|
||||
dstr << ", " << getDefault(vParamDecl[i]->getTypeIdPtr(), "", nPtr->getId(), true, true)
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
}
|
||||
|
||||
dstr << ");" << endl;
|
||||
|
@ -164,7 +164,7 @@ string CodeGenerator::generateTSServerDispatch(const NamespacePtr &nPtr, const I
|
|||
if (isSimple(vParamDecl[i]->getTypeIdPtr()->getTypePtr()))
|
||||
{
|
||||
dstr << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId(), true, true)
|
||||
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -134,7 +134,7 @@ string CodeGenerator::generateTS(const StructPtr &pPtr, const string &sNamespace
|
|||
if (isSimple(member[i]->getTypePtr()))
|
||||
{
|
||||
s << getDefault(member[i], member[i]->def(), sNamespace, true, true)
|
||||
<< (isRawOrString(member[i]->getTypePtr()) ? ", 1" : "");
|
||||
<< representArgument(member[i]->getTypePtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ string CodeGenerator::generateTS(const StructPtr &pPtr, const string &sNamespace
|
|||
string sFuncName = toFunctionName(member[i], "write");
|
||||
|
||||
s << TAB << "os." << sFuncName << "(" << member[i]->getTag() << ", this." << member[i]->getId()
|
||||
<< (isRawOrString(member[i]->getTypePtr()) ? ", 1" : "") << ");" << endl;
|
||||
<< representArgument(member[i]->getTypePtr()) << ");" << endl;
|
||||
}
|
||||
DEL_TAB; // end of _writeTo
|
||||
s << TAB << "}" << endl;
|
||||
|
|
|
@ -68,23 +68,25 @@ string CodeGenerator::toFunctionName(const TypeIdPtr& pPtr, const string& sActio
|
|||
return "";
|
||||
}
|
||||
|
||||
bool CodeGenerator::isRawOrString(const TypePtr& pPtr) const
|
||||
string CodeGenerator::representArgument(const TypePtr& pPtr) const
|
||||
{
|
||||
BuiltinPtr bPtr = BuiltinPtr::dynamicCast(pPtr);
|
||||
if (bPtr)
|
||||
{
|
||||
if (_bUseStringRepresent && bPtr->kind() == Builtin::KindLong)
|
||||
if (bPtr->kind() == Builtin::KindLong && _iLongType != CodeGenerator::Number)
|
||||
{
|
||||
return true;
|
||||
stringstream str;
|
||||
str << ", " << _iLongType;
|
||||
return str.str();
|
||||
}
|
||||
|
||||
if (_bStringBinaryEncoding && bPtr->kind() == Builtin::KindString)
|
||||
{
|
||||
return true;
|
||||
return ", 1";
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
|
||||
string CodeGenerator::getClassName(const TypePtr& pPtr)
|
||||
|
@ -163,8 +165,7 @@ string CodeGenerator::getDataType(const TypePtr& pPtr, const bool &bCastEnumAsAn
|
|||
{
|
||||
return IDL_NAMESPACE_STR + "Stream.BinBuffer";
|
||||
}
|
||||
|
||||
return IDL_NAMESPACE_STR + "Stream.List(" + getDataType(vPtr->getTypePtr(), bCastEnumAsAny) + (isRawOrString(vPtr->getTypePtr()) ? ", 1" : "") + ")";
|
||||
return IDL_NAMESPACE_STR + "Stream.List(" + getDataType(vPtr->getTypePtr(), bCastEnumAsAny) + representArgument(vPtr->getTypePtr()) + ")";
|
||||
}
|
||||
|
||||
StructPtr sPtr = StructPtr::dynamicCast(pPtr);
|
||||
|
@ -179,20 +180,10 @@ string CodeGenerator::getDataType(const TypePtr& pPtr, const bool &bCastEnumAsAn
|
|||
MapPtr mPtr = MapPtr::dynamicCast(pPtr);
|
||||
if (mPtr)
|
||||
{
|
||||
bool bLeft = isRawOrString(mPtr->getLeftTypePtr());
|
||||
bool bRight = isRawOrString(mPtr->getRightTypePtr());
|
||||
|
||||
if (!bRight && !bLeft) {
|
||||
return IDL_NAMESPACE_STR + "Stream.Map(" + getDataType(mPtr->getLeftTypePtr(), bCastEnumAsAny) + ", " + getDataType(mPtr->getRightTypePtr(), bCastEnumAsAny) + ")";
|
||||
} else if (bRight && bLeft) {
|
||||
return IDL_NAMESPACE_STR + "Stream.Map(" + getDataType(mPtr->getLeftTypePtr(), bCastEnumAsAny) + ", " + getDataType(mPtr->getRightTypePtr(), bCastEnumAsAny) + ", 1, 1)";
|
||||
} else if (bRight) {
|
||||
return IDL_NAMESPACE_STR + "Stream.Map(" + getDataType(mPtr->getLeftTypePtr(), bCastEnumAsAny) + ", " + getDataType(mPtr->getRightTypePtr(), bCastEnumAsAny) + ", 0, 1)";
|
||||
} else if (bLeft) {
|
||||
return IDL_NAMESPACE_STR + "Stream.Map(" + getDataType(mPtr->getLeftTypePtr(), bCastEnumAsAny) + ", " + getDataType(mPtr->getRightTypePtr(), bCastEnumAsAny) + ", 1)";
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
return IDL_NAMESPACE_STR + "Stream.Map(" + getDataType(mPtr->getLeftTypePtr(), bCastEnumAsAny) + ", " +
|
||||
getDataType(mPtr->getRightTypePtr(), bCastEnumAsAny) +
|
||||
representArgument(mPtr->getLeftTypePtr()) +
|
||||
representArgument(mPtr->getRightTypePtr()) + ")";
|
||||
}
|
||||
|
||||
EnumPtr ePtr = EnumPtr::dynamicCast(pPtr);
|
||||
|
@ -221,9 +212,18 @@ string CodeGenerator::getTsType(const TypePtr &pPtr, const bool bStream, const b
|
|||
case Builtin::KindByte : return "number";
|
||||
case Builtin::KindShort : return "number";
|
||||
case Builtin::KindInt : return "number";
|
||||
case Builtin::KindLong : return _bUseStringRepresent ? "string" : "number";
|
||||
case Builtin::KindFloat : return "number";
|
||||
case Builtin::KindDouble : return "number";
|
||||
case Builtin::KindLong :
|
||||
{
|
||||
switch (_iLongType)
|
||||
{
|
||||
case CodeGenerator::Number : return "number";
|
||||
case CodeGenerator::String : return "string";
|
||||
case CodeGenerator::BigInt : return "bigint";
|
||||
default : assert(false);
|
||||
}
|
||||
}
|
||||
default : assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -375,11 +375,20 @@ string CodeGenerator::getDefault(const TypeIdPtr & pPtr, const string &sDefault,
|
|||
sTemp = "0";
|
||||
}
|
||||
|
||||
if (_bUseStringRepresent)
|
||||
{
|
||||
if (bPtr->kind() == Builtin::KindLong)
|
||||
{
|
||||
switch (_iLongType)
|
||||
{
|
||||
case CodeGenerator::String:
|
||||
{
|
||||
sTemp = "\"" + sTemp + "\"";
|
||||
break;
|
||||
}
|
||||
case CodeGenerator::BigInt:
|
||||
{
|
||||
sTemp = sTemp + "n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -40,7 +40,7 @@ void usage()
|
|||
cout << " --server just for server side source file." << endl;
|
||||
cout << " --ts generate typescript file." << endl;
|
||||
cout << " --dts generate d.ts file." << endl;
|
||||
cout << " --use-string-represent use <string> represent <long> type." << endl;
|
||||
cout << " --long-type=[number|string|bigint] use <Number|String|BigInt> represent <long> type, default is <Number>." << endl;
|
||||
cout << " --string-binary-encoding get string raw bytes <BinBuffer>." << endl;
|
||||
cout << " --enum-reverse-mappings reverse mapping from enum values to enum names." << endl;
|
||||
cout << " --optimize=[0|s] support \"s\" to reduce code size, default is 0." << endl;
|
||||
|
@ -130,12 +130,25 @@ int main(int argc, char* argv[])
|
|||
generator.setEnableServer(option.hasParam("server"));
|
||||
generator.setTargetPath(option.hasParam("dir")?option.getValue("dir"):"./");
|
||||
generator.setUseSpecialPath(option.hasParam("relative"));
|
||||
generator.setUseStringRepresent(option.hasParam("use-string-represent"));
|
||||
generator.setStringBinaryEncoding(option.hasParam("string-binary-encoding"));
|
||||
generator.setEnumReverseMappings(option.hasParam("enum-reverse-mappings"));
|
||||
generator.setEnableTS(option.hasParam("ts"));
|
||||
generator.setEnableDTS(option.hasParam("dts"));
|
||||
|
||||
if (option.hasParam("long-type"))
|
||||
{
|
||||
string longType = TC_Common::lower(option.getValue("long-type"));
|
||||
if (longType == "string")
|
||||
{
|
||||
generator.setLongType(CodeGenerator::String);
|
||||
}
|
||||
else if (longType == "bigint")
|
||||
{
|
||||
generator.setLongType(CodeGenerator::BigInt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (option.hasParam("optimize"))
|
||||
{
|
||||
string level = TC_Common::lower(option.getValue("optimize"));
|
||||
|
|
Loading…
Reference in New Issue
Block a user