Example #1
0
        public SymbolImplementation BuildMethod(SourceMethodDefinitionSymbol methodSymbol)
        {
            var methodBody  = methodSymbol.Syntax.Body;
            var symbolTable = (ISymbolTable)methodSymbol.Parent;

            _rootScope    = new SymbolScope(symbolTable);
            _currentScope = _rootScope;

            var symbolContext      = methodSymbol;
            var implementationNode = methodBody;

            var statements       = new List <BoundStatement>();
            var statementBuilder = new StatementBinder(this, symbolContext, _diagnostics);

            if (symbolContext.Parameters != null)
            {
                int parameterCount = symbolContext.Parameters.Length;
                for (int paramIndex = 0; paramIndex < parameterCount; paramIndex++)
                {
                    _currentScope.AddSymbol(symbolContext.Parameters[paramIndex]);
                }
            }

            foreach (var statementNode in implementationNode.Statements)
            {
                var statement = statementBuilder.BuildStatement(statementNode);
                if (statement != null)
                {
                    statements.Add(statement);
                }
            }

            return(new SymbolImplementation(statements.ToImmutableArray(), _rootScope));
        }
        public SymbolImplementation BuildMethod(SourceMethodDefinitionSymbol methodSymbol)
        {
            var methodBody = methodSymbol.Syntax.Body;
            var symbolTable = (ISymbolTable) methodSymbol.Parent;

            _rootScope = new SymbolScope(symbolTable);
            _currentScope = _rootScope;

            var symbolContext = methodSymbol;
            var implementationNode = methodBody;

            var statements = new List<BoundStatement>();
            var statementBuilder = new StatementBinder(this, symbolContext, _diagnostics);

            if (symbolContext.Parameters != null)
            {
                int parameterCount = symbolContext.Parameters.Length;
                for (int paramIndex = 0; paramIndex < parameterCount; paramIndex++)
                    _currentScope.AddSymbol(symbolContext.Parameters[paramIndex]);
            }

            foreach (var statementNode in implementationNode.Statements)
            {
                var statement = statementBuilder.BuildStatement(statementNode);
                if (statement != null)
                    statements.Add(statement);
            }

            return new SymbolImplementation(statements.ToImmutableArray(), _rootScope);
        }