Optimization: tokenlist::addtoken
This commit is contained in:
parent
bc1ab4c48a
commit
5e0a575091
|
@ -936,6 +936,9 @@ void CheckOther::checkSwitchCaseFallThrough()
|
||||||
|
|
||||||
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
||||||
|
if (!symbolDatabase)
|
||||||
|
return;
|
||||||
|
|
||||||
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
||||||
if (i->type != Scope::eSwitch || !i->classStart) // Find the beginning of a switch
|
if (i->type != Scope::eSwitch || !i->classStart) // Find the beginning of a switch
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -678,7 +678,7 @@ void TemplateSimplifier::expandTemplate(
|
||||||
|
|
||||||
// member function implemented outside class definition
|
// member function implemented outside class definition
|
||||||
else if (TemplateSimplifier::instantiateMatch(tok3, name, typeParametersInDeclaration.size(), ":: ~| %var% (")) {
|
else if (TemplateSimplifier::instantiateMatch(tok3, name, typeParametersInDeclaration.size(), ":: ~| %var% (")) {
|
||||||
tokenlist.addtoken(newName.c_str(), tok3->linenr(), tok3->fileIndex());
|
tokenlist.addtoken(newName, tok3->linenr(), tok3->fileIndex());
|
||||||
while (tok3->str() != "::")
|
while (tok3->str() != "::")
|
||||||
tok3 = tok3->next();
|
tok3 = tok3->next();
|
||||||
}
|
}
|
||||||
|
@ -720,7 +720,7 @@ void TemplateSimplifier::expandTemplate(
|
||||||
|
|
||||||
// replace name..
|
// replace name..
|
||||||
if (Token::Match(tok3, (name + " !!<").c_str())) {
|
if (Token::Match(tok3, (name + " !!<").c_str())) {
|
||||||
tokenlist.addtoken(newName.c_str(), tok3->linenr(), tok3->fileIndex());
|
tokenlist.addtoken(newName, tok3->linenr(), tok3->fileIndex());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,43 +79,44 @@ void TokenList::deleteTokens(Token *tok)
|
||||||
// add a token.
|
// add a token.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void TokenList::addtoken(const char str[], const unsigned int lineno, const unsigned int fileno, bool split)
|
void TokenList::addtoken(const std::string & str, const unsigned int lineno, const unsigned int fileno, bool split)
|
||||||
{
|
{
|
||||||
if (str[0] == 0)
|
if (str.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If token contains # characters, split it up
|
// If token contains # characters, split it up
|
||||||
if (split && std::strstr(str, "##")) {
|
if (split) {
|
||||||
std::string temp;
|
size_t begin = 0;
|
||||||
for (unsigned int i = 0; str[i]; ++i) {
|
size_t end = 0;
|
||||||
if (std::strncmp(&str[i], "##", 2) == 0) {
|
while ((end = str.find("##", begin)) != std::string::npos) {
|
||||||
addtoken(temp.c_str(), lineno, fileno, false);
|
addtoken(str.substr(begin, end - begin), lineno, fileno, false);
|
||||||
temp.clear();
|
addtoken("##", lineno, fileno, false);
|
||||||
addtoken("##", lineno, fileno, false);
|
begin = end+2;
|
||||||
++i;
|
}
|
||||||
} else
|
if (begin != 0) {
|
||||||
temp += str[i];
|
addtoken(str.substr(begin), lineno, fileno, false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
addtoken(temp.c_str(), lineno, fileno, false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace hexadecimal value with decimal
|
// Replace hexadecimal value with decimal
|
||||||
std::ostringstream str2;
|
std::string str2;
|
||||||
if (MathLib::isHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
|
if (MathLib::isHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
|
||||||
str2 << MathLib::toLongNumber(str);
|
std::ostringstream str2stream;
|
||||||
} else if (std::strncmp(str, "_Bool", 5) == 0) {
|
str2stream << MathLib::toLongNumber(str);
|
||||||
str2 << "bool";
|
str2 = str2stream.str();
|
||||||
|
} else if (str.compare(0, 5, "_Bool") == 0) {
|
||||||
|
str2 = "bool";
|
||||||
} else {
|
} else {
|
||||||
str2 << str;
|
str2 = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_back) {
|
if (_back) {
|
||||||
_back->insertToken(str2.str());
|
_back->insertToken(str2);
|
||||||
} else {
|
} else {
|
||||||
_front = new Token(&_back);
|
_front = new Token(&_back);
|
||||||
_back = _front;
|
_back = _front;
|
||||||
_back->str(str2.str());
|
_back->str(str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
_back->linenr(lineno);
|
_back->linenr(lineno);
|
||||||
|
@ -207,12 +208,12 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
bool expandedMacro = false;
|
bool expandedMacro = false;
|
||||||
|
|
||||||
// Read one byte at a time from code and create tokens
|
// Read one byte at a time from code and create tokens
|
||||||
for (char ch = (char)code.get(); code.good(); ch = (char)code.get()) {
|
for (char ch = (char)code.get(); code.good() && ch; ch = (char)code.get()) {
|
||||||
if (ch == Preprocessor::macroChar) {
|
if (ch == Preprocessor::macroChar) {
|
||||||
while (code.peek() == Preprocessor::macroChar)
|
while (code.peek() == Preprocessor::macroChar)
|
||||||
code.get();
|
code.get();
|
||||||
if (!CurrentToken.empty()) {
|
if (!CurrentToken.empty()) {
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
addtoken(CurrentToken, lineno, FileIndex, true);
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
}
|
}
|
||||||
CurrentToken.clear();
|
CurrentToken.clear();
|
||||||
|
@ -255,12 +256,12 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
lineno = 0;
|
lineno = 0;
|
||||||
} else {
|
} else {
|
||||||
// Add previous token
|
// Add previous token
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex);
|
addtoken(CurrentToken, lineno, FileIndex);
|
||||||
if (!CurrentToken.empty())
|
if (!CurrentToken.empty())
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
|
|
||||||
// Add content of the string
|
// Add content of the string
|
||||||
addtoken(line.c_str(), lineno, FileIndex);
|
addtoken(line, lineno, FileIndex);
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +327,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
addtoken(CurrentToken, lineno, FileIndex, true);
|
||||||
if (!CurrentToken.empty()) {
|
if (!CurrentToken.empty()) {
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
expandedMacro = false;
|
expandedMacro = false;
|
||||||
|
@ -348,7 +349,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
// Add "++", "--", ">>" or ... token
|
// Add "++", "--", ">>" or ... token
|
||||||
if (std::strchr("+-<>=:&|", ch) && (code.peek() == ch))
|
if (std::strchr("+-<>=:&|", ch) && (code.peek() == ch))
|
||||||
CurrentToken += (char)code.get();
|
CurrentToken += (char)code.get();
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex);
|
addtoken(CurrentToken, lineno, FileIndex);
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
CurrentToken.clear();
|
CurrentToken.clear();
|
||||||
expandedMacro = false;
|
expandedMacro = false;
|
||||||
|
@ -357,7 +358,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
|
|
||||||
CurrentToken += ch;
|
CurrentToken += ch;
|
||||||
}
|
}
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
addtoken(CurrentToken, lineno, FileIndex, true);
|
||||||
if (!CurrentToken.empty())
|
if (!CurrentToken.empty())
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
_front->assignProgressValues();
|
_front->assignProgressValues();
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
*/
|
*/
|
||||||
static void deleteTokens(Token *tok);
|
static void deleteTokens(Token *tok);
|
||||||
|
|
||||||
void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno, bool split = false);
|
void addtoken(const std::string & str, const unsigned int lineno, const unsigned int fileno, bool split = false);
|
||||||
void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno);
|
void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno);
|
||||||
|
|
||||||
static void insertTokens(Token *dest, const Token *src, unsigned int n);
|
static void insertTokens(Token *dest, const Token *src, unsigned int n);
|
||||||
|
|
Loading…
Reference in New Issue