コード例 #1
0
        private static BoundScope CreateParentScope(BoundGlobalScope previous)
        {
            var stack = new Stack <BoundGlobalScope>();

            while (previous != null)
            {
                stack.Push(previous);
                previous = previous.Previous;
            }

            var parent = CreateRootScope();

            while (stack.Count > 0)
            {
                previous = stack.Pop();
                var scope = new BoundScope(parent);

                foreach (var f in previous.Functions)
                {
                    scope.TryDeclareFunction(f);
                }

                foreach (var v in previous.Variables)
                {
                    scope.TryDeclareVariable(v);
                }

                parent = scope;
            }

            return(parent);
        }
コード例 #2
0
        private static BoundScope CreateRootScope()
        {
            var result = new BoundScope(null);

            foreach (var f in BuiltinFunctions.GetAll())
            {
                result.TryDeclareFunction(f);
            }

            return(result);
        }
コード例 #3
0
        public Binder(BoundScope parent, FunctionSymbol function)
        {
            _scope    = new BoundScope(parent);
            _function = function;

            if (function != null)
            {
                foreach (var p in function.Parameters)
                {
                    _scope.TryDeclareVariable(p);
                }
            }
        }
コード例 #4
0
        private BoundStatement BindBlockStatement(BlockStatementSyntax syntax)
        {
            var statements = ImmutableArray.CreateBuilder <BoundStatement>();

            _scope = new BoundScope(_scope);
            foreach (var statementSyntax in syntax.Statements)
            {
                var boundStatement = BindStatement(statementSyntax);
                statements.Add(boundStatement);
            }
            _scope = _scope.Parent;
            return(new BoundBlockStatement(statements.ToImmutable()));
        }
コード例 #5
0
        private BoundStatement BindForStatement(ForStatementSyntax syntax)
        {
            var lowerBound = BindExpression(syntax.LowerBound, TypeSymbol.Int);
            var upperBound = BindExpression(syntax.UpperBound, TypeSymbol.Int);

            _scope = new BoundScope(_scope);

            var variable = BindVariable(syntax.Identifier, isReadOnly: true, TypeSymbol.Int);
            var body     = BindStatement(syntax.Body);

            _scope = _scope.Parent;

            return(new BoundForStatement(variable, lowerBound, upperBound, body));
        }
コード例 #6
0
        private BoundStatement BindForStatement(ForStatementSyntax syntax)
        {
            var name     = syntax.Identifier.Text;
            var variable = new VariableSymbol(name, true, typeof(int));

            _scope = new BoundScope(_scope);

            if (!_scope.TryDeclare(variable))
            {
                _diagnostics.ReportVariableAlreadyDeclared(syntax.Identifier.Span, name);
            }
            var lowerBound = BindExpression(syntax.LowerBound, typeof(int));
            var upperBound = BindExpression(syntax.UpperBound, typeof(int));
            var body       = BindStatement(syntax.Body);

            _scope = _scope.Parent;
            return(new BoundForStatement(variable, lowerBound, upperBound, body));
        }
コード例 #7
0
 public BoundScope(BoundScope parent)
 {
     Parent = parent;
 }
コード例 #8
0
 public Binder(BoundScope parent)
 {
     scope = new BoundScope(parent);
 }