[cfe-commits] r74086 - in /cfe/trunk: include/clang/Parse/DeclSpec.h include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseTentative.cpp lib/Sema/SemaType.cpp

Anders Carlsson andersca at mac.com
Wed Jun 24 10:47:45 PDT 2009


Author: andersca
Date: Wed Jun 24 12:47:40 2009
New Revision: 74086

URL: http://llvm.org/viewvc/llvm-project?rev=74086&view=rev
Log:
Parse the C++0x decltype specifier.

Modified:
    cfe/trunk/include/clang/Parse/DeclSpec.h
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/lib/Parse/ParseTentative.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=74086&r1=74085&r2=74086&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jun 24 12:47:40 2009
@@ -82,6 +82,7 @@
     TST_typename,     // Typedef, C++ class-name or enum name, etc.
     TST_typeofType,
     TST_typeofExpr,
+    TST_decltype,     // C++0x decltype
     TST_error         // erroneous type
   };
   

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=74086&r1=74085&r2=74086&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Jun 24 12:47:40 2009
@@ -1071,6 +1071,7 @@
   AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0);
   AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0);
   void ParseTypeofSpecifier(DeclSpec &DS);
+  void ParseDecltypeSpecifier(DeclSpec &DS);
 
   /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
   /// enter a new C++ declarator scope and exit it when the function is

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=74086&r1=74085&r2=74086&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Jun 24 12:47:40 2009
@@ -1025,6 +1025,10 @@
       ParseTypeofSpecifier(DS);
       continue;
 
+    case tok::kw_decltype:
+      ParseDecltypeSpecifier(DS);
+      continue;
+
     case tok::less:
       // GCC ObjC supports types like "<SomeProtocol>" as a synonym for
       // "id<SomeProtocol>".  This is hopelessly old fashioned and dangerous,
@@ -1102,6 +1106,7 @@
 /// [GNU]   typeof-specifier
 /// [OBJC]  class-name objc-protocol-refs[opt]    [TODO]
 /// [OBJC]  typedef-name objc-protocol-refs[opt]  [TODO]
+/// [C++0x] 'decltype' ( expression )
 bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
                                         const char *&PrevSpec,
                                       const ParsedTemplateInfo &TemplateInfo) {
@@ -1242,6 +1247,11 @@
     ParseTypeofSpecifier(DS);
     return true;
 
+  // C++0x decltype support.
+  case tok::kw_decltype:
+    ParseDecltypeSpecifier(DS);
+    return true;
+      
   case tok::kw___ptr64:
   case tok::kw___w64:
   case tok::kw___cdecl:

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=74086&r1=74085&r2=74086&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Jun 24 12:47:40 2009
@@ -355,6 +355,53 @@
                                               move(AssertMessage));
 }
 
+/// ParseDecltypeSpecifier - Parse a C++0x decltype specifier.
+///
+/// 'decltype' ( expression )
+///
+void Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
+  assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier");
+
+  SourceLocation StartLoc = ConsumeToken();
+  SourceLocation LParenLoc = Tok.getLocation();
+  
+    
+  if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, 
+                       "decltype")) {
+    SkipUntil(tok::r_paren);
+    return;
+  }
+  
+  
+  // Parse the expression
+  
+  // C++0x [dcl.type.simple]p4:
+  //   The operand of the decltype specifier is an unevaluated operand.
+  EnterExpressionEvaluationContext Unevaluated(Actions,
+                                               Action::Unevaluated);
+  OwningExprResult Result = ParseExpression();
+  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;
+  // Check for duplicate type specifiers (e.g. "int decltype(a)").
+  if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, 
+                         Result.release()))
+    Diag(StartLoc, diag::err_invalid_decl_spec_combination) << 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

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=74086&r1=74085&r2=74086&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Wed Jun 24 12:47:40 2009
@@ -543,6 +543,7 @@
 /// [GNU]     typeof-specifier
 /// [GNU]     '_Complex'
 /// [C++0x]   'auto'                                                [TODO]
+/// [C++0x]   'decltype' ( expression )
 ///
 ///         type-name:
 ///           class-name
@@ -695,7 +696,7 @@
 
     return TPResult::True();
 
-    // GNU typeof support.
+  // GNU typeof support.
   case tok::kw_typeof: {
     if (NextToken().isNot(tok::l_paren))
       return TPResult::True();
@@ -716,6 +717,10 @@
     return TPResult::True();
   }
 
+  // C++0x decltype support.
+  case tok::kw_decltype:
+    return TPResult::True();
+
   default:
     return TPResult::False();
   }

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=74086&r1=74085&r2=74086&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jun 24 12:47:40 2009
@@ -236,6 +236,17 @@
     Result = Context.getTypeOfExprType(E);
     break;
   }
+  case DeclSpec::TST_decltype: {
+    Expr *E = static_cast<Expr *>(DS.getTypeRep());
+    assert(E && "Didn't get an expression for decltype?");
+    // TypeQuals handled by caller.
+    
+    // FIXME: Use the right type!
+    Result = Context.IntTy;
+    isInvalid = true;
+    break;
+  }
+    
   case DeclSpec::TST_error:
     Result = Context.IntTy;
     isInvalid = true;





More information about the cfe-commits mailing list