[cfe-commits] r90027 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Parse/DeclSpec.h lib/Parse/ParseExprCXX.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaType.cpp test/Parser/cxx0x-literal-operators.cpp

Sean Hunt rideau3 at gmail.com
Fri Nov 27 20:44:29 PST 2009


Author: coppro
Date: Fri Nov 27 22:44:28 2009
New Revision: 90027

URL: http://llvm.org/viewvc/llvm-project?rev=90027&view=rev
Log:
Add Parser support for C++0x literal operators ('operator "" i').
DeclarationName can't handle them yet, so right now Parser just errors out on them.

Added:
    cfe/trunk/test/Parser/cxx0x-literal-operators.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/include/clang/Parse/DeclSpec.h
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=90027&r1=90026&r2=90027&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Nov 27 22:44:28 2009
@@ -242,6 +242,10 @@
 // C++ operator overloading
 def err_operator_missing_type_specifier : Error<
   "missing type specifier after 'operator'">;
+def err_operator_string_not_empty : Error<
+  "string literal after 'operator' must be '\"\"'">;
+def err_unsupported_literal_operator : Error<
+  "C++0x literal operator support is currently under development">;
 
 // Classes.
 def err_anon_type_definition : Error<

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

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Fri Nov 27 22:44:28 2009
@@ -484,6 +484,8 @@
     IK_OperatorFunctionId,
     /// \brief A conversion function name, e.g., operator int.
     IK_ConversionFunctionId,
+    /// \brief A user-defined literal name, e.g., operator "" _i.
+    IK_LiteralOperatorId,
     /// \brief A constructor name.
     IK_ConstructorName,
     /// \brief A destructor name.
@@ -495,7 +497,8 @@
   /// \brief Anonymous union that holds extra data associated with the
   /// parsed unqualified-id.
   union {
-    /// \brief When Kind == IK_Identifier, the parsed identifier.
+    /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind
+    /// == IK_UserLiteralId, the identifier suffix.
     IdentifierInfo *Identifier;
     
     /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator
@@ -607,6 +610,22 @@
     EndLocation = EndLoc;
     ConversionFunctionId = Ty;
   }
+
+  /// \brief Specific that this unqualified-id was parsed as a
+  /// literal-operator-id.
+  ///
+  /// \param Id the parsed identifier.
+  ///
+  /// \param OpLoc the location of the 'operator' keyword.
+  ///
+  /// \param IdLoc the location of the identifier.
+  void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
+                              SourceLocation IdLoc) {
+    Kind = IK_LiteralOperatorId;
+    Identifier = const_cast<IdentifierInfo *>(Id);
+    StartLocation = OpLoc;
+    EndLocation = IdLoc;
+  }
   
   /// \brief Specify that this unqualified-id was parsed as a constructor name.
   ///

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Fri Nov 27 22:44:28 2009
@@ -1031,6 +1031,27 @@
     Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
     return false;
   }
+
+  // Parse a literal-operator-id.
+  //
+  //   literal-operator-id: [C++0x 13.5.8]
+  //     operator "" identifier
+
+  if (getLang().CPlusPlus0x && Tok.is(tok::string_literal)) {
+    if (Tok.getLength() != 2)
+      Diag(Tok.getLocation(), diag::err_operator_string_not_empty);
+    ConsumeStringToken();
+
+    if (Tok.isNot(tok::identifier)) {
+      Diag(Tok.getLocation(), diag::err_expected_ident);
+      return true;
+    }
+
+    IdentifierInfo *II = Tok.getIdentifierInfo();
+    Result.setLiteralOperatorId(II, KeywordLoc, ConsumeToken());
+    Diag(KeywordLoc, diag::err_unsupported_literal_operator);
+    return true;
+  }
   
   // Parse a conversion-function-id.
   //

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Nov 27 22:44:28 2009
@@ -1765,7 +1765,10 @@
     case UnqualifiedId::IK_OperatorFunctionId:
       return Context.DeclarationNames.getCXXOperatorName(
                                                          Name.OperatorFunctionId.Operator);
-      
+
+    case UnqualifiedId::IK_LiteralOperatorId:
+      assert(false && "We don't support these; Parse shouldn't have allowed propagation");
+
     case UnqualifiedId::IK_ConversionFunctionId: {
       QualType Ty = GetTypeFromParser(Name.ConversionFunctionId);
       if (Ty.isNull())

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Nov 27 22:44:28 2009
@@ -2823,6 +2823,7 @@
   switch (Name.getKind()) {
   case UnqualifiedId::IK_Identifier:
   case UnqualifiedId::IK_OperatorFunctionId:
+  case UnqualifiedId::IK_LiteralOperatorId:
   case UnqualifiedId::IK_ConversionFunctionId:
     break;
       

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Nov 27 22:44:28 2009
@@ -879,6 +879,7 @@
   switch (D.getName().getKind()) {
   case UnqualifiedId::IK_Identifier:
   case UnqualifiedId::IK_OperatorFunctionId:
+  case UnqualifiedId::IK_LiteralOperatorId:
   case UnqualifiedId::IK_TemplateId:
     T = ConvertDeclSpecToType(D, *this);
     

Added: cfe/trunk/test/Parser/cxx0x-literal-operators.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-literal-operators.cpp?rev=90027&view=auto

==============================================================================
--- cfe/trunk/test/Parser/cxx0x-literal-operators.cpp (added)
+++ cfe/trunk/test/Parser/cxx0x-literal-operators.cpp Fri Nov 27 22:44:28 2009
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
+
+void operator "" (); // expected-error {{expected identifier}}
+void operator "k" foo(); // expected-error {{string literal after 'operator' must be '""'}} \
+                         // expected-error {{C++0x literal operator support is currently under development}}
\ No newline at end of file





More information about the cfe-commits mailing list