Fixed #1204 (Tokenizer::findClassFunction broken)

This commit is contained in:
Daniel Marjamäki 2010-01-02 08:33:54 +01:00
parent 82ae064218
commit 6af5e434d8
2 changed files with 11 additions and 25 deletions

View File

@ -4553,18 +4553,13 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const char classnam
if (indentlevel < 0 || tok == NULL) if (indentlevel < 0 || tok == NULL)
return NULL; return NULL;
std::ostringstream classPattern; const std::string classPattern(std::string("class ") + classname + " :|{");
classPattern << "class " << classname << " :|{"; const std::string internalPattern(std::string("!!~ ") + funcname + " (");
const std::string externalPattern(std::string(classname) + " :: " + funcname + " (");
std::ostringstream internalPattern;
internalPattern << funcname << " (";
std::ostringstream externalPattern;
externalPattern << classname << " :: " << funcname << " (";
for (; tok; tok = tok->next()) for (; tok; tok = tok->next())
{ {
if (indentlevel == 0 && Token::Match(tok, classPattern.str().c_str())) if (indentlevel == 0 && Token::Match(tok, classPattern.c_str()))
{ {
while (tok && tok->str() != "{") while (tok && tok->str() != "{")
tok = tok->next(); tok = tok->next();
@ -4583,17 +4578,8 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const char classnam
else else
{ {
for (; tok; tok = tok->next()) // skip the block
{ tok = tok->link();
if (tok->str() == "{")
++indentlevel;
else if (tok->str() == "}")
{
--indentlevel;
if (indentlevel <= 0)
break;
}
}
if (tok == NULL) if (tok == NULL)
return NULL; return NULL;
@ -4611,17 +4597,17 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const char classnam
if (indentlevel == 1) if (indentlevel == 1)
{ {
// Member function implemented in the class declaration? // Member function implemented in the class declaration?
if (tok->str() != "~" && Token::Match(tok->next(), internalPattern.str().c_str())) if (Token::Match(tok->previous(), internalPattern.c_str()))
{ {
const Token *tok2 = tok->next(); const Token *tok2 = tok;
while (tok2 && tok2->str() != "{" && tok2->str() != ";") while (tok2 && tok2->str() != "{" && tok2->str() != ";")
tok2 = tok2->next(); tok2 = tok2->next();
if (tok2 && tok2->str() == "{") if (tok2 && tok2->str() == "{")
return tok->next(); return tok;
} }
} }
else if (indentlevel == 0 && Token::Match(tok, externalPattern.str().c_str())) else if (indentlevel == 0 && Token::Match(tok, externalPattern.c_str()))
{ {
return tok; return tok;
} }

View File

@ -2254,7 +2254,7 @@ private:
const char code[] = const char code[] =
"class Fred" "class Fred"
"{\n" "{\n"
"public:\n" // "public:\n"
" Fred()\n" " Fred()\n"
" { }\n" " { }\n"
"};\n"; "};\n";