|
| 1 | +/* |
| 2 | + * Cppcheck - A tool for static C/C++ code analysis |
| 3 | + * Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +#include "templatesimplifier.h" |
| 20 | +#include "token.h" |
| 21 | + |
| 22 | +//--------------------------------------------------------------------------- |
| 23 | +#ifdef _MSC_VER |
| 24 | +#pragma warning(disable: 4503) |
| 25 | +#endif |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +//--------------------------------------------------------------------------- |
| 30 | + |
| 31 | +TemplateSimplifier::TemplateSimplifier() |
| 32 | +{ |
| 33 | +} |
| 34 | + |
| 35 | +TemplateSimplifier::~TemplateSimplifier() |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +void TemplateSimplifier::cleanupAfterSimplify(Token *tokens) |
| 40 | +{ |
| 41 | + bool goback = false; |
| 42 | + for (Token *tok = tokens; tok; tok = tok->next()) { |
| 43 | + if (goback) { |
| 44 | + tok = tok->previous(); |
| 45 | + goback = false; |
| 46 | + } |
| 47 | + if (tok->str() == "(") |
| 48 | + tok = tok->link(); |
| 49 | + |
| 50 | + else if (Token::Match(tok, "%type% <") && |
| 51 | + (!tok->previous() || tok->previous()->str() == ";")) { |
| 52 | + const Token *tok2 = tok->tokAt(2); |
| 53 | + std::string type; |
| 54 | + while (Token::Match(tok2, "%type% ,") || Token::Match(tok2, "%num% ,")) { |
| 55 | + type += tok2->str() + ","; |
| 56 | + tok2 = tok2->tokAt(2); |
| 57 | + } |
| 58 | + if (Token::Match(tok2, "%type% > (") || Token::Match(tok2, "%num% > (")) { |
| 59 | + type += tok2->str(); |
| 60 | + tok->str(tok->str() + "<" + type + ">"); |
| 61 | + Token::eraseTokens(tok, tok2->tokAt(2)); |
| 62 | + if (tok == tokens) |
| 63 | + goback = true; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments