Remember the T_TEMPLATE token we use to force the parser to recognize a template-id.

This commit is contained in:
Roberto Raggi
2010-08-12 12:18:49 +02:00
parent 7f04af17a1
commit efb600665d
8 changed files with 43 additions and 27 deletions

View File

@@ -3687,6 +3687,8 @@ unsigned TemplateDeclarationAST::lastToken() const
/** \generated */
unsigned TemplateIdAST::firstToken() const
{
if (template_token)
return template_token;
if (identifier_token)
return identifier_token;
if (less_token)
@@ -3711,6 +3713,8 @@ unsigned TemplateIdAST::lastToken() const
return less_token + 1;
if (identifier_token)
return identifier_token + 1;
if (template_token)
return template_token + 1;
return 0;
}

View File

@@ -2214,6 +2214,7 @@ protected:
class CPLUSPLUS_EXPORT TemplateIdAST: public NameAST
{
public:
unsigned template_token;
unsigned identifier_token;
unsigned less_token;
ExpressionListAST *template_argument_list;
@@ -2221,7 +2222,8 @@ public:
public:
TemplateIdAST()
: identifier_token(0)
: template_token(0)
, identifier_token(0)
, less_token(0)
, template_argument_list(0)
, greater_token(0)

View File

@@ -802,6 +802,7 @@ DestructorNameAST *DestructorNameAST::clone(MemoryPool *pool) const
TemplateIdAST *TemplateIdAST::clone(MemoryPool *pool) const
{
TemplateIdAST *ast = new (pool) TemplateIdAST;
ast->template_token = template_token;
ast->identifier_token = identifier_token;
ast->less_token = less_token;
for (ExpressionListAST *iter = template_argument_list, **ast_iter = &ast->template_argument_list;

View File

@@ -1347,6 +1347,8 @@ bool ASTMatcher::match(TemplateIdAST *node, TemplateIdAST *pattern)
(void) node;
(void) pattern;
pattern->template_token = node->template_token;
pattern->identifier_token = node->identifier_token;
pattern->less_token = node->less_token;

View File

@@ -419,14 +419,14 @@ bool Parser::parseClassOrNamespaceName(NameAST *&node)
}
} else if (LA() == T_TEMPLATE) {
unsigned template_token = consumeToken();
if (parseTemplateId(node))
if (parseTemplateId(node, template_token))
return true;
rewind(template_token);
}
return false;
}
bool Parser::parseTemplateId(NameAST *&node)
bool Parser::parseTemplateId(NameAST *&node, unsigned template_token)
{
DEBUG_THIS_RULE();
@@ -434,6 +434,7 @@ bool Parser::parseTemplateId(NameAST *&node)
if (LA() == T_IDENTIFIER && LA(2) == T_LESS) {
TemplateIdAST *ast = new (_pool) TemplateIdAST;
ast->template_token = template_token;
ast->identifier_token = consumeToken();
ast->less_token = consumeToken();
if (LA() == T_GREATER || parseTemplateArgumentList(
@@ -2642,7 +2643,7 @@ bool Parser::parseUnqualifiedName(NameAST *&node, bool acceptTemplateId)
return true;
} else if (LA() == T_TEMPLATE) {
unsigned template_token = consumeToken();
if (parseTemplateId(node))
if (parseTemplateId(node, template_token))
return true;
rewind(template_token);
}

View File

@@ -147,7 +147,7 @@ public:
bool parseMemInitializerList(MemInitializerListAST *&node);
bool parseMemberSpecification(DeclarationAST *&node);
bool parseMultiplicativeExpression(ExpressionAST *&node);
bool parseTemplateId(NameAST *&node);
bool parseTemplateId(NameAST *&node, unsigned template_token = 0);
bool parseClassOrNamespaceName(NameAST *&node);
bool parseNameId(NameAST *&node);
bool parseName(NameAST *&node, bool acceptTemplateId = true);