aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean Hunt <scshunt@csclub.uwaterloo.ca>2011-05-19 05:37:45 +0000
committerSean Hunt <scshunt@csclub.uwaterloo.ca>2011-05-19 05:37:45 +0000
commitdb5d44b775c60166074acd184ca9f1981c10c2a7 (patch)
treec52212d75860727890b85255baa863089c41ddae /lib
parent0ee33912f8ec3453856c8a32ed2c2e8007bed614 (diff)
Implement __underlying_type for libc++.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131633 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Parse/ParseDecl.cpp8
-rw-r--r--lib/Parse/ParseDeclCXX.cpp36
-rw-r--r--lib/Parse/ParseExprCXX.cpp1
-rw-r--r--lib/Parse/ParseTentative.cpp5
-rw-r--r--lib/Sema/DeclSpec.cpp1
-rw-r--r--lib/Sema/SemaDecl.cpp3
-rw-r--r--lib/Sema/SemaTemplateVariadic.cpp3
-rw-r--r--lib/Sema/SemaType.cpp23
8 files changed, 78 insertions, 2 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index d7b90f129c..eadd5464f2 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1859,6 +1859,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
ParseDecltypeSpecifier(DS);
continue;
+ case tok::kw___underlying_type:
+ ParseUnderlyingTypeSpecifier(DS);
+
// OpenCL qualifiers:
case tok::kw_private:
if (!getLang().OpenCL)
@@ -2129,6 +2132,11 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, bool& isInvalid,
ParseDecltypeSpecifier(DS);
return true;
+ // C++0x type traits support.
+ case tok::kw___underlying_type:
+ ParseUnderlyingTypeSpecifier(DS);
+ return true;
+
// OpenCL qualifiers:
case tok::kw_private:
if (!getLang().OpenCL)
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 91b55d5b58..f623c8e5b6 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -572,6 +572,42 @@ void Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
Diag(StartLoc, DiagID) << PrevSpec;
}
+void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) {
+ assert(Tok.is(tok::kw___underlying_type) &&
+ "Not an underlying type specifier");
+
+ SourceLocation StartLoc = ConsumeToken();
+ SourceLocation LParenLoc = Tok.getLocation();
+
+ if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
+ "__underlying_type")) {
+ SkipUntil(tok::r_paren);
+ return;
+ }
+
+ TypeResult Result = ParseTypeName();
+ if (Result.isInvalid()) {
+ SkipUntil(tok::r_paren);
+ return;
+ }
+
+ // Match the ')'
+ SourceLocation RParenLoc;
+ if (Tok.is(tok::r_paren))
+ RParenLoc = ConsumeParen();
+ else
+ MatchRHSPunctuation(tok::r_paren, LParenLoc);
+
+ if (RParenLoc.isInvalid())
+ return;
+
+ const char *PrevSpec = 0;
+ unsigned DiagID;
+ if (DS.SetTypeSpecType(DeclSpec::TST_underlying_type, StartLoc, PrevSpec,
+ DiagID, Result.release()))
+ Diag(StartLoc, DiagID) << PrevSpec;
+}
+
/// ParseClassName - Parse a C++ class-name, which names a class. Note
/// that we only check that the result names a type; semantic analysis
/// will need to verify that the type names a class. The result is
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index 7410dbecf1..0862af323e 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -962,6 +962,7 @@ bool Parser::isCXXSimpleTypeSpecifier() const {
case tok::kw_bool:
case tok::kw_decltype:
case tok::kw_typeof:
+ case tok::kw___underlying_type:
return true;
default:
diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp
index 12152c36cc..78d2c9091b 100644
--- a/lib/Parse/ParseTentative.cpp
+++ b/lib/Parse/ParseTentative.cpp
@@ -694,6 +694,7 @@ Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) {
case tok::kw_char16_t:
case tok::kw_char32_t:
case tok::kw_decltype:
+ case tok::kw___underlying_type:
case tok::kw_thread_local:
case tok::kw__Decimal32:
case tok::kw__Decimal64:
@@ -1012,6 +1013,10 @@ Parser::TPResult Parser::isCXXDeclarationSpecifier() {
case tok::kw_decltype:
return TPResult::True();
+ // C++0x type traits support
+ case tok::kw___underlying_type:
+ return TPResult::True();
+
default:
return TPResult::False();
}
diff --git a/lib/Sema/DeclSpec.cpp b/lib/Sema/DeclSpec.cpp
index 0f20d10b07..d6f8f91bbf 100644
--- a/lib/Sema/DeclSpec.cpp
+++ b/lib/Sema/DeclSpec.cpp
@@ -309,6 +309,7 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
case DeclSpec::TST_typeofExpr: return "typeof";
case DeclSpec::TST_auto: return "auto";
case DeclSpec::TST_decltype: return "(decltype)";
+ case DeclSpec::TST_underlying_type: return "__underlying_type";
case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
case DeclSpec::TST_error: return "(error)";
}
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7c6cde2296..fd28f2b6ee 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2864,7 +2864,8 @@ static bool RebuildDeclaratorInCurrentInstantiation(Sema &S, Declarator &D,
switch (DS.getTypeSpecType()) {
case DeclSpec::TST_typename:
case DeclSpec::TST_typeofType:
- case DeclSpec::TST_decltype: {
+ case DeclSpec::TST_decltype:
+ case DeclSpec::TST_underlying_type: {
// Grab the type from the parser.
TypeSourceInfo *TSI = 0;
QualType T = S.GetTypeFromParser(DS.getRepAsType(), &TSI);
diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp
index 096d353bcc..100c6a77a0 100644
--- a/lib/Sema/SemaTemplateVariadic.cpp
+++ b/lib/Sema/SemaTemplateVariadic.cpp
@@ -617,7 +617,8 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
const DeclSpec &DS = D.getDeclSpec();
switch (DS.getTypeSpecType()) {
case TST_typename:
- case TST_typeofType: {
+ case TST_typeofType:
+ case TST_underlying_type: {
QualType T = DS.getRepAsType().get();
if (!T.isNull() && T->containsUnexpandedParameterPack())
return true;
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 06548a44dd..dbacb47812 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -836,6 +836,29 @@ static QualType ConvertDeclSpecToType(Sema &S, TypeProcessingState &state) {
}
break;
}
+ case DeclSpec::TST_underlying_type:
+ // FIXME: Preserve type source info?
+ Result = S.GetTypeFromParser(DS.getRepAsType());
+ assert(!Result.isNull() && "Didn't get a type for __underlying_type?");
+ if (!Result->isDependentType()) {
+ if (Result->isEnumeralType()) {
+ EnumDecl *ED = Result->getAs<EnumType>()->getDecl();
+ S.DiagnoseUseOfDecl(ED, DS.getTypeSpecTypeLoc());
+ QualType UnderlyingType = ED->getIntegerType();
+ if (UnderlyingType.isNull()) {
+ declarator.setInvalidType(true);
+ Result = Context.IntTy;
+ } else {
+ Result = UnderlyingType;
+ }
+ } else {
+ S.Diag(DS.getTypeSpecTypeLoc(),
+ diag::err_only_enums_have_underlying_types);
+ Result = Context.IntTy;
+ }
+ }
+ break;
+
case DeclSpec::TST_auto: {
// TypeQuals handled by caller.
Result = Context.getAutoType(QualType());