[cfe-commits] r39223 - in /cfe/cfe/trunk: AST/SemaDecl.cpp AST/SemaType.cpp Parse/DeclSpec.cpp Parse/ParseDecl.cpp Parse/Parser.cpp Sema/SemaDecl.cpp Sema/SemaType.cpp include/clang/Parse/DeclSpec.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:41:27 PDT 2007
Author: sabre
Date: Wed Jul 11 11:41:27 2007
New Revision: 39223
URL: http://llvm.org/viewvc/llvm-project?rev=39223&view=rev
Log:
Finish converting DeclSpec to use accessors.
Modified:
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/AST/SemaType.cpp
cfe/cfe/trunk/Parse/DeclSpec.cpp
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Parse/Parser.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaType.cpp
cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:41:27 2007
@@ -75,7 +75,7 @@
}
Decl *New;
- if (D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef) {
+ if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
New = ParseTypedefDecl(S, D, PrevDecl);
} else if (D.isFunctionDeclarator())
New = new FunctionDecl(II, GetTypeForDeclarator(D, S), PrevDecl);
@@ -135,8 +135,10 @@
// void bar() { X(); } <-- implicit decl for X in another scope.
// Set a Declarator for the implicit definition: int foo();
+ const char *Dummy;
DeclSpec DS;
- DS.TypeSpecType = DeclSpec::TST_int;
+ bool Error = DS.SetTypeSpecType(DeclSpec::TST_int, Dummy);
+ assert(!Error && "Error setting up implicit decl!");
Declarator D(DS, Declarator::BlockContext);
D.AddTypeInfo(DeclaratorTypeInfo::getFunction(false, false, true, Loc));
D.SetIdentifier(&II, Loc);
Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:41:27 2007
@@ -24,28 +24,29 @@
// FIXME: Should move the logic from DeclSpec::Finish to here for validity
// checking.
- switch (DS.TypeSpecType) {
+ switch (DS.getTypeSpecType()) {
default: return TypeRef(); // FIXME: Handle unimp cases!
case DeclSpec::TST_void: return Ctx.VoidTy;
case DeclSpec::TST_char:
- if (DS.TypeSpecSign == DeclSpec::TSS_unspecified)
+ if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
return Ctx.CharTy;
- else if (DS.TypeSpecSign == DeclSpec::TSS_signed)
+ else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed)
return Ctx.SignedCharTy;
else {
- assert(DS.TypeSpecSign == DeclSpec::TSS_unsigned && "Unknown TSS value");
+ assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
+ "Unknown TSS value");
return Ctx.UnsignedCharTy;
}
case DeclSpec::TST_int:
- if (DS.TypeSpecSign != DeclSpec::TSS_unsigned) {
- switch (DS.TypeSpecWidth) {
+ if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) {
+ switch (DS.getTypeSpecWidth()) {
case DeclSpec::TSW_unspecified: return Ctx.IntTy;
case DeclSpec::TSW_short: return Ctx.ShortTy;
case DeclSpec::TSW_long: return Ctx.LongTy;
case DeclSpec::TSW_longlong: return Ctx.LongLongTy;
}
} else {
- switch (DS.TypeSpecWidth) {
+ switch (DS.getTypeSpecWidth()) {
case DeclSpec::TSW_unspecified: return Ctx.UnsignedIntTy;
case DeclSpec::TSW_short: return Ctx.UnsignedShortTy;
case DeclSpec::TSW_long: return Ctx.UnsignedLongTy;
@@ -53,17 +54,17 @@
}
}
case DeclSpec::TST_float:
- if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+ if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified)
return Ctx.FloatTy;
- assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+ assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex &&
"FIXME: imaginary types not supported yet!");
return Ctx.FloatComplexTy;
case DeclSpec::TST_double: {
- bool isLong = DS.TypeSpecWidth == DeclSpec::TSW_long;
- if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+ bool isLong = DS.getTypeSpecWidth() == DeclSpec::TSW_long;
+ if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified)
return isLong ? Ctx.LongDoubleTy : Ctx.DoubleTy;
- assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+ assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex &&
"FIXME: imaginary types not supported yet!");
return isLong ? Ctx.LongDoubleComplexTy : Ctx.DoubleComplexTy;
}
Modified: cfe/cfe/trunk/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/DeclSpec.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/DeclSpec.cpp (original)
+++ cfe/cfe/trunk/Parse/DeclSpec.cpp Wed Jul 11 11:41:27 2007
@@ -124,12 +124,23 @@
return false;
}
+bool DeclSpec::SetStorageClassSpecThread(const char *&PrevSpec) {
+ if (SCS_thread_specified) {
+ PrevSpec = "__thread";
+ return true;
+ }
+ SCS_thread_specified = true;
+ return false;
+}
+
/// These methods set the specified attribute of the DeclSpec, but return true
/// and ignore the request if invalid (e.g. "extern" then "auto" is
/// specified).
bool DeclSpec::SetTypeSpecWidth(TSW W, const char *&PrevSpec) {
- if (TypeSpecWidth != TSW_unspecified)
+ if (TypeSpecWidth != TSW_unspecified &&
+ // Allow turning long -> long long.
+ (W != TSW_longlong || TypeSpecWidth != TSW_long))
return BadSpecifier(TypeSpecWidth, PrevSpec);
TypeSpecWidth = W;
return false;
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:41:27 2007
@@ -280,12 +280,12 @@
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, PrevSpec);
break;
case tok::kw_extern:
- if (DS.SCS_thread_specified)
+ if (DS.isThreadSpecified())
Diag(Tok, diag::ext_thread_before, "extern");
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, PrevSpec);
break;
case tok::kw_static:
- if (DS.SCS_thread_specified)
+ if (DS.isThreadSpecified())
Diag(Tok, diag::ext_thread_before, "static");
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, PrevSpec);
break;
@@ -296,10 +296,7 @@
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, PrevSpec);
break;
case tok::kw___thread:
- if (DS.SCS_thread_specified)
- isInvalid = 2, PrevSpec = "__thread";
- else
- DS.SCS_thread_specified = true;
+ isInvalid = DS.SetStorageClassSpecThread(PrevSpec)*2;
break;
// type-specifiers
@@ -307,12 +304,10 @@
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, PrevSpec);
break;
case tok::kw_long:
- if (DS.TypeSpecWidth != DeclSpec::TSW_long) {
+ if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, PrevSpec);
- } else {
- DS.TypeSpecWidth = DeclSpec::TSW_unspecified;
+ else
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, PrevSpec);
- }
break;
case tok::kw_signed:
isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, PrevSpec);
@@ -997,7 +992,7 @@
// FIXME: Get better loc info from declspecs!
Diag(DeclaratorInfo.getIdentifierLoc(),
diag::err_invalid_storage_class_in_func_decl);
- DS.StorageClassSpec = DeclSpec::SCS_unspecified;
+ DS.ClearStorageClassSpecs();
break;
}
Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:41:27 2007
@@ -232,12 +232,15 @@
// Install builtin types.
// TODO: Move this someplace more useful.
{
+ const char *Dummy;
+
//__builtin_va_list
DeclSpec DS;
- DS.StorageClassSpec = DeclSpec::SCS_typedef;
+ bool Error = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Dummy);
// TODO: add a 'TST_builtin' type?
- DS.TypeSpecType = DeclSpec::TST_int;
+ Error |= DS.SetTypeSpecType(DeclSpec::TST_int, Dummy);
+ assert(!Error && "Error setting up __builtin_va_list!");
Declarator D(DS, Declarator::FileContext);
D.SetIdentifier(PP.getIdentifierInfo("__builtin_va_list"),SourceLocation());
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:41:27 2007
@@ -75,7 +75,7 @@
}
Decl *New;
- if (D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef) {
+ if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
New = ParseTypedefDecl(S, D, PrevDecl);
} else if (D.isFunctionDeclarator())
New = new FunctionDecl(II, GetTypeForDeclarator(D, S), PrevDecl);
@@ -135,8 +135,10 @@
// void bar() { X(); } <-- implicit decl for X in another scope.
// Set a Declarator for the implicit definition: int foo();
+ const char *Dummy;
DeclSpec DS;
- DS.TypeSpecType = DeclSpec::TST_int;
+ bool Error = DS.SetTypeSpecType(DeclSpec::TST_int, Dummy);
+ assert(!Error && "Error setting up implicit decl!");
Declarator D(DS, Declarator::BlockContext);
D.AddTypeInfo(DeclaratorTypeInfo::getFunction(false, false, true, Loc));
D.SetIdentifier(&II, Loc);
Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:41:27 2007
@@ -24,28 +24,29 @@
// FIXME: Should move the logic from DeclSpec::Finish to here for validity
// checking.
- switch (DS.TypeSpecType) {
+ switch (DS.getTypeSpecType()) {
default: return TypeRef(); // FIXME: Handle unimp cases!
case DeclSpec::TST_void: return Ctx.VoidTy;
case DeclSpec::TST_char:
- if (DS.TypeSpecSign == DeclSpec::TSS_unspecified)
+ if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
return Ctx.CharTy;
- else if (DS.TypeSpecSign == DeclSpec::TSS_signed)
+ else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed)
return Ctx.SignedCharTy;
else {
- assert(DS.TypeSpecSign == DeclSpec::TSS_unsigned && "Unknown TSS value");
+ assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
+ "Unknown TSS value");
return Ctx.UnsignedCharTy;
}
case DeclSpec::TST_int:
- if (DS.TypeSpecSign != DeclSpec::TSS_unsigned) {
- switch (DS.TypeSpecWidth) {
+ if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) {
+ switch (DS.getTypeSpecWidth()) {
case DeclSpec::TSW_unspecified: return Ctx.IntTy;
case DeclSpec::TSW_short: return Ctx.ShortTy;
case DeclSpec::TSW_long: return Ctx.LongTy;
case DeclSpec::TSW_longlong: return Ctx.LongLongTy;
}
} else {
- switch (DS.TypeSpecWidth) {
+ switch (DS.getTypeSpecWidth()) {
case DeclSpec::TSW_unspecified: return Ctx.UnsignedIntTy;
case DeclSpec::TSW_short: return Ctx.UnsignedShortTy;
case DeclSpec::TSW_long: return Ctx.UnsignedLongTy;
@@ -53,17 +54,17 @@
}
}
case DeclSpec::TST_float:
- if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+ if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified)
return Ctx.FloatTy;
- assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+ assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex &&
"FIXME: imaginary types not supported yet!");
return Ctx.FloatComplexTy;
case DeclSpec::TST_double: {
- bool isLong = DS.TypeSpecWidth == DeclSpec::TSW_long;
- if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+ bool isLong = DS.getTypeSpecWidth() == DeclSpec::TSW_long;
+ if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified)
return isLong ? Ctx.LongDoubleTy : Ctx.DoubleTy;
- assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+ assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex &&
"FIXME: imaginary types not supported yet!");
return isLong ? Ctx.LongDoubleComplexTy : Ctx.DoubleComplexTy;
}
Modified: cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=39223&r1=39222&r2=39223&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:41:27 2007
@@ -93,6 +93,8 @@
PQ_FunctionSpecifier = 8
};
+private:
+
// storage-class-specifier
SCS StorageClassSpec : 3;
bool SCS_thread_specified : 1;
@@ -103,8 +105,6 @@
TSS TypeSpecSign : 2;
TST TypeSpecType : 4;
-private:
-
// type-qualifiers
unsigned TypeQualifiers : 3; // Bitwise OR of TQ.
@@ -176,6 +176,7 @@
/// and ignore the request if invalid (e.g. "extern" then "auto" is
/// specified). The name of the previous specifier is returned in prevspec.
bool SetStorageClassSpec(SCS S, const char *&PrevSpec);
+ bool SetStorageClassSpecThread(const char *&PrevSpec);
bool SetTypeSpecWidth(TSW W, const char *&PrevSpec);
bool SetTypeSpecComplex(TSC C, const char *&PrevSpec);
bool SetTypeSpecSign(TSS S, const char *&PrevSpec);
More information about the cfe-commits
mailing list