Cppcheck
settings.h
Go to the documentation of this file.
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 #ifndef settingsH
00020 #define settingsH
00021 
00022 #include <list>
00023 #include <vector>
00024 #include <string>
00025 #include <set>
00026 #include "config.h"
00027 #include "suppressions.h"
00028 #include "standards.h"
00029 
00030 /// @addtogroup Core
00031 /// @{
00032 
00033 
00034 /**
00035  * @brief This is just a container for general settings so that we don't need
00036  * to pass individual values to functions or constructors now or in the
00037  * future when we might have even more detailed settings.
00038  */
00039 class CPPCHECKLIB Settings {
00040 private:
00041     /** @brief Code to append in the checks */
00042     std::string _append;
00043 
00044     /** @brief enable extra checks by id */
00045     std::set<std::string> _enabled;
00046 
00047     /** @brief terminate checking */
00048     bool _terminate;
00049 
00050 public:
00051     Settings();
00052 
00053     /** @brief Is --debug given? */
00054     bool debug;
00055 
00056     /** @brief Is --debug-warnings given? */
00057     bool debugwarnings;
00058 
00059     /** @brief Is --debug-fp given? */
00060     bool debugFalsePositive;
00061 
00062     /** @brief Inconclusive checks */
00063     bool inconclusive;
00064 
00065     /**
00066      * When this flag is false (default) then experimental
00067      * heuristics and checks are disabled.
00068      *
00069      * It should not be possible to enable this from any client.
00070      */
00071     bool experimental;
00072 
00073     /** @brief Is --quiet given? */
00074     bool _errorsOnly;
00075 
00076     /** @brief Is --inline-suppr given? */
00077     bool _inlineSuppressions;
00078 
00079     /** @brief Is --verbose given? */
00080     bool _verbose;
00081 
00082     /** @brief Request termination of checking */
00083     void terminate() {
00084         _terminate = true;
00085     }
00086 
00087     /** @brief termination requested? */
00088     bool terminated() const {
00089         return _terminate;
00090     }
00091 
00092     /** @brief Force checking the files with "too many" configurations (--force). */
00093     bool _force;
00094 
00095     /** @brief Use relative paths in output. */
00096     bool _relativePaths;
00097 
00098     /** @brief Paths used as base for conversion to relative paths. */
00099     std::vector<std::string> _basePaths;
00100 
00101     /** @brief write XML results (--xml) */
00102     bool _xml;
00103 
00104     /** @brief XML version (--xmlver=..) */
00105     int _xml_version;
00106 
00107     /** @brief How many processes/threads should do checking at the same
00108         time. Default is 1. (-j N) */
00109     unsigned int _jobs;
00110 
00111     /** @brief If errors are found, this value is returned from main().
00112         Default value is 0. */
00113     int _exitCode;
00114 
00115     /** @brief The output format in which the errors are printed in text mode,
00116         e.g. "{severity} {file}:{line} {message} {id}" */
00117     std::string _outputFormat;
00118 
00119     /** @brief show timing information (--showtime=file|summary|top5) */
00120     unsigned int _showtime;
00121 
00122     /** @brief List of include paths, e.g. "my/includes/" which should be used
00123         for finding include files inside source files. (-I) */
00124     std::list<std::string> _includePaths;
00125 
00126     /** @brief assign append code (--append) */
00127     bool append(const std::string &filename);
00128 
00129     /** @brief get append code (--append) */
00130     const std::string &append() const;
00131 
00132     /** @brief Maximum number of configurations to check before bailing.
00133         Default is 12. (--max-configs=N) */
00134     unsigned int _maxConfigs;
00135 
00136     /**
00137      * @brief Returns true if given id is in the list of
00138      * enabled extra checks (--enable)
00139      * @param str id for the extra check, e.g. "style"
00140      * @return true if the check is enabled.
00141      */
00142     bool isEnabled(const std::string &str) const;
00143 
00144     /**
00145      * @brief Enable extra checks by id. See isEnabled()
00146      * @param str single id or list of id values to be enabled
00147      * or empty string to enable all. e.g. "style,possibleError"
00148      * @return error message. empty upon success
00149      */
00150     std::string addEnabled(const std::string &str);
00151 
00152     enum Language {
00153         None, C, CPP
00154     };
00155 
00156     /** @brief Name of the language that is enforced. Empty per default. */
00157     Language enforcedLang;
00158 
00159     /** @brief suppress message (--suppressions) */
00160     Suppressions nomsg;
00161 
00162     /** @brief suppress exitcode */
00163     Suppressions nofail;
00164 
00165     /** @brief defines given by the user */
00166     std::string userDefines;
00167 
00168     /** @brief undefines given by the user */
00169     std::set<std::string> userUndefs;
00170 
00171     /** @brief forced includes given by the user */
00172     std::list<std::string> userIncludes;
00173 
00174     /** @brief --report-progress */
00175     bool reportProgress;
00176 
00177     /** Rule */
00178     class CPPCHECKLIB Rule {
00179     public:
00180         Rule()
00181             : id("rule") // default id
00182             , severity("style") { // default severity
00183         }
00184 
00185         std::string pattern;
00186         std::string id;
00187         std::string severity;
00188         std::string summary;
00189     };
00190 
00191     /**
00192      * @brief Extra rules
00193      */
00194     std::list<Rule> rules;
00195 
00196     /** Is the 'configuration checking' wanted? */
00197     bool checkConfiguration;
00198 
00199     /** Struct contains standards settings */
00200     Standards standards;
00201 
00202     /** size of standard types */
00203     unsigned int sizeof_bool;
00204     unsigned int sizeof_short;
00205     unsigned int sizeof_int;
00206     unsigned int sizeof_long;
00207     unsigned int sizeof_long_long;
00208     unsigned int sizeof_float;
00209     unsigned int sizeof_double;
00210     unsigned int sizeof_long_double;
00211     unsigned int sizeof_wchar_t;
00212     unsigned int sizeof_size_t;
00213     unsigned int sizeof_pointer;
00214 
00215     enum PlatformType {
00216         Unspecified, // whatever system this code was compiled on
00217         Win32A,
00218         Win32W,
00219         Win64,
00220         Unix32,
00221         Unix64
00222     };
00223 
00224     /** platform type */
00225     PlatformType platformType;
00226 
00227     /** set the platform type for predefined platforms */
00228     bool platform(PlatformType type);
00229 
00230     /** set the platform type for user specified platforms */
00231     bool platformFile(const std::string &filename);
00232 };
00233 
00234 /// @}
00235 
00236 #endif // SETTINGS_H