Improve creation of link() for Token class. Tokenizer::simplifyTokenList() should now return
code where Token::link() actually works.
This commit is contained in:
parent
6eadbaae04
commit
c385b3e045
|
@ -1491,7 +1491,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const char clas
|
|||
// Allocate..
|
||||
if (indent == 0 || Token::Match(tok, (std::string(varname) + " =").c_str()))
|
||||
{
|
||||
AllocType alloc = GetAllocationType(tok->tokAt((indent>0) ? 2 : 3));
|
||||
AllocType alloc = GetAllocationType(tok->tokAt((indent > 0) ? 2 : 3));
|
||||
if (alloc != No)
|
||||
{
|
||||
if (Alloc != No && Alloc != alloc)
|
||||
|
|
|
@ -521,7 +521,7 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
|
|||
// New type..
|
||||
std::vector<std::string> types2;
|
||||
s = "";
|
||||
for (const Token *tok3 = tok2->tokAt(2); tok3->str()!=">"; tok3 = tok3->next())
|
||||
for (const Token *tok3 = tok2->tokAt(2); tok3->str() != ">"; tok3 = tok3->next())
|
||||
{
|
||||
if (tok3->str() != ",")
|
||||
types2.push_back(tok3->str());
|
||||
|
@ -574,7 +574,7 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
|
|||
s = name + " < " + type2 + " >";
|
||||
for (std::string::size_type pos = s.find(","); pos != std::string::npos; pos = s.find(",", pos + 2))
|
||||
{
|
||||
s.insert(pos+1, " ");
|
||||
s.insert(pos + 1, " ");
|
||||
s.insert(pos, " ");
|
||||
}
|
||||
for (Token *tok4 = tok2; tok4; tok4 = tok4->next())
|
||||
|
@ -725,11 +725,16 @@ void Tokenizer::simplifyNamespaces()
|
|||
}
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyTokenList()
|
||||
bool Tokenizer::createLinks()
|
||||
{
|
||||
std::list<Token*> links;
|
||||
for (Token *token = _tokens; token; token = token->next())
|
||||
{
|
||||
if (token->link())
|
||||
{
|
||||
token->link(0);
|
||||
}
|
||||
|
||||
if (token->str() == "{")
|
||||
{
|
||||
links.push_back(token);
|
||||
|
@ -739,7 +744,7 @@ void Tokenizer::simplifyTokenList()
|
|||
if (links.size() == 0)
|
||||
{
|
||||
// Error, { and } don't match.
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
token->link(links.back());
|
||||
|
@ -751,8 +756,15 @@ void Tokenizer::simplifyTokenList()
|
|||
if (links.size() > 0)
|
||||
{
|
||||
// Error, { and } don't match.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyTokenList()
|
||||
{
|
||||
createLinks();
|
||||
|
||||
simplifyNamespaces();
|
||||
|
||||
|
@ -1240,6 +1252,8 @@ void Tokenizer::simplifyTokenList()
|
|||
modified |= simplifyRedundantParanthesis();
|
||||
modified |= simplifyCalculations();
|
||||
}
|
||||
|
||||
createLinks();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -176,6 +176,14 @@ private:
|
|||
|
||||
void InsertTokens(Token *dest, Token *src, unsigned int n);
|
||||
|
||||
/**
|
||||
* Setup links for tokens so that one can call Token::link().
|
||||
*
|
||||
* @return false if there was a mismatch with tokens, this
|
||||
* should mean that source code was not valid.
|
||||
*/
|
||||
bool createLinks();
|
||||
|
||||
Token *_tokensBack;
|
||||
std::map<std::string, unsigned int> _typeSize;
|
||||
std::vector<std::string> _files;
|
||||
|
|
Loading…
Reference in New Issue