remove the last old-fashioned Diag method. Transition complete!

llvm-svn: 59714
This commit is contained in:
Chris Lattner 2008-11-20 06:38:18 +00:00
parent f7e3f6d294
commit 651d42dba5
9 changed files with 79 additions and 89 deletions

View File

@ -162,11 +162,6 @@ DiagnosticInfo Sema::Diag(SourceLocation Loc, unsigned DiagID) {
DiagID);
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg;
return true;
}
const LangOptions &Sema::getLangOptions() const {
return PP.getLangOptions();
}

View File

@ -23,7 +23,6 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/OwningPtr.h"
#include <string>
#include <vector>
namespace llvm {
@ -228,7 +227,6 @@ public:
/// The primitive diagnostic helpers.
DiagnosticInfo Diag(SourceLocation Loc, unsigned DiagID);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
virtual void DeleteExpr(ExprTy *E);
virtual void DeleteStmt(StmtTy *S);

View File

@ -530,7 +530,7 @@ void Sema::CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD) {
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->getName();
Diag(OldDecl->getLocation(), diag::err_previous_definition);
}
}
@ -549,8 +549,8 @@ VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
// Verify the old decl was also a variable.
VarDecl *Old = dyn_cast<VarDecl>(OldD);
if (!Old) {
Diag(New->getLocation(), diag::err_redefinition_different_kind,
New->getName());
Diag(New->getLocation(), diag::err_redefinition_different_kind)
<< New->getName();
Diag(OldD->getLocation(), diag::err_previous_definition);
return New;
}
@ -561,7 +561,7 @@ VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
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->getName();
Diag(Old->getLocation(), diag::err_previous_definition);
return New;
}
@ -569,20 +569,20 @@ VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
if (New->getStorageClass() == VarDecl::Static &&
(Old->getStorageClass() == VarDecl::None ||
Old->getStorageClass() == VarDecl::Extern)) {
Diag(New->getLocation(), diag::err_static_non_static, New->getName());
Diag(New->getLocation(), diag::err_static_non_static) << New->getName();
Diag(Old->getLocation(), diag::err_previous_definition);
return New;
}
// C99 6.2.2p4: Check if we have a non-static decl followed by a static.
if (New->getStorageClass() != VarDecl::Static &&
Old->getStorageClass() == VarDecl::Static) {
Diag(New->getLocation(), diag::err_non_static_static, New->getName());
Diag(New->getLocation(), diag::err_non_static_static) << New->getName();
Diag(Old->getLocation(), diag::err_previous_definition);
return New;
}
// 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->getName();
Diag(Old->getLocation(), diag::err_previous_definition);
}
return New;
@ -603,8 +603,8 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
// that function shall not have incomplete type.
if (Param->getType()->isIncompleteType() &&
!Param->isInvalidDecl()) {
Diag(Param->getLocation(), diag::err_typecheck_decl_incomplete_type,
Param->getType().getAsString());
Diag(Param->getLocation(), diag::err_typecheck_decl_incomplete_type)
<< Param->getType().getAsString();
Param->setInvalidDecl();
HasInvalidParm = true;
}
@ -900,8 +900,8 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
case DeclSpec::SCS_auto:
case DeclSpec::SCS_register:
case DeclSpec::SCS_mutable:
Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_func,
R.getAsString());
Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_func)
<< R.getAsString();
InvalidDecl = true;
break;
case DeclSpec::SCS_unspecified: SC = FunctionDecl::None; break;
@ -1163,8 +1163,8 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
IdentifierInfo *II = Name.getAsIdentifierInfo();
if (!II) {
Diag(D.getIdentifierLoc(), diag::err_bad_variable_name,
Name.getAsString());
Diag(D.getIdentifierLoc(), diag::err_bad_variable_name)
<< Name.getAsString();
return 0;
}
@ -1180,8 +1180,8 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
// C99 6.9p2: The storage-class specifiers auto and register shall not
// appear in the declaration specifiers in an external declaration.
if (SC == VarDecl::Auto || SC == VarDecl::Register) {
Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_fscope,
R.getAsString());
Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_fscope)
<< R.getAsString();
InvalidDecl = true;
}
}
@ -1864,10 +1864,9 @@ void Sema::ActOnUninitializedDecl(DeclTy *dcl) {
if (getLangOptions().CPlusPlus &&
Context.getCanonicalType(Type).isConstQualified() &&
Var->getStorageClass() != VarDecl::Extern)
Diag(Var->getLocation(),
diag::err_const_var_requires_init,
Var->getName(),
SourceRange(Var->getLocation(), Var->getLocation()));
Diag(Var->getLocation(), diag::err_const_var_requires_init)
<< Var->getName()
<< SourceRange(Var->getLocation(), Var->getLocation());
#endif
}
}
@ -1913,8 +1912,8 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
if (IDecl->isBlockVarDecl() &&
IDecl->getStorageClass() != VarDecl::Extern) {
if (T->isIncompleteType() && !IDecl->isInvalidDecl()) {
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
T.getAsString());
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
<< T.getAsString();
IDecl->setInvalidDecl();
}
}
@ -1931,8 +1930,8 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
// C99 6.9.2p3: If the declaration of an identifier for an object is
// a tentative definition and has internal linkage (C99 6.2.2p3), the
// declared type shall not be an incomplete type.
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
T.getAsString());
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
<< T.getAsString();
IDecl->setInvalidDecl();
}
}
@ -1982,8 +1981,8 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
IdentifierInfo *II = D.getIdentifier();
if (Decl *PrevDecl = LookupDecl(II, Decl::IDNS_Ordinary, S)) {
if (S->isDeclScope(PrevDecl)) {
Diag(D.getIdentifierLoc(), diag::err_param_redefinition,
dyn_cast<NamedDecl>(PrevDecl)->getName());
Diag(D.getIdentifierLoc(), diag::err_param_redefinition)
<< cast<NamedDecl>(PrevDecl)->getName();
// Recover by removing the name
II = 0;
@ -2071,8 +2070,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
// 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->getName();
Diag(Definition->getLocation(), diag::err_previous_definition);
}
@ -2113,7 +2111,7 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
if (I->second->getSubStmt() == 0) {
LabelStmt *L = I->second;
// Emit error.
Diag(L->getIdentLoc(), diag::err_undeclared_label_use, L->getName());
Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName();
// At this point, we have gotos that use the bogus label. Stitch it into
// the function body so that they aren't leaked and that the AST is well
@ -2712,8 +2710,8 @@ void Sema::ActOnFields(Scope* S,
// struct S { struct S {} X; };
// We discover this when we complete the outer S. Reject and ignore the
// outer S.
Diag(DefRecord->getLocation(), diag::err_nested_redefinition,
DefRecord->getKindName());
Diag(DefRecord->getLocation(), diag::err_nested_redefinition)
<< DefRecord->getKindName();
Diag(RecLoc, diag::err_previous_definition);
Record->setInvalidDecl();
return;
@ -2737,8 +2735,8 @@ void Sema::ActOnFields(Scope* S,
// C99 6.7.2.1p2 - A field may not be a function type.
if (FDTy->isFunctionType()) {
Diag(FD->getLocation(), diag::err_field_declared_as_function,
FD->getName());
Diag(FD->getLocation(), diag::err_field_declared_as_function)
<< FD->getName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
@ -2746,7 +2744,7 @@ void Sema::ActOnFields(Scope* S,
// C99 6.7.2.1p2 - A field may not be an incomplete type except...
if (FDTy->isIncompleteType()) {
if (!Record) { // Incomplete ivar type is always an error.
Diag(FD->getLocation(), diag::err_field_incomplete, FD->getName());
Diag(FD->getLocation(), diag::err_field_incomplete) << FD->getName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
@ -2754,14 +2752,14 @@ void Sema::ActOnFields(Scope* S,
if (i != NumFields-1 || // ... that the last member ...
!Record->isStruct() || // ... of a structure ...
!FDTy->isArrayType()) { //... may have incomplete array type.
Diag(FD->getLocation(), diag::err_field_incomplete, FD->getName());
Diag(FD->getLocation(), diag::err_field_incomplete) << FD->getName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
}
if (NumNamedMembers < 1) { //... must have more than named member ...
Diag(FD->getLocation(), diag::err_flexible_array_empty_struct,
FD->getName());
Diag(FD->getLocation(), diag::err_flexible_array_empty_struct)
<< FD->getName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
@ -2782,16 +2780,16 @@ void Sema::ActOnFields(Scope* S,
// it. Note that GCC supports variable sized arrays in the middle of
// structures.
if (i != NumFields-1) {
Diag(FD->getLocation(), diag::err_variable_sized_type_in_struct,
FD->getName());
Diag(FD->getLocation(), diag::err_variable_sized_type_in_struct)
<< FD->getName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
}
// We support flexible arrays at the end of structs in other structs
// as an extension.
Diag(FD->getLocation(), diag::ext_flexible_array_in_struct,
FD->getName());
Diag(FD->getLocation(), diag::ext_flexible_array_in_struct)
<< FD->getName();
if (Record)
Record->setHasFlexibleArrayMember(true);
}
@ -2799,8 +2797,8 @@ void Sema::ActOnFields(Scope* S,
}
/// A field cannot be an Objective-c object
if (FDTy->isObjCInterfaceType()) {
Diag(FD->getLocation(), diag::err_statically_allocated_object,
FD->getName());
Diag(FD->getLocation(), diag::err_statically_allocated_object)
<< FD->getName();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
@ -2939,8 +2937,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
// enum e0 {
// E0 = sizeof(enum e0 { E1 })
// };
Diag(Enum->getLocation(), diag::err_nested_redefinition,
Enum->getName());
Diag(Enum->getLocation(), diag::err_nested_redefinition) << Enum->getName();
Diag(EnumLoc, diag::err_previous_definition);
Enum->setInvalidDecl();
return;
@ -2973,8 +2970,8 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
V.trunc(IntWidth);
V.extend(InitVal.getBitWidth());
if (V != InitVal)
Diag(ECD->getLocation(), diag::ext_enum_value_not_int,
InitVal.toString(10));
Diag(ECD->getLocation(), diag::ext_enum_value_not_int)
<< InitVal.toString(10);
}
// Keep track of the size of positive and negative values.
@ -3176,8 +3173,8 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name,
// If a name was specified then failure indicates the name
// wasn't found. Otherwise failure indicates the stack was
// empty.
Diag(PragmaLoc, diag::warn_pragma_pack_pop_failed,
Name ? "no record matching name" : "stack empty");
Diag(PragmaLoc, diag::warn_pragma_pack_pop_failed)
<< (Name ? "no record matching name" : "stack empty");
// FIXME: Warn about popping named records as MSVC does.
} else {

View File

@ -1814,8 +1814,8 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
if (CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(FnDecl)) {
if (MethodDecl->isStatic())
return Diag(FnDecl->getLocation(),
diag::err_operator_overload_static,
FnDecl->getName());
diag::err_operator_overload_static)
<< FnDecl->getName();
} else {
bool ClassOrEnumParam = false;
for (FunctionDecl::param_iterator Param = FnDecl->param_begin(),
@ -1830,8 +1830,8 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
if (!ClassOrEnumParam)
return Diag(FnDecl->getLocation(),
diag::err_operator_overload_needs_class_or_enum,
FnDecl->getName());
diag::err_operator_overload_needs_class_or_enum)
<< FnDecl->getName();
}
// C++ [over.oper]p8:
@ -1898,16 +1898,15 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
// Overloaded operators other than operator() cannot be variadic.
if (Op != OO_Call &&
FnDecl->getType()->getAsFunctionTypeProto()->isVariadic()) {
return Diag(FnDecl->getLocation(),
diag::err_operator_overload_variadic,
FnDecl->getName());
return Diag(FnDecl->getLocation(), diag::err_operator_overload_variadic)
<< FnDecl->getName();
}
// Some operators must be non-static member functions.
if (MustBeMemberOperator && !isa<CXXMethodDecl>(FnDecl)) {
return Diag(FnDecl->getLocation(),
diag::err_operator_overload_must_be_member,
FnDecl->getName());
diag::err_operator_overload_must_be_member)
<< FnDecl->getName();
}
// C++ [over.inc]p1:
@ -1932,8 +1931,8 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
DK = diag::err_operator_overload_post_inc_must_be_int;
else
DK = diag::err_operator_overload_post_dec_must_be_int;
return Diag(LastParam->getLocation(), DK,
Context.getCanonicalType(LastParam->getType()).getAsString());
return Diag(LastParam->getLocation(), DK)
<< Context.getCanonicalType(LastParam->getType()).getAsString();
}
}

View File

@ -1568,8 +1568,8 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
// first, check the condition.
if (!condT->isScalarType()) { // C99 6.5.15p2
Diag(cond->getLocStart(), diag::err_typecheck_cond_expect_scalar,
condT.getAsString());
Diag(cond->getLocStart(), diag::err_typecheck_cond_expect_scalar)
<< condT.getAsString();
return QualType();
}

View File

@ -190,8 +190,8 @@ Sema::ExprResult Sema::ActOnClassMessage(
isSuper = true;
ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
if (!ClassDecl)
return Diag(lbrac, diag::error_no_super_class,
getCurMethodDecl()->getClassInterface()->getName());
return Diag(lbrac, diag::error_no_super_class)
<< getCurMethodDecl()->getClassInterface()->getName();
if (getCurMethodDecl()->isInstance()) {
QualType superTy = Context.getObjCInterfaceType(ClassDecl);
superTy = Context.getPointerType(superTy);
@ -214,8 +214,8 @@ Sema::ExprResult Sema::ActOnClassMessage(
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->getName();
}
} else
ClassDecl = getObjCInterfaceDecl(receiverName);

View File

@ -143,8 +143,8 @@ void InitListChecker::CheckListElementTypes(InitListExpr *IList,
} else if (DeclType->isVoidType() || DeclType->isFunctionType()) {
// This type is invalid, issue a diagnostic.
Index++;
SemaRef->Diag(IList->getLocStart(), diag::err_illegal_initializer_type,
DeclType.getAsString());
SemaRef->Diag(IList->getLocStart(), diag::err_illegal_initializer_type)
<< DeclType.getAsString();
hadError = true;
} else {
// In C, all types are either scalars or aggregates, but

View File

@ -182,7 +182,7 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
// 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->getName();
Diag(LabelDecl->getIdentLoc(), diag::err_previous_definition);
return SubStmt;
}
@ -572,8 +572,9 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
if (!getLangOptions().CPlusPlus) {
if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
// C99 6.8.5p3: The declaration part of a 'for' statement shall only
// declare identifiers for objects having storage class 'auto' or
// 'register'.
for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end();
DI!=DE; ++DI) {
VarDecl *VD = dyn_cast<VarDecl>(*DI);
@ -616,8 +617,9 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
ScopedDecl *D = DS->getSolitaryDecl();
FirstType = cast<ValueDecl>(D)->getType();
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
// C99 6.8.5p3: The declaration part of a 'for' statement shall only
// declare identifiers for objects having storage class 'auto' or
// 'register'.
VarDecl *VD = cast<VarDecl>(D);
if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
@ -836,7 +838,7 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info))
// FIXME: We currently leak memory here.
return Diag(Literal->getLocStart(),
diag::err_asm_invalid_output_constraint, OutputConstraint);
diag::err_asm_invalid_output_constraint) << OutputConstraint;
// Check that the output exprs are valid lvalues.
ParenExpr *OutputExpr = cast<ParenExpr>(Exprs[i]);
@ -894,7 +896,7 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
if (!Context.Target.isValidGCCRegisterName(Clobber.c_str()))
// FIXME: We currently leak memory here.
return Diag(Literal->getLocStart(),
diag::err_asm_unknown_register_name, Clobber.c_str());
diag::err_asm_unknown_register_name) << Clobber.c_str();
}
return new AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,

View File

@ -46,14 +46,14 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS) {
if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
Result = Context.WCharTy;
else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) {
Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec,
DS.getSpecifierName(DS.getTypeSpecType()));
Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec)
<< DS.getSpecifierName(DS.getTypeSpecType());
Result = Context.getSignedWCharType();
} else {
assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
"Unknown TSS value");
Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec,
DS.getSpecifierName(DS.getTypeSpecType()));
Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec)
<< DS.getSpecifierName(DS.getTypeSpecType());
Result = Context.getUnsignedWCharType();
}
break;
@ -430,8 +430,8 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
// C99 6.7.5.3p1: The return type may not be a function or array type.
if (T->isArrayType() || T->isFunctionType()) {
Diag(DeclType.Loc, diag::err_func_returning_array_function,
T.getAsString());
Diag(DeclType.Loc, diag::err_func_returning_array_function)
<< T.getAsString();
T = Context.IntTy;
D.setInvalidType(true);
}
@ -654,8 +654,7 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type,
// Check the attribute arguments.
if (Attr.getNumArgs() != 1) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments,
std::string("1"));
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
return;
}
Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0));