|
Cppcheck
|
00001 /* 00002 * Cppcheck - A tool for static C/C++ code analysis 00003 * Copyright (C) 2007-2013 Daniel Marjamäki and Cppcheck team. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 00020 //--------------------------------------------------------------------------- 00021 #ifndef tokenlistH 00022 #define tokenlistH 00023 //--------------------------------------------------------------------------- 00024 00025 #include <string> 00026 #include <vector> 00027 #include "config.h" 00028 00029 class Token; 00030 class Settings; 00031 00032 /// @addtogroup Core 00033 /// @{ 00034 00035 class CPPCHECKLIB TokenList { 00036 public: 00037 TokenList(const Settings* settings); 00038 ~TokenList(); 00039 00040 void setSettings(const Settings *settings) { 00041 _settings = settings; 00042 } 00043 00044 /** 00045 * Delete all tokens in given token list 00046 * @param tok token list to delete 00047 */ 00048 static void deleteTokens(Token *tok); 00049 00050 void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno, bool split = false); 00051 void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno); 00052 00053 static void insertTokens(Token *dest, const Token *src, unsigned int n); 00054 00055 /** 00056 * Create tokens from code. 00057 * The code must be preprocessed first: 00058 * - multiline strings are not handled. 00059 * - UTF in the code are not handled. 00060 * - comments are not handled. 00061 * @param code input stream for code 00062 * @param file0 source file name 00063 */ 00064 bool createTokens(std::istream &code, const std::string& file0 = ""); 00065 00066 /** Deallocate list */ 00067 void deallocateTokens(); 00068 00069 /** get first token of list */ 00070 const Token *front() const { 00071 return _front; 00072 } 00073 Token *front() { 00074 return _front; 00075 } 00076 00077 /** get last token of list */ 00078 const Token *back() const { 00079 return _back; 00080 } 00081 Token *back() { 00082 return _back; 00083 } 00084 00085 /** 00086 * Get filenames (the sourcefile + the files it include). 00087 * The first filename is the filename for the sourcefile 00088 * @return vector with filenames 00089 */ 00090 const std::vector<std::string>& getFiles() const { 00091 return _files; 00092 } 00093 00094 /** 00095 * get filename for given token 00096 * @param tok The given token 00097 * @return filename for the given token 00098 */ 00099 const std::string& file(const Token *tok) const; 00100 00101 /** 00102 * Get file:line for a given token 00103 * @param tok given token 00104 * @return location for given token 00105 */ 00106 std::string fileLine(const Token *tok) const; 00107 00108 void createAst(); 00109 00110 private: 00111 /** Disable copy constructor, no implementation */ 00112 TokenList(const TokenList &); 00113 00114 /** Disable assignment operator, no implementation */ 00115 TokenList &operator=(const TokenList &); 00116 00117 public: 00118 00119 private: /// private 00120 /** Token list */ 00121 Token *_front, *_back; 00122 00123 /** filenames for the tokenized source code (source + included) */ 00124 std::vector<std::string> _files; 00125 00126 /** settings */ 00127 const Settings* _settings; 00128 }; 00129 00130 /// @} 00131 00132 //--------------------------------------------------------------------------- 00133 #endif
1.7.6.1