diff options
author | Abramo Bagnara <abramo.bagnara@gmail.com> | 2012-01-27 09:46:47 +0000 |
---|---|---|
committer | Abramo Bagnara <abramo.bagnara@gmail.com> | 2012-01-27 09:46:47 +0000 |
commit | e4b92761b43ced611c417ae478568610f1ad7b1e (patch) | |
tree | bdafe8db4aa7a40adf4a0d5e8f9725d5ac456e4d /lib/Parse/ParseExprCXX.cpp | |
parent | 69d53845c68a4f01920b58ba6ce507d78220689c (diff) |
Added source location for the template keyword in AST template-id expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149127 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseExprCXX.cpp')
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 104 |
1 files changed, 55 insertions, 49 deletions
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index d35203e941..2f373830e2 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -264,15 +264,13 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, // Commit to parsing the template-id. TPA.Commit(); TemplateTy Template; - if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName(getCurScope(), - TemplateKWLoc, - SS, - TemplateName, - ObjectType, - EnteringContext, - Template)) { - if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, - TemplateKWLoc, false)) + if (TemplateNameKind TNK + = Actions.ActOnDependentTemplateName(getCurScope(), + SS, TemplateKWLoc, TemplateName, + ObjectType, EnteringContext, + Template)) { + if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc, + TemplateName, false)) return true; } else return true; @@ -307,8 +305,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, TemplateId->NumArgs); if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), - /*FIXME:*/SourceLocation(), - SS, + SS, + TemplateId->TemplateKWLoc, TemplateId->Template, TemplateId->TemplateNameLoc, TemplateId->LAngleLoc, @@ -404,8 +402,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, // specializations) still want to see the original template-id // token. ConsumeToken(); - if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, - SourceLocation(), false)) + if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), + TemplateName, false)) return true; continue; } @@ -426,14 +424,14 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName(getCurScope(), - Tok.getLocation(), SS, + SS, SourceLocation(), TemplateName, ObjectType, EnteringContext, Template)) { // Consume the identifier. ConsumeToken(); - if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, - SourceLocation(), false)) - return true; + if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), + TemplateName, false)) + return true; } else return true; @@ -505,13 +503,15 @@ ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { // CXXScopeSpec SS; ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); - + + SourceLocation TemplateKWLoc; UnqualifiedId Name; - if (ParseUnqualifiedId(SS, - /*EnteringContext=*/false, - /*AllowDestructorName=*/false, - /*AllowConstructorName=*/false, + if (ParseUnqualifiedId(SS, + /*EnteringContext=*/false, + /*AllowDestructorName=*/false, + /*AllowConstructorName=*/false, /*ObjectType=*/ ParsedType(), + TemplateKWLoc, Name)) return ExprError(); @@ -519,10 +519,9 @@ ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { // followed by a postfix-expression suffix. if (isAddressOfOperand && isPostfixExpressionSuffixStart()) isAddressOfOperand = false; - - return Actions.ActOnIdExpression(getCurScope(), SS, Name, Tok.is(tok::l_paren), - isAddressOfOperand); - + + return Actions.ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Name, + Tok.is(tok::l_paren), isAddressOfOperand); } /// ParseLambdaExpression - Parse a C++0x lambda expression. @@ -1030,6 +1029,8 @@ Parser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); CCLoc = ConsumeToken(); } else if (Tok.is(tok::annot_template_id)) { + // FIXME: retrieve TemplateKWLoc from template-id annotation and + // store it in the pseudo-dtor node (to be used when instantiating it). FirstTypeName.setTemplateId( (TemplateIdAnnotation *)Tok.getAnnotationValue()); ConsumeToken(); @@ -1067,9 +1068,10 @@ Parser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, // If there is a '<', the second type name is a template-id. Parse // it as such. if (Tok.is(tok::less) && - ParseUnqualifiedIdTemplateId(SS, Name, NameLoc, false, ObjectType, - SecondTypeName, /*AssumeTemplateName=*/true, - /*TemplateKWLoc*/SourceLocation())) + ParseUnqualifiedIdTemplateId(SS, SourceLocation(), + Name, NameLoc, + false, ObjectType, SecondTypeName, + /*AssumeTemplateName=*/true)) return ExprError(); return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, @@ -1502,13 +1504,13 @@ bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { /// /// \returns true if a parse error occurred, false otherwise. bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, + SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc, bool EnteringContext, ParsedType ObjectType, UnqualifiedId &Id, - bool AssumeTemplateId, - SourceLocation TemplateKWLoc) { + bool AssumeTemplateId) { assert((AssumeTemplateId || Tok.is(tok::less)) && "Expected '<' to finish parsing a template-id"); @@ -1519,7 +1521,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, case UnqualifiedId::IK_OperatorFunctionId: case UnqualifiedId::IK_LiteralOperatorId: if (AssumeTemplateId) { - TNK = Actions.ActOnDependentTemplateName(getCurScope(), TemplateKWLoc, SS, + TNK = Actions.ActOnDependentTemplateName(getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext, Template); if (TNK == TNK_Non_template) @@ -1550,9 +1552,10 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword) << Name << FixItHint::CreateInsertion(Id.StartLocation, "template "); - TNK = Actions.ActOnDependentTemplateName(getCurScope(), TemplateKWLoc, - SS, Id, ObjectType, - EnteringContext, Template); + TNK = Actions.ActOnDependentTemplateName(getCurScope(), + SS, TemplateKWLoc, Id, + ObjectType, EnteringContext, + Template); if (TNK == TNK_Non_template) return true; } @@ -1575,9 +1578,10 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, bool MemberOfUnknownSpecialization; TemplateName.setIdentifier(Name, NameLoc); if (ObjectType) { - TNK = Actions.ActOnDependentTemplateName(getCurScope(), TemplateKWLoc, SS, - TemplateName, ObjectType, - EnteringContext, Template); + TNK = Actions.ActOnDependentTemplateName(getCurScope(), + SS, TemplateKWLoc, TemplateName, + ObjectType, EnteringContext, + Template); if (TNK == TNK_Non_template) return true; } else { @@ -1880,12 +1884,12 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, ParsedType ObjectType, + SourceLocation& TemplateKWLoc, UnqualifiedId &Result) { // Handle 'A::template B'. This is for template-ids which have not // already been annotated by ParseOptionalCXXScopeSpecifier(). bool TemplateSpecified = false; - SourceLocation TemplateKWLoc; if (getLang().CPlusPlus && Tok.is(tok::kw_template) && (ObjectType || SS.isSet())) { TemplateSpecified = true; @@ -1923,9 +1927,9 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, // If the next token is a '<', we may have a template. if (TemplateSpecified || Tok.is(tok::less)) - return ParseUnqualifiedIdTemplateId(SS, Id, IdLoc, EnteringContext, - ObjectType, Result, - TemplateSpecified, TemplateKWLoc); + return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, Id, IdLoc, + EnteringContext, ObjectType, + Result, TemplateSpecified); return false; } @@ -1969,6 +1973,7 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, // We have already parsed a template-id; consume the annotation token as // our unqualified-id. Result.setTemplateId(TemplateId); + TemplateKWLoc = TemplateId->TemplateKWLoc; ConsumeToken(); return false; } @@ -1988,10 +1993,10 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, if ((Result.getKind() == UnqualifiedId::IK_OperatorFunctionId || Result.getKind() == UnqualifiedId::IK_LiteralOperatorId) && (TemplateSpecified || Tok.is(tok::less))) - return ParseUnqualifiedIdTemplateId(SS, 0, SourceLocation(), - EnteringContext, ObjectType, - Result, - TemplateSpecified, TemplateKWLoc); + return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, + 0, SourceLocation(), + EnteringContext, ObjectType, + Result, TemplateSpecified); return false; } @@ -2028,9 +2033,10 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, if (TemplateSpecified || Tok.is(tok::less)) { Result.setDestructorName(TildeLoc, ParsedType(), ClassNameLoc); - return ParseUnqualifiedIdTemplateId(SS, ClassName, ClassNameLoc, - EnteringContext, ObjectType, Result, - TemplateSpecified, TemplateKWLoc); + return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, + ClassName, ClassNameLoc, + EnteringContext, ObjectType, + Result, TemplateSpecified); } // Note that this is a destructor name. |