Exemplo n.º 1
0
        void AddMoreTypeInfo()
        {
            //--------
            //copy all
            Freeze();
            //
            Dictionary <string, TypeSymbol> tempSymbols = new Dictionary <string, TypeSymbol>();
            int typeCount = typeSymbols.Count;

            foreach (var kp in typeSymbols)
            {
                tempSymbols.Add(kp.Key, kp.Value);
            }

            //Cef- find tune detail of base type
            foreach (TypeSymbol t in tempSymbols.Values)
            {
                switch (t.TypeSymbolKind)
                {
                default:
                    throw new NotSupportedException();

                case TypeSymbolKind.Simple:
                {
                    SimpleTypeSymbol simpleType = (SimpleTypeSymbol)t;
                    if (simpleType.PrimitiveTypeKind == PrimitiveTypeKind.NotPrimitiveType)
                    {
                        //resolve base type
                        CodeTypeDeclaration typedecl = simpleType.CreatedByTypeDeclaration;
                        if (typedecl != null && typedecl.BaseTypes != null && typedecl.BaseTypes.Count > 0)
                        {
                            CefResolvingContext ctx = new CefResolvingContext(this, null, ResolvingContextKind.Base);
                            simpleType.BaseType = ctx.ResolveType(typedecl.BaseTypes[0]);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                }
                break;

                case TypeSymbolKind.TypeDef:
                {
                    CTypeDefTypeSymbol  typedefSymbol = (CTypeDefTypeSymbol)t;
                    CefResolvingContext ctx           = new CefResolvingContext(this, null, ResolvingContextKind.Base);
                    typedefSymbol.ReferToTypeSymbol = ctx.ResolveType(typedefSymbol.OriginalTypeDecl);
                }
                break;
                }
            }
            //-------
            //assign bridge information
            //-------
            //swap
            this.typeSymbols = tempSymbols;
        }
Exemplo n.º 2
0
 protected virtual void PreviewVisitTypeDef(CTypeDefTypeSymbol t)
 {
 }
Exemplo n.º 3
0
        public void SetTypeSystem(List <CodeCompilationUnit> compilationUnits)
        {
            Reset();
            //-----------------------
            this.compilationUnits = compilationUnits;
            //-----------------------
            //resolve cu's file path

            foreach (CodeCompilationUnit cu in compilationUnits)
            {
                //check absolute path for include file
                foreach (IncludeFileDirective includeDirective in cu._includeFiles)
                {
                    //remove " from begin and end of the original IncludeFile
                    if (includeDirective.SystemFolder)
                    {
                        continue;
                    }
                    //
                    string include_file = includeDirective.IncludeFile.Substring(1, includeDirective.IncludeFile.Length - 2);
                    includeDirective.ResolvedAbsoluteFilePath = RootFolder + "\\" + include_file;
                    //check
                    if (!System.IO.File.Exists(includeDirective.ResolvedAbsoluteFilePath))
                    {
                        //file not found
                        if (!(includeDirective.ResolvedAbsoluteFilePath.EndsWith("mac.h") ||
                              includeDirective.ResolvedAbsoluteFilePath.EndsWith("linux.h")))
                        {
                            throw new NotSupportedException();
                        }
                    }
                }
                //
                _compilationUnitDics.Add(cu.Filename, cu);
            }


            List <CodeMethodDeclaration> cppMethodList = new List <CodeMethodDeclaration>();

            //-----------------------
            //1. collect
            foreach (CodeCompilationUnit cu in compilationUnits)
            {
                //
                RegisterTypeDeclaration(cu.GlobalTypeDecl);
                //extract type from global typedecl
                foreach (CodeMemberDeclaration mb in cu.GlobalTypeDecl.GetMemberIter())
                {
                    switch (mb.MemberKind)
                    {
                    case CodeMemberKind.Method:
                    {
                        //check if this method has C++ explicit ower type
                        CodeMethodDeclaration metDecl = (CodeMethodDeclaration)mb;
                        if (metDecl.CppExplicitOwnerType != null)
                        {
                            //add this to typedecl later
                            cppMethodList.Add(metDecl);
                        }
                    }
                    break;

                    case CodeMemberKind.TypeDef:
                    {
                        CodeCTypeDef ctypeDef = (CodeCTypeDef)mb;
                        //
                        CTypeDefTypeSymbol ctypedefTypeSymbol = new CTypeDefTypeSymbol(ctypeDef.Name, ctypeDef.From);
                        ctypedefTypeSymbol.CreatedTypeCTypeDef = ctypeDef;
                        //---

                        TypeSymbol existing;
                        if (TryGetType(ctypeDef.Name, out existing))
                        {
                            throw new NotSupportedException();
                        }
                        RegisterType(ctypeDef.Name, ctypedefTypeSymbol);
                    }
                    break;

                    case CodeMemberKind.Type:
                    {
                        RegisterTypeDeclaration((CodeTypeDeclaration)mb);
                    }
                    break;
                    }
                }

                int typeCount = cu.TypeCount;
                for (int i = 0; i < typeCount; ++i)
                {
                    RegisterTypeDeclaration(cu.GetTypeDeclaration(i));
                }
            }
            //-----------------------
            //temp fix
            int methodCount = cppMethodList.Count;

            if (methodCount > 0)
            {
                //find owner and add the implementation
                for (int i = 0; i < methodCount; ++i)
                {
                    CodeMethodDeclaration metdecl = cppMethodList[i];
                    if (metdecl.LineComments != null)
                    {
                        //for cef, some line comment has transformation info
                    }
                }
            }
            //-----------------------
            ResolveBaseTypes();
            ResolveTypeMembers();
            //-----------------------

            AddMoreTypeInfo();
            //
            var cefTypeBridgeTxPlanner = new CefTypeBridgeTransformPlanner();

            cefTypeBridgeTxPlanner.AssignTypeBridgeInfo(this.typeSymbols);
            //
            this.Planner = cefTypeBridgeTxPlanner;

            //-----------------------
            //do class classification


            foreach (CodeTypeDeclaration t in typedeclDic.Values)
            {
                string name = t.Name;
                if (name.EndsWith("Callback"))
                {
                    _v_callBackClasses.Add(t);
                }
                else if (name.EndsWith("Handler"))
                {
                    _v_handlerClasses.Add(t);
                }
                else if (name.EndsWith("CToCpp"))
                {
                    //implementation
                    cToCppClasses.Add(t);
                }
                else if (name.EndsWith("CppToC"))
                {
                    //implementation
                    cppToCClasses.Add(t);
                }
                else
                {
                    switch (t.Kind)
                    {
                    default:
                    {
                        if (t.IsGlobalCompilationUnitType)
                        {
                            _fileModuleClasses.Add(t);
                        }
                        else if (t.IsTemplateTypeDefinition)
                        {
                            _templateClasses.Add(t);
                        }
                        else if (t.BaseIsVirtual)
                        {
                            _v_instanceClasses.Add(t);
                        }
                        else
                        {
                            if (t.BaseTypes != null && t.BaseTypes.Count > 0)
                            {
                                CodeTypeReference baseType = t.BaseTypes[0];
                                if (baseType.ResolvedType != null)
                                {
                                    switch (baseType.Name)
                                    {
                                    default:

                                        break;

                                    case "CefStructBase":
                                    case "CefBaseScoped":
                                    case "CefBaseRefCounted":
                                        _cefBaseTypes.Add(t);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                switch (t.Name)
                                {
                                default:
                                    break;

                                case "CefScopedSandboxInfo":
                                case "CefBaseRefCounted":
                                case "CefBaseScoped":
                                case "CefRefCount":
                                    break;
                                }
                            }
                        }
                    }
                    break;

                    case TypeKind.Enum:
                        if (!CefResolvingContext.IsAllLowerLetter(name))
                        {
                        }
                        _enumClasses.Add(t);
                        break;

                    case TypeKind.Struct:
                        if (!CefResolvingContext.IsAllLowerLetter(name))
                        {
                            if (name.EndsWith("Traits"))
                            {
                            }
                            else
                            {
                            }
                        }
                        _plainCStructs.Add(t);
                        break;
                    }
                }
            }
            //-----------------------
            //for analysis

            foreach (CodeTypeDeclaration t in typedeclDic.Values)
            {
                TypeSymbol resolvedType = t.ResolvedType;
                if (t.BaseTypes.Count == 0)
                {
                    //
                }
                else
                {
                    TypeSymbol        baseType = t.BaseTypes[0].ResolvedType;
                    TypeHierarchyNode found;
                    if (!hierarchy.TryGetValue(baseType, out found))
                    {
                        found = new TypeHierarchyNode(baseType);
                        hierarchy.Add(baseType, found);
                    }

                    if (found.Type != resolvedType)
                    {
                        found.AddTypeSymbol(resolvedType);
                    }
                }
            }
            //-----------------------
        }
Exemplo n.º 4
0
        void RegisterTypeDeclaration(CodeTypeDeclaration typeDecl)
        {
            //1. collect

            if (typeDecl.IsGlobalCompilationUnitType)
            {
                //this is global type
                if (typeDecl.MemberCount == 0)
                {
                    //skip this global type
                    return;
                }
            }

            if (!typeDecl.IsForwardDecl && typeDecl.Name != null)
            {
                CodeTypeDeclaration existingDecl;
                if (typedeclDic.TryGetValue(typeDecl.FullName, out existingDecl))
                {
                    //found
                    throw new Exception("duplicated key " + typeDecl.Name);
                }

                typedeclDic.Add(typeDecl.FullName, typeDecl);
                //-----------------------

                SimpleTypeSymbol typeSymbol = new SimpleTypeSymbol(typeDecl);
                typeDecl.ResolvedType = typeSymbol;
                //

                TypeSymbol existingTypeSymbol;
                if (TryGetType(typeSymbol.Name, out existingTypeSymbol))
                {
                    //have existing value
                    throw new NotSupportedException();
                }
                else
                {
                    RegisterType(typeSymbol.Name, typeSymbol);
                }
                //
                //and sub types
                if (!typeDecl.IsGlobalCompilationUnitType)
                {
                    foreach (CodeMemberDeclaration subType in typeDecl.GetSubTypeIter())
                    {
                        if (subType.MemberKind == CodeMemberKind.TypeDef)
                        {
                            CodeCTypeDef ctypeDef = (CodeCTypeDef)subType;
                            //

                            CTypeDefTypeSymbol ctypedefTypeSymbol = new CTypeDefTypeSymbol(ctypeDef.Name, ctypeDef.From);
                            ctypedefTypeSymbol.CreatedTypeCTypeDef = ctypeDef;
                            ctypedefTypeSymbol.ParentType          = typeSymbol;

                            //---
                            RegisterType(typeSymbol.Name + "." + ctypeDef.Name, ctypedefTypeSymbol);
                            List <TypeSymbol> nestedTypes = typeSymbol.NestedTypeSymbols;
                            if (nestedTypes == null)
                            {
                                typeSymbol.NestedTypeSymbols = nestedTypes = new List <TypeSymbol>();
                            }
                            nestedTypes.Add(ctypedefTypeSymbol);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
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);
        }