Convert IdentifierInfo's to be printed the same as DeclarationNames
with implicit quotes around them. This has a bunch of follow-on
effects and requires tweaking to a whole lot of code. This causes
a regression in two tests (xfailed) by causing it to emit things like:
Line 10: duplicate interface declaration for category 'MyClass1' ('Category1')
instead of:
Line 10: duplicate interface declaration for category 'MyClass1(Category1)'
I will fix this in a follow-up commit.
As part of this, I had to start switching stuff to use ->getDeclName() instead
of Decl::getName() for consistency. This is good, but I was planning to do this
as an independent patch. There will be several follow-on patches
to clean up some of the mess, but this patch is already too big.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59917 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index efdb329..8547ef4 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -482,6 +482,7 @@
unsigned ArgNo = *DiagStr++ - '0';
switch (getArgKind(ArgNo)) {
+ // ---- STRINGS ----
case Diagnostic::ak_std_string: {
const std::string &S = getArgStdStr(ArgNo);
assert(ModifierLen == 0 && "No modifiers for strings yet");
@@ -494,12 +495,7 @@
OutStr.append(S, S + strlen(S));
break;
}
- case Diagnostic::ak_identifierinfo: {
- const IdentifierInfo *II = getArgIdentifier(ArgNo);
- assert(ModifierLen == 0 && "No modifiers for strings yet");
- OutStr.append(II->getName(), II->getName() + II->getLength());
- break;
- }
+ // ---- INTEGERS ----
case Diagnostic::ak_sint: {
int Val = getArgSInt(ArgNo);
@@ -535,6 +531,15 @@
}
break;
}
+ // ---- NAMES and TYPES ----
+ case Diagnostic::ak_identifierinfo: {
+ OutStr.push_back('\'');
+ const IdentifierInfo *II = getArgIdentifier(ArgNo);
+ assert(ModifierLen == 0 && "No modifiers for strings yet");
+ OutStr.append(II->getName(), II->getName() + II->getLength());
+ OutStr.push_back('\'');
+ break;
+ }
case Diagnostic::ak_qualtype:
case Diagnostic::ak_declarationname:
OutStr.push_back('\'');
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 0a7d2db..2a33531 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -977,7 +977,7 @@
if (!MI->isIdenticalTo(*OtherMI, *this)) {
Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef)
<< MacroNameTok.getIdentifierInfo();
- Diag(OtherMI->getDefinitionLoc(), diag::ext_pp_macro_redef2);
+ Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
}
delete OtherMI;
}
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 3262c0d..1b5a0a5 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1945,7 +1945,7 @@
if (Tok.isNot(tok::l_paren)) {
if (!getLang().CPlusPlus) {
- Diag(Tok, diag::err_expected_lparen_after) << BuiltinII;
+ Diag(Tok, diag::err_expected_lparen_after_id) << BuiltinII;
return;
}
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 9f9b306..21b3dac 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -829,7 +829,7 @@
// All of these start with an open paren.
if (Tok.isNot(tok::l_paren)) {
- Diag(Tok, diag::err_expected_lparen_after) << BuiltinII;
+ Diag(Tok, diag::err_expected_lparen_after_id) << BuiltinII;
return ExprResult(true);
}
diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp
index d7ecbfa..17eba03 100644
--- a/lib/Parse/ParsePragma.cpp
+++ b/lib/Parse/ParsePragma.cpp
@@ -45,13 +45,13 @@
PP.Lex(Tok);
} else if (Tok.is(tok::identifier)) {
const IdentifierInfo *II = Tok.getIdentifierInfo();
- if (II == &PP.getIdentifierTable().get("show")) {
+ if (II->isStr("show")) {
Kind = Action::PPK_Show;
PP.Lex(Tok);
} else {
- if (II == &PP.getIdentifierTable().get("push")) {
+ if (II->isStr("push")) {
Kind = Action::PPK_Push;
- } else if (II == &PP.getIdentifierTable().get("pop")) {
+ } else if (II->isStr("pop")) {
Kind = Action::PPK_Pop;
} else {
PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_invalid_action);
@@ -76,7 +76,7 @@
PP.Lex(Tok);
if (Tok.isNot(tok::numeric_constant)) {
- PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed)<<II;
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
return;
}
@@ -87,7 +87,7 @@
PP.Lex(Tok);
}
} else {
- PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed) << II;
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
return;
}
}
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 0947445..09f6efb 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -719,7 +719,7 @@
if (lhsType->isPointerType() || lhsType->isBlockPointerType()) {
if (DeclRefExpr *DR = EvalAddr(RetValExp))
Diag(DR->getLocStart(), diag::warn_ret_stack_addr)
- << DR->getDecl()->getIdentifier() << RetValExp->getSourceRange();
+ << DR->getDecl()->getDeclName() << RetValExp->getSourceRange();
// Skip over implicit cast expressions when checking for block expressions.
if (ImplicitCastExpr *IcExpr =
@@ -735,8 +735,7 @@
// Check for a reference to the stack
if (DeclRefExpr *DR = EvalVal(RetValExp))
Diag(DR->getLocStart(), diag::warn_ret_stack_ref)
- << DR->getDecl()->getIdentifier()
- << RetValExp->getSourceRange();
+ << DR->getDecl()->getDeclName() << RetValExp->getSourceRange();
}
}
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index fba9f33..c3b1302 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -325,7 +325,7 @@
TypedefDecl *Old = dyn_cast<TypedefDecl>(OldD);
if (!Old) {
Diag(New->getLocation(), diag::err_redefinition_different_kind)
- << New->getName();
+ << New->getDeclName();
Diag(OldD->getLocation(), diag::err_previous_definition);
return New;
}
@@ -364,7 +364,7 @@
return New;
}
- Diag(New->getLocation(), diag::err_redefinition) << New->getName();
+ Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName();
Diag(Old->getLocation(), diag::err_previous_definition);
return New;
}
@@ -418,7 +418,7 @@
FunctionDecl *Old = dyn_cast<FunctionDecl>(OldD);
if (!Old) {
Diag(New->getLocation(), diag::err_redefinition_different_kind)
- << New->getName();
+ << New->getDeclName();
Diag(OldD->getLocation(), diag::err_previous_definition);
return New;
}
@@ -537,7 +537,7 @@
OldDecl->getStorageClass() != VarDecl::PrivateExtern &&
VD->getStorageClass() != VarDecl::Extern &&
VD->getStorageClass() != VarDecl::PrivateExtern) {
- Diag(VD->getLocation(), diag::err_redefinition) << VD->getName();
+ Diag(VD->getLocation(), diag::err_redefinition) << VD->getDeclName();
Diag(OldDecl->getLocation(), diag::err_previous_definition);
}
}
@@ -557,7 +557,7 @@
VarDecl *Old = dyn_cast<VarDecl>(OldD);
if (!Old) {
Diag(New->getLocation(), diag::err_redefinition_different_kind)
- << New->getName();
+ << New->getDeclName();
Diag(OldD->getLocation(), diag::err_previous_definition);
return New;
}
@@ -568,7 +568,7 @@
QualType OldCType = Context.getCanonicalType(Old->getType());
QualType NewCType = Context.getCanonicalType(New->getType());
if (OldCType != NewCType && !Context.typesAreCompatible(OldCType, NewCType)) {
- Diag(New->getLocation(), diag::err_redefinition) << New->getName();
+ Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName();
Diag(Old->getLocation(), diag::err_previous_definition);
return New;
}
@@ -589,7 +589,7 @@
}
// Variables with external linkage are analyzed in FinalizeDeclaratorGroup.
if (New->getStorageClass() != VarDecl::Extern && !New->isFileVarDecl()) {
- Diag(New->getLocation(), diag::err_redefinition) << New->getName();
+ Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName();
Diag(Old->getLocation(), diag::err_previous_definition);
}
return New;
@@ -849,7 +849,7 @@
if (PrevDecl == 0) {
// No previous declaration in the qualifying scope.
Diag(D.getIdentifierLoc(), diag::err_typecheck_no_member)
- << Name.getAsString() << D.getCXXScopeSpec().getRange();
+ << Name << D.getCXXScopeSpec().getRange();
} else if (!CurContext->Encloses(DC)) {
// The qualifying scope doesn't enclose the original declaration.
// Emit diagnostic based on current scope.
@@ -1987,8 +1987,7 @@
IdentifierInfo *II = D.getIdentifier();
if (Decl *PrevDecl = LookupDecl(II, Decl::IDNS_Ordinary, S)) {
if (S->isDeclScope(PrevDecl)) {
- Diag(D.getIdentifierLoc(), diag::err_param_redefinition)
- << cast<NamedDecl>(PrevDecl)->getName();
+ Diag(D.getIdentifierLoc(), diag::err_param_redefinition) << II;
// Recover by removing the name
II = 0;
@@ -2076,7 +2075,7 @@
// See if this is a redefinition.
const FunctionDecl *Definition;
if (FD->getBody(Definition)) {
- Diag(FD->getLocation(), diag::err_redefinition) << FD->getName();
+ Diag(FD->getLocation(), diag::err_redefinition) << FD->getDeclName();
Diag(Definition->getLocation(), diag::err_previous_definition);
}
@@ -2804,7 +2803,7 @@
/// A field cannot be an Objective-c object
if (FDTy->isObjCInterfaceType()) {
Diag(FD->getLocation(), diag::err_statically_allocated_object)
- << FD->getName();
+ << FD->getDeclName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index e4811df..ce63d13 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -274,7 +274,7 @@
if (!FD->getType()->isIncompleteType() &&
S.Context.getTypeAlign(FD->getType()) <= 8)
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
- << Attr.getName() << FD->getType().getAsString();
+ << Attr.getName() << FD->getType();
else
FD->addAttr(new PackedAttr(1));
} else
@@ -533,8 +533,7 @@
else if (TypeLen == 9 && !memcmp(TypeStr, "protected", 9))
type = VisibilityAttr::ProtectedVisibility;
else {
- S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
- << "visibility" << TypeStr;
+ S.Diag(Attr.getLoc(), diag::warn_attribute_unknown_visibility) << TypeStr;
return;
}
@@ -1142,8 +1141,7 @@
default:
#if 0
// TODO: when we have the full set of attributes, warn about unknown ones.
- S.Diag(Attr->getLoc(), diag::warn_attribute_ignored)
- << Attr->getName()->getName();
+ S.Diag(Attr->getLoc(), diag::warn_attribute_ignored) << Attr->getName();
#endif
break;
}
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index d65d6ff..a92ad95 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -75,7 +75,7 @@
// class member names.
return S->Diag(DRE->getSourceRange().getBegin(),
diag::err_param_default_argument_references_param)
- << Param->getName() << DefaultArg->getSourceRange();
+ << Param->getDeclName() << DefaultArg->getSourceRange();
} else if (VarDecl *VDecl = dyn_cast<VarDecl>(Decl)) {
// C++ [dcl.fct.default]p7
// Local variables shall not be used in default argument
@@ -83,7 +83,7 @@
if (VDecl->isBlockVarDecl())
return S->Diag(DRE->getSourceRange().getBegin(),
diag::err_param_default_argument_references_local)
- << VDecl->getName() << DefaultArg->getSourceRange();
+ << VDecl->getDeclName() << DefaultArg->getSourceRange();
}
return false;
@@ -650,7 +650,7 @@
QualType BaseType = Context.getTypeDeclType((TypeDecl *)BaseTy);
if (!BaseType->isRecordType())
return Diag(IdLoc, diag::err_base_init_does_not_name_class)
- << BaseType.getAsString() << SourceRange(IdLoc, RParenLoc);
+ << BaseType << SourceRange(IdLoc, RParenLoc);
// C++ [class.base.init]p2:
// [...] Unless the mem-initializer-id names a nonstatic data
@@ -1271,7 +1271,7 @@
} else {
// This is an invalid name redefinition.
Diag(Namespc->getLocation(), diag::err_redefinition_different_kind)
- << Namespc->getName();
+ << Namespc->getDeclName();
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
Namespc->setInvalidDecl();
// Continue on to push Namespc as current DeclContext and return it.
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index bac4831..49bfad7 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -111,7 +111,7 @@
<< SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);
else if (SuperClassEntry->isForwardDecl())
Diag(SuperLoc, diag::err_undef_superclass)
- << SuperClassEntry->getName() << ClassName
+ << SuperClassEntry->getDeclName() << ClassName
<< SourceRange(AtInterfaceLoc, ClassLoc);
}
IDecl->setSuperClass(SuperClassEntry);
@@ -481,7 +481,7 @@
// This implementation and its interface do not have the same
// super class.
Diag(SuperClassLoc, diag::err_conflicting_super_class)
- << SDecl->getName();
+ << SDecl->getDeclName();
Diag(SDecl->getLocation(), diag::err_previous_definition);
}
}
@@ -553,17 +553,16 @@
if (Context.getCanonicalType(ImplIvar->getType()) !=
Context.getCanonicalType(ClsIvar->getType())) {
Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type)
- << ImplIvar->getIdentifier();
- Diag(ClsIvar->getLocation(), diag::err_previous_definition)
- << ClsIvar->getIdentifier();
+ << ImplIvar->getIdentifier()
+ << ImplIvar->getType() << ClsIvar->getType();
+ Diag(ClsIvar->getLocation(), diag::err_previous_definition);
}
// TODO: Two mismatched (unequal width) Ivar bitfields should be diagnosed
// as error.
else if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) {
Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name)
- << ImplIvar->getIdentifier();
- Diag(ClsIvar->getLocation(), diag::err_previous_definition)
- << ClsIvar->getIdentifier();
+ << ImplIvar->getIdentifier() << ClsIvar->getIdentifier();
+ Diag(ClsIvar->getLocation(), diag::err_previous_definition);
return;
}
--numIvars;
@@ -581,7 +580,7 @@
Diag(ImpLoc, diag::warn_incomplete_impl);
IncompleteImpl = true;
}
- Diag(ImpLoc, diag::warn_undef_method_impl) << method->getSelector().getName();
+ Diag(ImpLoc, diag::warn_undef_method_impl) << method->getDeclName();
}
/// FIXME: Type hierarchies in Objective-C can be deep. We could most
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index bebde38..fd72651 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -417,12 +417,12 @@
// diagnose the problem.
if (SS && !SS->isEmpty())
return Diag(Loc, diag::err_typecheck_no_member)
- << Name.getAsString() << SS->getRange();
+ << Name << SS->getRange();
else if (Name.getNameKind() == DeclarationName::CXXOperatorName ||
Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
return Diag(Loc, diag::err_undeclared_use) << Name.getAsString();
else
- return Diag(Loc, diag::err_undeclared_var_use) << Name.getAsString();
+ return Diag(Loc, diag::err_undeclared_var_use) << Name;
}
}
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index d092793..f587dd6 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -214,8 +214,7 @@
return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
Args, NumArgs);
}
- return Diag(receiverLoc, diag::err_undeclared_var_use)
- << receiverName->getName();
+ return Diag(receiverLoc, diag::err_undeclared_var_use) << receiverName;
}
} else
ClassDecl = getObjCInterfaceDecl(receiverName);
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 15d955c..204d161 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -62,7 +62,7 @@
return new DeclStmt(DG, StartLoc, EndLoc);
}
else {
- DeclGroupOwningRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
+ DeclGroupOwningRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
return new DeclStmt(DG, StartLoc, EndLoc);
}
}
@@ -194,7 +194,7 @@
// Otherwise, this label was either forward reference or multiply defined. If
// multiply defined, reject it now.
if (LabelDecl->getSubStmt()) {
- Diag(IdentLoc, diag::err_redefinition_of_label) << LabelDecl->getName();
+ Diag(IdentLoc, diag::err_redefinition_of_label) << LabelDecl->getID();
Diag(LabelDecl->getIdentLoc(), diag::err_previous_definition);
return SubStmt;
}
@@ -773,10 +773,10 @@
if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns)
if (FunctionDecl *FD = getCurFunctionDecl())
Diag(ReturnLoc, diag::ext_return_has_expr)
- << FD->getIdentifier() << RetValExp->getSourceRange();
+ << FD->getIdentifier() << 0/*function*/<< RetValExp->getSourceRange();
else
Diag(ReturnLoc, diag::ext_return_has_expr)
- << getCurMethodDecl()->getSelector().getName()
+ << getCurMethodDecl()->getDeclName() << 1 /*method*/
<< RetValExp->getSourceRange();
}
return new ReturnStmt(ReturnLoc, RetValExp);
@@ -788,9 +788,9 @@
if (getLangOptions().C99) DiagID = diag::ext_return_missing_expr;
if (FunctionDecl *FD = getCurFunctionDecl())
- Diag(ReturnLoc, DiagID) << FD->getIdentifier();
+ Diag(ReturnLoc, DiagID) << FD->getIdentifier() << 0/*fn*/;
else
- Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getSelector().getName();
+ Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1/*meth*/;
return new ReturnStmt(ReturnLoc, (Expr*)0);
}
@@ -813,7 +813,7 @@
}
Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
- bool IsSimple,
+ bool IsSimple,
bool IsVolatile,
unsigned NumOutputs,
unsigned NumInputs,