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._propertyObj)) { Function.IsProperty = true; } else if (decorator.Contains(ProjectState._staticmethodObj)) { // TODO: Warn if IsClassMethod is set Function.IsStatic = true; } else if (decorator.Contains(ProjectState._classmethodObj)) { // 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; types = decorator.Call(expr, this, new[] { types }, ExpressionEvaluator.EmptyNames); } } } ddg.Scope.AddLocatedVariable(Ast.Name, Ast.NameExpression, this).AddTypes(this, types); } if (!Function.IsStatic && Ast.Parameters.Count > 0) { VariableDef param; INamespaceSet firstParam; var clsScope = ddg.Scope as ClassScope; if (clsScope == null) { firstParam = Function.IsClassMethod ? ProjectState._typeObj.SelfSet : NamespaceSet.Empty; } else { firstParam = Function.IsClassMethod ? clsScope.Class.SelfSet : clsScope.Class.Instance.SelfSet; } if (Scope.Variables.TryGetValue(Ast.Parameters[0].Name, out param)) { param.AddTypes(this, firstParam, false); } } }
public override void PostWalk(CallExpression node) { PostWalkWorker(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; } }
// CallExpression public override bool Walk(CallExpression node) { return ShouldWalkWorker(node); }