void GenerateCsCode(CodeStringBuilder stbuilder) { CodeStringBuilder codeBuilder = new CodeStringBuilder(); CodeTypeDeclaration orgDecl = this.OriginalDecl; TypePlan _typeTxInfo = orgDecl.TypePlan; // AddComment(orgDecl.LineComments, codeBuilder); //for cef, if enum class end with flags_t //we add FlagsAttribute to this enum type if (orgDecl.Name.EndsWith("flags_t")) { codeBuilder.AppendLine("[Flags]"); } codeBuilder.AppendLine("public enum " + orgDecl.Name + enum_base + "{"); //transform enum int i = 0; foreach (FieldPlan fieldTx in _typeTxInfo.fields) { if (i > 0) { codeBuilder.AppendLine(","); } i++; CodeFieldDeclaration codeFieldDecl = fieldTx.fieldDecl; // AddComment(codeFieldDecl.LineComments, codeBuilder); // if (codeFieldDecl.InitExpression != null) { string initExpr = codeFieldDecl.InitExpression.ToString(); //cef specific if (initExpr == "UINT_MAX") { codeBuilder.Append(codeFieldDecl.Name + "=uint.MaxValue"); } else { codeBuilder.Append(codeFieldDecl.Name + "=" + codeFieldDecl.InitExpression.ToString()); } } else { codeBuilder.Append(codeFieldDecl.Name); } } codeBuilder.AppendLine("}"); // stbuilder.Append(codeBuilder.ToString()); }
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 } }
void GenerateCsCode(CefCodeGenOutput output) { CodeStringBuilder csCode = new CodeStringBuilder(); CodeTypeDeclaration typedecl = this.OriginalDecl; //------- csCode.AppendLine("//CefCStructTx::GenerateCsCode, " + (++codeNum)); //------- csCode.AppendLine("[StructLayout(LayoutKind.Sequential)]"); csCode.AppendLine("struct " + typedecl.Name + "{"); int i = 0; foreach (CodeMemberDeclaration mb in typedecl.GetMemberIter()) { if (mb.MemberKind == CodeMemberKind.Field) { //------- csCode.AppendLine("//CefCStructTx::GenerateCsCode-Field, " + (++codeNum)); //------- CodeFieldDeclaration fieldDecl = (CodeFieldDeclaration)mb; // AddComment(fieldDecl.LineComments, csCode); // string fieldTypeName = fieldDecl.FieldType.ToString(); //field type switch (fieldTypeName) { default: { if (fieldTypeName.EndsWith("_t")) { csCode.Append("public " + fieldTypeName); } else { throw new NotSupportedException(); } } break; case "void*": csCode.Append("public IntPtr"); break; case "int": case "float": case "double": csCode.Append("public " + fieldTypeName); break; case "cef_string_t": csCode.Append("public _cef_string_utf16_t"); break; case "size_t": csCode.Append("public int"); break; case "uint32": csCode.Append("public uint"); break; case "char16": csCode.Append("public char"); break; } csCode.AppendLine(" " + fieldDecl.Name + ";"); } i++; } csCode.AppendLine("}"); // output._csCode.Append(csCode.ToString()); }
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()); //------------------------------------------------------------------ }