public static BoundScope CreateParentScopes(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 v in previous.Variables) { scope.TryDeclare(v); } parent = scope; } return(parent); }
public BoundGlobalScope( BoundGlobalScope previous, ImmutableArray <Diagnostic> diagnostics, ImmutableArray <VariableSymbol> variables, BoundStatement statement) { Previous = previous; Diagnostics = diagnostics; Variables = variables; Statement = statement; }
public static BoundGlobalScope BindGlobalScope(BoundGlobalScope previous, CompilationUnitSyntax syntax) { var parentScope = CreateParentScopes(previous); var binder = new Binder(parentScope); var statement = binder.BindStatement(syntax.Statement); var variables = binder._scope.GetDeclaredVariables(); var diagnostics = binder._diagnostics.ToImmutableArray(); if (previous != null) { diagnostics = diagnostics.InsertRange(0, previous.Diagnostics); } return(new BoundGlobalScope(previous, diagnostics, variables, statement)); }