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); }
private BoundStatement BindForStatement(ForStatementSyntax syntax) { var lowerBound = BindExpression(syntax.LowerBound, TypeSymbol.Int); var upperBound = BindExpression(syntax.UpperBound, TypeSymbol.Int); _scope = new BoundScope(_scope); // TODO (R) isReadOnly: true by Immo var variable = DeclareVariable(syntax.Identifier, TypeSymbol.Int, false); var statement = BindStatement(syntax.Statement); _scope = _scope.Parent; return(new BoundForStatement(variable, lowerBound, upperBound, statement)); }
private BoundStatement BindBlockStatement(BlockStatementSyntax statement) { var statements = ImmutableArray.CreateBuilder <BoundStatement>(); _scope = new BoundScope(_scope); foreach (var s in statement.Statements) { statements.Add(BindStatement(s)); } _scope = _scope.Parent; return(new BoundBlockStatement(statements.ToImmutable())); }
private Binder(BoundScope parent) { _scope = new BoundScope(parent); }
public BoundScope(BoundScope parent) { Parent = parent; _variables = new Dictionary <string, VariableSymbol>(); }