public LambdaExpr(Parameter[] parameters, Stmt body) { _function = new FunctionDefinition(null, parameters, body); }
public override void PostWalk(FunctionDefinition node) { Debug.Assert(_currentFunc == node); Debug.Assert(_currentScope == node); PopScope(); }
internal LambdaExpr(FunctionDefinition function) { _function = function; }
private void PopScope() { _scopes.Add(_currentScope); _currentScope = _currentScope.Parent; _finallyCount.RemoveAt(_finallyCount.Count - 1); if (_currentScope is FunctionDefinition) _currentFunc = (FunctionDefinition)_currentScope; }
public override bool Walk(FunctionDefinition node) { if (!node.IsLambda) node.TotemVariable = DefineVariable(node.Name); foreach (Parameter p in node.Parameters) if (p.DefaultValue != null) p.DefaultValue.Walk(this); PushScope(node); foreach (Parameter p in node.Parameters) p.Walk(_parameter); node.Body.Walk(this); return false; }
public virtual void PostWalk(FunctionDefinition node) { }
private void PushScope(ScopeStmt node) { node.Parent = _currentScope; _currentScope = node; _finallyCount.Add(0); if (_currentScope is FunctionDefinition) _currentFunc = (FunctionDefinition)_currentScope; }
public override void PostWalk(FunctionDefinition node) { }
// FunctionDefinition public virtual bool Walk(FunctionDefinition node) { return true; }
// FunctionDefinition public override bool Walk(FunctionDefinition node) { return false; }
private Stmt ParseFuncDeclaration(bool requireName = true) { Eat(TokenType.KeywordFunc); int gstart = GetStart(); string name = null; if (!PeekToken(TokenType.Name) && requireName) { ReportSyntaxError(gstart, GetEnd(), "Function has no name."); return null; } else if (PeekToken(TokenType.Name)) { NameToken nt = (NameToken)NextToken(); name = nt.Name; } Eat(TokenType.LeftParenthesis); int lStart = GetStart(), lEnd = GetEnd(), grouping = _tokenizer.GroupingLevel; Parameter[] parameters = ParseVarArgsList(); FunctionDefinition ret; if (parameters == null) { // error in parameters ret = new FunctionDefinition(name, new Parameter[0]); ret.SetLoc(_globalParent, gstart, lEnd); return ret; } int rStart = GetStart(), rEnd = GetEnd(); ret = new FunctionDefinition(name, parameters); PushFunction(ret); Stmt body = ParseFuncBody(); FunctionDefinition ret2 = PopFunction(); Debug.Assert(ret == ret2); ret.Body = body; if (_sink != null) { _sink.MatchPair( new SourceSpan(_tokenizer.IndexToLocation(lStart), _tokenizer.IndexToLocation(lEnd)), new SourceSpan(_tokenizer.IndexToLocation(rStart), _tokenizer.IndexToLocation(rEnd)), grouping ); } ret.SetLoc(_globalParent, gstart, GetEnd()); return ret; }
private void PushFunction(FunctionDefinition function) { if (_functions == null) { _functions = new Stack<FunctionDefinition>(); } _functions.Push(function); }
private LambdaExpr ParseLambdaBody(int startPosition, Parameter[] parameters) { Expr exp; LambdaExpr ret; Stmt st; if (PeekToken(TokenType.LeftBrace)) { var inFinally = _inFinally; var inLoop = _inLoop; var return_ = _return; var isGenerator = _isGenerator; var isAsync = _isAsync; _inLoop = false; _inFinally = false; _return = false; _isGenerator = false; _isAsync = false; FunctionDefinition fnDef = new FunctionDefinition(null, parameters); PushFunction(fnDef); st = ParseBlock(); FunctionDefinition fnDef2 = PopFunction(); Debug.Assert(fnDef == fnDef2); fnDef.Body = st; ret = new LambdaExpr(fnDef); _inLoop = inLoop; _inFinally = inFinally; _return = return_; _isGenerator = isGenerator; _isAsync = isAsync; } else { exp = ParseExpr(); st = new ReturnStmt(exp); st.SetLoc(_globalParent, exp.IndexSpan); ret = new LambdaExpr(parameters, st); } ret.SetLoc(_globalParent, startPosition, GetEnd()); return ret; }
public override bool Walk(FunctionDefinition node) { UpdateLoops(node); return base.Walk(node); }