Begin work on supporting "N3206: Override control: Eliminating Attributes", from

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3206.htm

This lands support for parsing virt-specifier-seq after member functions, including the
contextual keywords 'final', and 'override'. The keywords are not yet used for anything.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123606 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index aebf82e..497c08b 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -112,6 +112,10 @@
   IdentifierInfo *Ident_vector;
   IdentifierInfo *Ident_pixel;
 
+  /// C++0x contextual keywords. 
+  IdentifierInfo *Ident_final;
+  IdentifierInfo *Ident_override;
+
   llvm::OwningPtr<PragmaHandler> AlignHandler;
   llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler;
   llvm::OwningPtr<PragmaHandler> OptionsHandler;
@@ -1521,6 +1525,9 @@
   
   ExprResult ParseCXX0XAlignArgument(SourceLocation Start);
 
+  bool isCXX0XVirtSpecifier() const;
+  void ParseOptionalCXX0XVirtSpecifierSeq();
+
   /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
   /// enter a new C++ declarator scope and exit it when the function is
   /// finished.
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index a5cdaa8..960a9fa 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -1261,6 +1261,39 @@
   }
 }
 
+/// isCXX0XVirtSpecifier - Determine whether the next token is a C++0x
+/// virt-specifier.
+///
+///       virt-specifier:
+///         override
+///         final
+///         new
+bool Parser::isCXX0XVirtSpecifier() const {
+  if (Tok.is(tok::kw_new))
+    return true;
+
+  if (Tok.isNot(tok::identifier))
+    return false;
+
+  const IdentifierInfo *II = Tok.getIdentifierInfo();
+  return II == Ident_override || II == Ident_final;
+}
+
+/// ParseOptionalCXX0XVirtSpecifierSeq - Parse a virt-specifier-seq.
+///
+///       virt-specifier-seq:
+///         virt-specifier
+///         virt-specifier-seq virt-specifier
+void Parser::ParseOptionalCXX0XVirtSpecifierSeq() {
+  if (!getLang().CPlusPlus0x)
+    return;
+
+  while (isCXX0XVirtSpecifier()) {
+    // FIXME: Actually do something with the specifier.
+    ConsumeToken();
+  }
+}
+
 /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration.
 ///
 ///       member-declaration:
@@ -1277,10 +1310,19 @@
 ///         member-declarator-list ',' member-declarator
 ///
 ///       member-declarator:
-///         declarator pure-specifier[opt]
+///         declarator virt-specifier-seq[opt] pure-specifier[opt]
 ///         declarator constant-initializer[opt]
 ///         identifier[opt] ':' constant-expression
 ///
+///       virt-specifier-seq:
+///         virt-specifier
+///         virt-specifier-seq virt-specifier
+///
+///       virt-specifier:
+///         override
+///         final
+///         new
+/// 
 ///       pure-specifier:
 ///         '= 0'
 ///
@@ -1470,6 +1512,8 @@
         SkipUntil(tok::comma, true, true);
     }
 
+    ParseOptionalCXX0XVirtSpecifierSeq();
+
     // pure-specifier:
     //   '= 0'
     //
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index aa0ad79..473c6ad 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -387,6 +387,12 @@
     ObjCTypeQuals[objc_byref] = &PP.getIdentifierTable().get("byref");
   }
 
+  // Initialize C++0x contextual keywords.
+  if (getLang().CPlusPlus0x) {
+    Ident_final = &PP.getIdentifierTable().get("final");
+    Ident_override = &PP.getIdentifierTable().get("override");
+  }
+
   Ident_super = &PP.getIdentifierTable().get("super");
 
   if (getLang().AltiVec) {
diff --git a/test/Parser/cxx0x-override-control-keywords.cpp b/test/Parser/cxx0x-override-control-keywords.cpp
new file mode 100644
index 0000000..5643621
--- /dev/null
+++ b/test/Parser/cxx0x-override-control-keywords.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+struct S {
+  virtual void final() final;
+  virtual void override() override;
+  virtual void n() new;
+};