Ejemplo n.º 1
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("/////////////////////////////////////////////////");
            //
        }
Ejemplo n.º 2
0
 protected virtual void VisitSimpleTypeBase3(SimpleTypeSymbol t, TemplateTypeSymbol3 baseT3)
 {
 }
Ejemplo n.º 3
0
        TypeSymbol SearchFromFirstBase(CodeTypeTemplateTypeReference firstBase, string typename)
        {
            if (firstBase == null)
            {
                return(null);
            }

            CodeTypeTemplateTypeReference templateTypeRef = (CodeTypeTemplateTypeReference)firstBase;

            //-----------
            //first base is not resolve
            switch (templateTypeRef.Items.Count)
            {
            case 3:
            {
                //we accept only known template name

                switch (firstBase.Name)
                {
                default:


                    break;

                case "CefCppToCScoped":
                case "CefCppToCRefCounted":
                //
                case "CefCToCppRefCounted":
                case "CefCToCppScoped":
                {
                    //c-to-cpp
                    //search in another scope item2
                    CodeTypeReference typeRef1 = templateTypeRef.Items[1];
                    if (typeRef1.Name == typename)
                    {
                        TypeSymbol foundSymbol1;
                        if (this._typeCollection.TryGetType(typename, out foundSymbol1))
                        {
                            return(foundSymbol1);
                        }
                    }
                    else
                    {
                    }

                    TemplateTypeSymbol3 t3 = (TemplateTypeSymbol3)templateTypeRef.ResolvedType;
                    TypeSymbol          t1 = t3.Item1;
                    //
                    switch (t1.TypeSymbolKind)
                    {
                    default:
                        break;

                    case TypeSymbolKind.Simple:
                    {
                        SimpleTypeSymbol s = (SimpleTypeSymbol)t1;
                        //check nested type

                        if (s.NestedTypeSymbols != null)
                        {
                            int nestedTypeCount = s.NestedTypeSymbols.Count;
                            for (int n = 0; n < nestedTypeCount; ++n)
                            {
                                TypeSymbol nestedType = s.NestedTypeSymbols[n];
                                switch (nestedType.TypeSymbolKind)
                                {
                                case TypeSymbolKind.Simple:
                                {
                                }
                                break;

                                case TypeSymbolKind.TypeDef:
                                {
                                    CTypeDefTypeSymbol cTypeDef = (CTypeDefTypeSymbol)nestedType;
                                    if (cTypeDef.Name == typename)
                                    {
                                        //found
                                        return(cTypeDef);
                                    }
                                }
                                break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                    break;
                    }
                }
                break;
                }
            }
            break;
            }
            return(null);
        }
Ejemplo n.º 4
0
 protected virtual void VisitTypeTemplate3(TemplateTypeSymbol3 t3)
 {
 }
Ejemplo n.º 5
0
        public TypeSymbol ResolveType(CodeTypeReference typeRef)
        {
            if (typeRef.ResolvedType != null)
            {
                return(typeRef.ResolvedType);
            }
            //recursive
            switch (typeRef.Kind)
            {
            case CodeTypeReferenceKind.Simple:
            {
                var simpleBase = (CodeSimpleTypeReference)typeRef;
                return(typeRef.ResolvedType = ResolveType(simpleBase.Name));
            }

            case CodeTypeReferenceKind.QualifiedName:
            {
                var qnameType = (CodeQualifiedNameType)typeRef;
                switch (qnameType.LeftPart.ToString())
                {
                //resolve wellknown type template
                case "std":
                    return(ResolveType(qnameType.RightPart));

                default:
                {
                    if (_currentResolvingType != null &&
                        _currentResolvingType.TemplateNotation != null)
                    {
                        //search ns from template notation

                        CodeTemplateParameter foundTemplatePar = null;
                        if (_currentResolvingType.TemplateNotation.TryGetTemplateParByParameterName(qnameType.LeftPart.ToString(), out foundTemplatePar))
                        {
                            //TODO: resolve template type parameter
                            return(typeRef.ResolvedType = new TemplateParameterTypeSymbol(foundTemplatePar));
                        }
                    }
                    //--
                    TypeSymbol found;
                    if (_typeCollection.TryGetType(typeRef.ToString(), out found))
                    {
                        return(found);
                    }
                    throw new NotSupportedException();
                }
                }
            }

            case CodeTypeReferenceKind.TypeTemplate:
            {
                //resolve wellknown type template
                var    typeTemplate = (CodeTypeTemplateTypeReference)typeRef;
                string templateName = typeTemplate.Name;
                //this version => just switch by name first
                //TODO: switch by num of template item
                switch (typeTemplate.Name)
                {
                default:
                    throw new NotSupportedException();

                case "CefOwnPtr":
                case "CefStructBase":
                {
                    TypeSymbol          resolve1 = ResolveType(typeTemplate.Items[0]);
                    TemplateTypeSymbol1 t1       = new TemplateTypeSymbol1(typeTemplate.Name);
                    t1.Item0 = resolve1;
                    return(typeRef.ResolvedType = t1);
                }

                case "multimap":
                case "map":
                {
                    TemplateTypeSymbol2 t2 = new TemplateTypeSymbol2(typeTemplate.Name);
                    t2.Item0 = ResolveType(typeTemplate.Items[0]);
                    t2.Item1 = ResolveType(typeTemplate.Items[1]);
                    return(typeRef.ResolvedType = t2);
                }

                case "CefCppToCScoped":
                case "CefCppToCRefCounted":
                {
                    //cpp to c
                    if (typeTemplate.Items.Count == 3)
                    {
                        //auto add native c/c++ type
                        TemplateTypeSymbol3 t3 = new TemplateTypeSymbol3(typeTemplate.Name);
                        t3.Item1 = ResolveType(typeTemplate.Items[1]);
                        t3.Item2 = this._typeCollection.RegisterBaseCToCppTypeSymbol(typeTemplate.Items[2]);
                        return(typeRef.ResolvedType = t3);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                case "CefCToCppScoped":
                case "CefCToCppRefCounted":
                case "CefCToCpp":
                {
                    //c to cpp
                    if (typeTemplate.Items.Count == 3)
                    {
                        //auto add native c/c++ type
                        TemplateTypeSymbol3 t3 = new TemplateTypeSymbol3(typeTemplate.Name);
                        t3.Item1 = ResolveType(typeTemplate.Items[1]);
                        t3.Item2 = this._typeCollection.RegisterBaseCToCppTypeSymbol(typeTemplate.Items[2]);
                        return(typeRef.ResolvedType = t3);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                case "RefCountedThreadSafe":
                {
                    switch (typeTemplate.Items.Count)
                    {
                    case 1:
                        return(typeRef.ResolvedType = ResolveType(typeTemplate.Items[0]));

                    case 2:
                        // from cef c api ,
                        //template <class T, typename Traits = DefaultRefCountedThreadSafeTraits<T> >
                        return(typeRef.ResolvedType = ResolveType(typeTemplate.Items[0]));

                    default:
                        throw new NotSupportedException();
                    }
                }

                case "CefRefPtr":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(ResolveType(typeTemplate.Items[0]), ContainerTypeKind.CefRefPtr));
                    }
                    throw new NotSupportedException();
                }

                case "CefRawPtr":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(ResolveType(typeTemplate.Items[0]), ContainerTypeKind.CefRawPtr));
                    }
                    throw new NotSupportedException();
                }

                case "scoped_ptr":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(ResolveType(typeTemplate.Items[0]), ContainerTypeKind.scoped_ptr));
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                case "vector":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new VecTypeSymbol(ResolveType(typeTemplate.Items[0])));
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
                }
            }

            case CodeTypeReferenceKind.Pointer:
            {
                var        pointerType = (CodePointerTypeReference)typeRef;
                TypeSymbol elementType = ResolveType(pointerType.ElementType);
                return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(elementType, ContainerTypeKind.Pointer));
            }

            case CodeTypeReferenceKind.ByRef:
            {
                var        byRefType   = (CodeByRefTypeReference)typeRef;
                TypeSymbol elementType = ResolveType(byRefType.ElementType);
                return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(elementType, ContainerTypeKind.ByRef));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }