diff --git a/src/code_generator.h b/src/code_generator.h index a37d42d..f42097d 100644 --- a/src/code_generator.h +++ b/src/code_generator.h @@ -157,9 +157,7 @@ private: string getTsType(const TypePtr &pPtr, const bool bStream = true, const bool bBase = false); - string getDefault(const TypeIdPtr & pPtr, const string &sDefault, const string & sNamespace); - - string getDefault(const TypeIdPtr & pPtr, const string &sDefault, const string & sNamespace, const bool bGlobal); + string getDefault(const TypeIdPtr & pPtr, const string &sDefault, const string & sNamespace, const bool &bGlobal = true, const bool &bCastEnumAsAny = false); private: string generateJS(const StructPtr &pPtr, const string &sNamespace, bool &bNeedAssert, bool &bQuickFunc); diff --git a/src/gen_proxy_ts.cpp b/src/gen_proxy_ts.cpp index 1d6af8a..049de9a 100644 --- a/src/gen_proxy_ts.cpp +++ b/src/gen_proxy_ts.cpp @@ -136,7 +136,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP if (isSimple(oPtr->getReturnPtr()->getTypePtr())) { - str << getDefault(oPtr->getReturnPtr(), oPtr->getReturnPtr()->def(), nPtr->getId()) + str << getDefault(oPtr->getReturnPtr(), oPtr->getReturnPtr()->def(), nPtr->getId(), true, true) << (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : ""); } else @@ -166,7 +166,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()) + str << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId(), true, true) << (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : ""); } else @@ -257,7 +257,7 @@ string CodeGenerator::generateTSProxy(const NamespacePtr &nPtr, const InterfaceP str << ", " << getDataType(oPtr->getReturnPtr()->getTypePtr(), true); } - str << ", " << getDefault(oPtr->getReturnPtr(), "", nPtr->getId(), true) + str << ", " << getDefault(oPtr->getReturnPtr(), "", nPtr->getId(), true, true) << (isRawOrString(oPtr->getReturnPtr()->getTypePtr()) ? ", 1" : ""); str << ")," << endl; diff --git a/src/gen_server_ts.cpp b/src/gen_server_ts.cpp index 6032c49..b42a9b3 100644 --- a/src/gen_server_ts.cpp +++ b/src/gen_server_ts.cpp @@ -141,7 +141,7 @@ string CodeGenerator::generateTSServerDispatch(const NamespacePtr &nPtr, const I if (vParamDecl[i]->isOut()) { - dstr << ", " << getDefault(vParamDecl[i]->getTypeIdPtr(), "", nPtr->getId(), true) + dstr << ", " << getDefault(vParamDecl[i]->getTypeIdPtr(), "", nPtr->getId(), true, true) << (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : ""); } @@ -163,7 +163,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()) + dstr << getDefault(vParamDecl[i]->getTypeIdPtr(), vParamDecl[i]->getTypeIdPtr()->def(), nPtr->getId(), true, true) << (isRawOrString(vParamDecl[i]->getTypeIdPtr()->getTypePtr()) ? ", 1" : ""); } else diff --git a/src/gen_ts.cpp b/src/gen_ts.cpp index 67e7e68..63de237 100644 --- a/src/gen_ts.cpp +++ b/src/gen_ts.cpp @@ -77,7 +77,7 @@ string CodeGenerator::generateTS(const ConstPtr &pPtr, const string &sNamespace, INC_TAB; s << TAB << "export const " << pPtr->getTypeIdPtr()->getId() << ": " << getTsType(pPtr->getTypeIdPtr()->getTypePtr()) << " = " - << getDefault(pPtr->getTypeIdPtr(), GET_CONST_GRAMMAR_PTR(pPtr)->v, sNamespace, false) << ";" + << getDefault(pPtr->getTypeIdPtr(), GET_CONST_GRAMMAR_PTR(pPtr)->v, sNamespace, false, true) << ";" << endl; DEL_TAB; return s.str(); @@ -104,7 +104,7 @@ string CodeGenerator::generateTS(const StructPtr &pPtr, const string &sNamespace { s << TAB << (member[i]->getId()) << ": " << getTsType(member[i]->getTypePtr()) << " = " - << getDefault(member[i], member[i]->def(), sNamespace) << ";" << endl; + << getDefault(member[i], member[i]->def(), sNamespace, true, true) << ";" << endl; } if (member.size() > 0) { @@ -133,7 +133,7 @@ string CodeGenerator::generateTS(const StructPtr &pPtr, const string &sNamespace if (isSimple(member[i]->getTypePtr())) { - s << getDefault(member[i], member[i]->def(), sNamespace) + s << getDefault(member[i], member[i]->def(), sNamespace, true, true) << (isRawOrString(member[i]->getTypePtr()) ? ", 1" : ""); } else diff --git a/src/idl_util.cpp b/src/idl_util.cpp index ec25eb6..a46da10 100644 --- a/src/idl_util.cpp +++ b/src/idl_util.cpp @@ -323,12 +323,7 @@ bool CodeGenerator::isBinBuffer(const TypePtr & pPtr) const return false; } -string CodeGenerator::getDefault(const TypeIdPtr & pPtr, const string &sDefault, const string& sNamespace) -{ - return getDefault(pPtr, sDefault, sNamespace, true); -} - -string CodeGenerator::getDefault(const TypeIdPtr & pPtr, const string &sDefault, const string& sNamespace, const bool bGlobal) +string CodeGenerator::getDefault(const TypeIdPtr & pPtr, const string &sDefault, const string& sNamespace, const bool &bGlobal, const bool &bCastEnumAsAny) { BuiltinPtr bPtr = BuiltinPtr::dynamicCast(pPtr->getTypePtr()); if (bPtr) @@ -438,7 +433,7 @@ string CodeGenerator::getDefault(const TypeIdPtr & pPtr, const string &sDefault, if (bGlobal) { - return "new " + getDataType(pPtr->getTypePtr(), true); + return "new " + getDataType(pPtr->getTypePtr(), bCastEnumAsAny); } return sDefault;