/// ParseTypeConstructorExpression - Parses a type constructor. ExprResult Parser::ParseTypeConstructor(SourceLocation IDLoc, RecordDecl *Record) { SmallVector<Expr*, 8> Arguments; SourceLocation RParenLoc = IDLoc; auto LParenLoc = Tok.getLocation(); auto E = ParseFunctionCallArgumentList(Arguments, RParenLoc); if(E.isInvalid()) return ExprError(); return Actions.ActOnTypeConstructorExpr(Context, IDLoc, LParenLoc, RParenLoc, Record, Arguments); }
/// ParseCallExpression - Parse a call expression ExprResult Parser::ParseCallExpression(SourceLocation IDLoc, FunctionDecl *Function) { SmallVector<Expr*, 8> Arguments; auto Loc = Tok.getLocation(); SourceLocation RParenLoc = Loc; auto Result = ParseFunctionCallArgumentList(Arguments, RParenLoc); if(Result.isInvalid()) return ExprError(); return Actions.ActOnCallExpr(Context, Loc, RParenLoc, IDLoc, Function, Arguments); }
Parser::StmtResult Parser::ParseCallStmt() { auto Loc = ConsumeToken(); SourceLocation RParenLoc = getExpectedLoc(); auto ID = Tok.getIdentifierInfo(); auto IDLoc = Tok.getLocation(); if(!ExpectAndConsume(tok::identifier)) return StmtError(); SmallVector<Expr*, 8> Arguments; if(!Tok.isAtStartOfStatement()) { if(ParseFunctionCallArgumentList(Arguments, RParenLoc).isInvalid()) SkipUntilNextStatement(); } return Actions.ActOnCallStmt(Context, Loc, RParenLoc, IDLoc, ID, Arguments, StmtLabel); }
/// ParseNameOrCall - Parse a name or a call expression ExprResult Parser::ParseNameOrCall() { auto IDInfo = Tok.getIdentifierInfo(); assert(IDInfo && "Token isn't an identifier"); auto IDRange = getTokenRange(); auto IDLoc = ConsumeToken(); if(DontResolveIdentifiers) return UnresolvedIdentifierExpr::Create(Context, IDRange, IDInfo); // [R504]: // object-name := // name auto Declaration = Actions.ResolveIdentifier(IDInfo); if(!Declaration) { if(IsPresent(tok::l_paren)) Declaration = Actions.ActOnImplicitFunctionDecl(Context, IDLoc, IDInfo); else Declaration = Actions.ActOnImplicitEntityDecl(Context, IDLoc, IDInfo); if(!Declaration) return ExprError(); } else { // INTEGER f // X = f(10) <-- implicit function declaration. if(IsPresent(tok::l_paren)) Declaration = Actions.ActOnPossibleImplicitFunctionDecl(Context, IDLoc, IDInfo, Declaration); } if(VarDecl *VD = dyn_cast<VarDecl>(Declaration)) { // FIXME: function returing array if(IsPresent(tok::l_paren) && VD->isFunctionResult() && isa<FunctionDecl>(Actions.CurContext)) { // FIXME: accessing function results from inner recursive functions return ParseRecursiveCallExpression(IDRange); } // the VarDecl is obtained from a NamedDecl which does not have a type // apply implicit typing rules in case VD does not have a type // FIXME: there should be a way to avoid re-applying the implicit rules // by returning a VarDecl instead of a NamedDecl when looking up a name in // the scope if (VD->getType().isNull()) Actions.ApplyImplicitRulesToArgument(VD,IDRange); return VarExpr::Create(Context, IDRange, VD); } else if(IntrinsicFunctionDecl *IFunc = dyn_cast<IntrinsicFunctionDecl>(Declaration)) { SmallVector<Expr*, 8> Arguments; SourceLocation RParenLoc = Tok.getLocation(); auto Result = ParseFunctionCallArgumentList(Arguments, RParenLoc); if(Result.isInvalid()) return ExprError(); return Actions.ActOnIntrinsicFunctionCallExpr(Context, IDLoc, IFunc, Arguments); } else if(FunctionDecl *Func = dyn_cast<FunctionDecl>(Declaration)) { // FIXME: allow subroutines, but errors in sema if(!IsPresent(tok::l_paren)) return FunctionRefExpr::Create(Context, IDRange, Func); if(!Func->isSubroutine()) { return ParseCallExpression(IDLoc, Func); } } else if(isa<SelfDecl>(Declaration) && isa<FunctionDecl>(Actions.CurContext)) return ParseRecursiveCallExpression(IDRange); else if(auto Record = dyn_cast<RecordDecl>(Declaration)) return ParseTypeConstructor(IDLoc, Record); Diag.Report(IDLoc, diag::err_expected_var); return ExprError(); }