public FunctionDefinition(string name, Parameter[] parameters, Stmt body) { ContractUtils.RequiresNotNullItems(parameters, "parameters"); if (name == null) { _name = "$lambda-" + Interlocked.Increment(ref _lambdaId); _lambda = true; } else { _name = name; } _parameters = parameters; _body = body; }
public BlockStmt(Stmt[] statements) { ContractUtils.RequiresNotNull(statements, "statements"); _statements = statements; }
public LambdaExpr(Parameter[] parameters, Stmt body) { _function = new FunctionDefinition(null, parameters, body); }
public RewrittenBodyStmt(Stmt originalBody, Expression body) { _body = body; _originalBody = originalBody; SetLoc(originalBody.GlobalParent, originalBody.IndexSpan); }
/// <summary> /// Called when parsing is complete, the body is built, the line mapping and language features are known. /// /// This is used in conjunction with the constructor which does not take a body. It enables creating /// the outer most PythonAst first so that nodes can always have a global parent. This lets an un-bound /// tree to still provide it's line information immediately after parsing. When we set the location /// of each node during construction we also set the global parent. When we name bind the global /// parent gets replaced with the real parent ScopeStatement. /// </summary> /// <param name="lineLocations">a mapping of where each line begins</param> /// <param name="body">The body of code</param> /// <param name="languageFeatures">The language features which were set during parsing.</param> public void ParsingFinished(int[] lineLocations, Stmt body, ModuleOptions languageFeatures) { ContractUtils.RequiresNotNull(body, "body"); if (_body != null) { throw new InvalidOperationException("cannot set body twice"); } _body = body; _lineLocations = lineLocations; _languageFeatures = languageFeatures; }
private TotemAst FinishParsing(Stmt ret) { var res = _globalParent; _globalParent = null; var lineLocs = _tokenizer.GetLineLocations(); // update line mapping if (_sourceUnit.HasLineMapping) { List<int> newLineMapping = new List<int>(); int last = 0; for (int i = 0; i < lineLocs.Length; i++) { while (newLineMapping.Count < i) { newLineMapping.Add(last); } last = lineLocs[i] + 1; newLineMapping.Add(lineLocs[i]); } lineLocs = newLineMapping.ToArray(); } res.ParsingFinished(lineLocs, ret, _languageFeatures); return res; }
private void UpdateLoops(Stmt stmt) { if (_inFinally || _inLoop) { if (!LoopAndFinallyLocations.ContainsKey(stmt.Span.Start.Line)) { LoopAndFinallyLocations.Add(stmt.Span.Start.Line, new Dictionary<int, bool>(LoopOrFinallyIds)); } } }
private void WalkLoopBody(Stmt body, bool isFinally) { bool inLoop = _inLoop; bool inFinally = _inFinally; int loopId = ++_loopId; _inFinally = false; _inLoop = true; _loopIds.Add(loopId, isFinally); body.Walk(this); _inLoop = inLoop; _inFinally = inFinally; LoopOrFinallyIds.Remove(loopId); }