示例#1
0
        void GenerateCsCode(CodeStringBuilder stbuilder)
        {
            CodeTypeDeclaration orgDecl      = this.OriginalDecl;
            CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl;

            CsCallToNativeCodeGen csCallToNativeCodeGen = new CsCallToNativeCodeGen();

            csCallToNativeCodeGen.GenerateCsCode(this, orgDecl, implTypeDecl, false, null, stbuilder);
        }
示例#2
0
        void GenerateCppImplNamespace(CodeTypeDeclaration orgDecl,
                                      List <MethodPlan> callToDotNetMets,
                                      CodeStringBuilder stbuilder)
        {
            string namespaceName = orgDecl.Name + "Ext"; //namespace

            this.CppImplClassNameId = _typePlan.CsInterOpTypeNameId;
            this.CppImplClassName   = namespaceName;
            //----------------------------------------------
            //create a cpp namespace
            stbuilder.Append("namespace " + namespaceName);
            stbuilder.AppendLine("{");


            int nn = callToDotNetMets.Count;

            for (int mm = 0; mm < nn; ++mm)
            {
                //implement on event notificationi
                MethodPlan met = callToDotNetMets[mm];
                met.CppMethodSwitchCaseName = namespaceName + "_" + met.Name + "_" + (mm + 1);
            }
            nn = callToDotNetMets.Count;
            for (int mm = 0; mm < nn; ++mm)
            {
                //implement on event notificationi
                MethodPlan met = callToDotNetMets[mm];
                //prepare data and call the callback
                GenerateCppImplMethodForNs(met, stbuilder);
            }
            stbuilder.AppendLine("}");
            //----------------------------------------------

            //----------------------------------------------
            //InternalHeaderForExportFunc.h
            _cppHeaderInternalForExportFuncAuto.AppendLine("namespace " + namespaceName);
            _cppHeaderInternalForExportFuncAuto.AppendLine("{");
            _cppHeaderInternalForExportFuncAuto.AppendLine("const int _typeName=" + "CefTypeName_" + orgDecl.Name + ";");
            for (int mm = 0; mm < nn; ++mm)
            {
                MethodPlan met = callToDotNetMets[mm];
                _cppHeaderInternalForExportFuncAuto.AppendLine("const int " + met.CppMethodSwitchCaseName + "=" + (mm + 1) + ";");
            }
            _cppHeaderInternalForExportFuncAuto.AppendLine("}");
            //----------------------------------------------
            //ExportFuncAuto.h
            _cppHeaderExportFuncAuto.AppendLine("namespace " + namespaceName);
            _cppHeaderExportFuncAuto.AppendLine("{");
            for (int mm = 0; mm < nn; ++mm)
            {
                //implement on event notificationi
                MethodPlan met = callToDotNetMets[mm];
                //prepare data and call the callback
                GenerateCppImplMethodDeclarationForNs(met, _cppHeaderExportFuncAuto);
            }
            _cppHeaderExportFuncAuto.AppendLine("}");
        }
示例#3
0
        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());
        }
示例#4
0
        public static void AddComment(Token[] lineTokens, CodeStringBuilder builder)
        {
            if (lineTokens == null)
            {
                return;
            }
            //
            StringBuilder stbuilder = new StringBuilder();
            int           j         = lineTokens.Length;
            int           lastLine  = j - 1;

            stbuilder.Append("/// <summary>\r\n");
            for (int i = 0; i < j; ++i)
            {
                //for cef, special care for first and last line
                string lineContent = lineTokens[i].Content;
                if (i == 0 || i == lastLine)
                {
                    if (lineContent.StartsWith("///"))
                    {
                        if (lineContent.Substring(3).Trim() == "")
                        {
                            continue; //skip this first and last line comment
                        }
                        else
                        {
                            stbuilder.AppendLine(lineContent);
                        }
                    }
                    else
                    {
                        stbuilder.AppendLine("/" + lineContent);
                    }
                }
                else
                {
                    if (!lineContent.StartsWith("///"))
                    {
                        if (lineContent.StartsWith("//"))
                        {
                            //append one /
                            stbuilder.AppendLine("/" + lineTokens[i].Content);
                            continue;
                        }
                    }
                }
            }
            stbuilder.Append("/// </summary>\r\n");

            builder.Append(stbuilder.ToString());
        }
示例#5
0
        void GenerateCppImplMethodDeclarationForNs(MethodPlan met, CodeStringBuilder stbuilder)
        {
            CodeMethodDeclaration metDecl = met.metDecl;

            stbuilder.AppendLine("//CefHandlerTx::GenerateCppImplMethodDeclarationForNs ," + (++codeGenNum));
            stbuilder.AppendLine("//gen! " + metDecl.ToString());
            //---------------------------

            //temp
            switch (metDecl.ReturnType.ToString())
            {
            case "FilterStatus":
                stbuilder.Append(metDecl.ReturnType.ResolvedType + " " + metDecl.Name + "(");
                break;

            case "ReturnValue":
                string ownerType = met.metDecl.OwnerTypeDecl.Name;
                stbuilder.Append(ownerType + "::" + metDecl.ReturnType + " " + metDecl.Name + "(");
                break;

            default:
                stbuilder.Append(metDecl.ReturnType + " " + metDecl.Name + "(");
                break;
            }

            List <CodeMethodParameter> pars = metDecl.Parameters;

            //first par is managed callback
            stbuilder.Append("managed_callback mcallback");
            int j = pars.Count;

            for (int i = 0; i < j; ++i)
            {
                stbuilder.Append(",");
                CodeMethodParameter par = pars[i];

                if (par.IsConstPar)
                {
                    stbuilder.Append("const ");
                }
                //parameter type

                stbuilder.Append(par.ParameterType.ResolvedType.FullName + " ");
                stbuilder.Append(par.ParameterName);
            }
            stbuilder.AppendLine(");");
        }
示例#6
0
        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("}");
            //----------------------------------------------
        }
示例#7
0
        void GenerateCsCode(CodeStringBuilder stbuilder)
        {
            CodeTypeDeclaration orgDecl      = this.OriginalDecl;
            CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl;

            CodeGenUtils.AddComments(orgDecl, implTypeDecl);
            CsCallToNativeCodeGen callToNativeCs = new CsCallToNativeCodeGen();

            callToNativeCs.GenerateCsCode(this, orgDecl, implTypeDecl, true, staticMethods, stbuilder, ss =>
            {
                if (cpp_callToDotNetMets != null)
                {
                    CsStructModuleCodeGen structModuleCodeGen = new CsStructModuleCodeGen();
                    structModuleCodeGen.GenerateCsStructClass(orgDecl,
                                                              cpp_callToDotNetMets,
                                                              ss, true);
                }
            });

            //--------------------------------------------------------
        }
示例#8
0
        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
            }
        }
示例#9
0
        public void GenerateBridge(string cefSrcFolder)
        {
            string cefDir = cefSrcFolder;
            List <CodeCompilationUnit> totalCuList_capi = new List <CodeCompilationUnit>();
            List <CodeCompilationUnit> totalCuList      = new List <CodeCompilationUnit>();
            List <CodeCompilationUnit> test_cpptoc_List = new List <CodeCompilationUnit>();
            //-----------------------------
            {
                //cpptoc folder
                string   libcef_dll_folder = cefDir + @"\libcef_dll";
                string[] onlyCppFiles      = System.IO.Directory.GetFiles(libcef_dll_folder + @"\cpptoc", "*.cc");
                //we skip some files
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[] {
                    "base_ref_counted_cpptoc.cc",
                    "base_scoped_cpptoc.cc"
                });
                int j = onlyCppFiles.Length;

                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyCppFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = ParseCppFile(onlyCppFiles[i]);
                    test_cpptoc_List.Add(cu);

                    //
                    CppToCsImplCodeGen cppToCsImplCodeGen = new CppToCsImplCodeGen();
                    string             onlyFileName       = System.IO.Path.GetFileName(cu.Filename);
                    if (onlyFileName == "v8interceptor_cpptoc.cc")
                    {
                        continue;
                    }


                    //cppToCsImplCodeGen.PatchCppMethod(cu, cefDir + @"\libcef_dll\cpptoc\" + onlyFileName, cefDir + @"\cpptoc");
                    cppToCsImplCodeGen.PatchCppMethod(cu, null, libcef_dll_folder + @"\cpptoc");
                }
            }
            //-----------------------------

            //-----------------------------
            {
                //cef capi
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\include\capi", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);
                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList_capi.Add(cu);
                }
            }
            {
                //cef capi/views
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\include\capi\views", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);
                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList_capi.Add(cu);
                }
            }


            {
                //include/internal
                totalCuList.Add(Parse(cefDir + @"\include\internal\cef_types.h"));
                totalCuList.Add(Parse(cefDir + @"\include\internal\cef_types_wrappers.h"));
                totalCuList.Add(Parse(cefDir + @"\include\internal\cef_win.h")); //for windows
            }


            {
                //include folder
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\include\", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);

                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }

                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList.Add(cu);
                }
            }

            //c to cpp
            {
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\libcef_dll\ctocpp", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);

                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList.Add(cu);
                }
            }

            //cpp to c
            {
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\libcef_dll\cpptoc", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);

                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList.Add(cu);
                }
            }

            //
            CefTypeCollection cefTypeCollection = new CefTypeCollection();

            cefTypeCollection.RootFolder = cefDir;
            cefTypeCollection.SetTypeSystem(totalCuList);



            //
            TypeTranformPlanner txPlanner = new TypeTranformPlanner();

            txPlanner.CefTypeCollection = cefTypeCollection;


            Dictionary <string, CefTypeTx> allTxPlans         = new Dictionary <string, CefTypeTx>();
            List <CefHandlerTx>            handlerPlans       = new List <CefHandlerTx>();
            List <CefCallbackTx>           callbackPlans      = new List <CefCallbackTx>();
            List <CefInstanceElementTx>    instanceClassPlans = new List <CefInstanceElementTx>();
            List <CefEnumTx>    enumTxPlans  = new List <CefEnumTx>();
            List <CefCStructTx> cstructPlans = new List <CefCStructTx>();
            //--

            //--
            int             typeName       = 1;
            List <TypePlan> typeTxInfoList = new List <TypePlan>();


            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._v_instanceClasses)
            {
                //eg. CefApp, CefBrowser, CefCommandLine, CefFrame
                CefInstanceElementTx instanceClassPlan = new CefInstanceElementTx(typedecl);
                instanceClassPlans.Add(instanceClassPlan);
                allTxPlans.Add(typedecl.Name, instanceClassPlan);
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                instanceClassPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                typeTxInfoList.Add(typeTxPlan);
            }


            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._v_handlerClasses)
            {
                //eg. CefDisplayHandler, CefDownloadHandler
                CefHandlerTx handlerPlan = new CefHandlerTx(typedecl);
                handlerPlans.Add(handlerPlan);
                allTxPlans.Add(typedecl.Name, handlerPlan);
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                handlerPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                typeTxInfoList.Add(typeTxPlan);
            }
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._v_callBackClasses)
            {
                //eg. CefAuthenCallback, CefPdfCallback
                CefCallbackTx callbackPlan = new CefCallbackTx(typedecl);
                callbackPlans.Add(callbackPlan);
                allTxPlans.Add(typedecl.Name, callbackPlan);
                ////
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                callbackPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                typeTxInfoList.Add(typeTxPlan);
            }
            //
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._enumClasses)
            {
                CefEnumTx enumTxPlan = new CefEnumTx(typedecl);
                enumTxPlans.Add(enumTxPlan);
                allTxPlans.Add(typedecl.Name, enumTxPlan);
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                enumTxPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
            }

            List <CodeTypeDeclaration> notFoundAbstractClasses = new List <CodeTypeDeclaration>();

            foreach (CodeTypeDeclaration typedecl in cefTypeCollection.cToCppClasses)
            {
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;

                //cef -specific
                TemplateTypeSymbol3 baseType0 = (TemplateTypeSymbol3)typedecl.BaseTypes[0].ResolvedType;
                //add information to our model
                SimpleTypeSymbol abstractType      = (SimpleTypeSymbol)baseType0.Item1;
                SimpleTypeSymbol underlying_c_type = (SimpleTypeSymbol)baseType0.Item2;

                CefTypeTx found;
                if (!allTxPlans.TryGetValue(abstractType.Name, out found))
                {
                    notFoundAbstractClasses.Add(typedecl);
                    continue;
                }
                found.UnderlyingCType = underlying_c_type;
                found.ImplTypeDecl    = typedecl;

                abstractType.CefTxPlan = found;
                ////[chrome] cpp<-to<-c  <--- ::::: <--- c-interface-to[external - user - lib] ....
            }
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection.cppToCClasses)
            {
                //callback, handle, visitor etc
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                //cef -specific
                TemplateTypeSymbol3 baseType0         = (TemplateTypeSymbol3)typedecl.BaseTypes[0].ResolvedType;
                SimpleTypeSymbol    abstractType      = (SimpleTypeSymbol)baseType0.Item1;
                SimpleTypeSymbol    underlying_c_type = (SimpleTypeSymbol)baseType0.Item2;
                CefTypeTx           found;
                if (!allTxPlans.TryGetValue(abstractType.Name, out found))
                {
                    notFoundAbstractClasses.Add(typedecl);
                    continue;
                }

                found.UnderlyingCType  = underlying_c_type;
                found.ImplTypeDecl     = typedecl;
                abstractType.CefTxPlan = found;

                ////[chrome]  cpp->to->c  ---> ::::: ---> c-interface-to [external-user-lib] ....
                ////eg. handlers and callbacks
            }
            //--------
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._plainCStructs)
            {
                //create raw type
                if (!typedecl.Name.EndsWith("Traits") &&
                    typedecl.Name.StartsWith("_"))
                {
                    //
                    CefCStructTx cstructTx = new CefCStructTx(typedecl);
                    cstructPlans.Add(cstructTx);
                    TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                    cstructTx.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                    typedecl.TypePlan             = typeTxPlan;
                    //
                    typeTxInfoList.Add(typeTxPlan);
                }
                else
                {
                }
            }

            //--------
            //code gen

            List <CefTypeTx> customImplClasses = new List <CefTypeTx>();
            StringBuilder    cppCodeStBuilder  = new StringBuilder();

            AddCppBuiltInBeginCode(cppCodeStBuilder);

            CodeStringBuilder cppHeaderInternalForExportFunc = new CodeStringBuilder();

            cppHeaderInternalForExportFunc.AppendLine(
                "//MIT, 2017, WinterDev\r\n" +
                "//AUTOGEN");


            foreach (TypePlan txinfo in typeTxInfoList)
            {
                cppHeaderInternalForExportFunc.AppendLine("const int CefTypeName_" + txinfo.TypeDecl.Name + " = " + txinfo.CsInterOpTypeNameId.ToString() + ";");
            }


            StringBuilder csCodeStBuilder = new StringBuilder();

            AddCsCodeHeader(csCodeStBuilder);
            CefCodeGenOutput codeGenOutput = null;

            foreach (CefTypeTx tx in enumTxPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);
                //get cs output
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
            }
            csCodeStBuilder.Append("}"); //close namespace
            //save to file
            System.IO.File.WriteAllText("CefEnums.cs", csCodeStBuilder.ToString());

            //-------------------------
            CodeStringBuilder cppHeaderExportFuncAuto = new CodeStringBuilder();

            cppHeaderExportFuncAuto.AppendLine("//AUTOGEN");
            //-------------------------

            //cef instance is quite large
            //so we spit the code gen into 2 sections
            int instance_count = instanceClassPlans.Count;
            int mid            = instance_count / 2;

            {
                //1st part
                csCodeStBuilder = new StringBuilder();
                AddCsCodeHeader(csCodeStBuilder);
                //-------------------------
                for (int cc = 0; cc < mid; ++cc)
                {
                    CefInstanceElementTx tx = instanceClassPlans[cc];
                    codeGenOutput = new CefCodeGenOutput();
                    tx.GenerateCode(codeGenOutput);
                    //----------------------------------------------------
                    cppCodeStBuilder.AppendLine();
                    cppCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                    cppCodeStBuilder.AppendLine();
                    //----------------------------------------------------
                    csCodeStBuilder.AppendLine();
                    csCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                    csCodeStBuilder.AppendLine();
                    //--------------------------------------------

                    cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                    cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                    //----------
                    if (tx.CppImplClassNameId > 0)
                    {
                        customImplClasses.Add(tx);
                    }
                }
                csCodeStBuilder.Append("}");
                //save to file
                System.IO.File.WriteAllText("CefInstances_P1.cs", csCodeStBuilder.ToString());
                //-------------------------
            }
            {
                //2nd part
                //1st part
                csCodeStBuilder = new StringBuilder();
                AddCsCodeHeader(csCodeStBuilder);

                for (int cc = mid; cc < instance_count; ++cc)
                {
                    CefInstanceElementTx tx = instanceClassPlans[cc];
                    codeGenOutput = new CefCodeGenOutput();
                    tx.GenerateCode(codeGenOutput);
                    //----------------------------------------------------
                    cppCodeStBuilder.AppendLine();
                    cppCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                    cppCodeStBuilder.AppendLine();
                    //----------------------------------------------------
                    csCodeStBuilder.AppendLine();
                    csCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                    csCodeStBuilder.AppendLine();
                    //--------------------------------------------

                    cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                    cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                    //----------
                    if (tx.CppImplClassNameId > 0)
                    {
                        customImplClasses.Add(tx);
                    }
                }
                csCodeStBuilder.Append("}");
                //save to file
                System.IO.File.WriteAllText("CefInstances_P2.cs", csCodeStBuilder.ToString());
                //-------------------------
            }



            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            foreach (CefCallbackTx tx in callbackPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);

                cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                //----------
                cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                //----------
                if (tx.CppImplClassNameId > 0)
                {
                    customImplClasses.Add(tx);
                }
            }
            csCodeStBuilder.Append("}");
            //save to file
            System.IO.File.WriteAllText("CefCallbacks.cs", csCodeStBuilder.ToString());
            //-------------------------
            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            foreach (CefHandlerTx tx in handlerPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);

                cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                //----------
                cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                //----------
            }
            csCodeStBuilder.Append("}");
            //save to file
            System.IO.File.WriteAllText("CefHandlers.cs", csCodeStBuilder.ToString());
            //-------------------------
            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            foreach (CefCStructTx tx in cstructPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
            }
            csCodeStBuilder.Append("}");
            //save to file
            System.IO.File.WriteAllText("CefPlainCStructs.cs", csCodeStBuilder.ToString());
            //-------------------------
            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            CsNativeHandlerSwitchTableCodeGen csNativeHandlerSwitchTableCodeGen = new CsNativeHandlerSwitchTableCodeGen();

            csNativeHandlerSwitchTableCodeGen.GenerateCefNativeRequestHandlers(handlerPlans, csCodeStBuilder);
            //cs...
            csCodeStBuilder.AppendLine("}");
            System.IO.File.WriteAllText("CefApiSwitchTables.cs", csCodeStBuilder.ToString());
            //--------
            //cpp
            CppSwicthTableCodeGen cppSwitchTableCodeGen = new CppSwicthTableCodeGen();

            cppSwitchTableCodeGen.CreateCppSwitchTableForInstanceMethods(cppCodeStBuilder, instanceClassPlans);
            cppSwitchTableCodeGen.CreateCppSwitchTableForStaticMethods(cppCodeStBuilder, instanceClassPlans);
            //
            CppInstanceMethodCodeGen instanceMetCodeGen = new CppInstanceMethodCodeGen();

            instanceMetCodeGen.CreateCppNewInstanceMethod(cppCodeStBuilder, customImplClasses);
            //--------
            cppCodeStBuilder.AppendLine("/////////////////////////////////////////////////");
            //
        }
示例#10
0
        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());
        }
示例#11
0
        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 = orgDecl.TypePlan;
            //-----------------------------------------------------------------------
            List <MethodPlan> onEventMethods = new List <MethodPlan>();

            int j      = _typePlan.methods.Count;
            int maxPar = 0;
            for (int i = 0; i < j; ++i)
            {
                MethodPlan metTx = _typePlan.methods[i];
                if (metTx.metDecl.IsVirtual)
                {
                    //this method need a callback to .net side (.net-side event listener)
                    if (metTx.metDecl.Name.StartsWith("On"))
                    {
                        onEventMethods.Add(metTx);
                    }
                }
                metTx.CppMethodSwitchCaseName = orgDecl.Name + "_" + metTx.Name + "_" + (i + 1);
                if (metTx.pars.Count > maxPar)
                {
                    maxPar = metTx.pars.Count;
                }
            }

            MaxMethodParCount = maxPar;
            //----------
            CppHandleCsMethodRequestCodeGen cppHandleCsMetCodeGen2 = new CppHandleCsMethodRequestCodeGen();
            cppHandleCsMetCodeGen2.PrepareInstanceCallFromCppToCsMethodName(
                this,
                orgDecl,
                ImplTypeDecl,
                this.UnderlyingCType);
            //
            cppHandleCsMetCodeGen2.GenerateCppCode(
                this,
                orgDecl,
                ImplTypeDecl,
                this.UnderlyingCType,
                stbuilder
                );

            //----------
            if (onEventMethods.Count > 0)
            {
                //the callback need some method to call to C# side
                var eventListenerCodeGen = new CppEventListenerInstanceImplCodeGen();
                eventListenerCodeGen.GenerateCppImplClass(
                    this,
                    _typePlan,
                    orgDecl,
                    onEventMethods,
                    stbuilder);
            }
        }
示例#12
0
        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());
            //------------------------------------------------------------------
        }
示例#13
0
        void GenerateCppImplMethodForNs(MethodPlan met, CodeStringBuilder stbuilder)
        {
            CodeMethodDeclaration metDecl = met.metDecl;

            stbuilder.AppendLine("//CefHandlerTx::GenerateCppImplMethodForNs ," + (++codeGenNum));
            stbuilder.AppendLine("//gen! " + metDecl.ToString());
            //---------------------------

            //temp
            if (metDecl.ReturnType.ToString() == "FilterStatus")
            {
                stbuilder.Append(metDecl.ReturnType.ResolvedType + " " + metDecl.Name + "(");
            }
            else if (metDecl.ReturnType.ToString() == "ReturnValue")
            {
                string ownerName = metDecl.OwnerTypeDecl.Name;
                stbuilder.Append(ownerName + "::" + metDecl.ReturnType + " " + metDecl.Name + "(");
            }
            else
            {
                stbuilder.Append(metDecl.ReturnType + " " + metDecl.Name + "(");
            }


            List <CodeMethodParameter> pars = metDecl.Parameters;
            int j = pars.Count;
            //transfer data slot
            bool hasSomeOutVars = false;

            CppTempParameterSlot[] dataTransferSlots = new CppTempParameterSlot[j];
            for (int i = 0; i < j; ++i)
            {
                CppTempParameterSlot transferSlot = new CppTempParameterSlot();
                CodeMethodParameter  par          = pars[i];
                transferSlot.par     = pars[i];
                dataTransferSlots[i] = transferSlot;
                //
                //
                string parTypeName = par.ParameterType.ToString();
                if (parTypeName == "CefRefPtr<CefV8Value>&")
                {
                    if (!par.IsConstPar)
                    {
                        transferSlot.newVarName  = "temp_" + i;
                        transferSlot.preStmt     = "auto " + transferSlot.newVarName + "=" + "CefV8ValueCToCpp::Unwrap(" + transferSlot.par.ParameterName + ");";
                        transferSlot.postStmt    = transferSlot.par.ParameterName + "= CefV8ValueCToCpp::Wrap(" + transferSlot.newVarName + ");";
                        transferSlot.isCppOutVar = true;
                        hasSomeOutVars           = true;
                    }
                }
                else if (parTypeName == "CefString&")
                {
                    if (!par.IsConstPar)
                    {
                        transferSlot.newVarName  = "temp_" + i;
                        transferSlot.preStmt     = "auto " + transferSlot.newVarName + "=" + transferSlot.par.ParameterName + ";";
                        transferSlot.postStmt    = transferSlot.par.ParameterName + "=" + transferSlot.newVarName + ";";
                        transferSlot.isCppOutVar = true;
                        hasSomeOutVars           = true;
                    }
                }
            }


            //first par is managed callback
            stbuilder.Append("managed_callback mcallback");
            for (int i = 0; i < j; ++i)
            {
                stbuilder.Append(",");
                CodeMethodParameter par = pars[i];
                if (par.IsConstPar)
                {
                    stbuilder.Append("const ");
                }
                //parameter type
                stbuilder.Append(par.ParameterType.ResolvedType.FullName + " ");
                stbuilder.Append(par.ParameterName);
            }
            stbuilder.AppendLine("){");
            //-----------

            for (int i = 0; i < j; ++i)
            {
                MethodParameter parTx = met.pars[i];
                parTx.ClearExtractCode();
                PrepareDataFromNativeToCs(parTx, "&vargs[" + (i + 1) + "]", parTx.Name, true);
            }
            //method body

            //-----------------------------
            //use native C data slot
            stbuilder.AppendLine("if(mcallback){");

            //'out' vars
            if (hasSomeOutVars)
            {
                //temp,
                for (int i = 0; i < j; ++i)
                {
                    CppTempParameterSlot transferSlot = dataTransferSlots[i];
                    if (transferSlot.isCppOutVar)
                    {
                        stbuilder.AppendLine(transferSlot.preStmt);
                    }
                }
            }
            //-----------------------------
            //
            string metArgsClassName = metDecl.Name + "Args";

            stbuilder.Append(metArgsClassName + " args1");
            //with ctors
            if (j == 0)
            {
                stbuilder.AppendLine(";");
            }
            else
            {
                stbuilder.Append("(");
                for (int i = 0; i < j; ++i)
                {
                    if (i > 0)
                    {
                        stbuilder.Append(",");
                    }
                    //
                    MethodParameter      par          = met.pars[i];
                    CppTempParameterSlot transferSlot = dataTransferSlots[i];
                    if (transferSlot.isCppOutVar)
                    {
                        stbuilder.Append("&" + transferSlot.newVarName);
                    }
                    else
                    {
                        //temp
                        string parType = par.TypeSymbol.ToString();
                        if (parType.EndsWith("&"))
                        {
                            stbuilder.Append("&");
                        }
                        stbuilder.Append(par.Name);
                    }
                }
                stbuilder.AppendLine(");");
            }
            stbuilder.AppendLine("mcallback( (_typeName << 16) | " + met.CppMethodSwitchCaseName + ",&args1.arg);");


            //------
            //'out' vars
            if (hasSomeOutVars)
            {
                //temp,
                for (int i = 0; i < j; ++i)
                {
                    CppTempParameterSlot transferSlot = dataTransferSlots[i];
                    if (transferSlot.isCppOutVar)
                    {
                        stbuilder.AppendLine(transferSlot.postStmt);
                    }
                }
            }

            //temp fix, arg extract code
            if (!met.ReturnPlan.IsVoid)
            {
                stbuilder.AppendLine("return args1.arg.myext_ret_value;");
            }
            stbuilder.AppendLine("}");


            //-------------------
            //default return if no managed callback
            if (!met.ReturnPlan.IsVoid)
            {
                string retTypeName = metDecl.ReturnType.ToString();
                if (retTypeName.StartsWith("CefRefPtr<"))
                {
                    stbuilder.Append("return nullptr;");
                }
                else
                {
                    switch (metDecl.ReturnType.ToString())
                    {
                    case "bool":
                        stbuilder.Append("return false;");
                        break;

                    case "FilterStatus":     //TODO: revisit here
                        stbuilder.Append("return (FilterStatus)0;");
                        break;

                    case "ReturnValue":
                    {
                        string ownerName = metDecl.OwnerTypeDecl.Name;
                        stbuilder.Append("return (" + ownerName + "::ReturnValue)0;");
                    }
                    break;

                    case "CefSize":
                        stbuilder.Append("return CefSize();");
                        break;

                    case "size_t":
                        stbuilder.Append("return 0;");
                        break;

                    case "int":
                        stbuilder.Append("return 0;");
                        break;

                    case "int64":
                        stbuilder.Append("return 0;");
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }

            stbuilder.AppendLine("}"); //method
        }