public override void GenerateCode(CefCodeGenOutput output) { CodeTypeDeclaration orgDecl = this.OriginalDecl; CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl; GenerateCppCode(output._cppCode); GenerateCsCode(output._csCode); //----------------------------------------------------------- string namespaceName = orgDecl.Name + "Ext"; CodeStringBuilder const_methodNames = new CodeStringBuilder(); CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen(); // CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder(); cppArgClassStBuilder.AppendLine("namespace " + orgDecl.Name + "Ext{"); int j = _typePlan.methods.Count; for (int i = 0; i < j; ++i) { MethodPlan met = _typePlan.methods[i]; cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder); const_methodNames.AppendLine("const int " + namespaceName + "_" + met.Name + "_" + (i + 1) + "=" + (i + 1) + ";"); } cppArgClassStBuilder.AppendLine("}"); //---------------------------------------------- output._cppHeaderExportFuncAuto.Append(cppArgClassStBuilder.ToString()); //---------------------------------------------- //InternalHeaderForExportFunc.h CodeStringBuilder internalHeader = output._cppHeaderInternalForExportFuncAuto; internalHeader.AppendLine("namespace " + namespaceName); internalHeader.AppendLine("{"); internalHeader.AppendLine("const int _typeName=" + "CefTypeName_" + orgDecl.Name + ";"); internalHeader.AppendLine(const_methodNames.ToString()); internalHeader.AppendLine("}"); //---------------------------------------------- }
void GenerateCppCode(CodeStringBuilder stbuilder) { #if DEBUG _dbug_cpp_count++; #endif // //create switch table for C#-interop // CodeTypeDeclaration orgDecl = this.OriginalDecl; CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl; TypePlan typeTxInfo = implTypeDecl.Name.Contains("CppToC") ? orgDecl.TypePlan : implTypeDecl.TypePlan; // FindStaticMethods(orgDecl.TypePlan); // CppHandleCsMethodRequestCodeGen cppHandlerReqCodeGen = new CppHandleCsMethodRequestCodeGen(); cppHandlerReqCodeGen.GenerateCppCode(this, orgDecl, implTypeDecl, this.UnderlyingCType, stbuilder); string namespaceName = orgDecl.Name + "Ext"; int j = cppHandlerReqCodeGen.callToDotNetMets.Count; if (j > 0) { CodeStringBuilder const_methodNames = new CodeStringBuilder(); //check if method has duplicate name or not //---------- Dictionary <string, MethodPlan> uniqueNames = new Dictionary <string, MethodPlan>(); foreach (MethodPlan met in cppHandlerReqCodeGen.callToDotNetMets) { MethodPlan existingMet; if (uniqueNames.TryGetValue(met.Name, out existingMet)) { string met_capi_name = FindCApiName(met.metDecl); string met_capi_nameOfExistingMet = FindCApiName(existingMet.metDecl); if (met_capi_nameOfExistingMet == null && met_capi_name == null) { throw new NotSupportedException(); } //rename both if possible existingMet.HasDuplicatedMethodName = true; if (met_capi_nameOfExistingMet != null) { existingMet.NewOverloadName = met_capi_nameOfExistingMet; } else { existingMet.NewOverloadName = existingMet.Name; } // met.HasDuplicatedMethodName = true; if (met_capi_name != null) { met.NewOverloadName = met_capi_name; } else { met.NewOverloadName = met.Name; } } else { uniqueNames.Add(met.Name, met); } } //----------------------- for (int i = 0; i < j; ++i) { MethodPlan met = cppHandlerReqCodeGen.callToDotNetMets[i]; if (met.HasDuplicatedMethodName) { const_methodNames.AppendLine("const int " + namespaceName + "_" + met.NewOverloadName + "_" + (i + 1) + "=" + (i + 1) + ";"); } else { const_methodNames.AppendLine("const int " + namespaceName + "_" + met.Name + "_" + (i + 1) + "=" + (i + 1) + ";"); } } //-------------- CppInstanceImplCodeGen instanceImplCodeGen = new CppInstanceImplCodeGen(); instanceImplCodeGen.GenerateCppImplClass(this, typeTxInfo, cppHandlerReqCodeGen.callToDotNetMets, orgDecl, stbuilder); cpp_callToDotNetMets = cppHandlerReqCodeGen.callToDotNetMets; //----------------------------------------------------------- CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen(); // CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder(); cppArgClassStBuilder.AppendLine("namespace " + namespaceName + "{"); for (int i = 0; i < j; ++i) { MethodPlan met = cppHandlerReqCodeGen.callToDotNetMets[i]; cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder); } cppArgClassStBuilder.AppendLine("}"); //---------------------------------------------- _output._cppHeaderExportFuncAuto.Append(cppArgClassStBuilder.ToString()); //---------------------------------------------- //InternalHeaderForExportFunc.h CodeStringBuilder internalHeader = _output._cppHeaderInternalForExportFuncAuto; internalHeader.AppendLine("namespace " + namespaceName); internalHeader.AppendLine("{"); internalHeader.AppendLine("const int _typeName=" + "CefTypeName_" + orgDecl.Name + ";"); internalHeader.AppendLine(const_methodNames.ToString()); internalHeader.AppendLine("}"); //---------------------------------------------- } if (staticMethods != null) { CppHandleCsMethodRequestCodeGen cppHandlerReqCodeGen2 = new CppHandleCsMethodRequestCodeGen(); cppHandlerReqCodeGen2.GenerateCppCodeStatic(staticMethods, orgDecl, implTypeDecl, stbuilder); CodeStringBuilder const_methodNames = new CodeStringBuilder(); //check if method has duplicate name or not for (int i = 0; i < j; ++i) { MethodPlan met = cppHandlerReqCodeGen.callToDotNetMets[i]; const_methodNames.AppendLine("const int " + namespaceName + "_" + met.Name + "_" + (i + 1) + "=" + (i + 1) + ";"); } //create static method for cpp type //in this version we don't create an custom impl of the class //----------------------------------------------------------- CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen(); // CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder(); cppArgClassStBuilder.AppendLine("namespace " + namespaceName + "{"); j = staticMethods.Count; for (int i = 0; i < j; ++i) { MethodPlan met = staticMethods[i]; cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder); } cppArgClassStBuilder.AppendLine("}"); //---------------------------------------------- //generate cpp class } }
public override void GenerateCode(CefCodeGenOutput output) { _cppHeaderExportFuncAuto = output._cppHeaderExportFuncAuto; _cppHeaderInternalForExportFuncAuto = output._cppHeaderInternalForExportFuncAuto; //cpp CodeTypeDeclaration orgDecl = this.OriginalDecl; CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl; CodeStringBuilder totalTypeMethod = new CodeStringBuilder(); if (implTypeDecl.Name.Contains("CppToC")) { _typePlan = orgDecl.TypePlan; } else { _typePlan = implTypeDecl.TypePlan; } //----------------------------------------------------------------------- List <MethodPlan> callToDotNetMets = new List <MethodPlan>(); CodeStringBuilder const_methodNames = new CodeStringBuilder(); int maxPar = 0; int j = _typePlan.methods.Count; for (int i = 0; i < j; ++i) { MethodPlan metTx = _typePlan.methods[i]; metTx.CppMethodSwitchCaseName = orgDecl.Name + "_" + metTx.Name + "_" + (i + 1); //----------------- CodeMethodDeclaration codeMethodDecl = metTx.metDecl; if (codeMethodDecl.IsAbstract || codeMethodDecl.IsVirtual) { callToDotNetMets.Add(metTx); } //----------------- if (metTx.pars.Count > maxPar) { maxPar = metTx.pars.Count; } const_methodNames.AppendLine("const int " + metTx.CppMethodSwitchCaseName + "=" + (i + 1) + ";"); } totalTypeMethod.AppendLine(const_methodNames.ToString()); //----------------------------------------------------------------------- if (callToDotNetMets.Count > 0) { GenerateCppImplNamespace(orgDecl, callToDotNetMets, output._cppCode); } //----------------------------------------------------------------------- //C# part CsStructModuleCodeGen structModuleCodeGen = new CsStructModuleCodeGen(); if (callToDotNetMets.Count > 0) { structModuleCodeGen.GenerateCsStructClass(orgDecl, callToDotNetMets, output._csCode, false); } //back to cpp again... CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen(); //------------------------------------------------------------------ CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder(); cppArgClassStBuilder.AppendLine("namespace " + orgDecl.Name + "Ext{"); for (int i = 0; i < j; ++i) { MethodPlan met = _typePlan.methods[i]; cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder); } cppArgClassStBuilder.AppendLine("}"); _cppHeaderExportFuncAuto.Append(cppArgClassStBuilder.ToString()); //------------------------------------------------------------------ }