blob: daf9500af88d0dfedf2682ad3c2bf2d87d28f2fa [file] [log] [blame]
Douglas Gregorb3bec712008-12-01 23:54:00 +00001//===--- ParseTemplate.cpp - Template Parsing -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements parsing of C++ templates.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Chris Lattner545f39e2009-01-29 05:15:15 +000015#include "clang/Parse/ParseDiagnostic.h"
Douglas Gregorb3bec712008-12-01 23:54:00 +000016#include "clang/Parse/DeclSpec.h"
17#include "clang/Parse/Scope.h"
Douglas Gregorb3bec712008-12-01 23:54:00 +000018using namespace clang;
19
Douglas Gregora9db0fa2009-05-12 23:25:50 +000020/// \brief Parse a template declaration, explicit instantiation, or
21/// explicit specialization.
22Parser::DeclPtrTy
23Parser::ParseDeclarationStartingWithTemplate(unsigned Context,
24 SourceLocation &DeclEnd,
25 AccessSpecifier AS) {
26 if (Tok.is(tok::kw_template) && NextToken().isNot(tok::less))
27 return ParseExplicitInstantiation(ConsumeToken(), DeclEnd);
28
29 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AS);
30}
31
Douglas Gregora08b6c72009-02-17 23:15:12 +000032/// \brief Parse a template declaration or an explicit specialization.
33///
34/// Template declarations include one or more template parameter lists
35/// and either the function or class template declaration. Explicit
36/// specializations contain one or more 'template < >' prefixes
37/// followed by a (possibly templated) declaration. Since the
38/// syntactic form of both features is nearly identical, we parse all
39/// of the template headers together and let semantic analysis sort
40/// the declarations from the explicit specializations.
Douglas Gregorb3bec712008-12-01 23:54:00 +000041///
42/// template-declaration: [C++ temp]
43/// 'export'[opt] 'template' '<' template-parameter-list '>' declaration
Douglas Gregora08b6c72009-02-17 23:15:12 +000044///
45/// explicit-specialization: [ C++ temp.expl.spec]
46/// 'template' '<' '>' declaration
Chris Lattner5261d0c2009-03-28 19:18:32 +000047Parser::DeclPtrTy
Anders Carlssoned20fb92009-03-26 00:52:18 +000048Parser::ParseTemplateDeclarationOrSpecialization(unsigned Context,
Chris Lattner9802a0a2009-04-02 04:16:50 +000049 SourceLocation &DeclEnd,
Anders Carlssoned20fb92009-03-26 00:52:18 +000050 AccessSpecifier AS) {
Douglas Gregorb3bec712008-12-01 23:54:00 +000051 assert((Tok.is(tok::kw_export) || Tok.is(tok::kw_template)) &&
52 "Token does not start a template declaration.");
53
Douglas Gregor8e7f9572008-12-02 00:41:28 +000054 // Enter template-parameter scope.
Douglas Gregor95d40792008-12-10 06:34:36 +000055 ParseScope TemplateParmScope(this, Scope::TemplateParamScope);
Douglas Gregor8e7f9572008-12-02 00:41:28 +000056
Douglas Gregor52473432008-12-24 02:52:09 +000057 // Parse multiple levels of template headers within this template
58 // parameter scope, e.g.,
59 //
60 // template<typename T>
61 // template<typename U>
62 // class A<T>::B { ... };
63 //
64 // We parse multiple levels non-recursively so that we can build a
65 // single data structure containing all of the template parameter
Douglas Gregora08b6c72009-02-17 23:15:12 +000066 // lists to easily differentiate between the case above and:
Douglas Gregor52473432008-12-24 02:52:09 +000067 //
68 // template<typename T>
69 // class A {
70 // template<typename U> class B;
71 // };
72 //
73 // In the first case, the action for declaring A<T>::B receives
74 // both template parameter lists. In the second case, the action for
75 // defining A<T>::B receives just the inner template parameter list
76 // (and retrieves the outer template parameter list from its
77 // context).
Douglas Gregora9db0fa2009-05-12 23:25:50 +000078 bool isSpecialiation = true;
Douglas Gregor52473432008-12-24 02:52:09 +000079 TemplateParameterLists ParamLists;
80 do {
81 // Consume the 'export', if any.
82 SourceLocation ExportLoc;
83 if (Tok.is(tok::kw_export)) {
84 ExportLoc = ConsumeToken();
85 }
86
87 // Consume the 'template', which should be here.
88 SourceLocation TemplateLoc;
89 if (Tok.is(tok::kw_template)) {
90 TemplateLoc = ConsumeToken();
91 } else {
92 Diag(Tok.getLocation(), diag::err_expected_template);
Chris Lattner5261d0c2009-03-28 19:18:32 +000093 return DeclPtrTy();
Douglas Gregor52473432008-12-24 02:52:09 +000094 }
95
96 // Parse the '<' template-parameter-list '>'
97 SourceLocation LAngleLoc, RAngleLoc;
98 TemplateParameterList TemplateParams;
99 ParseTemplateParameters(ParamLists.size(), TemplateParams, LAngleLoc,
100 RAngleLoc);
101
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000102 if (!TemplateParams.empty())
103 isSpecialiation = false;
104
Douglas Gregor52473432008-12-24 02:52:09 +0000105 ParamLists.push_back(
106 Actions.ActOnTemplateParameterList(ParamLists.size(), ExportLoc,
107 TemplateLoc, LAngleLoc,
Jay Foad9e6bef42009-05-21 09:52:38 +0000108 TemplateParams.data(),
Douglas Gregor52473432008-12-24 02:52:09 +0000109 TemplateParams.size(), RAngleLoc));
110 } while (Tok.is(tok::kw_export) || Tok.is(tok::kw_template));
111
112 // Parse the actual template declaration.
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000113 return ParseSingleDeclarationAfterTemplate(Context,
114 ParsedTemplateInfo(&ParamLists,
115 isSpecialiation),
Douglas Gregore3298aa2009-05-12 21:31:51 +0000116 DeclEnd, AS);
117}
Chris Lattnera17991f2009-03-29 16:50:03 +0000118
Douglas Gregore3298aa2009-05-12 21:31:51 +0000119/// \brief Parse a single declaration that declares a template,
120/// template specialization, or explicit instantiation of a template.
121///
122/// \param TemplateParams if non-NULL, the template parameter lists
123/// that preceded this declaration. In this case, the declaration is a
124/// template declaration, out-of-line definition of a template, or an
125/// explicit template specialization. When NULL, the declaration is an
126/// explicit template instantiation.
127///
128/// \param TemplateLoc when TemplateParams is NULL, the location of
129/// the 'template' keyword that indicates that we have an explicit
130/// template instantiation.
131///
132/// \param DeclEnd will receive the source location of the last token
133/// within this declaration.
134///
135/// \param AS the access specifier associated with this
136/// declaration. Will be AS_none for namespace-scope declarations.
137///
138/// \returns the new declaration.
139Parser::DeclPtrTy
140Parser::ParseSingleDeclarationAfterTemplate(
141 unsigned Context,
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000142 const ParsedTemplateInfo &TemplateInfo,
Douglas Gregore3298aa2009-05-12 21:31:51 +0000143 SourceLocation &DeclEnd,
144 AccessSpecifier AS) {
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000145 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
146 "Template information required");
147
Douglas Gregore3298aa2009-05-12 21:31:51 +0000148 // Parse the declaration specifiers.
149 DeclSpec DS;
150 // FIXME: Pass TemplateLoc through for explicit template instantiations
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000151 ParseDeclarationSpecifiers(DS, TemplateInfo, AS);
Douglas Gregore3298aa2009-05-12 21:31:51 +0000152
153 if (Tok.is(tok::semi)) {
154 DeclEnd = ConsumeToken();
155 return Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
156 }
157
158 // Parse the declarator.
159 Declarator DeclaratorInfo(DS, (Declarator::TheContext)Context);
160 ParseDeclarator(DeclaratorInfo);
161 // Error parsing the declarator?
162 if (!DeclaratorInfo.hasName()) {
163 // If so, skip until the semi-colon or a }.
164 SkipUntil(tok::r_brace, true, true);
165 if (Tok.is(tok::semi))
166 ConsumeToken();
167 return DeclPtrTy();
168 }
169
170 // If we have a declaration or declarator list, handle it.
171 if (isDeclarationAfterDeclarator()) {
172 // Parse this declaration.
Douglas Gregor2ae1d772009-06-23 23:11:28 +0000173 DeclPtrTy ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
174 TemplateInfo);
Douglas Gregore3298aa2009-05-12 21:31:51 +0000175
176 if (Tok.is(tok::comma)) {
177 Diag(Tok, diag::err_multiple_template_declarators)
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000178 << (int)TemplateInfo.Kind;
Douglas Gregore3298aa2009-05-12 21:31:51 +0000179 SkipUntil(tok::semi, true, false);
180 return ThisDecl;
181 }
182
183 // Eat the semi colon after the declaration.
184 ExpectAndConsume(tok::semi, diag::err_expected_semi_declation);
185 return ThisDecl;
186 }
187
188 if (DeclaratorInfo.isFunctionDeclarator() &&
189 isStartOfFunctionDefinition()) {
190 if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
191 Diag(Tok, diag::err_function_declared_typedef);
192
193 if (Tok.is(tok::l_brace)) {
194 // This recovery skips the entire function body. It would be nice
195 // to simply call ParseFunctionDefinition() below, however Sema
196 // assumes the declarator represents a function, not a typedef.
197 ConsumeBrace();
198 SkipUntil(tok::r_brace, true);
199 } else {
200 SkipUntil(tok::semi);
201 }
202 return DeclPtrTy();
203 }
204 return ParseFunctionDefinition(DeclaratorInfo);
205 }
206
207 if (DeclaratorInfo.isFunctionDeclarator())
208 Diag(Tok, diag::err_expected_fn_body);
209 else
210 Diag(Tok, diag::err_invalid_token_after_toplevel_declarator);
211 SkipUntil(tok::semi);
212 return DeclPtrTy();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000213}
214
215/// ParseTemplateParameters - Parses a template-parameter-list enclosed in
Douglas Gregor279272e2009-02-04 19:02:06 +0000216/// angle brackets. Depth is the depth of this template-parameter-list, which
217/// is the number of template headers directly enclosing this template header.
218/// TemplateParams is the current list of template parameters we're building.
219/// The template parameter we parse will be added to this list. LAngleLoc and
220/// RAngleLoc will receive the positions of the '<' and '>', respectively,
221/// that enclose this template parameter list.
Douglas Gregor52473432008-12-24 02:52:09 +0000222bool Parser::ParseTemplateParameters(unsigned Depth,
223 TemplateParameterList &TemplateParams,
224 SourceLocation &LAngleLoc,
225 SourceLocation &RAngleLoc) {
Douglas Gregorb3bec712008-12-01 23:54:00 +0000226 // Get the template parameter list.
227 if(!Tok.is(tok::less)) {
228 Diag(Tok.getLocation(), diag::err_expected_less_after) << "template";
229 return false;
230 }
Douglas Gregor52473432008-12-24 02:52:09 +0000231 LAngleLoc = ConsumeToken();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000232
233 // Try to parse the template parameter list.
Douglas Gregor52473432008-12-24 02:52:09 +0000234 if (Tok.is(tok::greater))
235 RAngleLoc = ConsumeToken();
236 else if(ParseTemplateParameterList(Depth, TemplateParams)) {
Douglas Gregorb3bec712008-12-01 23:54:00 +0000237 if(!Tok.is(tok::greater)) {
238 Diag(Tok.getLocation(), diag::err_expected_greater);
239 return false;
240 }
Douglas Gregor52473432008-12-24 02:52:09 +0000241 RAngleLoc = ConsumeToken();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000242 }
243 return true;
244}
245
246/// ParseTemplateParameterList - Parse a template parameter list. If
247/// the parsing fails badly (i.e., closing bracket was left out), this
248/// will try to put the token stream in a reasonable position (closing
249/// a statement, etc.) and return false.
250///
251/// template-parameter-list: [C++ temp]
252/// template-parameter
253/// template-parameter-list ',' template-parameter
Douglas Gregor52473432008-12-24 02:52:09 +0000254bool
255Parser::ParseTemplateParameterList(unsigned Depth,
256 TemplateParameterList &TemplateParams) {
Douglas Gregorb3bec712008-12-01 23:54:00 +0000257 while(1) {
Chris Lattner5261d0c2009-03-28 19:18:32 +0000258 if (DeclPtrTy TmpParam
Douglas Gregor52473432008-12-24 02:52:09 +0000259 = ParseTemplateParameter(Depth, TemplateParams.size())) {
260 TemplateParams.push_back(TmpParam);
261 } else {
Douglas Gregorb3bec712008-12-01 23:54:00 +0000262 // If we failed to parse a template parameter, skip until we find
263 // a comma or closing brace.
264 SkipUntil(tok::comma, tok::greater, true, true);
265 }
266
267 // Did we find a comma or the end of the template parmeter list?
268 if(Tok.is(tok::comma)) {
269 ConsumeToken();
270 } else if(Tok.is(tok::greater)) {
271 // Don't consume this... that's done by template parser.
272 break;
273 } else {
274 // Somebody probably forgot to close the template. Skip ahead and
275 // try to get out of the expression. This error is currently
276 // subsumed by whatever goes on in ParseTemplateParameter.
277 // TODO: This could match >>, and it would be nice to avoid those
278 // silly errors with template <vec<T>>.
279 // Diag(Tok.getLocation(), diag::err_expected_comma_greater);
280 SkipUntil(tok::greater, true, true);
281 return false;
282 }
283 }
284 return true;
285}
286
287/// ParseTemplateParameter - Parse a template-parameter (C++ [temp.param]).
288///
289/// template-parameter: [C++ temp.param]
290/// type-parameter
291/// parameter-declaration
292///
293/// type-parameter: (see below)
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000294/// 'class' ...[opt][C++0x] identifier[opt]
Douglas Gregorb3bec712008-12-01 23:54:00 +0000295/// 'class' identifier[opt] '=' type-id
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000296/// 'typename' ...[opt][C++0x] identifier[opt]
Douglas Gregorb3bec712008-12-01 23:54:00 +0000297/// 'typename' identifier[opt] '=' type-id
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000298/// 'template' ...[opt][C++0x] '<' template-parameter-list '>' 'class' identifier[opt]
Douglas Gregorb3bec712008-12-01 23:54:00 +0000299/// 'template' '<' template-parameter-list '>' 'class' identifier[opt] = id-expression
Chris Lattner5261d0c2009-03-28 19:18:32 +0000300Parser::DeclPtrTy
Douglas Gregor52473432008-12-24 02:52:09 +0000301Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
Chris Lattner4e7a4202009-01-04 23:51:17 +0000302 if(Tok.is(tok::kw_class) ||
303 (Tok.is(tok::kw_typename) &&
304 // FIXME: Next token has not been annotated!
Chris Lattner5d7eace2009-01-06 05:06:21 +0000305 NextToken().isNot(tok::annot_typename))) {
Douglas Gregor52473432008-12-24 02:52:09 +0000306 return ParseTypeParameter(Depth, Position);
Douglas Gregorb3bec712008-12-01 23:54:00 +0000307 }
Chris Lattner4e7a4202009-01-04 23:51:17 +0000308
309 if(Tok.is(tok::kw_template))
310 return ParseTemplateTemplateParameter(Depth, Position);
311
312 // If it's none of the above, then it must be a parameter declaration.
313 // NOTE: This will pick up errors in the closure of the template parameter
314 // list (e.g., template < ; Check here to implement >> style closures.
315 return ParseNonTypeTemplateParameter(Depth, Position);
Douglas Gregorb3bec712008-12-01 23:54:00 +0000316}
317
318/// ParseTypeParameter - Parse a template type parameter (C++ [temp.param]).
319/// Other kinds of template parameters are parsed in
320/// ParseTemplateTemplateParameter and ParseNonTypeTemplateParameter.
321///
322/// type-parameter: [C++ temp.param]
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000323/// 'class' ...[opt][C++0x] identifier[opt]
Douglas Gregorb3bec712008-12-01 23:54:00 +0000324/// 'class' identifier[opt] '=' type-id
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000325/// 'typename' ...[opt][C++0x] identifier[opt]
Douglas Gregorb3bec712008-12-01 23:54:00 +0000326/// 'typename' identifier[opt] '=' type-id
Chris Lattner5261d0c2009-03-28 19:18:32 +0000327Parser::DeclPtrTy Parser::ParseTypeParameter(unsigned Depth, unsigned Position){
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000328 assert((Tok.is(tok::kw_class) || Tok.is(tok::kw_typename)) &&
329 "A type-parameter starts with 'class' or 'typename'");
330
331 // Consume the 'class' or 'typename' keyword.
332 bool TypenameKeyword = Tok.is(tok::kw_typename);
333 SourceLocation KeyLoc = ConsumeToken();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000334
Anders Carlsson9c85fa02009-06-12 19:58:00 +0000335 // Grab the ellipsis (if given).
336 bool Ellipsis = false;
337 SourceLocation EllipsisLoc;
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000338 if (Tok.is(tok::ellipsis)) {
Anders Carlsson9c85fa02009-06-12 19:58:00 +0000339 Ellipsis = true;
340 EllipsisLoc = ConsumeToken();
Anders Carlsson647d1ab2009-06-12 23:09:56 +0000341
342 if (!getLang().CPlusPlus0x)
343 Diag(EllipsisLoc, diag::err_variadic_templates);
Anders Carlsson9c85fa02009-06-12 19:58:00 +0000344 }
345
Douglas Gregorb3bec712008-12-01 23:54:00 +0000346 // Grab the template parameter name (if given)
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000347 SourceLocation NameLoc;
348 IdentifierInfo* ParamName = 0;
Douglas Gregorb3bec712008-12-01 23:54:00 +0000349 if(Tok.is(tok::identifier)) {
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000350 ParamName = Tok.getIdentifierInfo();
351 NameLoc = ConsumeToken();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000352 } else if(Tok.is(tok::equal) || Tok.is(tok::comma) ||
353 Tok.is(tok::greater)) {
354 // Unnamed template parameter. Don't have to do anything here, just
355 // don't consume this token.
356 } else {
357 Diag(Tok.getLocation(), diag::err_expected_ident);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000358 return DeclPtrTy();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000359 }
360
Chris Lattner5261d0c2009-03-28 19:18:32 +0000361 DeclPtrTy TypeParam = Actions.ActOnTypeParameter(CurScope, TypenameKeyword,
Anders Carlsson9c85fa02009-06-12 19:58:00 +0000362 Ellipsis, EllipsisLoc,
Chris Lattner5261d0c2009-03-28 19:18:32 +0000363 KeyLoc, ParamName, NameLoc,
364 Depth, Position);
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000365
Douglas Gregorb3bec712008-12-01 23:54:00 +0000366 // Grab a default type id (if given).
Douglas Gregorb3bec712008-12-01 23:54:00 +0000367 if(Tok.is(tok::equal)) {
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000368 SourceLocation EqualLoc = ConsumeToken();
Douglas Gregor9225a7e2009-02-10 19:49:53 +0000369 SourceLocation DefaultLoc = Tok.getLocation();
Douglas Gregor6c0f4062009-02-18 17:45:20 +0000370 TypeResult DefaultType = ParseTypeName();
371 if (!DefaultType.isInvalid())
Douglas Gregor9225a7e2009-02-10 19:49:53 +0000372 Actions.ActOnTypeParameterDefault(TypeParam, EqualLoc, DefaultLoc,
Douglas Gregor6c0f4062009-02-18 17:45:20 +0000373 DefaultType.get());
Douglas Gregorb3bec712008-12-01 23:54:00 +0000374 }
375
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000376 return TypeParam;
Douglas Gregorb3bec712008-12-01 23:54:00 +0000377}
378
379/// ParseTemplateTemplateParameter - Handle the parsing of template
380/// template parameters.
381///
382/// type-parameter: [C++ temp.param]
383/// 'template' '<' template-parameter-list '>' 'class' identifier[opt]
384/// 'template' '<' template-parameter-list '>' 'class' identifier[opt] = id-expression
Chris Lattner5261d0c2009-03-28 19:18:32 +0000385Parser::DeclPtrTy
Douglas Gregor52473432008-12-24 02:52:09 +0000386Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
Douglas Gregorb3bec712008-12-01 23:54:00 +0000387 assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
388
389 // Handle the template <...> part.
390 SourceLocation TemplateLoc = ConsumeToken();
Douglas Gregor52473432008-12-24 02:52:09 +0000391 TemplateParameterList TemplateParams;
Douglas Gregord406b032009-02-06 22:42:48 +0000392 SourceLocation LAngleLoc, RAngleLoc;
Douglas Gregor77f7ced2009-02-10 19:52:54 +0000393 {
394 ParseScope TemplateParmScope(this, Scope::TemplateParamScope);
395 if(!ParseTemplateParameters(Depth + 1, TemplateParams, LAngleLoc,
396 RAngleLoc)) {
Chris Lattner5261d0c2009-03-28 19:18:32 +0000397 return DeclPtrTy();
Douglas Gregor77f7ced2009-02-10 19:52:54 +0000398 }
Douglas Gregorb3bec712008-12-01 23:54:00 +0000399 }
400
401 // Generate a meaningful error if the user forgot to put class before the
402 // identifier, comma, or greater.
403 if(!Tok.is(tok::kw_class)) {
404 Diag(Tok.getLocation(), diag::err_expected_class_before)
405 << PP.getSpelling(Tok);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000406 return DeclPtrTy();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000407 }
408 SourceLocation ClassLoc = ConsumeToken();
409
410 // Get the identifier, if given.
Douglas Gregor279272e2009-02-04 19:02:06 +0000411 SourceLocation NameLoc;
412 IdentifierInfo* ParamName = 0;
Douglas Gregorb3bec712008-12-01 23:54:00 +0000413 if(Tok.is(tok::identifier)) {
Douglas Gregor279272e2009-02-04 19:02:06 +0000414 ParamName = Tok.getIdentifierInfo();
415 NameLoc = ConsumeToken();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000416 } else if(Tok.is(tok::equal) || Tok.is(tok::comma) || Tok.is(tok::greater)) {
417 // Unnamed template parameter. Don't have to do anything here, just
418 // don't consume this token.
419 } else {
420 Diag(Tok.getLocation(), diag::err_expected_ident);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000421 return DeclPtrTy();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000422 }
423
Douglas Gregord406b032009-02-06 22:42:48 +0000424 TemplateParamsTy *ParamList =
425 Actions.ActOnTemplateParameterList(Depth, SourceLocation(),
426 TemplateLoc, LAngleLoc,
427 &TemplateParams[0],
428 TemplateParams.size(),
429 RAngleLoc);
430
Chris Lattner5261d0c2009-03-28 19:18:32 +0000431 Parser::DeclPtrTy Param
Douglas Gregor9225a7e2009-02-10 19:49:53 +0000432 = Actions.ActOnTemplateTemplateParameter(CurScope, TemplateLoc,
433 ParamList, ParamName,
434 NameLoc, Depth, Position);
435
436 // Get the a default value, if given.
437 if (Tok.is(tok::equal)) {
438 SourceLocation EqualLoc = ConsumeToken();
439 OwningExprResult DefaultExpr = ParseCXXIdExpression();
440 if (DefaultExpr.isInvalid())
441 return Param;
442 else if (Param)
443 Actions.ActOnTemplateTemplateParameterDefault(Param, EqualLoc,
444 move(DefaultExpr));
445 }
446
447 return Param;
Douglas Gregorb3bec712008-12-01 23:54:00 +0000448}
449
450/// ParseNonTypeTemplateParameter - Handle the parsing of non-type
451/// template parameters (e.g., in "template<int Size> class array;").
Douglas Gregor2fa10442008-12-18 19:37:40 +0000452///
Douglas Gregorb3bec712008-12-01 23:54:00 +0000453/// template-parameter:
454/// ...
455/// parameter-declaration
456///
457/// NOTE: It would be ideal to simply call out to ParseParameterDeclaration(),
458/// but that didn't work out to well. Instead, this tries to recrate the basic
459/// parsing of parameter declarations, but tries to constrain it for template
460/// parameters.
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000461/// FIXME: We need to make a ParseParameterDeclaration that works for
462/// non-type template parameters and normal function parameters.
Chris Lattner5261d0c2009-03-28 19:18:32 +0000463Parser::DeclPtrTy
Douglas Gregor52473432008-12-24 02:52:09 +0000464Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000465 SourceLocation StartLoc = Tok.getLocation();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000466
467 // Parse the declaration-specifiers (i.e., the type).
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000468 // FIXME: The type should probably be restricted in some way... Not all
Douglas Gregorb3bec712008-12-01 23:54:00 +0000469 // declarators (parts of declarators?) are accepted for parameters.
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000470 DeclSpec DS;
471 ParseDeclarationSpecifiers(DS);
Douglas Gregorb3bec712008-12-01 23:54:00 +0000472
473 // Parse this as a typename.
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000474 Declarator ParamDecl(DS, Declarator::TemplateParamContext);
475 ParseDeclarator(ParamDecl);
Chris Lattner8376d2e2009-01-05 01:24:05 +0000476 if (DS.getTypeSpecType() == DeclSpec::TST_unspecified && !DS.getTypeRep()) {
Douglas Gregorb3bec712008-12-01 23:54:00 +0000477 // This probably shouldn't happen - and it's more of a Sema thing, but
478 // basically we didn't parse the type name because we couldn't associate
479 // it with an AST node. we should just skip to the comma or greater.
480 // TODO: This is currently a placeholder for some kind of Sema Error.
481 Diag(Tok.getLocation(), diag::err_parse_error);
482 SkipUntil(tok::comma, tok::greater, true, true);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000483 return DeclPtrTy();
Douglas Gregorb3bec712008-12-01 23:54:00 +0000484 }
485
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000486 // Create the parameter.
Chris Lattner5261d0c2009-03-28 19:18:32 +0000487 DeclPtrTy Param = Actions.ActOnNonTypeTemplateParameter(CurScope, ParamDecl,
488 Depth, Position);
Douglas Gregorb3bec712008-12-01 23:54:00 +0000489
Douglas Gregor9225a7e2009-02-10 19:49:53 +0000490 // If there is a default value, parse it.
Chris Lattner8376d2e2009-01-05 01:24:05 +0000491 if (Tok.is(tok::equal)) {
Douglas Gregor9225a7e2009-02-10 19:49:53 +0000492 SourceLocation EqualLoc = ConsumeToken();
493
494 // C++ [temp.param]p15:
495 // When parsing a default template-argument for a non-type
496 // template-parameter, the first non-nested > is taken as the
497 // end of the template-parameter-list rather than a greater-than
498 // operator.
499 GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
500
501 OwningExprResult DefaultArg = ParseAssignmentExpression();
502 if (DefaultArg.isInvalid())
503 SkipUntil(tok::comma, tok::greater, true, true);
504 else if (Param)
505 Actions.ActOnNonTypeTemplateParameterDefault(Param, EqualLoc,
506 move(DefaultArg));
Douglas Gregorb3bec712008-12-01 23:54:00 +0000507 }
508
Douglas Gregor8e7f9572008-12-02 00:41:28 +0000509 return Param;
Douglas Gregorb3bec712008-12-01 23:54:00 +0000510}
Douglas Gregor2fa10442008-12-18 19:37:40 +0000511
Douglas Gregora08b6c72009-02-17 23:15:12 +0000512/// \brief Parses a template-id that after the template name has
513/// already been parsed.
514///
515/// This routine takes care of parsing the enclosed template argument
516/// list ('<' template-parameter-list [opt] '>') and placing the
517/// results into a form that can be transferred to semantic analysis.
518///
519/// \param Template the template declaration produced by isTemplateName
520///
521/// \param TemplateNameLoc the source location of the template name
522///
523/// \param SS if non-NULL, the nested-name-specifier preceding the
524/// template name.
525///
526/// \param ConsumeLastToken if true, then we will consume the last
527/// token that forms the template-id. Otherwise, we will leave the
528/// last token in the stream (e.g., so that it can be replaced with an
529/// annotation token).
530bool
Douglas Gregordd13e842009-03-30 22:58:21 +0000531Parser::ParseTemplateIdAfterTemplateName(TemplateTy Template,
Douglas Gregora08b6c72009-02-17 23:15:12 +0000532 SourceLocation TemplateNameLoc,
533 const CXXScopeSpec *SS,
534 bool ConsumeLastToken,
535 SourceLocation &LAngleLoc,
536 TemplateArgList &TemplateArgs,
537 TemplateArgIsTypeList &TemplateArgIsType,
538 TemplateArgLocationList &TemplateArgLocations,
539 SourceLocation &RAngleLoc) {
540 assert(Tok.is(tok::less) && "Must have already parsed the template-name");
541
542 // Consume the '<'.
543 LAngleLoc = ConsumeToken();
544
545 // Parse the optional template-argument-list.
546 bool Invalid = false;
547 {
548 GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
549 if (Tok.isNot(tok::greater))
550 Invalid = ParseTemplateArgumentList(TemplateArgs, TemplateArgIsType,
551 TemplateArgLocations);
552
553 if (Invalid) {
554 // Try to find the closing '>'.
555 SkipUntil(tok::greater, true, !ConsumeLastToken);
556
557 return true;
558 }
559 }
560
Douglas Gregorf2d87392009-02-25 23:02:36 +0000561 if (Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater))
Douglas Gregora08b6c72009-02-17 23:15:12 +0000562 return true;
563
Douglas Gregorf2d87392009-02-25 23:02:36 +0000564 // Determine the location of the '>' or '>>'. Only consume this
565 // token if the caller asked us to.
Douglas Gregora08b6c72009-02-17 23:15:12 +0000566 RAngleLoc = Tok.getLocation();
567
Douglas Gregorf2d87392009-02-25 23:02:36 +0000568 if (Tok.is(tok::greatergreater)) {
Douglas Gregor3bb30002009-02-26 21:00:50 +0000569 if (!getLang().CPlusPlus0x) {
570 const char *ReplaceStr = "> >";
571 if (NextToken().is(tok::greater) || NextToken().is(tok::greatergreater))
572 ReplaceStr = "> > ";
573
574 Diag(Tok.getLocation(), diag::err_two_right_angle_brackets_need_space)
Douglas Gregor61be3602009-02-27 17:53:17 +0000575 << CodeModificationHint::CreateReplacement(
576 SourceRange(Tok.getLocation()), ReplaceStr);
Douglas Gregor3bb30002009-02-26 21:00:50 +0000577 }
Douglas Gregorf2d87392009-02-25 23:02:36 +0000578
579 Tok.setKind(tok::greater);
580 if (!ConsumeLastToken) {
581 // Since we're not supposed to consume the '>>' token, we need
582 // to insert a second '>' token after the first.
583 PP.EnterToken(Tok);
584 }
585 } else if (ConsumeLastToken)
Douglas Gregora08b6c72009-02-17 23:15:12 +0000586 ConsumeToken();
587
588 return false;
589}
590
Douglas Gregor0c281a82009-02-25 19:37:18 +0000591/// \brief Replace the tokens that form a simple-template-id with an
592/// annotation token containing the complete template-id.
593///
594/// The first token in the stream must be the name of a template that
595/// is followed by a '<'. This routine will parse the complete
596/// simple-template-id and replace the tokens with a single annotation
597/// token with one of two different kinds: if the template-id names a
598/// type (and \p AllowTypeAnnotation is true), the annotation token is
599/// a type annotation that includes the optional nested-name-specifier
600/// (\p SS). Otherwise, the annotation token is a template-id
601/// annotation that does not include the optional
602/// nested-name-specifier.
603///
604/// \param Template the declaration of the template named by the first
605/// token (an identifier), as returned from \c Action::isTemplateName().
606///
607/// \param TemplateNameKind the kind of template that \p Template
608/// refers to, as returned from \c Action::isTemplateName().
609///
610/// \param SS if non-NULL, the nested-name-specifier that precedes
611/// this template name.
612///
613/// \param TemplateKWLoc if valid, specifies that this template-id
614/// annotation was preceded by the 'template' keyword and gives the
615/// location of that keyword. If invalid (the default), then this
616/// template-id was not preceded by a 'template' keyword.
617///
618/// \param AllowTypeAnnotation if true (the default), then a
619/// simple-template-id that refers to a class template, template
620/// template parameter, or other template that produces a type will be
621/// replaced with a type annotation token. Otherwise, the
622/// simple-template-id is always replaced with a template-id
623/// annotation token.
Douglas Gregordd13e842009-03-30 22:58:21 +0000624void Parser::AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
Douglas Gregor0c281a82009-02-25 19:37:18 +0000625 const CXXScopeSpec *SS,
626 SourceLocation TemplateKWLoc,
627 bool AllowTypeAnnotation) {
Douglas Gregor2fa10442008-12-18 19:37:40 +0000628 assert(getLang().CPlusPlus && "Can only annotate template-ids in C++");
629 assert(Template && Tok.is(tok::identifier) && NextToken().is(tok::less) &&
630 "Parser isn't at the beginning of a template-id");
631
632 // Consume the template-name.
Douglas Gregor0c281a82009-02-25 19:37:18 +0000633 IdentifierInfo *Name = Tok.getIdentifierInfo();
Douglas Gregor2fa10442008-12-18 19:37:40 +0000634 SourceLocation TemplateNameLoc = ConsumeToken();
635
Douglas Gregora08b6c72009-02-17 23:15:12 +0000636 // Parse the enclosed template argument list.
637 SourceLocation LAngleLoc, RAngleLoc;
Douglas Gregor6f37b582009-02-09 19:34:22 +0000638 TemplateArgList TemplateArgs;
639 TemplateArgIsTypeList TemplateArgIsType;
Douglas Gregor35d81bb2009-02-09 23:23:08 +0000640 TemplateArgLocationList TemplateArgLocations;
Douglas Gregora08b6c72009-02-17 23:15:12 +0000641 bool Invalid = ParseTemplateIdAfterTemplateName(Template, TemplateNameLoc,
642 SS, false, LAngleLoc,
643 TemplateArgs,
644 TemplateArgIsType,
645 TemplateArgLocations,
646 RAngleLoc);
Douglas Gregor35d81bb2009-02-09 23:23:08 +0000647
Jay Foad9e6bef42009-05-21 09:52:38 +0000648 ASTTemplateArgsPtr TemplateArgsPtr(Actions, TemplateArgs.data(),
649 TemplateArgIsType.data(),
Douglas Gregora08b6c72009-02-17 23:15:12 +0000650 TemplateArgs.size());
Douglas Gregoraf0d0092009-02-09 21:04:56 +0000651
Douglas Gregora08b6c72009-02-17 23:15:12 +0000652 if (Invalid) // FIXME: How to recover from a broken template-id?
653 return;
Douglas Gregor2fa10442008-12-18 19:37:40 +0000654
Douglas Gregor8e458f42009-02-09 18:46:07 +0000655 // Build the annotation token.
Douglas Gregoraabb8502009-03-31 00:43:58 +0000656 if (TNK == TNK_Type_template && AllowTypeAnnotation) {
Douglas Gregora08b6c72009-02-17 23:15:12 +0000657 Action::TypeResult Type
Douglas Gregordd13e842009-03-30 22:58:21 +0000658 = Actions.ActOnTemplateIdType(Template, TemplateNameLoc,
659 LAngleLoc, TemplateArgsPtr,
660 &TemplateArgLocations[0],
661 RAngleLoc);
Douglas Gregora08b6c72009-02-17 23:15:12 +0000662 if (Type.isInvalid()) // FIXME: better recovery?
663 return;
664
665 Tok.setKind(tok::annot_typename);
666 Tok.setAnnotationValue(Type.get());
Douglas Gregor0c281a82009-02-25 19:37:18 +0000667 if (SS && SS->isNotEmpty())
668 Tok.setLocation(SS->getBeginLoc());
669 else if (TemplateKWLoc.isValid())
670 Tok.setLocation(TemplateKWLoc);
671 else
672 Tok.setLocation(TemplateNameLoc);
Douglas Gregora08b6c72009-02-17 23:15:12 +0000673 } else {
Douglas Gregoraabb8502009-03-31 00:43:58 +0000674 // Build a template-id annotation token that can be processed
675 // later.
Douglas Gregor0c281a82009-02-25 19:37:18 +0000676 Tok.setKind(tok::annot_template_id);
Douglas Gregor8e458f42009-02-09 18:46:07 +0000677 TemplateIdAnnotation *TemplateId
Douglas Gregor0c281a82009-02-25 19:37:18 +0000678 = TemplateIdAnnotation::Allocate(TemplateArgs.size());
Douglas Gregor8e458f42009-02-09 18:46:07 +0000679 TemplateId->TemplateNameLoc = TemplateNameLoc;
Douglas Gregor0c281a82009-02-25 19:37:18 +0000680 TemplateId->Name = Name;
Chris Lattner5261d0c2009-03-28 19:18:32 +0000681 TemplateId->Template = Template.getAs<void*>();
Douglas Gregor0c281a82009-02-25 19:37:18 +0000682 TemplateId->Kind = TNK;
Douglas Gregor8e458f42009-02-09 18:46:07 +0000683 TemplateId->LAngleLoc = LAngleLoc;
Douglas Gregor0c281a82009-02-25 19:37:18 +0000684 TemplateId->RAngleLoc = RAngleLoc;
685 void **Args = TemplateId->getTemplateArgs();
686 bool *ArgIsType = TemplateId->getTemplateArgIsType();
687 SourceLocation *ArgLocs = TemplateId->getTemplateArgLocations();
688 for (unsigned Arg = 0, ArgEnd = TemplateArgs.size(); Arg != ArgEnd; ++Arg) {
Douglas Gregor8e458f42009-02-09 18:46:07 +0000689 Args[Arg] = TemplateArgs[Arg];
Douglas Gregor0c281a82009-02-25 19:37:18 +0000690 ArgIsType[Arg] = TemplateArgIsType[Arg];
691 ArgLocs[Arg] = TemplateArgLocations[Arg];
692 }
Douglas Gregor8e458f42009-02-09 18:46:07 +0000693 Tok.setAnnotationValue(TemplateId);
Douglas Gregor0c281a82009-02-25 19:37:18 +0000694 if (TemplateKWLoc.isValid())
695 Tok.setLocation(TemplateKWLoc);
696 else
697 Tok.setLocation(TemplateNameLoc);
698
699 TemplateArgsPtr.release();
Douglas Gregor8e458f42009-02-09 18:46:07 +0000700 }
701
702 // Common fields for the annotation token
Douglas Gregor2fa10442008-12-18 19:37:40 +0000703 Tok.setAnnotationEndLoc(RAngleLoc);
Douglas Gregor2fa10442008-12-18 19:37:40 +0000704
Douglas Gregor2fa10442008-12-18 19:37:40 +0000705 // In case the tokens were cached, have Preprocessor replace them with the
706 // annotation token.
707 PP.AnnotateCachedTokens(Tok);
708}
709
Douglas Gregor0c281a82009-02-25 19:37:18 +0000710/// \brief Replaces a template-id annotation token with a type
711/// annotation token.
712///
Douglas Gregord7cb0372009-04-01 21:51:26 +0000713/// If there was a failure when forming the type from the template-id,
714/// a type annotation token will still be created, but will have a
715/// NULL type pointer to signify an error.
716void Parser::AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS) {
Douglas Gregor0c281a82009-02-25 19:37:18 +0000717 assert(Tok.is(tok::annot_template_id) && "Requires template-id tokens");
718
719 TemplateIdAnnotation *TemplateId
720 = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
Douglas Gregoraabb8502009-03-31 00:43:58 +0000721 assert((TemplateId->Kind == TNK_Type_template ||
722 TemplateId->Kind == TNK_Dependent_template_name) &&
723 "Only works for type and dependent templates");
Douglas Gregor0c281a82009-02-25 19:37:18 +0000724
725 ASTTemplateArgsPtr TemplateArgsPtr(Actions,
726 TemplateId->getTemplateArgs(),
727 TemplateId->getTemplateArgIsType(),
728 TemplateId->NumArgs);
729
730 Action::TypeResult Type
Douglas Gregordd13e842009-03-30 22:58:21 +0000731 = Actions.ActOnTemplateIdType(TemplateTy::make(TemplateId->Template),
732 TemplateId->TemplateNameLoc,
733 TemplateId->LAngleLoc,
734 TemplateArgsPtr,
735 TemplateId->getTemplateArgLocations(),
736 TemplateId->RAngleLoc);
Douglas Gregor0c281a82009-02-25 19:37:18 +0000737 // Create the new "type" annotation token.
738 Tok.setKind(tok::annot_typename);
Douglas Gregord7cb0372009-04-01 21:51:26 +0000739 Tok.setAnnotationValue(Type.isInvalid()? 0 : Type.get());
Douglas Gregor0c281a82009-02-25 19:37:18 +0000740 if (SS && SS->isNotEmpty()) // it was a C++ qualified type name.
741 Tok.setLocation(SS->getBeginLoc());
742
743 // We might be backtracking, in which case we need to replace the
744 // template-id annotation token with the type annotation within the
745 // set of cached tokens. That way, we won't try to form the same
746 // class template specialization again.
747 PP.ReplaceLastTokenWithAnnotation(Tok);
748 TemplateId->Destroy();
Douglas Gregor0c281a82009-02-25 19:37:18 +0000749}
750
Douglas Gregor2fa10442008-12-18 19:37:40 +0000751/// ParseTemplateArgument - Parse a C++ template argument (C++ [temp.names]).
752///
753/// template-argument: [C++ 14.2]
Douglas Gregora8b2fbf2009-06-22 20:57:11 +0000754/// constant-expression
Douglas Gregor2fa10442008-12-18 19:37:40 +0000755/// type-id
756/// id-expression
Douglas Gregor6f37b582009-02-09 19:34:22 +0000757void *Parser::ParseTemplateArgument(bool &ArgIsType) {
Douglas Gregor8e458f42009-02-09 18:46:07 +0000758 // C++ [temp.arg]p2:
759 // In a template-argument, an ambiguity between a type-id and an
760 // expression is resolved to a type-id, regardless of the form of
761 // the corresponding template-parameter.
762 //
763 // Therefore, we initially try to parse a type-id.
Douglas Gregor341ac792009-02-10 00:53:15 +0000764 if (isCXXTypeId(TypeIdAsTemplateArgument)) {
Douglas Gregor6f37b582009-02-09 19:34:22 +0000765 ArgIsType = true;
Douglas Gregor6c0f4062009-02-18 17:45:20 +0000766 TypeResult TypeArg = ParseTypeName();
767 if (TypeArg.isInvalid())
768 return 0;
769 return TypeArg.get();
Douglas Gregor8e458f42009-02-09 18:46:07 +0000770 }
771
Douglas Gregora8b2fbf2009-06-22 20:57:11 +0000772 OwningExprResult ExprArg = ParseConstantExpression();
Douglas Gregor35d81bb2009-02-09 23:23:08 +0000773 if (ExprArg.isInvalid() || !ExprArg.get())
Douglas Gregor6f37b582009-02-09 19:34:22 +0000774 return 0;
Douglas Gregor8e458f42009-02-09 18:46:07 +0000775
Douglas Gregor6f37b582009-02-09 19:34:22 +0000776 ArgIsType = false;
777 return ExprArg.release();
Douglas Gregor2fa10442008-12-18 19:37:40 +0000778}
779
780/// ParseTemplateArgumentList - Parse a C++ template-argument-list
781/// (C++ [temp.names]). Returns true if there was an error.
782///
783/// template-argument-list: [C++ 14.2]
784/// template-argument
785/// template-argument-list ',' template-argument
Douglas Gregor6f37b582009-02-09 19:34:22 +0000786bool
787Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
Douglas Gregor35d81bb2009-02-09 23:23:08 +0000788 TemplateArgIsTypeList &TemplateArgIsType,
789 TemplateArgLocationList &TemplateArgLocations) {
Douglas Gregor2fa10442008-12-18 19:37:40 +0000790 while (true) {
Douglas Gregor6f37b582009-02-09 19:34:22 +0000791 bool IsType = false;
Douglas Gregor35d81bb2009-02-09 23:23:08 +0000792 SourceLocation Loc = Tok.getLocation();
Douglas Gregor6f37b582009-02-09 19:34:22 +0000793 void *Arg = ParseTemplateArgument(IsType);
794 if (Arg) {
795 TemplateArgs.push_back(Arg);
796 TemplateArgIsType.push_back(IsType);
Douglas Gregor35d81bb2009-02-09 23:23:08 +0000797 TemplateArgLocations.push_back(Loc);
Douglas Gregor6f37b582009-02-09 19:34:22 +0000798 } else {
Douglas Gregor2fa10442008-12-18 19:37:40 +0000799 SkipUntil(tok::comma, tok::greater, true, true);
800 return true;
801 }
Douglas Gregor6f37b582009-02-09 19:34:22 +0000802
Douglas Gregor2fa10442008-12-18 19:37:40 +0000803 // If the next token is a comma, consume it and keep reading
804 // arguments.
805 if (Tok.isNot(tok::comma)) break;
806
807 // Consume the comma.
808 ConsumeToken();
809 }
810
Douglas Gregorf2d87392009-02-25 23:02:36 +0000811 return Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater);
Douglas Gregor2fa10442008-12-18 19:37:40 +0000812}
813
Douglas Gregore3298aa2009-05-12 21:31:51 +0000814/// \brief Parse a C++ explicit template instantiation
815/// (C++ [temp.explicit]).
816///
817/// explicit-instantiation:
818/// 'template' declaration
Douglas Gregora9db0fa2009-05-12 23:25:50 +0000819Parser::DeclPtrTy
820Parser::ParseExplicitInstantiation(SourceLocation TemplateLoc,
821 SourceLocation &DeclEnd) {
822 return ParseSingleDeclarationAfterTemplate(Declarator::FileContext,
823 ParsedTemplateInfo(TemplateLoc),
824 DeclEnd, AS_none);
Douglas Gregore3298aa2009-05-12 21:31:51 +0000825}