SimplifyTemplates: some simple refactoring so template name is properly seen. If it's not properly handled then bailout. Related with #1464

This commit is contained in:
Daniel Marjamäki 2010-03-04 17:34:14 +01:00
parent d881fd7a31
commit b55a7f2815
1 changed files with 18 additions and 17 deletions

View File

@ -1632,36 +1632,37 @@ void Tokenizer::simplifyTemplates()
if (!tok) if (!tok)
break; break;
// if this is a template function, get the position of the function name // get the position of the template name
unsigned int pos = 0; unsigned int namepos = 0;
if (Token::Match(tok, "> %type% *|&| %var% (")) if (Token::Match(tok, "> class %type% {|:"))
pos = 2; namepos = 2;
else if (Token::Match(tok, "> %type% %type% *|&| %var% (")) else if (Token::Match(tok, "> %type% *|&| %type% ("))
pos = 3; namepos = 2;
if (pos > 0 && (tok->tokAt(pos)->str() == "*" || tok->tokAt(pos)->str() == "&")) else if (Token::Match(tok, "> %type% %type% *|&| %type% ("))
++pos; namepos = 3;
else
continue;
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
++namepos;
if (_settings && _settings->_debug) if (_settings && _settings->_debug)
{ {
int tempPos = pos; if (!Token::Match(tok->tokAt(namepos), "%var%"))
if (tempPos == 0)
tempPos = 2;
if (!Token::Match(tok->tokAt(tempPos), "%var%"))
{ {
std::cout << "simplifyTemplates error: " std::cout << "simplifyTemplates error: "
<< file(tok->tokAt(tempPos)) << file(tok->tokAt(namepos))
<< ": " << ": "
<< tok->tokAt(tempPos)->linenr() << tok->tokAt(namepos)->linenr()
<< ": " << ": "
<< tok->tokAt(tempPos)->str() << tok->tokAt(namepos)->str()
<< std::endl; << std::endl;
} }
} }
// name of template function/class.. // name of template function/class..
const std::string name(tok->strAt(pos > 0 ? pos : 2)); const std::string name(tok->strAt(namepos));
const bool isfunc(pos > 0); const bool isfunc(tok->strAt(namepos + 1) == "(");
// locate template usage.. // locate template usage..