[cfe-commits] r123606 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDeclCXX.cpp lib/Parse/Parser.cpp test/Parser/cxx0x-override-control-keywords.cpp

Douglas Gregor dgregor at apple.com
Mon Jan 17 09:44:24 PST 2011


On Jan 16, 2011, at 3:56 PM, Anders Carlsson wrote:

> Author: andersca
> Date: Sun Jan 16 17:56:42 2011
> New Revision: 123606
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=123606&view=rev
> Log:
> 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.
> 
> 
> Added:
>    cfe/trunk/test/Parser/cxx0x-override-control-keywords.cpp
> Modified:
>    cfe/trunk/include/clang/Parse/Parser.h
>    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>    cfe/trunk/lib/Parse/Parser.cpp
> 
> Modified: cfe/trunk/include/clang/Parse/Parser.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=123606&r1=123605&r2=123606&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Parse/Parser.h (original)
> +++ cfe/trunk/include/clang/Parse/Parser.h Sun Jan 16 17:56:42 2011
> @@ -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.
> 
> Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=123606&r1=123605&r2=123606&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sun Jan 16 17:56:42 2011
> @@ -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'
>     //
> 
> Modified: cfe/trunk/lib/Parse/Parser.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=123606&r1=123605&r2=123606&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/Parser.cpp (original)
> +++ cfe/trunk/lib/Parse/Parser.cpp Sun Jan 16 17:56:42 2011
> @@ -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");
> +  }

How about initializing these to NULL in the constructor, then have isCXX0XVirtSpecifier() initialize them only when it sees an identifier at that position?

	- Doug





More information about the cfe-commits mailing list