Ejemplo n.º 1
0
        private void ResolveSymbolTypes(DogeClassDefinition @class,
                                        DogeSymbolTable symbolTable,
                                        ICollection <IList <string> > usingDefinitions,
                                        IList <string> fullName)
        {
            foreach (var field in @class.FieldDefinitions)
            {
                var symbol = symbolTable.GetSymbolTable(fullName).GetSymbol(field.Name);
                symbol.TypeSymbol = symbolTable.ResolveSymbol(
                    symbol.Type !,
                    s => s.SymbolType == DogeSymbolType.Type,
                    s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type,
                    usingDefinitions);
            }

            foreach (var property in @class.PropertyDefinitions)
            {
                var symbol = symbolTable.GetSymbolTable(fullName).GetSymbol(property.Name);
                symbol.TypeSymbol = symbolTable.ResolveSymbol(
                    symbol.Type !,
                    s => s.SymbolType == DogeSymbolType.Type,
                    s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type,
                    usingDefinitions);
            }

            foreach (var method in @class.MethodDefinitions)
            {
                var symbol = symbolTable.GetSymbolTable(fullName).GetSymbol(method.Name);
                if (symbol.Type == null)
                {
                    continue;
                }
                symbol.TypeSymbol = symbolTable.ResolveSymbol(
                    symbol.Type !,
                    s => s.SymbolType == DogeSymbolType.Type,
                    s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type,
                    usingDefinitions);

                method.Method.ReturnTypeSymbol = new DogeSymbolNode(symbolTable.ResolveSymbol(
                                                                        method.Method.ReturnType,
                                                                        s => s.SymbolType == DogeSymbolType.Type,
                                                                        s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type,
                                                                        usingDefinitions),
                                                                    method.Method.ReturnTypeIdentifier.File,
                                                                    method.Method.ReturnTypeIdentifier.TokenRange);

                foreach (var parameter in method.Method.Parameters)
                {
                    parameter.TypeSymbol = new DogeSymbolNode(symbolTable.ResolveSymbol(
                                                                  parameter.Type,
                                                                  s => s.SymbolType == DogeSymbolType.Type,
                                                                  s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type,
                                                                  usingDefinitions),
                                                              parameter.TypeIdentifier.File,
                                                              parameter.TypeIdentifier.TokenRange);
                }
            }
        }
Ejemplo n.º 2
0
        private void ResolveSymbols(DogeNode node,
                                    DogeSymbolTable symbolTable,
                                    IDictionary <string, DogeLocalDeclarationStatement> locals,
                                    ICollection <IList <string> > usingDefinitions,
                                    IList <string> fullName)
        {
            void resolveSymbols(DogeNode node) =>
            ResolveSymbols(
                node,
                symbolTable,
                locals,
                usingDefinitions,
                fullName);

            switch (node)
            {
            case DogeStatementList statementList:
                var localsOuter = locals.ToDictionary(x => x.Key, x => x.Value);
                foreach (var statement in statementList.Statements)
                {
                    resolveSymbols(statement);
                }
                locals = localsOuter;
                break;

            case DogeWhileStatement whileStatement:
                resolveSymbols(whileStatement.Condition);
                resolveSymbols(whileStatement.Body);
                break;

            case DogeIfStatement ifStatement:
                resolveSymbols(ifStatement.Condition);
                resolveSymbols(ifStatement.Body);
                if (ifStatement.Else != null)
                {
                    resolveSymbols(ifStatement.Else);
                }
                break;

            case DogeLocalDeclarationStatement localDeclarationStatement:
                if (localDeclarationStatement.Value != null)
                {
                    resolveSymbols(localDeclarationStatement.Value);
                }
                localDeclarationStatement.TypeSymbol = new DogeSymbolNode(symbolTable.ResolveSymbol(
                                                                              localDeclarationStatement.Type,
                                                                              s => s.SymbolType == DogeSymbolType.Type,
                                                                              s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type,
                                                                              usingDefinitions),
                                                                          localDeclarationStatement.File,
                                                                          localDeclarationStatement.TokenRange);
                locals.Add(localDeclarationStatement.Name, localDeclarationStatement);
                break;

            case DogeExpressionStatement expressionStatement:
                expressionStatement.Expression = ResolveExpressionSymbols(
                    expressionStatement.Expression,
                    symbolTable,
                    locals,
                    usingDefinitions,
                    fullName);
                break;
            }
        }