Commit efb60066 authored by Roberto Raggi's avatar Roberto Raggi

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

parent 7f04af17
......@@ -483,17 +483,8 @@ bool CheckSymbols::visit(NamedTypeSpecifierAST *)
bool CheckSymbols::visit(ElaboratedTypeSpecifierAST *ast)
{
accept(ast->attribute_list);
if (ast->name) {
if (const Name *name = ast->name->name) {
if (name->isNameId() || name->isTemplateNameId()) {
addUse(ast->name, Use::Type);
return false;
}
}
}
accept(ast->name);
addUse(ast->name, Use::Type);
return false;
}
......@@ -678,7 +669,7 @@ bool CheckSymbols::visit(DestructorNameAST *ast)
bool CheckSymbols::visit(QualifiedNameAST *ast)
{
if (ast->name) {
ClassOrNamespace *b = 0;
ClassOrNamespace *binding = 0;
if (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list) {
NestedNameSpecifierAST *nested_name_specifier = it->value;
if (NameAST *class_or_namespace_name = nested_name_specifier->class_or_namespace_name) { // ### remove shadowing
......@@ -687,29 +678,39 @@ bool CheckSymbols::visit(QualifiedNameAST *ast)
accept(template_id->template_argument_list);
const Name *name = class_or_namespace_name->name;
b = _context.lookupType(name, enclosingScope());
addType(b, class_or_namespace_name);
binding = _context.lookupType(name, enclosingScope());
addType(binding, class_or_namespace_name);
for (it = it->next; b && it; it = it->next) {
for (it = it->next; it; it = it->next) {
NestedNameSpecifierAST *nested_name_specifier = it->value;
if (NameAST *class_or_namespace_name = nested_name_specifier->class_or_namespace_name) {
if (TemplateIdAST *template_id = class_or_namespace_name->asTemplateId())
accept(template_id->template_argument_list);
if (TemplateIdAST *template_id = class_or_namespace_name->asTemplateId()) {
if (template_id->template_token) {
addUse(template_id, Use::Type);
binding = 0; // there's no way we can find a binding.
}
b = b->findType(class_or_namespace_name->name);
addType(b, class_or_namespace_name);
accept(template_id->template_argument_list);
if (! binding)
continue;
}
if (binding) {
binding = binding->findType(class_or_namespace_name->name);
addType(binding, class_or_namespace_name);
}
}
}
}
}
if (b && ast->unqualified_name) {
if (binding && ast->unqualified_name) {
if (ast->unqualified_name->asDestructorName() != 0) {
if (hasVirtualDestructor(b))
if (hasVirtualDestructor(binding))
addUse(ast->unqualified_name, Use::VirtualMethod);
} else {
addTypeOrStatic(b->find(ast->unqualified_name->name), ast->unqualified_name);
addTypeOrStatic(binding->find(ast->unqualified_name->name), ast->unqualified_name);
}
}
}
......@@ -805,6 +806,9 @@ void CheckSymbols::addUse(NameAST *ast, Use::Kind kind)
if (DestructorNameAST *dtor = ast->asDestructorName())
startToken = dtor->identifier_token;
else if (TemplateIdAST *templ = ast->asTemplateId())
startToken = templ->identifier_token;
addUse(startToken, kind);
}
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -771,11 +771,13 @@ virtual bool visit(DestructorNameAST *ast)
virtual bool visit(TemplateIdAST *ast)
{
if (ast->template_token)
terminal(ast->template_token, ast);
if (ast->identifier_token)
terminal(ast->identifier_token, ast);
if (ast->less_token)
terminal(ast->less_token, ast);
for (TemplateArgumentListAST *iter = ast->template_argument_list; iter; iter = iter->next)
for (ExpressionListAST *iter = ast->template_argument_list; iter; iter = iter->next)
nonterminal(iter->value);
if (ast->greater_token)
terminal(ast->greater_token, ast);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment