diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-04-27 04:48:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-04-27 04:48:22 +0000 |
commit | 3b887354b1b667c97d070ddc67b5354353c4c07b (patch) | |
tree | 6918d42ba0eff9ecd953365c511ddd0289e3d874 /lib/Parse/ParseStmt.cpp | |
parent | 173d51286bcaff4b6b76eebf6542d3b1311142e2 (diff) |
Extend Sema::ClassifyName() to support C++, ironing out a few issues
in the classification of template names and using declarations. We now
properly typo-correct the leading identifiers in statements to types,
templates, values, etc. As an added bonus, this reduces the number of
lookups required for disambiguation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130288 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index a324bdc045..3aec4ea210 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -113,7 +113,7 @@ Retry: return ParseLabeledStatement(attrs); } - if (!getLang().CPlusPlus) { + if (Next.isNot(tok::coloncolon)) { // FIXME: Temporarily enable this code only for C. CXXScopeSpec SS; IdentifierInfo *Name = Tok.getIdentifierInfo(); @@ -147,7 +147,7 @@ Retry: // we're in a syntactic context we haven't handled yet. break; - case Sema::NC_Type: + case Sema::NC_Type: { // We have a type. In C, this means that we have a declaration. if (!getLang().CPlusPlus) { ParsedType Type = Classification.getType(); @@ -195,9 +195,15 @@ Retry: return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd); } - // In C++, we might also have a functional-style cast. - // FIXME: Implement this! + // In C++, we might also have a functional-style cast. Just annotate + // this as a type token. + Tok.setKind(tok::annot_typename); + setTypeAnnotation(Tok, Classification.getType()); + Tok.setAnnotationEndLoc(NameLoc); + Tok.setLocation(NameLoc); + PP.AnnotateCachedTokens(Tok); break; + } case Sema::NC_Expression: ConsumeToken(); // the identifier @@ -211,7 +217,20 @@ Retry: if (AnnotateTemplateIdToken( TemplateTy::make(Classification.getTemplateName()), Classification.getTemplateNameKind(), - SS, Id)) { + SS, Id, SourceLocation(), + /*AllowTypeAnnotation=*/false)) { + // Handle errors here by skipping up to the next semicolon or '}', and + // eat the semicolon if that's what stopped us. + SkipUntil(tok::r_brace, /*StopAtSemi=*/true, /*DontConsume=*/true); + if (Tok.is(tok::semi)) + ConsumeToken(); + return StmtError(); + } + + // If the next token is '::', jump right into parsing a + // nested-name-specifier. We don't want to leave the template-id + // hanging. + if (NextToken().is(tok::coloncolon) && TryAnnotateCXXScopeToken(false)){ // Handle errors here by skipping up to the next semicolon or '}', and // eat the semicolon if that's what stopped us. SkipUntil(tok::r_brace, /*StopAtSemi=*/true, /*DontConsume=*/true); |