summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-25 19:37:18 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-25 19:37:18 +0000
commit7f74112756f6cada66df1237b86788e71401bae5 (patch)
tree2c7296f80da41208e16e683772df61b8d7ab6837 /clang/lib/Parse/Parser.cpp
parent22a87f94a9259c9295dc22d3d7e4b6c54e242f19 (diff)
downloadbcm5719-llvm-7f74112756f6cada66df1237b86788e71401bae5.tar.gz
bcm5719-llvm-7f74112756f6cada66df1237b86788e71401bae5.zip
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type When we parse a template-id that names a type, it will become either a template-id annotation (which is a parsed representation of a template-id that has not yet been through semantic analysis) or a typename annotation (where semantic analysis has resolved the template-id to an actual type), depending on the context. We only produce a type in contexts where we know that we only need type information, e.g., in a type specifier. Otherwise, we create a template-id annotation that can later be "upgraded" by transforming it into a typename annotation when the parser needs a type. This occurs, for example, when we've parsed "std::vector<int>" above and then see the '::' after it. However, it means that when writing something like this: template<> class Outer::Inner<int> { ... }; We have two tokens to represent Outer::Inner<int>: one token for the nested name specifier Outer::, and one template-id annotation token for Inner<int>, which will be passed to semantic analysis to define the class template specialization. Most of the churn in the template tests in this patch come from an improvement in our error recovery from ill-formed template-ids. llvm-svn: 65467
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r--clang/lib/Parse/Parser.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 7b09d2105c2..a3ed0278466 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -778,31 +778,41 @@ bool Parser::TryAnnotateTypeOrScopeToken() {
// them with the annotation token.
PP.AnnotateCachedTokens(Tok);
return true;
- } else if (!getLang().CPlusPlus) {
+ }
+
+ if (!getLang().CPlusPlus) {
// If we're in C, we can't have :: tokens at all (the lexer won't return
// them). If the identifier is not a type, then it can't be scope either,
// just early exit.
return false;
}
- // If this is a template-id, annotate the template-id token.
+ // If this is a template-id, annotate with a template-id or type token.
if (NextToken().is(tok::less)) {
DeclTy *Template;
if (TemplateNameKind TNK
= Actions.isTemplateName(*Tok.getIdentifierInfo(),
- CurScope, Template, &SS)) {
+ CurScope, Template, &SS))
AnnotateTemplateIdToken(Template, TNK, &SS);
- return true;
- }
}
- // We either have an identifier that is not a type name or we have
- // just created a template-id that might be a type name. Both
- // cases will be handled below.
+ // The current token, which is either an identifier or a
+ // template-id, is not part of the annotation. Fall through to
+ // push that token back into the stream and complete the C++ scope
+ // specifier annotation.
}
- // FIXME: check for a template-id token here, and look it up if it
- // names a type.
+ if (Tok.is(tok::annot_template_id)) {
+ TemplateIdAnnotation *TemplateId
+ = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
+ if (TemplateId->Kind == TNK_Class_template) {
+ // A template-id that refers to a type was parsed into a
+ // template-id annotation in a context where we weren't allowed
+ // to produce a type annotation token. Update the template-id
+ // annotation token to a type annotation token now.
+ return !AnnotateTemplateIdTokenAsType(&SS);
+ }
+ }
if (SS.isEmpty())
return false;
@@ -825,8 +835,8 @@ bool Parser::TryAnnotateTypeOrScopeToken() {
}
/// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
-/// annotates C++ scope specifiers. This returns true if the token was
-/// annotated.
+/// annotates C++ scope specifiers and template-ids. This returns
+/// true if the token was annotated.
///
/// Note that this routine emits an error if you call it with ::new or ::delete
/// as the current tokens, so only call it in contexts where these are invalid.
@@ -838,7 +848,7 @@ bool Parser::TryAnnotateCXXScopeToken() {
CXXScopeSpec SS;
if (!ParseOptionalCXXScopeSpecifier(SS))
- return false;
+ return Tok.is(tok::annot_template_id);
// Push the current token back into the token stream (or revert it if it is
// cached) and use an annotation scope token for current token.
OpenPOWER on IntegriCloud