Ejemplo n.º 1
0
        internal void Init(INamedTypeSymbol sym, ClassSymbolInfo info)
        {
            IsEnum       = sym.TypeKind == TypeKind.Enum;
            IsEntryClass = HasAttribute(sym, "Cs2Lua.EntryAttribute");
            IsValueType  = sym.IsValueType;

            IsInnerOfGenericType = IsInnerClassOfGenericType(sym);

            ExistConstructor       = false;
            ExistStaticConstructor = false;
            SemanticInfo           = sym;
            ClassSemanticInfo      = info;

            Key     = GetFullName(sym);
            BaseKey = GetFullName(sym.BaseType);
            if (BaseKey == SymbolTable.PrefixExternClassName("System.Object") || BaseKey == SymbolTable.PrefixExternClassName("System.ValueType"))
            {
                BaseKey = string.Empty;
            }

            GenericTypeKey = ClassInfo.GetFullNameWithTypeParameters(sym);

            References.Clear();
            IgnoreReferences.Clear();
        }
Ejemplo n.º 2
0
        private void InitRecursively(INamedTypeSymbol typeSym)
        {
            string key = ClassInfo.GetFullName(typeSym);

            if (!m_ClassSymbols.ContainsKey(key))
            {
                ClassSymbolInfo csi = new ClassSymbolInfo();
                m_ClassSymbols.Add(key, csi);
                csi.Init(typeSym, m_Compilation, this);
            }
            foreach (var newSym in typeSym.GetTypeMembers())
            {
                InitRecursively(newSym);
            }
        }
Ejemplo n.º 3
0
        internal void Init(INamedTypeSymbol typeSym, CSharpCompilation compilation, SymbolTable symTable)
        {
            if (typeSym.TypeKind == TypeKind.Error)
            {
                Logger.Instance.ReportIllegalType(typeSym);
                return;
            }

            IsInterface = typeSym.TypeKind == TypeKind.Interface;

            foreach (var intf in typeSym.AllInterfaces)
            {
                string          key = ClassInfo.GetFullName(intf);
                ClassSymbolInfo isi;
                if (!symTable.ClassSymbols.TryGetValue(key, out isi))
                {
                    isi = new ClassSymbolInfo();
                    symTable.ClassSymbols.Add(key, isi);
                    isi.Init(intf, compilation, symTable);
                }
            }

            ClassKey     = ClassInfo.GetFullName(typeSym);
            BaseClassKey = ClassInfo.GetFullName(typeSym.BaseType);
            if (BaseClassKey == "System.Object" || BaseClassKey == "System.ValueType")
            {
                BaseClassKey = string.Empty;
            }
            ExistConstructor       = false;
            ExistStaticConstructor = false;

            if (typeSym.GetAttributes().Length > 0)
            {
                ExistAttributes = true;
            }

            bool fieldUseExplicitTypeParams  = false;
            bool staticUseExplicitTypeParams = false;

            TypeSymbol = typeSym;
            foreach (var sym in TypeSymbol.GetMembers())
            {
                var fsym = sym as IFieldSymbol;
                if (null != fsym)
                {
                    FieldSymbols.Add(fsym);

                    if (fsym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }
                    CheckFieldUseExplicitTypeParam(fsym, compilation, ref fieldUseExplicitTypeParams, ref staticUseExplicitTypeParams);
                }
            }
            foreach (var sym in TypeSymbol.GetMembers())
            {
                var msym = sym as IMethodSymbol;
                if (null != msym)
                {
                    if (msym.MethodKind == MethodKind.Constructor && !msym.IsImplicitlyDeclared)
                    {
                        ExistConstructor = true;
                    }
                    else if (msym.MethodKind == MethodKind.StaticConstructor && !msym.IsImplicitlyDeclared)
                    {
                        ExistStaticConstructor = true;
                    }
                    MethodSymbols.Add(msym);

                    if (msym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }

                    string name = msym.Name;
                    if (name[0] == '.')
                    {
                        name = name.Substring(1);
                    }
                    string manglingName = SymbolTable.CalcMethodMangling(msym, symTable.AssemblySymbol);
                    if (msym.IsExtensionMethod && msym.Parameters.Length > 0)
                    {
                        var targetType = msym.Parameters[0].Type as INamedTypeSymbol;
                        if (null != targetType)
                        {
                            string          key = ClassInfo.GetFullNameWithTypeParameters(targetType);
                            ClassSymbolInfo csi;
                            if (!symTable.ClassSymbols.TryGetValue(key, out csi))
                            {
                                csi = new ClassSymbolInfo();
                                symTable.ClassSymbols.Add(key, csi);
                                csi.Init(targetType, compilation, symTable);
                            }
                            if (!csi.ExtensionClasses.ContainsKey(ClassKey))
                            {
                                csi.ExtensionClasses.Add(ClassKey, typeSym);
                                csi.GenerateBasicCtor = true;
                            }
                            bool needMangling;
                            bool isOverloaded;
                            if (csi.SymbolOverloadFlags.TryGetValue(name, out isOverloaded))
                            {
                                if (csi.MethodNames.Contains(manglingName))
                                {
                                    continue;
                                }
                                csi.SymbolOverloadFlags[name] = true;
                                needMangling = true;
                            }
                            else
                            {
                                if (SymbolOverloadFlags.TryGetValue(name, out isOverloaded))
                                {
                                    csi.SymbolOverloadFlags.Add(name, true);
                                    needMangling = true;
                                }
                                else
                                {
                                    csi.SymbolOverloadFlags.Add(name, false);
                                    needMangling = false;
                                }
                            }
                            if (needMangling)
                            {
                                csi.MethodNames.Add(manglingName);

                                SymbolOverloadFlags[name] = true;
                                MethodNames.Add(manglingName);
                            }
                            else
                            {
                                SymbolOverloadFlags.Add(name, false);
                                MethodNames.Add(name);
                            }
                        }
                    }
                    else
                    {
                        if (!SymbolOverloadFlags.ContainsKey(name))
                        {
                            SymbolOverloadFlags.Add(name, false);

                            MethodNames.Add(name);
                        }
                        else
                        {
                            SymbolOverloadFlags[name] = true;

                            MethodNames.Add(manglingName);
                        }
                    }
                    continue;
                }
                var psym = sym as IPropertySymbol;
                if (null != psym && !psym.IsIndexer)
                {
                    PropertySymbols.Add(psym);

                    if (psym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }
                    continue;
                }
                var esym = sym as IEventSymbol;
                if (null != esym)
                {
                    EventSymbols.Add(esym);

                    if (esym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }
                    continue;
                }
            }
            BuildInterfaceInfo(typeSym, compilation, symTable);
        }
Ejemplo n.º 4
0
        internal void Init(INamedTypeSymbol typeSym, CSharpCompilation compilation, SymbolTable symTable)
        {
            if (typeSym.TypeKind == TypeKind.Error)
            {
                Logger.Instance.ReportIllegalType(typeSym);
                return;
            }

            IsInterface = typeSym.TypeKind == TypeKind.Interface;

            foreach (var intf in typeSym.AllInterfaces)
            {
                string          key = ClassInfo.GetFullName(intf);
                ClassSymbolInfo isi;
                if (!symTable.ClassSymbols.TryGetValue(key, out isi))
                {
                    isi = new ClassSymbolInfo();
                    symTable.ClassSymbols.Add(key, isi);
                    isi.Init(intf, compilation, symTable);
                }
            }

            ClassKey     = ClassInfo.GetFullName(typeSym);
            BaseClassKey = ClassInfo.GetFullName(typeSym.BaseType);
            if (BaseClassKey == SymbolTable.PrefixExternClassName("System.Object") || BaseClassKey == SymbolTable.PrefixExternClassName("System.ValueType"))
            {
                BaseClassKey = string.Empty;
            }
            ExistConstructor       = false;
            ExistStaticConstructor = false;

            if (typeSym.GetAttributes().Length > 0)
            {
                ExistAttributes = true;
            }

            Dictionary <string, int> memberCounts = new Dictionary <string, int>();

            SymbolTable.Instance.CalcMemberCount(ClassKey, memberCounts);

            bool fieldUseExplicitTypeParams  = false;
            bool staticUseExplicitTypeParams = false;

            TypeSymbol = typeSym;
            var members = typeSym.GetMembers();

            foreach (var sym in members)
            {
                var fsym = sym as IFieldSymbol;
                if (null != fsym)
                {
                    FieldSymbols.Add(fsym);

                    if (fsym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }
                    CheckFieldUseExplicitTypeParam(fsym, compilation, ref fieldUseExplicitTypeParams, ref staticUseExplicitTypeParams);
                }
            }
            foreach (var sym in members)
            {
                var msym = sym as IMethodSymbol;
                if (null != msym)
                {
                    if (msym.MethodKind == MethodKind.Constructor && !msym.IsImplicitlyDeclared)
                    {
                        ExistConstructor = true;
                    }
                    else if (msym.MethodKind == MethodKind.StaticConstructor && !msym.IsImplicitlyDeclared)
                    {
                        ExistStaticConstructor = true;
                    }
                    MethodSymbols.Add(msym);

                    if (msym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }

                    string name = msym.Name;
                    if (name[0] == '.')
                    {
                        name = name.Substring(1);
                    }
                    bool isOverloaded;
                    int  count;
                    if (memberCounts.TryGetValue(name, out count))
                    {
                        isOverloaded = count > 1;
                    }
                    else
                    {
                        isOverloaded = false;
                    }
                    if (!SymbolOverloadFlags.ContainsKey(name))
                    {
                        SymbolOverloadFlags.Add(name, isOverloaded);
                    }
                    else
                    {
                        SymbolOverloadFlags[name] = isOverloaded;
                    }
                    continue;
                }
                var psym = sym as IPropertySymbol;
                if (null != psym && !psym.IsIndexer)
                {
                    PropertySymbols.Add(psym);

                    if (psym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }
                    continue;
                }
                var esym = sym as IEventSymbol;
                if (null != esym)
                {
                    EventSymbols.Add(esym);

                    if (esym.GetAttributes().Length > 0)
                    {
                        ExistAttributes = true;
                    }
                    continue;
                }
            }
            BuildInterfaceInfo(typeSym, compilation, symTable);
        }