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 | d6fb7ef028d9aa0b3e8943b7bc049c524437b407 (patch) | |
tree | 3e378ac3ed8c27d88bf386b5e822433829a3908d /lib/Parse/Parser.cpp | |
parent | 80d2f3059326f99ebf7c867db1c7f106ec9485f5 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61208 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r-- | lib/Parse/Parser.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 058182eee6..48b0d5f422 100644 --- a/lib/Parse/Parser.cpp +++ b/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 |