Example #1
0
 private void CheckPartialTypes()
 {
     while (partialTypes_.Count > 0)
     {
         var types = partialTypes_.Values.ToArray();
         partialTypes_.Clear();
         foreach (var typeDeclarations in types)
         {
             PartialTypeDeclaration major    = typeDeclarations.Min();
             LuaSyntaxNodeTransfor  transfor = new LuaSyntaxNodeTransfor(this, null);
             transfor.AcceptPartialType(major, typeDeclarations);
         }
     }
 }
Example #2
0
        private IEnumerable <LuaCompilationUnitSyntax> Create()
        {
            List <LuaCompilationUnitSyntax> luaCompilationUnits = new List <LuaCompilationUnitSyntax>();

            foreach (SyntaxTree syntaxTree in compilation_.SyntaxTrees)
            {
                SemanticModel         semanticModel         = GetSemanticModel(syntaxTree);
                CompilationUnitSyntax compilationUnitSyntax = (CompilationUnitSyntax)syntaxTree.GetRoot();
                LuaSyntaxNodeTransfor transfor = new LuaSyntaxNodeTransfor(this, semanticModel);
                var luaCompilationUnit         = (LuaCompilationUnitSyntax)compilationUnitSyntax.Accept(transfor);
                luaCompilationUnits.Add(luaCompilationUnit);
            }
            CheckExportEnums();
            CheckPartialTypes();
            CheckRefactorNames();
            return(luaCompilationUnits.Where(i => !i.IsEmpty));
        }
Example #3
0
        public LuaExpressionSyntax GetTypeName(ISymbol symbol, LuaSyntaxNodeTransfor transfor)
        {
            Contract.Assert(symbol != null);
            if (symbol.Kind == SymbolKind.TypeParameter)
            {
                return(new LuaIdentifierNameSyntax(symbol.Name));
            }

            if (symbol.Kind == SymbolKind.ArrayType)
            {
                var arrayType = (IArrayTypeSymbol)symbol;
                LuaExpressionSyntax elementTypeExpression = GetTypeName(arrayType.ElementType, transfor);
                return(new LuaInvocationExpressionSyntax(arrayType.Rank == 1 ? LuaIdentifierNameSyntax.Array : LuaIdentifierNameSyntax.MultiArray, elementTypeExpression));
            }

            var namedTypeSymbol = (INamedTypeSymbol)symbol;

            if (namedTypeSymbol.TypeKind == TypeKind.Enum)
            {
                return(LuaIdentifierNameSyntax.Int);
            }

            if (namedTypeSymbol.IsDelegateType())
            {
                return(LuaIdentifierNameSyntax.Delegate);
            }

            LuaIdentifierNameSyntax baseTypeName = GetTypeShortName(namedTypeSymbol, transfor);
            var typeArguments = GetTypeArguments(namedTypeSymbol, transfor);

            if (typeArguments.Count == 0)
            {
                return(baseTypeName);
            }
            else
            {
                var invocationExpression = new LuaInvocationExpressionSyntax(baseTypeName);
                invocationExpression.AddArguments(typeArguments);
                return(invocationExpression);
            }
        }
Example #4
0
        internal LuaIdentifierNameSyntax GetTypeShortName(ISymbol symbol, LuaSyntaxNodeTransfor transfor = null)
        {
            string name = GetTypeShortString(symbol);

            if (MayHaveCodeMeta(symbol))
            {
                TypeMetaInfo info = typeMetas_.GetOrDefault(name);
                if (info != null)
                {
                    string newName = info.Model.Name;
                    if (newName != null)
                    {
                        name = newName;
                    }
                }
            }
            if (transfor != null)
            {
                transfor.ImportTypeName(ref name, symbol);
            }
            return(new LuaIdentifierNameSyntax(name));
        }
Example #5
0
 private void FillTypeArguments(List <LuaExpressionSyntax> typeArguments, INamedTypeSymbol typeSymbol, LuaSyntaxNodeTransfor transfor)
 {
     foreach (var typeArgument in typeSymbol.TypeArguments)
     {
         LuaExpressionSyntax typeArgumentExpression = GetTypeName(typeArgument, transfor);
         typeArguments.Add(typeArgumentExpression);
     }
 }
Example #6
0
        private void FillExternalTypeArgument(List <LuaExpressionSyntax> typeArguments, INamedTypeSymbol typeSymbol, LuaSyntaxNodeTransfor transfor)
        {
            var externalType = typeSymbol.ContainingType;

            if (externalType != null)
            {
                FillExternalTypeArgument(typeArguments, externalType, transfor);
                FillTypeArguments(typeArguments, externalType, transfor);
            }
        }
Example #7
0
        private List <LuaExpressionSyntax> GetTypeArguments(INamedTypeSymbol typeSymbol, LuaSyntaxNodeTransfor transfor)
        {
            List <LuaExpressionSyntax> typeArguments = new List <LuaExpressionSyntax>();

            FillExternalTypeArgument(typeArguments, typeSymbol, transfor);
            FillTypeArguments(typeArguments, typeSymbol, transfor);
            return(typeArguments);
        }