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); }
private static BoundScope CreateRootScope() { var result = new BoundScope(null); foreach (var f in BuiltinFunctions.GetAll()) { result.TryDeclareFunction(f); } return(result); }
public Binder(BoundScope parent, FunctionSymbol function) { _scope = new BoundScope(parent); _function = function; if (function != null) { foreach (var p in function.Parameters) { _scope.TryDeclareVariable(p); } } }
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())); }
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)); }
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)); }
public BoundScope(BoundScope parent) { Parent = parent; }
public Binder(BoundScope parent) { scope = new BoundScope(parent); }