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); }
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 VariableSymbol BindVariable(SyntaxToken identifier, bool isReadOnly, TypeSymbol type) { var name = identifier.Text ?? "?"; var declare = !identifier.IsMissing; var variable = new VariableSymbol(name, isReadOnly, type); if (declare && !scope.TryDeclareVariable(variable)) { diagnostics.ReportVariableAlreadyDeclared(identifier.Span, name); } return(variable); }
private VariableSymbol BindVariable(SyntaxToken identifier, bool isReadOnly, TypeSymbol type) { var name = identifier.Text ?? "?"; var declare = !identifier.IsMissing; var variable = _function == null ? (VariableSymbol) new GlobalVariableSymbol(name, isReadOnly, type) : new LocalVariableSymbol(name, isReadOnly, type); if (declare && !_scope.TryDeclareVariable(variable)) { _diagnostics.ReportSymbolAlreadyDeclared(identifier.Span, name); } return(variable); }