diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-18 07:48:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-18 07:48:38 +0000 |
commit | 1ab3b96de160e4fbffec2a776e284a48a3bb543d (patch) | |
tree | 9ab728aaab0602c9e14a93602a50d62932a74f5e | |
parent | d3b64655fa81ff1e1d5f944198239e4908035d79 (diff) |
Change a couple of the Parser::Diag methods to return DiagnosticInfo
and let the clients push whatever they want into the DiagnosticInfo
instead of hard coding a few forms. Also switch various clients to
use Diag(Tok, ...) instead of Diag(Tok.getLocation(), ...) as the
canonical form to simplify the code a bit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59509 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Parse/Parser.h | 9 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 70 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 25 | ||||
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 8 | ||||
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 14 | ||||
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 42 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 26 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 26 |
8 files changed, 105 insertions, 115 deletions
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index e6d3464c76..e6d7df5d37 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -27,6 +27,7 @@ namespace clang { class ObjCDeclSpec; class PragmaHandler; class Scope; + class DiagnosticInfo; /// Parser - This implements a parser for the C family of languages. After /// parsing units of the grammar, productions are invoked to handle whatever has @@ -312,15 +313,11 @@ private: //===--------------------------------------------------------------------===// // Diagnostic Emission and Error recovery. - bool Diag(SourceLocation Loc, unsigned DiagID, - const std::string &Msg = std::string()); + DiagnosticInfo Diag(SourceLocation Loc, unsigned DiagID); + DiagnosticInfo Diag(const Token &Tok, unsigned DiagID); bool Diag(SourceLocation Loc, unsigned DiagID, const SourceRange &R); bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, const SourceRange& R1); - bool Diag(const Token &Tok, unsigned DiagID, - const std::string &M = std::string()) { - return Diag(Tok.getLocation(), DiagID, M); - } /// SkipUntil - Read tokens until we get to the specified token, then consume /// it (unless DontConsume is true). Because we cannot guarantee that the diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 048fafbe2d..b73ee61a86 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -533,7 +533,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { break; case tok::kw_extern: if (DS.isThreadSpecified()) - Diag(Tok, diag::ext_thread_before, "extern"); + Diag(Tok, diag::ext_thread_before) << "extern"; isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec); break; case tok::kw___private_extern__: @@ -542,7 +542,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { break; case tok::kw_static: if (DS.isThreadSpecified()) - Diag(Tok, diag::ext_thread_before, "static"); + Diag(Tok, diag::ext_thread_before) << "static"; isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec); break; case tok::kw_auto: @@ -587,8 +587,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); DS.SetRangeEnd(EndProtoLoc); - Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id, - SourceRange(Loc, EndProtoLoc)); + Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id) + << SourceRange(Loc, EndProtoLoc); // Need to support trailing type qualifiers (e.g. "id<p> const"). // If a type specifier follows, it will be diagnosed elsewhere. continue; @@ -597,10 +597,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { // If the specifier combination wasn't legal, issue a diagnostic. if (isInvalid) { assert(PrevSpec && "Method did not return previous specifier!"); - if (isInvalid == 1) // Error. - Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec); - else // extwarn. - Diag(Tok, diag::ext_duplicate_declspec, PrevSpec); + // Pick between error or extwarn. + unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination + : diag::ext_duplicate_declspec; + Diag(Tok, DiagID) << PrevSpec; } DS.SetRangeEnd(Tok.getLocation()); ConsumeToken(); @@ -771,10 +771,10 @@ bool Parser::MaybeParseTypeSpecifier(DeclSpec &DS, int& isInvalid, // If the specifier combination wasn't legal, issue a diagnostic. if (isInvalid) { assert(PrevSpec && "Method did not return previous specifier!"); - if (isInvalid == 1) // Error. - Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec); - else // extwarn. - Diag(Tok, diag::ext_duplicate_declspec, PrevSpec); + // Pick between error or extwarn. + unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination + : diag::ext_duplicate_declspec; + Diag(Tok, DiagID) << PrevSpec; } DS.SetRangeEnd(Tok.getLocation()); ConsumeToken(); // whatever we parsed above. @@ -875,8 +875,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, // Empty structs are an extension in C (C99 6.7.2.1p7), but are allowed in // C++. if (Tok.is(tok::r_brace) && !getLang().CPlusPlus) - Diag(Tok, diag::ext_empty_struct_union_enum, - DeclSpec::getSpecifierName((DeclSpec::TST)TagType)); + Diag(Tok, diag::ext_empty_struct_union_enum) + << DeclSpec::getSpecifierName((DeclSpec::TST)TagType); llvm::SmallVector<DeclTy*, 32> FieldDecls; llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; @@ -932,7 +932,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, if (Tok.is(tok::semi)) { ConsumeToken(); } else if (Tok.is(tok::r_brace)) { - Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list); + Diag(Tok, diag::ext_expected_semi_decl_list); break; } else { Diag(Tok, diag::err_expected_semi_decl_list); @@ -1033,7 +1033,7 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS) { // TODO: semantic analysis on the declspec for enums. const char *PrevSpec = 0; if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, TagDecl)) - Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); + Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } /// ParseEnumBody - Parse a {} enclosed enumerator-list. @@ -1051,7 +1051,7 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) { // C does not allow an empty enumerator-list, C++ does [dcl.enum]. if (Tok.is(tok::r_brace) && !getLang().CPlusPlus) - Diag(Tok, diag::ext_empty_struct_union_enum, "enum"); + Diag(Tok, diag::ext_empty_struct_union_enum) << "enum"; llvm::SmallVector<DeclTy*, 32> EnumConstantDecls; @@ -1277,10 +1277,10 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) { // If the specifier combination wasn't legal, issue a diagnostic. if (isInvalid) { assert(PrevSpec && "Method did not return previous specifier!"); - if (isInvalid == 1) // Error. - Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec); - else // extwarn. - Diag(Tok, diag::ext_duplicate_declspec, PrevSpec); + // Pick between error or extwarn. + unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination + : diag::ext_duplicate_declspec; + Diag(Tok, DiagID) << PrevSpec; } ConsumeToken(); } @@ -1359,12 +1359,10 @@ void Parser::ParseDeclaratorInternal(Declarator &D, bool PtrOperator) { if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) { if (DS.getTypeQualifiers() & DeclSpec::TQ_const) Diag(DS.getConstSpecLoc(), - diag::err_invalid_reference_qualifier_application, - "const"); + diag::err_invalid_reference_qualifier_application) << "const"; if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile) Diag(DS.getVolatileSpecLoc(), - diag::err_invalid_reference_qualifier_application, - "volatile"); + diag::err_invalid_reference_qualifier_application) << "volatile"; } // Recursively parse the declarator. @@ -1374,8 +1372,8 @@ void Parser::ParseDeclaratorInternal(Declarator &D, bool PtrOperator) { // C++ [dcl.ref]p4: There shall be no references to references. DeclaratorChunk& InnerChunk = D.getTypeObject(D.getNumTypeObjects() - 1); if (InnerChunk.Kind == DeclaratorChunk::Reference) { - Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference, - D.getIdentifier() ? D.getIdentifier()->getName() : "type name"); + Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference) + << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name"); // Once we've complained about the reference-to-referwnce, we // can go ahead and build the (technically ill-formed) @@ -1483,7 +1481,7 @@ void Parser::ParseDirectDeclarator(Declarator &D) { if (getLang().CPlusPlus) Diag(Tok, diag::err_expected_unqualified_id); else - Diag(Tok, diag::err_expected_ident_lparen); // Expected identifier or '('. + Diag(Tok, diag::err_expected_ident_lparen); D.SetIdentifier(0, Tok.getLocation()); D.setInvalidType(true); } @@ -1636,7 +1634,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, // This parameter list may be empty. if (Tok.is(tok::r_paren)) { if (RequiresArg) { - Diag(Tok.getLocation(), diag::err_argument_required_after_attribute); + Diag(Tok, diag::err_argument_required_after_attribute); delete AttrList; } @@ -1666,7 +1664,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, // C99 6.7.5.3p11. !Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) { if (RequiresArg) { - Diag(Tok.getLocation(), diag::err_argument_required_after_attribute); + Diag(Tok, diag::err_argument_required_after_attribute); delete AttrList; } @@ -1834,11 +1832,11 @@ void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, // Reject 'typedef int y; int test(x, y)', but continue parsing. if (Actions.isTypeName(*ParmII, CurScope)) - Diag(Tok, diag::err_unexpected_typedef_ident, ParmII->getName()); + Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII->getName(); // Verify that the argument identifier has not already been mentioned. if (!ParamsSoFar.insert(ParmII)) { - Diag(Tok.getLocation(), diag::err_param_redefinition, ParmII->getName()); + Diag(Tok, diag::err_param_redefinition) <<ParmII->getName(); } else { // Remember this identifier in ParamInfo. ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, @@ -1938,7 +1936,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { if (Tok.isNot(tok::l_paren)) { if (!getLang().CPlusPlus) { - Diag(Tok, diag::err_expected_lparen_after, BuiltinII->getName()); + Diag(Tok, diag::err_expected_lparen_after) << BuiltinII->getName(); return; } @@ -1950,7 +1948,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { // Check for duplicate type specifiers. if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, Result.Val)) - Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); + Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; // FIXME: Not accurate, the range gets one token more than it should. DS.SetRangeEnd(Tok.getLocation()); @@ -1972,7 +1970,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { const char *PrevSpec = 0; // Check for duplicate type specifiers (e.g. "int typeof(int)"). if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, Ty)) - Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); + Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } else { // we have an expression. ExprResult Result = ParseExpression(); @@ -1985,7 +1983,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { // Check for duplicate type specifiers (e.g. "int typeof(int)"). if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, Result.Val)) - Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); + Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } DS.SetRangeEnd(RParenLoc); } diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 48ced22723..560edc131b 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -83,9 +83,8 @@ Parser::DeclTy *Parser::ParseNamespace(unsigned Context) { return NamespcDecl; } else { - unsigned D = Ident ? diag::err_expected_lbrace : - diag::err_expected_ident_lbrace; - Diag(Tok.getLocation(), D); + Diag(Tok, Ident ? diag::err_expected_lbrace : + diag::err_expected_ident_lbrace); } return 0; @@ -142,14 +141,14 @@ Parser::TypeTy *Parser::ParseClassName(const CXXScopeSpec *SS) { // Parse the class-name. // FIXME: Alternatively, parse a simple-template-id. if (Tok.isNot(tok::identifier)) { - Diag(Tok.getLocation(), diag::err_expected_class_name); + Diag(Tok, diag::err_expected_class_name); return 0; } // We have an identifier; check whether it is actually a type. TypeTy *Type = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, SS); if (!Type) { - Diag(Tok.getLocation(), diag::err_expected_class_name); + Diag(Tok, diag::err_expected_class_name); return 0; } @@ -247,8 +246,8 @@ void Parser::ParseClassSpecifier(DeclSpec &DS) { if (!Name && TK != Action::TK_Definition) { // We have a declaration or reference to an anonymous class. - Diag(StartLoc, diag::err_anon_type_definition, - DeclSpec::getSpecifierName(TagType)); + Diag(StartLoc, diag::err_anon_type_definition) + << DeclSpec::getSpecifierName(TagType); // Skip the rest of this declarator, up until the comma or semicolon. SkipUntil(tok::comma, true); @@ -273,12 +272,12 @@ void Parser::ParseClassSpecifier(DeclSpec &DS) { else if (TK == Action::TK_Definition) { // FIXME: Complain that we have a base-specifier list but no // definition. - Diag(Tok.getLocation(), diag::err_expected_lbrace); + Diag(Tok, diag::err_expected_lbrace); } const char *PrevSpec = 0; if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, TagDecl)) - Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); + Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. @@ -353,8 +352,8 @@ Parser::BaseResult Parser::ParseBaseSpecifier(DeclTy *ClassDecl) SourceLocation VirtualLoc = ConsumeToken(); if (IsVirtual) { // Complain about duplicate 'virtual' - Diag(VirtualLoc, diag::err_dup_virtual, - SourceRange(VirtualLoc, VirtualLoc)); + Diag(VirtualLoc, diag::err_dup_virtual) + << SourceRange(VirtualLoc, VirtualLoc); } IsVirtual = true; @@ -731,7 +730,7 @@ Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) { // FIXME: parse '::'[opt] nested-name-specifier[opt] if (Tok.isNot(tok::identifier)) { - Diag(Tok.getLocation(), diag::err_expected_member_or_base_name); + Diag(Tok, diag::err_expected_member_or_base_name); return true; } @@ -742,7 +741,7 @@ Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) { // Parse the '('. if (Tok.isNot(tok::l_paren)) { - Diag(Tok.getLocation(), diag::err_expected_lparen); + Diag(Tok, diag::err_expected_lparen); return true; } SourceLocation LParenLoc = ConsumeParen(); diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 467eef03b6..32a7c0a060 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -270,7 +270,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) { if (Tok.isNot(tok::colon)) { Diag(Tok, diag::err_expected_colon); - Diag(OpToken, diag::err_matching, "?"); + Diag(OpToken, diag::err_matching) << "?"; Actions.DeleteExpr(LHS.Val); Actions.DeleteExpr(TernaryMiddle.Val); return ExprResult(true); @@ -599,8 +599,8 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { DeclSpec DS; ParseCXXSimpleTypeSpecifier(DS); if (Tok.isNot(tok::l_paren)) - return Diag(Tok.getLocation(), diag::err_expected_lparen_after_type, - DS.getSourceRange()); + return Diag(Tok, diag::err_expected_lparen_after_type) + << DS.getSourceRange(); Res = ParseCXXTypeConstructExpression(DS); // This can be followed by postfix-expr pieces. @@ -808,7 +808,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { // All of these start with an open paren. if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, BuiltinII->getName()); + Diag(Tok, diag::err_expected_lparen_after) << BuiltinII->getName(); return ExprResult(true); } diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 19b521b264..006c79158a 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -198,17 +198,13 @@ Parser::ExprResult Parser::ParseCXXCasts() { TypeTy *CastTy = ParseTypeName(); SourceLocation RAngleBracketLoc = Tok.getLocation(); - if (ExpectAndConsume(tok::greater, diag::err_expected_greater)) { - Diag(LAngleBracketLoc, diag::err_matching, "<"); - return ExprResult(true); - } + if (ExpectAndConsume(tok::greater, diag::err_expected_greater)) + return Diag(LAngleBracketLoc, diag::err_matching) << "<"; SourceLocation LParenLoc = Tok.getLocation(), RParenLoc; - if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, CastName); - return ExprResult(true); - } + if (Tok.isNot(tok::l_paren)) + return Diag(Tok, diag::err_expected_lparen_after) << CastName; ExprResult Result = ParseSimpleParenExpression(RParenLoc); @@ -515,7 +511,7 @@ bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { // Parse one or more of the type specifiers. if (!MaybeParseTypeSpecifier(DS, isInvalid, PrevSpec)) { - Diag(Tok.getLocation(), diag::err_operator_missing_type_specifier); + Diag(Tok, diag::err_operator_missing_type_specifier); return true; } while (MaybeParseTypeSpecifier(DS, isInvalid, PrevSpec)) ; diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index f6d77cfb50..45ce3e1d92 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -412,7 +412,7 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { return; if (Tok.isNot(tok::identifier)) { - Diag(Tok.getLocation(), diag::err_expected_ident); + Diag(Tok, diag::err_expected_ident); SkipUntil(tok::r_paren); return; } @@ -431,7 +431,7 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { ConsumeToken(); // consume method name } } else { - Diag(AttrName, diag::err_objc_expected_property_attr, II->getName()); + Diag(AttrName, diag::err_objc_expected_property_attr) << II->getName(); SkipUntil(tok::r_paren); return; } @@ -625,7 +625,7 @@ Parser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { ConsumeParen(); else if (Tok.getLocation() == TypeStartLoc) { // If we didn't eat any tokens, then this isn't a type. - Diag(Tok.getLocation(), diag::err_expected_type); + Diag(Tok, diag::err_expected_type); SkipUntil(tok::r_paren); } else { // Otherwise, we found *something*, but didn't get a ')' in the right @@ -678,8 +678,8 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, IdentifierInfo *SelIdent = ParseObjCSelector(selLoc); if (!SelIdent) { // missing selector name. - Diag(Tok.getLocation(), diag::err_expected_selector_for_method, - SourceRange(mLoc, Tok.getLocation())); + Diag(Tok, diag::err_expected_selector_for_method) + << SourceRange(mLoc, Tok.getLocation()); // Skip until we get a ; or {}. SkipUntil(tok::r_brace); return 0; @@ -1089,7 +1089,7 @@ Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { IdentifierInfo *classId = Tok.getIdentifierInfo(); SourceLocation classLoc = ConsumeToken(); // consume class-name; if (Tok.isNot(tok::semi)) { - Diag(Tok, diag::err_expected_semi_after, "@compatibility_alias"); + Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; return 0; } DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, @@ -1138,7 +1138,7 @@ Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { ConsumeToken(); // consume ',' } if (Tok.isNot(tok::semi)) - Diag(Tok, diag::err_expected_semi_after, "@synthesize"); + Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; return 0; } @@ -1168,7 +1168,7 @@ Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { ConsumeToken(); // consume ',' } if (Tok.isNot(tok::semi)) - Diag(Tok, diag::err_expected_semi_after, "@dynamic"); + Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; return 0; } @@ -1195,7 +1195,7 @@ Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { Parser::StmtResult Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { ConsumeToken(); // consume synchronized if (Tok.isNot(tok::l_paren)) { - Diag (Tok, diag::err_expected_lparen_after, "@synchronized"); + Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; return true; } ConsumeParen(); // '(' @@ -1205,12 +1205,12 @@ Parser::StmtResult Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { return true; } if (Tok.isNot(tok::r_paren)) { - Diag (Tok, diag::err_expected_lbrace); + Diag(Tok, diag::err_expected_lbrace); return true; } ConsumeParen(); // ')' if (Tok.isNot(tok::l_brace)) { - Diag (Tok, diag::err_expected_lbrace); + Diag(Tok, diag::err_expected_lbrace); return true; } // Enter a scope to hold everything within the compound stmt. Compound @@ -1241,7 +1241,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { ConsumeToken(); // consume try if (Tok.isNot(tok::l_brace)) { - Diag (Tok, diag::err_expected_lbrace); + Diag(Tok, diag::err_expected_lbrace); return true; } StmtResult CatchStmts; @@ -1299,8 +1299,8 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { FirstPart, CatchBody.Val, CatchStmts.Val); ExitScope(); } else { - Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after, - "@catch clause"); + Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) + << "@catch clause"; return true; } catch_or_finally_seen = true; @@ -1411,7 +1411,7 @@ Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { case tok::objc_selector: return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); default: - return Diag(AtLoc, diag::err_unexpected_at); + return Diag(AtLoc, diag::err_unexpected_at); } } } @@ -1604,7 +1604,7 @@ Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { SourceLocation EncLoc = ConsumeToken(); if (Tok.isNot(tok::l_paren)) - return Diag(Tok, diag::err_expected_lparen_after, "@encode"); + return Diag(Tok, diag::err_expected_lparen_after) << "@encode"; SourceLocation LParenLoc = ConsumeParen(); @@ -1619,12 +1619,11 @@ Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { /// objc-protocol-expression /// @protocol ( protocol-name ) -Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) -{ +Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { SourceLocation ProtoLoc = ConsumeToken(); if (Tok.isNot(tok::l_paren)) - return Diag(Tok, diag::err_expected_lparen_after, "@protocol"); + return Diag(Tok, diag::err_expected_lparen_after) << "@protocol"; SourceLocation LParenLoc = ConsumeParen(); @@ -1642,12 +1641,11 @@ Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) /// objc-selector-expression /// @selector '(' objc-keyword-selector ')' -Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) -{ +Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { SourceLocation SelectorLoc = ConsumeToken(); if (Tok.isNot(tok::l_paren)) - return Diag(Tok, diag::err_expected_lparen_after, "@selector"); + return Diag(Tok, diag::err_expected_lparen_after) << "@selector"; llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; SourceLocation LParenLoc = ConsumeParen(); diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 30c62e3a3c..49b8180904 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -171,7 +171,7 @@ Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) { if (Tok.is(tok::semi)) { ConsumeToken(); } else if (!Res.isInvalid) { - Diag(Tok, diag::err_expected_semi_after, SemiError); + Diag(Tok, diag::err_expected_semi_after) << SemiError; // Skip until we see a } or ;, but don't eat it. SkipUntil(tok::r_brace, true, true); } @@ -246,7 +246,7 @@ Parser::StmtResult Parser::ParseCaseStatement() { } if (Tok.isNot(tok::colon)) { - Diag(Tok, diag::err_expected_colon_after, "'case'"); + Diag(Tok, diag::err_expected_colon_after) << "'case'"; SkipUntil(tok::colon); return true; } @@ -279,7 +279,7 @@ Parser::StmtResult Parser::ParseDefaultStatement() { SourceLocation DefaultLoc = ConsumeToken(); // eat the 'default'. if (Tok.isNot(tok::colon)) { - Diag(Tok, diag::err_expected_colon_after, "'default'"); + Diag(Tok, diag::err_expected_colon_after) << "'default'"; SkipUntil(tok::colon); return true; } @@ -424,7 +424,7 @@ Parser::StmtResult Parser::ParseIfStatement() { SourceLocation IfLoc = ConsumeToken(); // eat the 'if'. if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "if"); + Diag(Tok, diag::err_expected_lparen_after) << "if"; SkipUntil(tok::semi); return true; } @@ -552,7 +552,7 @@ Parser::StmtResult Parser::ParseSwitchStatement() { SourceLocation SwitchLoc = ConsumeToken(); // eat the 'switch'. if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "switch"); + Diag(Tok, diag::err_expected_lparen_after) << "switch"; SkipUntil(tok::semi); return true; } @@ -633,7 +633,7 @@ Parser::StmtResult Parser::ParseWhileStatement() { ConsumeToken(); // eat the 'while'. if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "while"); + Diag(Tok, diag::err_expected_lparen_after) << "while"; SkipUntil(tok::semi); return true; } @@ -732,7 +732,7 @@ Parser::StmtResult Parser::ParseDoStatement() { ExitScope(); if (!Body.isInvalid) { Diag(Tok, diag::err_expected_while); - Diag(DoLoc, diag::err_matching, "do"); + Diag(DoLoc, diag::err_matching) << "do"; SkipUntil(tok::semi, false, true); } return true; @@ -741,7 +741,7 @@ Parser::StmtResult Parser::ParseDoStatement() { if (Tok.isNot(tok::l_paren)) { ExitScope(); - Diag(Tok, diag::err_expected_lparen_after, "do/while"); + Diag(Tok, diag::err_expected_lparen_after) << "do/while"; SkipUntil(tok::semi, false, true); return true; } @@ -774,7 +774,7 @@ Parser::StmtResult Parser::ParseForStatement() { SourceLocation ForLoc = ConsumeToken(); // eat the 'for'. if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "for"); + Diag(Tok, diag::err_expected_lparen_after) << "for"; SkipUntil(tok::semi); return true; } @@ -1064,15 +1064,15 @@ Parser::StmtResult Parser::ParseAsmStatement(bool &msAsm) { // GNU asms accept, but warn, about type-qualifiers other than volatile. if (DS.getTypeQualifiers() & DeclSpec::TQ_const) - Diag(Loc, diag::w_asm_qualifier_ignored, "const"); + Diag(Loc, diag::w_asm_qualifier_ignored) << "const"; if (DS.getTypeQualifiers() & DeclSpec::TQ_restrict) - Diag(Loc, diag::w_asm_qualifier_ignored, "restrict"); + Diag(Loc, diag::w_asm_qualifier_ignored) << "restrict"; // Remember if this was a volatile asm. bool isVolatile = DS.getTypeQualifiers() & DeclSpec::TQ_volatile; bool isSimple = false; if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "asm"); + Diag(Tok, diag::err_expected_lparen_after) << "asm"; SkipUntil(tok::r_paren); return true; } @@ -1191,7 +1191,7 @@ bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names, Constraints.push_back(Constraint.Val); if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "asm operand"); + Diag(Tok, diag::err_expected_lparen_after) << "asm operand"; SkipUntil(tok::r_paren); return true; } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index a9ce22d047..d0d1871829 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -41,10 +41,12 @@ Parser::Parser(Preprocessor &pp, Action &actions) Action::~Action() {} -bool Parser::Diag(SourceLocation Loc, unsigned DiagID, - const std::string &Msg) { - Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID) << Msg; - return true; +DiagnosticInfo Parser::Diag(SourceLocation Loc, unsigned DiagID) { + return Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID); +} + +DiagnosticInfo Parser::Diag(const Token &Tok, unsigned DiagID) { + return Diag(Tok.getLocation(), DiagID); } bool Parser::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, @@ -81,7 +83,7 @@ SourceLocation Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, case tok::greater: LHSName = "<"; DID = diag::err_expected_greater; break; } Diag(Tok, DID); - Diag(LHSLoc, diag::err_matching, LHSName); + Diag(LHSLoc, diag::err_matching) << LHSName; SkipUntil(RHSTok); return R; } @@ -99,7 +101,7 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID, return false; } - Diag(Tok, DiagID, Msg); + Diag(Tok, DiagID) << Msg; if (SkipToTok != tok::unknown) SkipUntil(SkipToTok); return true; @@ -405,7 +407,7 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() { } const char *PrevSpec = 0; if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec)) - Diag(AtLoc, diag::err_invalid_decl_spec_combination, PrevSpec); + Diag(AtLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; if (Tok.isObjCAtKeyword(tok::objc_protocol)) return ParseObjCAtProtocolDeclaration(AtLoc, DS.getAttributes()); return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()); @@ -609,8 +611,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // C99 6.9.1p6: those declarators shall declare only identifiers from // the identifier list. if (i == FTI.NumArgs) { - Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param, - ParmDeclarator.getIdentifier()->getName()); + Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param) + << ParmDeclarator.getIdentifier()->getName(); break; } @@ -618,8 +620,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // Reject redefinitions of parameters. if (FTI.ArgInfo[i].Param) { Diag(ParmDeclarator.getIdentifierLoc(), - diag::err_param_redefinition, - ParmDeclarator.getIdentifier()->getName()); + diag::err_param_redefinition) + << ParmDeclarator.getIdentifier()->getName(); } else { FTI.ArgInfo[i].Param = Param; } @@ -689,7 +691,7 @@ Parser::ExprResult Parser::ParseSimpleAsm() { SourceLocation Loc = ConsumeToken(); if (Tok.isNot(tok::l_paren)) { - Diag(Tok, diag::err_expected_lparen_after, "asm"); + Diag(Tok, diag::err_expected_lparen_after) << "asm"; return true; } |