Beispiel #1
0
        private static BoundScope CreateParentScopes(BoundGlobalScope previous)
        {
            // submission 3 => submission 2 => submission 1
            var stack = new Stack <BoundGlobalScope>();

            while (previous != null)
            {
                stack.Push(previous);
                previous = previous.Previous;
            }
            // submission 1 => submission 2 => submission 3
            BoundScope parent = null;

            while (stack.Count > 0)
            {
                previous = stack.Pop();
                var scope = new BoundScope(parent);
                foreach (var v in previous.Variables)
                {
                    scope.TryDeclare(v);
                }
                parent = scope;
            }

            return(parent);
        }
Beispiel #2
0
 public BoundGlobalScope(BoundGlobalScope previous, ImmutableArray <Diagnostic> diagnostics, ImmutableArray <VariableSymbol> variables, BoundStatement statement)
 {
     Statement   = statement;
     Variables   = variables;
     Diagnostics = diagnostics;
     Previous    = previous;
 }
Beispiel #3
0
        public static BoundGlobalScope BindGlobalScope(BoundGlobalScope previous, CompilationUnitSyntax syntax)
        {
            var parentScope    = CreateParentScopes(previous);
            var binder         = new Binder(parentScope);
            var boundStatement = binder.BindStatement(syntax.Statement);
            var variables      = binder._scope.GetDeclaredVariables();
            var diagnostics    = binder.Diagnostics.ToImmutableArray();

            //Since in CLI, the variables from different lines are chaining (nested)
            //we need to chain the diagnostics too.
            //otherwise, statements like a=b will give error, but
            //when we reference a again, it will not have the same error
            if (previous != null)
            {
                diagnostics = diagnostics.InsertRange(0, previous.Diagnostics);
            }

            return(new BoundGlobalScope(previous, diagnostics, variables, boundStatement));
        }