68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
|
/*
|
||
|
* Cppcheck - A tool for static C/C++ code analysis
|
||
|
* Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "templatesimplifier.h"
|
||
|
#include "token.h"
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
#ifdef _MSC_VER
|
||
|
#pragma warning(disable: 4503)
|
||
|
#endif
|
||
|
|
||
|
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
|
||
|
TemplateSimplifier::TemplateSimplifier()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
TemplateSimplifier::~TemplateSimplifier()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
|
||
|
{
|
||
|
bool goback = false;
|
||
|
for (Token *tok = tokens; tok; tok = tok->next()) {
|
||
|
if (goback) {
|
||
|
tok = tok->previous();
|
||
|
goback = false;
|
||
|
}
|
||
|
if (tok->str() == "(")
|
||
|
tok = tok->link();
|
||
|
|
||
|
else if (Token::Match(tok, "%type% <") &&
|
||
|
(!tok->previous() || tok->previous()->str() == ";")) {
|
||
|
const Token *tok2 = tok->tokAt(2);
|
||
|
std::string type;
|
||
|
while (Token::Match(tok2, "%type% ,") || Token::Match(tok2, "%num% ,")) {
|
||
|
type += tok2->str() + ",";
|
||
|
tok2 = tok2->tokAt(2);
|
||
|
}
|
||
|
if (Token::Match(tok2, "%type% > (") || Token::Match(tok2, "%num% > (")) {
|
||
|
type += tok2->str();
|
||
|
tok->str(tok->str() + "<" + type + ">");
|
||
|
Token::eraseTokens(tok, tok2->tokAt(2));
|
||
|
if (tok == tokens)
|
||
|
goback = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|