diff options
| author | Douglas Gregor <dgregor@apple.com> | 2008-12-18 19:37:40 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2008-12-18 19:37:40 +0000 |
| commit | 55ad91fecb076c4afadb2cf0591e1bc94db6df0b (patch) | |
| tree | 6ee2558608a2372f2d130e18adc9b7fa3f0b45d7 /clang/lib/Parse/Parser.cpp | |
| parent | 9443f0ea5e233948c36b180b8551987df0fbdd45 (diff) | |
| download | bcm5719-llvm-55ad91fecb076c4afadb2cf0591e1bc94db6df0b.tar.gz bcm5719-llvm-55ad91fecb076c4afadb2cf0591e1bc94db6df0b.zip | |
Ultrasimplistic sketch for the parsing of C++ template-ids. This won't
become useful or correct until we (1) parse template arguments
correctly, (2) have some way to turn template-ids into types,
declarators, etc., and (3) have a real representation of templates.
llvm-svn: 61208
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
| -rw-r--r-- | clang/lib/Parse/Parser.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 058182eee6b..48b0d5f422e 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -722,6 +722,7 @@ Parser::OwningExprResult Parser::ParseSimpleAsm() { /// specifier, and another one to get the actual type inside /// ParseDeclarationSpecifiers). void Parser::TryAnnotateTypeOrScopeToken() { + // FIXME: what about template-ids? if (Tok.is(tok::annot_qualtypename) || Tok.is(tok::annot_cxxscope)) return; @@ -730,23 +731,39 @@ void Parser::TryAnnotateTypeOrScopeToken() { MaybeParseCXXScopeSpecifier(SS); if (Tok.is(tok::identifier)) { - TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, &SS); - if (Ty) { - // This is a typename. Replace the current token in-place with an - // annotation type token. - Tok.setKind(tok::annot_qualtypename); - Tok.setAnnotationValue(Ty); - Tok.setAnnotationEndLoc(Tok.getLocation()); - if (SS.isNotEmpty()) // it was a C++ qualified type name. - Tok.setLocation(SS.getBeginLoc()); - - // In case the tokens were cached, have Preprocessor replace them with the - // annotation token. - PP.AnnotateCachedTokens(Tok); - return; + DeclTy *Template = 0; + // If this is a template-id, annotate the template-id token. + if (getLang().CPlusPlus && NextToken().is(tok::less) && + (Template = Actions.isTemplateName(*Tok.getIdentifierInfo(), CurScope, + &SS))) + AnnotateTemplateIdToken(Template, &SS); + else { + // Determine whether the identifier is a type name. + TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, &SS); + if (Ty) { + // This is a typename. Replace the current token in-place with an + // annotation type token. + Tok.setKind(tok::annot_qualtypename); + Tok.setAnnotationValue(Ty); + Tok.setAnnotationEndLoc(Tok.getLocation()); + if (SS.isNotEmpty()) // it was a C++ qualified type name. + Tok.setLocation(SS.getBeginLoc()); + + // In case the tokens were cached, have Preprocessor replace + // them with the annotation token. + PP.AnnotateCachedTokens(Tok); + return; + } } + + // 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. } + // FIXME: check for a template-id token here, and look it up if it + // names a type. + if (SS.isNotEmpty()) { // A C++ scope specifier that isn't followed by a typename. // Push the current token back into the token stream (or revert it if it is |

