Пример #1
0
 void ResolveBaseTypes()
 {
     //2. resolve allbase type
     foreach (CodeTypeDeclaration typedecl in typedeclDic.Values)
     {
         //resolve base type
         List <CodeTypeReference> baseTypes = typedecl.BaseTypes;
         if (baseTypes.Count == 0)
         {
             //eg. struct
         }
         else
         {
             foreach (CodeTypeReference baseType in baseTypes)
             {
                 CefResolvingContext resolvingContext = new CefResolvingContext(this, typedecl, ResolvingContextKind.Base);
                 baseType.ResolvedType = resolvingContext.ResolveType(baseType);
                 if (baseType.ResolvedType == null)
                 {
                     throw new NotSupportedException();
                 }
             }
         }
     }
 }
Пример #2
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;
        }
Пример #3
0
 public void RegisterType(string typeName, TypeSymbol tt)
 {
     if (_freeze)
     {
         if (!(typeName.StartsWith("cef_") && CefResolvingContext.IsAllLowerLetter(typeName)))
         {
             Console.WriteLine(typeName);
         }
         else
         {
             //for cef only!
         }
     }
     typeSymbols.Add(typeName, tt);
 }
Пример #4
0
        internal TypeSymbol RegisterBaseCToCppTypeSymbol(CodeTypeReference cToCppTypeReference)
        {
#if DEBUG
            if (!CefResolvingContext.IsAllLowerLetter(cToCppTypeReference.Name))
            {
                //cef-name convention
                throw new NotSupportedException();
            }
#endif
            TypeSymbol found;
            if (!typeSymbols.TryGetValue(cToCppTypeReference.Name, out found))
            {
                //if not found then create the new simple type
                found = new SimpleTypeSymbol(cToCppTypeReference.Name);
                RegisterType(cToCppTypeReference.Name, found);
            }
            return(cToCppTypeReference.ResolvedType = found);
        }
Пример #5
0
        void ResolveTypeMembers()
        {
            foreach (CodeTypeDeclaration typedecl in typedeclDic.Values)
            {
                foreach (CodeMethodDeclaration metDecl in typedecl.GetMethodIter())
                {
                    switch (metDecl.MethodKind)
                    {
                    default: throw new NotSupportedException();

                    case MethodKind.Ctor:
                    case MethodKind.Dtor:
                    {
                        foreach (CodeMethodParameter p in metDecl.Parameters)
                        {
                            CefResolvingContext resolvingContext = new CefResolvingContext(this, typedecl, ResolvingContextKind.MethodParReturnType);
                            //
                            p.ParameterType.ResolvedType = resolvingContext.ResolveType(p.ParameterType);
                        }
                    }
                    break;

                    case MethodKind.Normal:
                    {
                        //resolve return type and type parameter
                        {
                            CefResolvingContext resolvingContext = new CefResolvingContext(this, typedecl, ResolvingContextKind.MethodParReturnType);
                            //
                            metDecl.ReturnType.ResolvedType = resolvingContext.ResolveType(metDecl.ReturnType);
                        }


                        foreach (CodeMethodParameter p in metDecl.Parameters)
                        {
                            CefResolvingContext resolvingContext = new CefResolvingContext(this, typedecl, ResolvingContextKind.MethodPar);
                            //
                            p.ParameterType.ResolvedType = resolvingContext.ResolveType(p.ParameterType);
                        }
                    }
                    break;
                    }
                }
            }
        }
Пример #6
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);
                    }
                }
            }
            //-----------------------
        }