internal void ProcessFunctionDecorators(DDG ddg) { if (Ast.Decorators != null) { var types = Function.SelfSet; Expression expr = Ast.NameExpression; foreach (var d in Ast.Decorators.Decorators) { if (d != null) { var decorator = ddg._eval.Evaluate(d); if (decorator.Contains(ProjectState.ClassInfos[BuiltinTypeId.Property])) { Function.IsProperty = true; } else if (decorator.Contains(ProjectState.ClassInfos[BuiltinTypeId.StaticMethod])) { // TODO: Warn if IsClassMethod is set Function.IsStatic = true; } else if (decorator.Contains(ProjectState.ClassInfos[BuiltinTypeId.ClassMethod])) { // TODO: Warn if IsStatic is set Function.IsClassMethod = true; } else { Expression nextExpr; if (!_decoratorCalls.TryGetValue(d, out nextExpr)) { nextExpr = _decoratorCalls[d] = new CallExpression(d, new[] { new Arg(expr) }); } expr = nextExpr; var decorated = AnalysisSet.Empty; foreach (var ns in decorator) { var fd = ns as FunctionInfo; if (fd != null && Scope.EnumerateTowardsGlobal.Any(s => s.AnalysisValue == fd)) { continue; } decorated = decorated.Union(ns.Call(expr, this, new[] { types }, ExpressionEvaluator.EmptyNames)); } // If processing decorators, update the current // function type. Otherwise, we are acting as if // each decorator returns the function unmodified. if (ddg.ProjectState.Limits.ProcessCustomDecorators) { types = decorated; } } } } ddg.Scope.AddLocatedVariable(Ast.Name, Ast.NameExpression, this).AddTypes(this, types); } if (!Function.IsStatic && Ast.Parameters.Count > 0) { VariableDef param; IAnalysisSet firstParam; var clsScope = ddg.Scope as ClassScope; if (clsScope == null) { firstParam = Function.IsClassMethod ? ProjectState.ClassInfos[BuiltinTypeId.Type].SelfSet : AnalysisSet.Empty; } else { firstParam = Function.IsClassMethod ? clsScope.Class.SelfSet : clsScope.Class.Instance.SelfSet; } if (Scope.TryGetVariable(Ast.Parameters[0].Name, out param)) { param.AddTypes(this, firstParam, false); } } }
public override bool Walk(CallExpression node) { ShouldExecute = false; return base.Walk(node); }
public override void PostWalk(CallExpression node) { if (IsInRange(node) && node.Target != null) { // For call nodes, we don't want either the call nor the called function to show up, // but if it is a method, then we do want to show the object on which it is called. // For example, given A.B.C(42), we want A.B to show. By the time we get here, we // already have A.B.C in the list, so we need to remove it and reinstate A.B, which // will be stored as a value in the dictionary with A.B.C as key. Expression oldNode; _expressions.TryGetValue(node.Target, out oldNode); _expressions.Remove(node.Target); if (oldNode != null) { _expressions.Add(oldNode, null); } // Hardcode some commonly used side-effect-free builtins to show even in calls. var name = node.Target as NameExpression; if (name != null && allowedCalls.Contains(name.Name) && node.Args.All(arg => IsValidTarget(arg.Expression))) { _expressions.Add(node, null); } } }
public override bool Walk(CallExpression node) { HasSideEffects = true; return false; }
public override bool Walk(CallExpression node) { node.Parent = _currentScope; return(base.Walk(node)); }
// trailer: '(' [ arglist_genexpr ] ')' | '[' subscriptlist ']' | '.' NAME private Expression AddTrailers(Expression ret, bool allowGeneratorExpression) { bool prevAllow = _allowIncomplete; try { _allowIncomplete = true; while (true) { switch (PeekToken().Kind) { case TokenKind.LeftParenthesis: if (!allowGeneratorExpression) return ret; NextToken(); string whitespace = _tokenWhiteSpace; List<string> commaWhiteSpace; bool ateTerminator; Arg[] args = FinishArgListOrGenExpr(out commaWhiteSpace, out ateTerminator); string closeParenWhiteSpace = _tokenWhiteSpace; CallExpression call; if (args != null) { call = FinishCallExpr(ret, args); } else { call = new CallExpression(ret, new Arg[0]); } if (_verbatim) { AddPreceedingWhiteSpace(call, whitespace); AddSecondPreceedingWhiteSpace(call, closeParenWhiteSpace); if (commaWhiteSpace != null) { AddListWhiteSpace(call, commaWhiteSpace.ToArray()); } if (!ateTerminator) { AddErrorMissingCloseGrouping(call); } } call.SetLoc(ret.StartIndex, GetEnd()); ret = call; break; case TokenKind.LeftBracket: NextToken(); whitespace = _tokenWhiteSpace; Expression index = ParseSubscriptList(out ateTerminator); IndexExpression ie = new IndexExpression(ret, index); string finishWhiteSpace = _tokenWhiteSpace; ie.SetLoc(ret.StartIndex, GetEnd()); if (_verbatim) { AddPreceedingWhiteSpace(ie, whitespace); AddSecondPreceedingWhiteSpace(ie, finishWhiteSpace); if (!ateTerminator) { AddErrorMissingCloseGrouping(ie); } } ret = ie; break; case TokenKind.Dot: NextToken(); whitespace = _tokenWhiteSpace; var name = ReadNameMaybeNone(); string nameWhitespace = _tokenWhiteSpace; MemberExpression fe = MakeMember(ret, name); fe.SetLoc(ret.StartIndex, GetStart(), GetEnd()); if (_verbatim) { AddPreceedingWhiteSpace(fe, whitespace); AddSecondPreceedingWhiteSpace(fe, nameWhitespace); if (!name.HasName) { AddErrorIsIncompleteNode(fe); } } ret = fe; break; case TokenKind.Constant: // abc.1, abc"", abc 1L, abc 0j ReportSyntaxError("invalid syntax"); ret = Error(_verbatim ? _lookaheadWhiteSpace + _lookahead.Token.VerbatimImage : null, ret); NextToken(); break; default: return ret; } } } finally { _allowIncomplete = prevAllow; } }
public override void PostWalk(CallExpression node) { if (node.NeedsLocalsDictionary()) { _currentScope.NeedsLocalsDictionary = true; } }
public override bool Walk(CallExpression node) { return UpdateLineInfo(node, true); }
public override void PostWalk(CallExpression node) { PostWalkWorker(node); }
// CallExpression public override bool Walk(CallExpression node) { return ShouldWalkWorker(node); }
// Not-Compound Statements public override bool Walk(CallExpression node) { AddTagIfNecessary(node); return base.Walk(node); }