[cfe-commits] r59509 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseObjc.cpp lib/Parse/ParseStmt.cpp lib/Parse/Parser.cpp
Chris Lattner
sabre at nondot.org
Mon Nov 17 23:48:38 PST 2008
Author: lattner
Date: Tue Nov 18 01:48:38 2008
New Revision: 59509
URL: http://llvm.org/viewvc/llvm-project?rev=59509&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Parse/Parser.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Nov 18 01:48:38 2008
@@ -27,6 +27,7 @@
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 @@
//===--------------------------------------------------------------------===//
// 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
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Nov 18 01:48:38 2008
@@ -533,7 +533,7 @@
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 @@
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 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
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 @@
// 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 @@
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 @@
// 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);
}
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Nov 18 01:48:38 2008
@@ -83,9 +83,8 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
// 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 @@
// 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();
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Nov 18 01:48:38 2008
@@ -270,7 +270,7 @@
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 @@
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 @@
// 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);
}
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue Nov 18 01:48:38 2008
@@ -198,17 +198,13 @@
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 @@
// 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)) ;
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Nov 18 01:48:38 2008
@@ -412,7 +412,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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::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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
/// 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 @@
/// 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();
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Tue Nov 18 01:48:38 2008
@@ -171,7 +171,7 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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;
}
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=59509&r1=59508&r2=59509&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Nov 18 01:48:38 2008
@@ -41,10 +41,12 @@
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 @@
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 @@
return false;
}
- Diag(Tok, DiagID, Msg);
+ Diag(Tok, DiagID) << Msg;
if (SkipToTok != tok::unknown)
SkipUntil(SkipToTok);
return true;
@@ -405,7 +407,7 @@
}
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 @@
// 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 @@
// 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 @@
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;
}
More information about the cfe-commits
mailing list