Refactor methods on DeclSpec to take a diagnostic& parameter, and reflect this

elsewhere.  Very slightly decouples DeclSpec users from knowing the exact
diagnostics to report, and makes it easier to provide different diagnostics in
some places.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77990 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John McCall 2009-08-03 20:12:06 +00:00
Родитель d1e1ef3b0a
Коммит fec54013fc
8 изменённых файлов: 242 добавлений и 157 удалений

Просмотреть файл

@ -267,27 +267,44 @@ public:
void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); } void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); } void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
/// These methods set the specified attribute of the DeclSpec, but return true /// These methods set the specified attribute of the DeclSpec and
/// and ignore the request if invalid (e.g. "extern" then "auto" is /// return false if there was no error. If an error occurs (for
/// specified). The name of the previous specifier is returned in prevspec. /// example, if we tried to set "auto" on a spec with "extern"
bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec); /// already set), they return true and set PrevSpec and DiagID
bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec); /// such that
bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec); /// Diag(Loc, DiagID) << PrevSpec;
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec); /// will yield a useful result.
bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec); ///
/// TODO: use a more general approach that still allows these
/// diagnostics to be ignored when desired.
bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
void *Rep = 0, bool Owned = false); unsigned &DiagID, void *Rep = 0, bool Owned = false);
bool SetTypeSpecError(); bool SetTypeSpecError();
void UpdateTypeRep(void *Rep) { TypeRep = Rep; } void UpdateTypeRep(void *Rep) { TypeRep = Rep; }
bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
const LangOptions &Lang); unsigned &DiagID, const LangOptions &Lang);
bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec); bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec); unsigned &DiagID);
bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec); bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec); bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool isFriendSpecified() const { return Friend_specified; } bool isFriendSpecified() const { return Friend_specified; }
SourceLocation getFriendSpecLoc() const { return FriendLoc; } SourceLocation getFriendSpecLoc() const { return FriendLoc; }

Просмотреть файл

@ -923,8 +923,9 @@ private:
void ParseDeclarationSpecifiers(DeclSpec &DS, void ParseDeclarationSpecifiers(DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
AccessSpecifier AS = AS_none); AccessSpecifier AS = AS_none);
bool ParseOptionalTypeSpecifier(DeclSpec &DS, int &isInvalid, bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
const char *&PrevSpec, const char *&PrevSpec,
unsigned &DiagID,
const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
void ParseSpecifierQualifierList(DeclSpec &DS); void ParseSpecifierQualifierList(DeclSpec &DS);

Просмотреть файл

@ -105,8 +105,12 @@ unsigned DeclSpec::getParsedSpecifiers() const {
return Res; return Res;
} }
template <class T> static bool BadSpecifier(T TPrev, const char *&PrevSpec) { template <class T> static bool BadSpecifier(T TNew, T TPrev,
const char *&PrevSpec,
unsigned &DiagID) {
PrevSpec = DeclSpec::getSpecifierName(TPrev); PrevSpec = DeclSpec::getSpecifierName(TPrev);
DiagID = (TNew == TPrev ? diag::ext_duplicate_declspec
: diag::err_invalid_decl_spec_combination);
return true; return true;
} }
@ -193,9 +197,10 @@ const char *DeclSpec::getSpecifierName(TQ T) {
} }
bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc,
const char *&PrevSpec) { const char *&PrevSpec,
unsigned &DiagID) {
if (StorageClassSpec != SCS_unspecified) if (StorageClassSpec != SCS_unspecified)
return BadSpecifier((SCS)StorageClassSpec, PrevSpec); return BadSpecifier(S, (SCS)StorageClassSpec, PrevSpec, DiagID);
StorageClassSpec = S; StorageClassSpec = S;
StorageClassSpecLoc = Loc; StorageClassSpecLoc = Loc;
assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield");
@ -203,9 +208,11 @@ bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc,
} }
bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc,
const char *&PrevSpec) { const char *&PrevSpec,
unsigned &DiagID) {
if (SCS_thread_specified) { if (SCS_thread_specified) {
PrevSpec = "__thread"; PrevSpec = "__thread";
DiagID = diag::ext_duplicate_declspec;
return true; return true;
} }
SCS_thread_specified = true; SCS_thread_specified = true;
@ -218,39 +225,46 @@ bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc,
/// and ignore the request if invalid (e.g. "extern" then "auto" is /// and ignore the request if invalid (e.g. "extern" then "auto" is
/// specified). /// specified).
bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
const char *&PrevSpec) { const char *&PrevSpec,
unsigned &DiagID) {
if (TypeSpecWidth != TSW_unspecified && if (TypeSpecWidth != TSW_unspecified &&
// Allow turning long -> long long. // Allow turning long -> long long.
(W != TSW_longlong || TypeSpecWidth != TSW_long)) (W != TSW_longlong || TypeSpecWidth != TSW_long))
return BadSpecifier((TSW)TypeSpecWidth, PrevSpec); return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
TypeSpecWidth = W; TypeSpecWidth = W;
TSWLoc = Loc; TSWLoc = Loc;
return false; return false;
} }
bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
const char *&PrevSpec) { const char *&PrevSpec,
unsigned &DiagID) {
if (TypeSpecComplex != TSC_unspecified) if (TypeSpecComplex != TSC_unspecified)
return BadSpecifier((TSC)TypeSpecComplex, PrevSpec); return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
TypeSpecComplex = C; TypeSpecComplex = C;
TSCLoc = Loc; TSCLoc = Loc;
return false; return false;
} }
bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
const char *&PrevSpec) { const char *&PrevSpec,
unsigned &DiagID) {
if (TypeSpecSign != TSS_unspecified) if (TypeSpecSign != TSS_unspecified)
return BadSpecifier((TSS)TypeSpecSign, PrevSpec); return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID);
TypeSpecSign = S; TypeSpecSign = S;
TSSLoc = Loc; TSSLoc = Loc;
return false; return false;
} }
bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
const char *&PrevSpec, void *Rep, const char *&PrevSpec,
bool Owned) { unsigned &DiagID,
if (TypeSpecType != TST_unspecified) void *Rep, bool Owned) {
return BadSpecifier((TST)TypeSpecType, PrevSpec); if (TypeSpecType != TST_unspecified) {
PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType);
DiagID = diag::err_invalid_decl_spec_combination;
return true;
}
TypeSpecType = T; TypeSpecType = T;
TypeRep = Rep; TypeRep = Rep;
TSTLoc = Loc; TSTLoc = Loc;
@ -266,10 +280,10 @@ bool DeclSpec::SetTypeSpecError() {
} }
bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
const LangOptions &Lang) { unsigned &DiagID, const LangOptions &Lang) {
// Duplicates turn into warnings pre-C99. // Duplicates turn into warnings pre-C99.
if ((TypeQualifiers & T) && !Lang.C99) if ((TypeQualifiers & T) && !Lang.C99)
return BadSpecifier(T, PrevSpec); return BadSpecifier(T, T, PrevSpec, DiagID);
TypeQualifiers |= T; TypeQualifiers |= T;
switch (T) { switch (T) {
@ -281,33 +295,38 @@ bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
return false; return false;
} }
bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec){ bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID) {
// 'inline inline' is ok. // 'inline inline' is ok.
FS_inline_specified = true; FS_inline_specified = true;
FS_inlineLoc = Loc; FS_inlineLoc = Loc;
return false; return false;
} }
bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec){ bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID) {
// 'virtual virtual' is ok. // 'virtual virtual' is ok.
FS_virtual_specified = true; FS_virtual_specified = true;
FS_virtualLoc = Loc; FS_virtualLoc = Loc;
return false; return false;
} }
bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec){ bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID) {
// 'explicit explicit' is ok. // 'explicit explicit' is ok.
FS_explicit_specified = true; FS_explicit_specified = true;
FS_explicitLoc = Loc; FS_explicitLoc = Loc;
return false; return false;
} }
bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec) { bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID) {
if (Friend_specified) { if (Friend_specified) {
PrevSpec = "friend"; PrevSpec = "friend";
DiagID = diag::ext_duplicate_declspec;
return true; return true;
} }
Friend_specified = true; Friend_specified = true;
FriendLoc = Loc; FriendLoc = Loc;
return false; return false;

Просмотреть файл

@ -673,7 +673,8 @@ bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
Diag(Loc, diag::err_unknown_typename) << Tok.getIdentifierInfo() << R; Diag(Loc, diag::err_unknown_typename) << Tok.getIdentifierInfo() << R;
const char *PrevSpec; const char *PrevSpec;
DS.SetTypeSpecType(DeclSpec::TST_error, Loc, PrevSpec); unsigned DiagID;
DS.SetTypeSpecType(DeclSpec::TST_error, Loc, PrevSpec, DiagID);
DS.SetRangeEnd(Tok.getLocation()); DS.SetRangeEnd(Tok.getLocation());
ConsumeToken(); ConsumeToken();
@ -710,8 +711,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
AccessSpecifier AS) { AccessSpecifier AS) {
DS.SetRangeStart(Tok.getLocation()); DS.SetRangeStart(Tok.getLocation());
while (1) { while (1) {
int isInvalid = false; bool isInvalid = false;
const char *PrevSpec = 0; const char *PrevSpec = 0;
unsigned DiagID = 0;
SourceLocation Loc = Tok.getLocation(); SourceLocation Loc = Tok.getLocation();
switch (Tok.getKind()) { switch (Tok.getKind()) {
@ -777,7 +780,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
ConsumeToken(); // The C++ scope. ConsumeToken(); // The C++ scope.
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
TypeRep); DiagID, TypeRep);
if (isInvalid) if (isInvalid)
break; break;
@ -790,7 +793,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
case tok::annot_typename: { case tok::annot_typename: {
if (Tok.getAnnotationValue()) if (Tok.getAnnotationValue())
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
Tok.getAnnotationValue()); DiagID, Tok.getAnnotationValue());
else else
DS.SetTypeSpecError(); DS.SetTypeSpecError();
DS.SetRangeEnd(Tok.getAnnotationEndLoc()); DS.SetRangeEnd(Tok.getAnnotationEndLoc());
@ -846,7 +849,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
goto DoneWithDeclSpec; goto DoneWithDeclSpec;
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
TypeRep); DiagID, TypeRep);
if (isInvalid) if (isInvalid)
break; break;
@ -913,112 +916,138 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
// storage-class-specifier // storage-class-specifier
case tok::kw_typedef: case tok::kw_typedef:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec); isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_extern: case tok::kw_extern:
if (DS.isThreadSpecified()) 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); isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw___private_extern__: case tok::kw___private_extern__:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_private_extern, Loc, isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_private_extern, Loc,
PrevSpec); PrevSpec, DiagID);
break; break;
case tok::kw_static: case tok::kw_static:
if (DS.isThreadSpecified()) 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); isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_auto: case tok::kw_auto:
if (getLang().CPlusPlus0x) if (getLang().CPlusPlus0x)
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec,
DiagID);
else else
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec); isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_register: case tok::kw_register:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec); isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_mutable: case tok::kw_mutable:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_mutable, Loc, PrevSpec); isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_mutable, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw___thread: case tok::kw___thread:
isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec)*2; isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec, DiagID);
break; break;
// function-specifier // function-specifier
case tok::kw_inline: case tok::kw_inline:
isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec); isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec, DiagID);
break; break;
case tok::kw_virtual: case tok::kw_virtual:
isInvalid = DS.SetFunctionSpecVirtual(Loc, PrevSpec); isInvalid = DS.SetFunctionSpecVirtual(Loc, PrevSpec, DiagID);
break; break;
case tok::kw_explicit: case tok::kw_explicit:
isInvalid = DS.SetFunctionSpecExplicit(Loc, PrevSpec); isInvalid = DS.SetFunctionSpecExplicit(Loc, PrevSpec, DiagID);
break; break;
// friend // friend
case tok::kw_friend: case tok::kw_friend:
isInvalid = DS.SetFriendSpec(Loc, PrevSpec); isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID);
break; break;
// type-specifier // type-specifier
case tok::kw_short: case tok::kw_short:
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec); isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_long: case tok::kw_long:
if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec); isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec,
DiagID);
else else
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec); isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_signed: case tok::kw_signed:
isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec); isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_unsigned: case tok::kw_unsigned:
isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec); isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Complex: case tok::kw__Complex:
isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec); isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Imaginary: case tok::kw__Imaginary:
isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec); isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_void: case tok::kw_void:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_char: case tok::kw_char:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_int: case tok::kw_int:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_float: case tok::kw_float:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_double: case tok::kw_double:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_wchar_t: case tok::kw_wchar_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_char16_t: case tok::kw_char16_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_char32_t: case tok::kw_char32_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_bool: case tok::kw_bool:
case tok::kw__Bool: case tok::kw__Bool:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Decimal32: case tok::kw__Decimal32:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Decimal64: case tok::kw__Decimal64:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Decimal128: case tok::kw__Decimal128:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec,
DiagID);
break; break;
// class-specifier: // class-specifier:
@ -1039,15 +1068,16 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
// cv-qualifier: // cv-qualifier:
case tok::kw_const: case tok::kw_const:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec,getLang())*2; isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec, DiagID,
getLang());
break; break;
case tok::kw_volatile: case tok::kw_volatile:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
getLang())*2; getLang());
break; break;
case tok::kw_restrict: case tok::kw_restrict:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
getLang())*2; getLang());
break; break;
// C++ typename-specifier: // C++ typename-specifier:
@ -1087,12 +1117,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
continue; continue;
} }
} }
// If the specifier combination wasn't legal, issue a diagnostic. // If the specifier wasn't legal, issue a diagnostic.
if (isInvalid) { if (isInvalid) {
assert(PrevSpec && "Method did not return previous specifier!"); assert(PrevSpec && "Method did not return previous specifier!");
// Pick between error or extwarn. assert(DiagID);
unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination
: diag::ext_duplicate_declspec;
Diag(Tok, DiagID) << PrevSpec; Diag(Tok, DiagID) << PrevSpec;
} }
DS.SetRangeEnd(Tok.getLocation()); DS.SetRangeEnd(Tok.getLocation());
@ -1143,8 +1171,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
/// [OBJC] class-name objc-protocol-refs[opt] [TODO] /// [OBJC] class-name objc-protocol-refs[opt] [TODO]
/// [OBJC] typedef-name objc-protocol-refs[opt] [TODO] /// [OBJC] typedef-name objc-protocol-refs[opt] [TODO]
/// [C++0x] 'decltype' ( expression ) /// [C++0x] 'decltype' ( expression )
bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid, bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, bool& isInvalid,
const char *&PrevSpec, const char *&PrevSpec,
unsigned &DiagID,
const ParsedTemplateInfo &TemplateInfo) { const ParsedTemplateInfo &TemplateInfo) {
SourceLocation Loc = Tok.getLocation(); SourceLocation Loc = Tok.getLocation();
@ -1154,7 +1183,8 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
// Annotate typenames and C++ scope specifiers. If we get one, just // Annotate typenames and C++ scope specifiers. If we get one, just
// recurse to handle whatever we get. // recurse to handle whatever we get.
if (TryAnnotateTypeOrScopeToken()) if (TryAnnotateTypeOrScopeToken())
return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, TemplateInfo); return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID,
TemplateInfo);
// Otherwise, not a type specifier. // Otherwise, not a type specifier.
return false; return false;
case tok::coloncolon: // ::foo::bar case tok::coloncolon: // ::foo::bar
@ -1165,7 +1195,8 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
// Annotate typenames and C++ scope specifiers. If we get one, just // Annotate typenames and C++ scope specifiers. If we get one, just
// recurse to handle whatever we get. // recurse to handle whatever we get.
if (TryAnnotateTypeOrScopeToken()) if (TryAnnotateTypeOrScopeToken())
return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, TemplateInfo); return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID,
TemplateInfo);
// Otherwise, not a type specifier. // Otherwise, not a type specifier.
return false; return false;
@ -1173,7 +1204,7 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
case tok::annot_typename: { case tok::annot_typename: {
if (Tok.getAnnotationValue()) if (Tok.getAnnotationValue())
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
Tok.getAnnotationValue()); DiagID, Tok.getAnnotationValue());
else else
DS.SetTypeSpecError(); DS.SetTypeSpecError();
DS.SetRangeEnd(Tok.getAnnotationEndLoc()); DS.SetRangeEnd(Tok.getAnnotationEndLoc());
@ -1196,62 +1227,70 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
} }
case tok::kw_short: case tok::kw_short:
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec); isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_long: case tok::kw_long:
if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec); isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec,
DiagID);
else else
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec); isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_signed: case tok::kw_signed:
isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec); isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_unsigned: case tok::kw_unsigned:
isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec); isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Complex: case tok::kw__Complex:
isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec); isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Imaginary: case tok::kw__Imaginary:
isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec); isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw_void: case tok::kw_void:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_char: case tok::kw_char:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_int: case tok::kw_int:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_float: case tok::kw_float:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_double: case tok::kw_double:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_wchar_t: case tok::kw_wchar_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_char16_t: case tok::kw_char16_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_char32_t: case tok::kw_char32_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_bool: case tok::kw_bool:
case tok::kw__Bool: case tok::kw__Bool:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID);
break; break;
case tok::kw__Decimal32: case tok::kw__Decimal32:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Decimal64: case tok::kw__Decimal64:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec,
DiagID);
break; break;
case tok::kw__Decimal128: case tok::kw__Decimal128:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec,
DiagID);
break; break;
// class-specifier: // class-specifier:
@ -1273,15 +1312,15 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
// cv-qualifier: // cv-qualifier:
case tok::kw_const: case tok::kw_const:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
getLang())*2; DiagID, getLang());
break; break;
case tok::kw_volatile: case tok::kw_volatile:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
getLang())*2; DiagID, getLang());
break; break;
case tok::kw_restrict: case tok::kw_restrict:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
getLang())*2; DiagID, getLang());
break; break;
// GNU typeof support. // GNU typeof support.
@ -1299,7 +1338,7 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
if (!getLang().CPlusPlus0x) if (!getLang().CPlusPlus0x)
return false; return false;
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec); isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, DiagID);
break; break;
case tok::kw___ptr64: case tok::kw___ptr64:
case tok::kw___w64: case tok::kw___w64:
@ -1318,8 +1357,6 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
if (isInvalid) { if (isInvalid) {
assert(PrevSpec && "Method did not return previous specifier!"); assert(PrevSpec && "Method did not return previous specifier!");
// Pick between error or extwarn. // Pick between error or extwarn.
unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination
: diag::ext_duplicate_declspec;
Diag(Tok, DiagID) << PrevSpec; Diag(Tok, DiagID) << PrevSpec;
} }
DS.SetRangeEnd(Tok.getLocation()); DS.SetRangeEnd(Tok.getLocation());
@ -1595,9 +1632,10 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
// TODO: semantic analysis on the declspec for enums. // TODO: semantic analysis on the declspec for enums.
const char *PrevSpec = 0; const char *PrevSpec = 0;
if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, unsigned DiagID;
if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, DiagID,
TagDecl.getAs<void>(), Owned)) TagDecl.getAs<void>(), Owned))
Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; Diag(StartLoc, DiagID) << PrevSpec;
} }
/// ParseEnumBody - Parse a {} enclosed enumerator-list. /// ParseEnumBody - Parse a {} enclosed enumerator-list.
@ -1883,22 +1921,23 @@ bool Parser::isDeclarationSpecifier() {
/// ///
void Parser::ParseTypeQualifierListOpt(DeclSpec &DS, bool AttributesAllowed) { void Parser::ParseTypeQualifierListOpt(DeclSpec &DS, bool AttributesAllowed) {
while (1) { while (1) {
int isInvalid = false; bool isInvalid = false;
const char *PrevSpec = 0; const char *PrevSpec = 0;
unsigned DiagID = 0;
SourceLocation Loc = Tok.getLocation(); SourceLocation Loc = Tok.getLocation();
switch (Tok.getKind()) { switch (Tok.getKind()) {
case tok::kw_const: case tok::kw_const:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, DiagID,
getLang())*2; getLang());
break; break;
case tok::kw_volatile: case tok::kw_volatile:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
getLang())*2; getLang());
break; break;
case tok::kw_restrict: case tok::kw_restrict:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
getLang())*2; getLang());
break; break;
case tok::kw___w64: case tok::kw___w64:
case tok::kw___ptr64: case tok::kw___ptr64:
@ -1927,9 +1966,6 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS, bool AttributesAllowed) {
// If the specifier combination wasn't legal, issue a diagnostic. // If the specifier combination wasn't legal, issue a diagnostic.
if (isInvalid) { if (isInvalid) {
assert(PrevSpec && "Method did not return previous specifier!"); assert(PrevSpec && "Method did not return previous specifier!");
// Pick between error or extwarn.
unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination
: diag::ext_duplicate_declspec;
Diag(Tok, DiagID) << PrevSpec; Diag(Tok, DiagID) << PrevSpec;
} }
ConsumeToken(); ConsumeToken();
@ -2831,10 +2867,11 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
} }
const char *PrevSpec = 0; const char *PrevSpec = 0;
unsigned DiagID;
// Check for duplicate type specifiers (e.g. "int typeof(int)"). // Check for duplicate type specifiers (e.g. "int typeof(int)").
if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec,
CastTy)) DiagID, CastTy))
Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; Diag(StartLoc, DiagID) << PrevSpec;
return; return;
} }
@ -2845,8 +2882,9 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
} }
const char *PrevSpec = 0; const char *PrevSpec = 0;
unsigned DiagID;
// Check for duplicate type specifiers (e.g. "int typeof(int)"). // Check for duplicate type specifiers (e.g. "int typeof(int)").
if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec,
Operand.release())) DiagID, Operand.release()))
Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; Diag(StartLoc, DiagID) << PrevSpec;
} }

Просмотреть файл

@ -410,10 +410,11 @@ void Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
return; return;
const char *PrevSpec = 0; const char *PrevSpec = 0;
unsigned DiagID;
// Check for duplicate type specifiers (e.g. "int decltype(a)"). // Check for duplicate type specifiers (e.g. "int decltype(a)").
if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec,
Result.release())) DiagID, Result.release()))
Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; Diag(StartLoc, DiagID) << PrevSpec;
} }
/// ParseClassName - Parse a C++ class-name, which names a class. Note /// ParseClassName - Parse a C++ class-name, which names a class. Note
@ -716,15 +717,16 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
Diag(Tok, diag::err_expected_lbrace); Diag(Tok, diag::err_expected_lbrace);
} }
const char *PrevSpec = 0;
if (TagOrTempResult.isInvalid()) { if (TagOrTempResult.isInvalid()) {
DS.SetTypeSpecError(); DS.SetTypeSpecError();
return; return;
} }
if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, const char *PrevSpec = 0;
unsigned DiagID;
if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, DiagID,
TagOrTempResult.get().getAs<void>(), Owned)) TagOrTempResult.get().getAs<void>(), Owned))
Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; Diag(StartLoc, DiagID) << PrevSpec;
if (DS.isFriendSpecified()) if (DS.isFriendSpecified())
Actions.ActOnFriendDecl(CurScope, DS.getFriendSpecLoc(), Actions.ActOnFriendDecl(CurScope, DS.getFriendSpecLoc(),

Просмотреть файл

@ -610,6 +610,7 @@ Parser::OwningExprResult Parser::ParseCXXCondition() {
void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
DS.SetRangeStart(Tok.getLocation()); DS.SetRangeStart(Tok.getLocation());
const char *PrevSpec; const char *PrevSpec;
unsigned DiagID;
SourceLocation Loc = Tok.getLocation(); SourceLocation Loc = Tok.getLocation();
switch (Tok.getKind()) { switch (Tok.getKind()) {
@ -622,50 +623,50 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
// type-name // type-name
case tok::annot_typename: { case tok::annot_typename: {
DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID,
Tok.getAnnotationValue()); Tok.getAnnotationValue());
break; break;
} }
// builtin types // builtin types
case tok::kw_short: case tok::kw_short:
DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec); DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_long: case tok::kw_long:
DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec); DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_signed: case tok::kw_signed:
DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec); DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_unsigned: case tok::kw_unsigned:
DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec); DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_void: case tok::kw_void:
DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_char: case tok::kw_char:
DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_int: case tok::kw_int:
DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_float: case tok::kw_float:
DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_double: case tok::kw_double:
DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_wchar_t: case tok::kw_wchar_t:
DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_char16_t: case tok::kw_char16_t:
DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_char32_t: case tok::kw_char32_t:
DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID);
break; break;
case tok::kw_bool: case tok::kw_bool:
DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec); DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID);
break; break;
// GNU typeof support. // GNU typeof support.
@ -696,15 +697,16 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) {
DS.SetRangeStart(Tok.getLocation()); DS.SetRangeStart(Tok.getLocation());
const char *PrevSpec = 0; const char *PrevSpec = 0;
int isInvalid = 0; unsigned DiagID;
bool isInvalid = 0;
// Parse one or more of the type specifiers. // Parse one or more of the type specifiers.
if (!ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec)) { if (!ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID)) {
Diag(Tok, diag::err_operator_missing_type_specifier); Diag(Tok, diag::err_operator_missing_type_specifier);
return true; return true;
} }
while (ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec)) ; while (ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID)) ;
return false; return false;
} }

Просмотреть файл

@ -522,8 +522,9 @@ Parser::ParseDeclarationOrFunctionDefinition(AccessSpecifier AS) {
return DeclGroupPtrTy(); return DeclGroupPtrTy();
} }
const char *PrevSpec = 0; const char *PrevSpec = 0;
if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec)) unsigned DiagID;
Diag(AtLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec, DiagID))
Diag(AtLoc, DiagID) << PrevSpec;
DeclPtrTy TheDecl; DeclPtrTy TheDecl;
if (Tok.isObjCAtKeyword(tok::objc_protocol)) if (Tok.isObjCAtKeyword(tok::objc_protocol))
@ -619,9 +620,10 @@ Parser::DeclPtrTy Parser::ParseFunctionDefinition(Declarator &D,
// declaration-specifiers are completely optional in the grammar. // declaration-specifiers are completely optional in the grammar.
if (getLang().ImplicitInt && D.getDeclSpec().isEmpty()) { if (getLang().ImplicitInt && D.getDeclSpec().isEmpty()) {
const char *PrevSpec; const char *PrevSpec;
unsigned DiagID;
D.getMutableDeclSpec().SetTypeSpecType(DeclSpec::TST_int, D.getMutableDeclSpec().SetTypeSpecType(DeclSpec::TST_int,
D.getIdentifierLoc(), D.getIdentifierLoc(),
PrevSpec); PrevSpec, DiagID);
D.SetRangeBegin(D.getDeclSpec().getSourceRange().getBegin()); D.SetRangeBegin(D.getDeclSpec().getSourceRange().getBegin());
} }

Просмотреть файл

@ -1394,6 +1394,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
bool Invalid = false; bool Invalid = false;
if (getLangOptions().CPlusPlus) { if (getLangOptions().CPlusPlus) {
const char* PrevSpec = 0; const char* PrevSpec = 0;
unsigned DiagID;
// C++ [class.union]p3: // C++ [class.union]p3:
// Anonymous unions declared in a named namespace or in the // Anonymous unions declared in a named namespace or in the
// global namespace shall be declared static. // global namespace shall be declared static.
@ -1405,7 +1406,8 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
Invalid = true; Invalid = true;
// Recover by adding 'static'. // Recover by adding 'static'.
DS.SetStorageClassSpec(DeclSpec::SCS_static, SourceLocation(), PrevSpec); DS.SetStorageClassSpec(DeclSpec::SCS_static, SourceLocation(),
PrevSpec, DiagID);
} }
// C++ [class.union]p3: // C++ [class.union]p3:
// A storage class is not allowed in a declaration of an // A storage class is not allowed in a declaration of an
@ -1418,7 +1420,7 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
// Recover by removing the storage specifier. // Recover by removing the storage specifier.
DS.SetStorageClassSpec(DeclSpec::SCS_unspecified, SourceLocation(), DS.SetStorageClassSpec(DeclSpec::SCS_unspecified, SourceLocation(),
PrevSpec); PrevSpec, DiagID);
} }
// C++ [class.union]p2: // C++ [class.union]p2:
@ -3434,8 +3436,9 @@ void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
// type. // type.
DeclSpec DS; DeclSpec DS;
const char* PrevSpec; // unused const char* PrevSpec; // unused
unsigned DiagID; // unused
DS.SetTypeSpecType(DeclSpec::TST_int, FTI.ArgInfo[i].IdentLoc, DS.SetTypeSpecType(DeclSpec::TST_int, FTI.ArgInfo[i].IdentLoc,
PrevSpec); PrevSpec, DiagID);
Declarator ParamD(DS, Declarator::KNRTypeListContext); Declarator ParamD(DS, Declarator::KNRTypeListContext);
ParamD.SetIdentifier(FTI.ArgInfo[i].Ident, FTI.ArgInfo[i].IdentLoc); ParamD.SetIdentifier(FTI.ArgInfo[i].Ident, FTI.ArgInfo[i].IdentLoc);
FTI.ArgInfo[i].Param = ActOnParamDeclarator(S, ParamD); FTI.ArgInfo[i].Param = ActOnParamDeclarator(S, ParamD);
@ -3688,7 +3691,8 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
// Set a Declarator for the implicit definition: int foo(); // Set a Declarator for the implicit definition: int foo();
const char *Dummy; const char *Dummy;
DeclSpec DS; DeclSpec DS;
bool Error = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, Dummy); unsigned DiagID;
bool Error = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, Dummy, DiagID);
Error = Error; // Silence warning. Error = Error; // Silence warning.
assert(!Error && "Error setting up implicit decl!"); assert(!Error && "Error setting up implicit decl!");
Declarator D(DS, Declarator::BlockContext); Declarator D(DS, Declarator::BlockContext);