This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
9. Update of rTemplateDecl2 function.
Without going into details we offer you to replace rTemplateDecl2() function with the given variant. This will exclude some errors while working with template classes.
bool Parser::rTemplateDecl2(Ptree*& decl,
TemplateDeclKind &kind)
{
Token tk;
Ptree *args = 0;
if(lex->GetToken(tk) != TEMPLATE)
return false;
if(lex->LookAhead(0) != '<') {
if (lex->LookAhead(0) == CLASS) {
// template instantiation
decl = 0;
kind = tdk_instantiation;
return true; // ignore TEMPLATE
}
decl = new (GC)
PtreeTemplateDecl(new (GC) LeafReserved(tk));
} else {
decl = new (GC)
PtreeTemplateDecl(new (GC) LeafReserved(tk));
if(lex->GetToken(tk) != '<')
return false;
decl = PtreeUtil::Snoc(decl, new (GC) Leaf(tk));
if(!rTempArgList(args))
return false;
if(lex->GetToken(tk) != '>')
return false;
}
decl =
PtreeUtil::Nconc(decl,
PtreeUtil::List(args, new (GC) Leaf(tk)));
// ignore nested TEMPLATE
while (lex->LookAhead(0) == TEMPLATE) {
lex->GetToken(tk);
if(lex->LookAhead(0) != '<')
break;
lex->GetToken(tk);
if(!rTempArgList(args))
return false;
if(lex->GetToken(tk) != '>')
return false;
}
if (args == 0)
// template < > declaration
kind = tdk_specialization;
else
// template < ... > declaration
kind = tdk_decl;
return true;
}
|