Esempio n. 1
0
        private static BoundScope CreateParentScope(BoundGlobalScope previous)
        {
            var stack = new Stack <BoundGlobalScope>();

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

                previous = previous.Previous;
            }

            BoundScope parent = null;

            while (stack.Count > 0)
            {
                previous = stack.Pop();

                var scope = new BoundScope(parent);

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

                parent = scope;
            }

            return(parent);
        }
Esempio n. 2
0
 public BoundGlobalScope(
     BoundGlobalScope previous,
     ImmutableArray <VariableSymbol> variables,
     ImmutableArray <Diagnostic> diagnostics,
     BoundStatement statement)
 {
     Previous    = previous;
     Variables   = variables;
     Diagnostics = diagnostics;
     Statement   = statement;
 }
Esempio n. 3
0
        public static BoundGlobalScope BindGlobalScope(BoundGlobalScope previous, SyntaxTree syntaxTree)
        {
            var parentScope = CreateParentScope(previous);
            var binder      = new Binder(parentScope);

            var statement = binder.BindStatement(syntaxTree.Root.Statement);

            var variables   = binder._scope.GetDeclaredVariables();
            var diagnostics = binder.Diagnostics.ToImmutableArray();

            if (previous != null)
            {
                diagnostics = diagnostics.InsertRange(0, previous.Diagnostics);
            }

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