"Fossies" - the Fresh Open Source Software Archive

Member "cppcheck-1.89/lib/settings.h" (1 Sep 2019, 10389 Bytes) of package /windows/misc/cppcheck-1.89.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "settings.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.88_vs_1.89.

    1 /*
    2  * Cppcheck - A tool for static C/C++ code analysis
    3  * Copyright (C) 2007-2019 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 //---------------------------------------------------------------------------
   20 #ifndef settingsH
   21 #define settingsH
   22 //---------------------------------------------------------------------------
   23 
   24 #include "config.h"
   25 #include "errorlogger.h"
   26 #include "importproject.h"
   27 #include "library.h"
   28 #include "platform.h"
   29 #include "standards.h"
   30 #include "suppressions.h"
   31 #include "timer.h"
   32 
   33 #include <list>
   34 #include <set>
   35 #include <string>
   36 #include <vector>
   37 
   38 namespace ValueFlow {
   39     class Value;
   40 }
   41 
   42 /// @addtogroup Core
   43 /// @{
   44 
   45 /**
   46  * @brief This is just a container for general settings so that we don't need
   47  * to pass individual values to functions or constructors now or in the
   48  * future when we might have even more detailed settings.
   49  */
   50 class CPPCHECKLIB Settings : public cppcheck::Platform {
   51 public:
   52     enum EnabledGroup {
   53         WARNING = 0x1,
   54         STYLE = 0x2,
   55         PERFORMANCE = 0x4,
   56         PORTABILITY = 0x8,
   57         INFORMATION = 0x10,
   58         UNUSED_FUNCTION = 0x20,
   59         MISSING_INCLUDE = 0x40,
   60         INTERNAL = 0x80
   61     };
   62 
   63 private:
   64     /** @brief enable extra checks by id */
   65     int mEnabled;
   66 
   67     /** @brief terminate checking */
   68     static bool mTerminated;
   69 
   70 public:
   71     Settings();
   72 
   73     std::list<std::string> addons;
   74 
   75     /** @brief Paths used as base for conversion to relative paths. */
   76     std::vector<std::string> basePaths;
   77 
   78     /** @brief --cppcheck-build-dir */
   79     std::string buildDir;
   80 
   81     /** Is the 'configuration checking' wanted? */
   82     bool checkConfiguration;
   83 
   84     /** Check for incomplete info in library files? */
   85     bool checkLibrary;
   86 
   87     /**
   88      * Check code in the headers, this is on by default but can
   89      * be turned off to save CPU */
   90     bool checkHeaders;
   91 
   92     /** Check unused templates */
   93     bool checkUnusedTemplates;
   94 
   95     /** @brief include paths excluded from checking the configuration */
   96     std::set<std::string> configExcludePaths;
   97 
   98     /** @brief Is --debug-simplified given? */
   99     bool debugSimplified;
  100 
  101     /** @brief Is --debug-normal given? */
  102     bool debugnormal;
  103 
  104     /** @brief Is --debug-warnings given? */
  105     bool debugwarnings;
  106 
  107     /** @brief Is --debug-template given? */
  108     bool debugtemplate;
  109 
  110     /** @brief Is --dump given? */
  111     bool dump;
  112     std::string dumpFile;
  113 
  114     enum Language {
  115         None, C, CPP
  116     };
  117 
  118     /** @brief Name of the language that is enforced. Empty per default. */
  119     Language enforcedLang;
  120 
  121     /** @brief Is --exception-handling given */
  122     bool exceptionHandling;
  123 
  124     // argv[0]
  125     std::string exename;
  126 
  127     /** @brief If errors are found, this value is returned from main().
  128         Default value is 0. */
  129     int exitCode;
  130 
  131     /**
  132      * When this flag is false (default) then experimental
  133      * heuristics and checks are disabled.
  134      *
  135      * It should not be possible to enable this from any client.
  136      */
  137     bool experimental;
  138 
  139     /** @brief Force checking the files with "too many" configurations (--force). */
  140     bool force;
  141 
  142     /** @brief List of include paths, e.g. "my/includes/" which should be used
  143         for finding include files inside source files. (-I) */
  144     std::list<std::string> includePaths;
  145 
  146     /** @brief Inconclusive checks */
  147     bool inconclusive;
  148 
  149     /** Do not only check how interface is used. Also check that interface is safe. */
  150     class CPPCHECKLIB SafeChecks {
  151     public:
  152         SafeChecks() : classes(false), externalFunctions(false), internalFunctions(false), externalVariables(false) {}
  153 
  154         static const char XmlRootName[];
  155         static const char XmlClasses[];
  156         static const char XmlExternalFunctions[];
  157         static const char XmlInternalFunctions[];
  158         static const char XmlExternalVariables[];
  159 
  160         /**
  161          * Public interface of classes
  162          * - public function parameters can have any value
  163          * - public functions can be called in any order
  164          * - public variables can have any value
  165          */
  166         bool classes;
  167 
  168         /**
  169          * External functions
  170          * - external functions can be called in any order
  171          * - function parameters can have any values
  172          */
  173         bool externalFunctions;
  174 
  175         /**
  176          * Experimental: assume that internal functions can be used in any way
  177          * This is only available in the GUI.
  178          */
  179         bool internalFunctions;
  180 
  181         /**
  182          * Global variables that can be modified outside the TU.
  183          * - Such variable can have "any" value
  184          */
  185         bool externalVariables;
  186     };
  187 
  188     SafeChecks safeChecks;
  189 
  190     /** @brief check unknown function return values */
  191     std::set<std::string> checkUnknownFunctionReturn;
  192 
  193     /** @brief Is --inline-suppr given? */
  194     bool inlineSuppressions;
  195 
  196     /** @brief How many processes/threads should do checking at the same
  197         time. Default is 1. (-j N) */
  198     unsigned int jobs;
  199 
  200     /** @brief Collect unmatched suppressions in one run.
  201       * This delays the reporting until all files are checked.
  202       * It is needed by checks that analyse the whole code base. */
  203     bool jointSuppressionReport;
  204 
  205     /** @brief --library= */
  206     std::list<std::string> libraries;
  207 
  208     /** Library */
  209     Library library;
  210 
  211     /** @brief Load average value */
  212     unsigned int loadAverage;
  213 
  214     /** @brief Maximum number of configurations to check before bailing.
  215         Default is 12. (--max-configs=N) */
  216     unsigned int maxConfigs;
  217 
  218     /** @brief --max-ctu-depth */
  219     int maxCtuDepth;
  220 
  221     /** @brief suppress exitcode */
  222     Suppressions nofail;
  223 
  224     /** @brief suppress message (--suppressions) */
  225     Suppressions nomsg;
  226 
  227     /** @brief write results (--output-file=&lt;file&gt;) */
  228     std::string outputFile;
  229 
  230     /** @brief plist output (--plist-output=&lt;dir&gt;) */
  231     std::string plistOutput;
  232 
  233     /** @brief Using -E for debugging purposes */
  234     bool preprocessOnly;
  235 
  236     ImportProject project;
  237 
  238     /** @brief Is --quiet given? */
  239     bool quiet;
  240 
  241     /** @brief Use relative paths in output. */
  242     bool relativePaths;
  243 
  244     /** @brief --report-progress */
  245     bool reportProgress;
  246 
  247     /** Rule */
  248     class CPPCHECKLIB Rule {
  249     public:
  250         Rule()
  251             : tokenlist("simple")         // use simple tokenlist
  252             , id("rule")                  // default id
  253             , severity(Severity::style) { // default severity
  254         }
  255 
  256         std::string tokenlist;
  257         std::string pattern;
  258         std::string id;
  259         std::string summary;
  260         Severity::SeverityType severity;
  261     };
  262 
  263     /**
  264      * @brief Extra rules
  265      */
  266     std::list<Rule> rules;
  267 
  268     /** @brief show timing information (--showtime=file|summary|top5) */
  269     SHOWTIME_MODES showtime;
  270 
  271     /** Struct contains standards settings */
  272     Standards standards;
  273 
  274     /** @brief The output format in which the errors are printed in text mode,
  275         e.g. "{severity} {file}:{line} {message} {id}" */
  276     std::string templateFormat;
  277 
  278     /** @brief The output format in which the error locations are printed in
  279      *  text mode, e.g. "{file}:{line} {info}" */
  280     std::string templateLocation;
  281 
  282     /** @brief defines given by the user */
  283     std::string userDefines;
  284 
  285     /** @brief undefines given by the user */
  286     std::set<std::string> userUndefs;
  287 
  288     /** @brief forced includes given by the user */
  289     std::list<std::string> userIncludes;
  290 
  291     /** @brief Is --verbose given? */
  292     bool verbose;
  293 
  294     /** @brief write XML results (--xml) */
  295     bool xml;
  296 
  297     /** @brief XML version (--xml-version=..) */
  298     int xml_version;
  299 
  300     /**
  301      * @brief return true if a included file is to be excluded in Preprocessor::getConfigs
  302      * @return true for the file to be excluded.
  303      */
  304     bool configurationExcluded(const std::string &file) const {
  305         for (std::set<std::string>::const_iterator i=configExcludePaths.begin(); i!=configExcludePaths.end(); ++i) {
  306             if (file.length()>=i->length() && file.compare(0,i->length(),*i)==0) {
  307                 return true;
  308             }
  309         }
  310         return false;
  311     }
  312 
  313     /**
  314      * @brief Enable extra checks by id. See isEnabled()
  315      * @param str single id or list of id values to be enabled
  316      * or empty string to enable all. e.g. "style,possibleError"
  317      * @return error message. empty upon success
  318      */
  319     std::string addEnabled(const std::string &str);
  320 
  321     /**
  322      * @brief Disables all severities, except from error.
  323      */
  324     void clearEnabled() {
  325         mEnabled = 0;
  326     }
  327 
  328     /**
  329      * @brief Returns true if given id is in the list of
  330      * enabled extra checks (--enable)
  331      * @param group group to be enabled
  332      * @return true if the check is enabled.
  333      */
  334     bool isEnabled(EnabledGroup group) const {
  335         return (mEnabled & group) == group;
  336     }
  337 
  338     /**
  339     * @brief Returns true if given severity is enabled
  340     * @return true if the check is enabled.
  341     */
  342     bool isEnabled(Severity::SeverityType severity) const;
  343 
  344     /**
  345     * @brief Returns true if given value can be shown
  346     * @return true if the value can be shown
  347     */
  348     bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
  349 
  350     /** Is posix library specified? */
  351     bool posix() const {
  352         return std::find(libraries.begin(), libraries.end(), "posix") != libraries.end();
  353     }
  354 
  355     /** @brief Request termination of checking */
  356     static void terminate(bool t = true) {
  357         Settings::mTerminated = t;
  358     }
  359 
  360     /** @brief termination requested? */
  361     static bool terminated() {
  362         return Settings::mTerminated;
  363     }
  364 };
  365 
  366 /// @}
  367 //---------------------------------------------------------------------------
  368 #endif // settingsH