[cfe-commits] r73247 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseTemplate.cpp lib/Sema/Sema.h lib/Sema/SemaTemplate.cpp test/SemaTemplate/variadic-parse.cpp
Douglas Gregor
dgregor at apple.com
Fri Jun 12 15:44:47 PDT 2009
On Jun 12, 2009, at 12:58 PM, Anders Carlsson wrote:
> Author: andersca
> Date: Fri Jun 12 14:58:00 2009
> New Revision: 73247
>
> URL: http://llvm.org/viewvc/llvm-project?rev=73247&view=rev
> Log:
> Parse support for C++0x type parameter packs.
Fun! Comments below.
> Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=73247&r1=73246&r2=73247&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseTemplate.cpp Fri Jun 12 14:58:00 2009
> @@ -290,11 +290,11 @@
> /// parameter-declaration
> ///
> /// type-parameter: (see below)
> -/// 'class' identifier[opt]
> +/// 'class' ...[opt] identifier[opt]
> /// 'class' identifier[opt] '=' type-id
> -/// 'typename' identifier[opt]
> +/// 'typename' ...[opt] identifier[opt]
> /// 'typename' identifier[opt] '=' type-id
> -/// 'template' '<' template-parameter-list '>' 'class'
> identifier[opt]
> +/// 'template' ...[opt] '<' template-parameter-list '>'
> 'class' identifier[opt]
> /// 'template' '<' template-parameter-list '>' 'class'
> identifier[opt] = id-expression
Please mark the C++0x-specific productions with "[C++0x]"
> Parser::DeclPtrTy
> Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
> @@ -319,9 +319,9 @@
> /// ParseTemplateTemplateParameter and ParseNonTypeTemplateParameter.
> ///
> /// type-parameter: [C++ temp.param]
> -/// 'class' identifier[opt]
> +/// 'class' ...[opt] identifier[opt]
> /// 'class' identifier[opt] '=' type-id
> -/// 'typename' identifier[opt]
> +/// 'typename' ...[opt] identifier[opt]
> /// 'typename' identifier[opt] '=' type-id
Same here.
> Parser::DeclPtrTy Parser::ParseTypeParameter(unsigned Depth,
> unsigned Position){
> assert((Tok.is(tok::kw_class) || Tok.is(tok::kw_typename)) &&
> @@ -331,6 +331,14 @@
> bool TypenameKeyword = Tok.is(tok::kw_typename);
> SourceLocation KeyLoc = ConsumeToken();
>
> + // Grab the ellipsis (if given).
> + bool Ellipsis = false;
> + SourceLocation EllipsisLoc;
> + if (getLang().CPlusPlus0x && Tok.is(tok::ellipsis)) {
> + Ellipsis = true;
> + EllipsisLoc = ConsumeToken();
> + }
> +
We should always parse the ellipsis when it's there (we know what the
user means!), then emit a diagnostic if we're not in C++0x mode.
> // Grab the template parameter name (if given)
> SourceLocation NameLoc;
> IdentifierInfo* ParamName = 0;
> @@ -347,6 +355,7 @@
> }
>
> DeclPtrTy TypeParam = Actions.ActOnTypeParameter(CurScope,
> TypenameKeyword,
> + Ellipsis,
> EllipsisLoc,
> KeyLoc,
> ParamName, NameLoc,
> Depth, Position);
>
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=73247&r1=73246&r2=73247&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Fri Jun 12 14:58:00 2009
> @@ -1880,7 +1880,8 @@
> bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl
> *PrevDecl);
> TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl);
>
> - virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename,
> + virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename,
> bool Ellipsis,
> + SourceLocation EllipsisLoc,
> SourceLocation KeyLoc,
> IdentifierInfo *ParamName,
> SourceLocation ParamNameLoc,
>
> Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=73247&r1=73246&r2=73247&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Jun 12 14:58:00 2009
> @@ -140,7 +140,8 @@
> /// ParamName is the location of the parameter name (if any).
> /// If the type parameter has a default argument, it will be added
> /// later via ActOnTypeParameterDefault.
> -Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename,
> +Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename,
> bool Ellipsis,
> + SourceLocation EllipsisLoc,
> SourceLocation KeyLoc,
> IdentifierInfo *ParamName,
> SourceLocation ParamNameLoc,
>
> Added: cfe/trunk/test/SemaTemplate/variadic-parse.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/variadic-parse.cpp?rev=73247&view=auto
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/test/SemaTemplate/variadic-parse.cpp (added)
> +++ cfe/trunk/test/SemaTemplate/variadic-parse.cpp Fri Jun 12
> 14:58:00 2009
> @@ -0,0 +1,6 @@
> +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
> +
> +// Parsing type parameter packs.
> +template <typename ... Args> struct T1 {};
> +template <typename ... > struct T2 {};
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list