version: 20190509

This commit is contained in:
superzheng 2019-05-09 19:10:02 +08:00
parent 888a032269
commit a5b3fdf39d
13 changed files with 122 additions and 98 deletions

View File

@ -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)

View File

@ -16,23 +16,23 @@ tars2node [OPTIONS] tarsfile
| 选项 | 作用 |
| ------------- | ------------- |
| --stream-path=[DIRECTORY] | 指定编解码模块名称,默认为 @tars/stream。 |
| --rpc-path=[DIRECTORY] | 指定 RPC 模块名称,默认为 @tars/rpc。 |
| --allow-reserved-namespace | 是否允许 `tars` 作为命名空间(因为此命名空间主要用于框架服务的 tars 文件定义)。 |
| --dir=[DIRECTORY] | 生成文件的输出目录。 |
| --relative | 限定所有的 `.tars` 文件都在当前目录寻找。|
| --tarsBase=[DIRECTORY] | 指定 `.tars` 文件的搜索目录。|
| --r | 转换嵌套的 `.tars` 文件。|
| --r-minimal | 精简依赖文件,移除非必须成员。|
| --r-reserved | 精简依赖文件时需保留的成员。|
| --client | 生成客户端的调用类代码。|
| --server | 生成服务端的框架代码。|
| --ts | 打开此选项将后将只生成 TypeScript (.ts) 代码。|
| --dts | 生成时附加 TypeScript 描述文件(.d.ts。|
| --use-string-represent | 当需要保持 <long> 类型的精度时,打开此选项使用 \<string\> 存储 \<long\>。|
| --string-binary-encoding | 遇到字符编码问题或需对原始数据进行存取时,打开此选项使用 \<buffer\> 存储 \<string\>。|
| --enum-reverse-mappings | 输出代码 \<enum\> 支持枚举值到枚举名的反向映射 。|
| --optimize=[0\|s] | 优化输出代码大小,默认为 0也就是不优化。|
| --stream-path=[DIRECTORY] | 指定编解码模块名称,默认为 @tars/stream。 |
| --rpc-path=[DIRECTORY] | 指定 RPC 模块名称,默认为 @tars/rpc。 |
| --allow-reserved-namespace | 是否允许 `tars` 作为命名空间(因为此命名空间主要用于框架服务的 tars 文件定义)。 |
| --dir=[DIRECTORY] | 生成文件的输出目录。 |
| --relative | 限定所有的 `.tars` 文件都在当前目录寻找。|
| --tarsBase=[DIRECTORY] | 指定 `.tars` 文件的搜索目录。|
| --r | 转换嵌套的 `.tars` 文件。|
| --r-minimal | 精简依赖文件,移除非必须成员。|
| --r-reserved | 精简依赖文件时需保留的成员。|
| --client | 生成客户端的调用类代码。|
| --server | 生成服务端的框架代码。|
| --ts | 打开此选项将后将只生成 TypeScript (.ts) 代码。|
| --dts | 生成时附加 TypeScript 描述文件(.d.ts。|
| --long-type=[number|string|bigint] | 可选择使用 \<Number\|String\|BigInt\> 表达 \<long\> 类型,默认值为 \<Number\>。|
| --string-binary-encoding | 遇到字符编码问题或需对原始数据进行存取时,打开此选项使用 \<buffer\> 存储 \<string\>。|
| --enum-reverse-mappings | 输出代码 \<enum\> 支持枚举值到枚举名的反向映射 。|
| --optimize=[0\|s] | 优化输出代码大小,默认为 0也就是不优化。|
## 例子

Binary file not shown.

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -100,8 +100,8 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
if (vParamDecl[i]->isOut()) continue;
str << TAB << "os." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "("
<< (i + 1) << ", " << vParamDecl[i]->getTypeIdPtr()->getId()
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
<< (i + 1) << ", " << vParamDecl[i]->getTypeIdPtr()->getId()
<< 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
{
@ -166,8 +166,8 @@ 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" : "");
str << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId())
<< representArgument(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
}
else
{
@ -220,8 +220,8 @@ string CodeGenerator::generateJSProxy(const NamespacePtr &nPtr, const InterfaceP
if (vParamDecl[i]->isOut()) continue;
str << TAB << PROTOCOL_VAR << "." << toFunctionName(vParamDecl[i]->getTypeIdPtr(), "write") << "(\""
<< vParamDecl[i]->getTypeIdPtr()->getId() << "\", " << vParamDecl[i]->getTypeIdPtr()->getId()
<< (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
<< vParamDecl[i]->getTypeIdPtr()->getId() << "\", " << vParamDecl[i]->getTypeIdPtr()->getId()
<< 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 << ")";
}

View File

@ -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;
}

View File

@ -89,8 +89,8 @@ string CodeGenerator::generateAsync(const NamespacePtr &nPtr, const InterfacePtr
str << TAB << PROTOCOL_VAR << "." << PROTOCOL_VAR << "Version = this.getRequestVersion();" << endl;
if (oPtr->getReturnPtr()->getTypePtr())
{
str << TAB << PROTOCOL_VAR << "." << toFunctionName(oPtr->getReturnPtr(), "write") << "(\"\", _ret"
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
str << TAB << PROTOCOL_VAR << "." << toFunctionName(oPtr->getReturnPtr(), "write") << "(\"\", _ret"
<< 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;
@ -109,8 +109,8 @@ string CodeGenerator::generateAsync(const NamespacePtr &nPtr, const InterfacePtr
str << TAB << "var os = new " << IDL_NAMESPACE_STR << "Stream." << IDL_TYPE << "OutputStream();" << endl;
if (oPtr->getReturnPtr()->getTypePtr())
{
str << TAB << "os." << toFunctionName(oPtr->getReturnPtr(), "write") << "(0, _ret"
<< (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : "") << ");" << endl;
str << TAB << "os." << toFunctionName(oPtr->getReturnPtr(), "write") << "(0, _ret"
<< 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
{

View File

@ -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
{

View File

@ -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;

View File

@ -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)
{
if (bPtr->kind() == Builtin::KindLong)
switch (_iLongType)
{
sTemp = "\"" + sTemp + "\"";
case CodeGenerator::String:
{
sTemp = "\"" + sTemp + "\"";
break;
}
case CodeGenerator::BigInt:
{
sTemp = sTemp + "n";
break;
}
}
}

View File

@ -26,24 +26,24 @@ void usage()
{
cout << "Version : " << GENERATOR_VERSION << endl;
cout << "Usage : " << EXECUTE_FILENAME << " [OPTION] " << "*." << TC_Common::lower(IDL_TYPE) << " file" << endl;
cout << " --version print " << EXECUTE_FILENAME << " version" << endl;
cout << " --rpc-path=[DIRECTORY] specify the path of rpc module." << endl;
cout << " --stream-path=[DIRECTORY] specify the path of stream module." << endl;
cout << " --allow-reserved-namespace allow you to use reserved word as a namespace." << endl;
cout << " --dir=DIRECTORY generate source file to DIRECTORY." << endl;
cout << " --relative use current path." << endl;
cout << " --base=DIRECTORY where to search " << IDL_TYPE << " files." << endl;
cout << " --r generate source all " << IDL_TYPE << " files." << endl;
cout << " --r-minimal minimize the dependent members." << endl;
cout << " --r-reserved list of names(split by \",\") that should be keeped." << endl;
cout << " --client just for client side source file." << endl;
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 << " --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;
cout << " --version print " << EXECUTE_FILENAME << " version" << endl;
cout << " --rpc-path=[DIRECTORY] specify the path of rpc module." << endl;
cout << " --stream-path=[DIRECTORY] specify the path of stream module." << endl;
cout << " --allow-reserved-namespace allow you to use reserved word as a namespace." << endl;
cout << " --dir=DIRECTORY generate source file to DIRECTORY." << endl;
cout << " --relative use current path." << endl;
cout << " --base=DIRECTORY where to search " << IDL_TYPE << " files." << endl;
cout << " --r generate source all " << IDL_TYPE << " files." << endl;
cout << " --r-minimal minimize the dependent members." << endl;
cout << " --r-reserved list of names(split by \",\") that should be keeped." << endl;
cout << " --client just for client side source file." << endl;
cout << " --server just for server side source file." << endl;
cout << " --ts generate typescript file." << endl;
cout << " --dts generate d.ts file." << 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;
cout << endl;
cout << EXECUTE_FILENAME << " support type: boolean char short int long float double list map" << 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"));