Blame lib/settings.h

Packit 2035a7
/*
Packit 2035a7
 * Cppcheck - A tool for static C/C++ code analysis
Packit 2035a7
 * Copyright (C) 2007-2017 Cppcheck team.
Packit 2035a7
 *
Packit 2035a7
 * This program is free software: you can redistribute it and/or modify
Packit 2035a7
 * it under the terms of the GNU General Public License as published by
Packit 2035a7
 * the Free Software Foundation, either version 3 of the License, or
Packit 2035a7
 * (at your option) any later version.
Packit 2035a7
 *
Packit 2035a7
 * This program is distributed in the hope that it will be useful,
Packit 2035a7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 2035a7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 2035a7
 * GNU General Public License for more details.
Packit 2035a7
 *
Packit 2035a7
 * You should have received a copy of the GNU General Public License
Packit 2035a7
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 2035a7
 */
Packit 2035a7
Packit 2035a7
//---------------------------------------------------------------------------
Packit 2035a7
#ifndef settingsH
Packit 2035a7
#define settingsH
Packit 2035a7
//---------------------------------------------------------------------------
Packit 2035a7
Packit 2035a7
#include "config.h"
Packit 2035a7
#include "errorlogger.h"
Packit 2035a7
#include "importproject.h"
Packit 2035a7
#include "library.h"
Packit 2035a7
#include "platform.h"
Packit 2035a7
#include "standards.h"
Packit 2035a7
#include "suppressions.h"
Packit 2035a7
#include "timer.h"
Packit 2035a7
Packit 2035a7
#include <list>
Packit 2035a7
#include <set>
Packit 2035a7
#include <string>
Packit 2035a7
#include <vector>
Packit 2035a7
Packit 2035a7
namespace ValueFlow {
Packit 2035a7
    class Value;
Packit 2035a7
}
Packit 2035a7
Packit 2035a7
/// @addtogroup Core
Packit 2035a7
/// @{
Packit 2035a7
Packit 2035a7
/**
Packit 2035a7
 * @brief This is just a container for general settings so that we don't need
Packit 2035a7
 * to pass individual values to functions or constructors now or in the
Packit 2035a7
 * future when we might have even more detailed settings.
Packit 2035a7
 */
Packit 2035a7
class CPPCHECKLIB Settings : public cppcheck::Platform {
Packit 2035a7
public:
Packit 2035a7
    enum EnabledGroup {
Packit 2035a7
        WARNING = 0x1,
Packit 2035a7
        STYLE = 0x2,
Packit 2035a7
        PERFORMANCE = 0x4,
Packit 2035a7
        PORTABILITY = 0x8,
Packit 2035a7
        INFORMATION = 0x10,
Packit 2035a7
        UNUSED_FUNCTION = 0x20,
Packit 2035a7
        MISSING_INCLUDE = 0x40,
Packit 2035a7
        INTERNAL = 0x80
Packit 2035a7
    };
Packit 2035a7
Packit 2035a7
private:
Packit 2035a7
    /** @brief enable extra checks by id */
Packit 2035a7
    int _enabled;
Packit 2035a7
Packit 2035a7
    /** @brief terminate checking */
Packit 2035a7
    static bool _terminated;
Packit 2035a7
Packit 2035a7
public:
Packit 2035a7
    Settings();
Packit 2035a7
Packit 2035a7
    /** @brief --cppcheck-build-dir */
Packit 2035a7
    std::string buildDir;
Packit 2035a7
Packit 2035a7
    /** @brief Is --debug given? */
Packit 2035a7
    bool debug;
Packit 2035a7
Packit 2035a7
    /** @brief Is --debug-normal given? */
Packit 2035a7
    bool debugnormal;
Packit 2035a7
Packit 2035a7
    /** @brief Is --debug-warnings given? */
Packit 2035a7
    bool debugwarnings;
Packit 2035a7
Packit 2035a7
    /** @brief Is --dump given? */
Packit 2035a7
    bool dump;
Packit 2035a7
    std::string dumpFile;
Packit 2035a7
Packit 2035a7
    /** @brief Is --exception-handling given */
Packit 2035a7
    bool exceptionHandling;
Packit 2035a7
Packit 2035a7
    /** @brief Inconclusive checks */
Packit 2035a7
    bool inconclusive;
Packit 2035a7
Packit 2035a7
    /** @brief Collect unmatched suppressions in one run.
Packit 2035a7
      * This delays the reporting until all files are checked.
Packit 2035a7
      * It is needed by checks that analyse the whole code base. */
Packit 2035a7
    bool jointSuppressionReport;
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * When this flag is false (default) then experimental
Packit 2035a7
     * heuristics and checks are disabled.
Packit 2035a7
     *
Packit 2035a7
     * It should not be possible to enable this from any client.
Packit 2035a7
     */
Packit 2035a7
    bool experimental;
Packit 2035a7
Packit 2035a7
    /** @brief Is --quiet given? */
Packit 2035a7
    bool quiet;
Packit 2035a7
Packit 2035a7
    /** @brief Is --inline-suppr given? */
Packit 2035a7
    bool inlineSuppressions;
Packit 2035a7
Packit 2035a7
    /** @brief Is --verbose given? */
Packit 2035a7
    bool verbose;
Packit 2035a7
Packit 2035a7
    /** @brief Request termination of checking */
Packit 2035a7
    static void terminate(bool t = true) {
Packit 2035a7
        Settings::_terminated = t;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /** @brief termination requested? */
Packit 2035a7
    static bool terminated() {
Packit 2035a7
        return Settings::_terminated;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /** @brief Force checking the files with "too many" configurations (--force). */
Packit 2035a7
    bool force;
Packit 2035a7
Packit 2035a7
    /** @brief Use relative paths in output. */
Packit 2035a7
    bool relativePaths;
Packit 2035a7
Packit 2035a7
    /** @brief Paths used as base for conversion to relative paths. */
Packit 2035a7
    std::vector<std::string> basePaths;
Packit 2035a7
Packit 2035a7
    /** @brief write results (--output-file=<file>) */
Packit 2035a7
    std::string outputFile;
Packit 2035a7
Packit 2035a7
    /** @brief plist output (--plist-output=<dir>) */
Packit 2035a7
    std::string plistOutput;
Packit 2035a7
Packit 2035a7
    /** @brief write XML results (--xml) */
Packit 2035a7
    bool xml;
Packit 2035a7
Packit 2035a7
    /** @brief XML version (--xml-version=..) */
Packit 2035a7
    int xml_version;
Packit 2035a7
Packit 2035a7
    /** @brief How many processes/threads should do checking at the same
Packit 2035a7
        time. Default is 1. (-j N) */
Packit 2035a7
    unsigned int jobs;
Packit 2035a7
Packit 2035a7
    /** @brief Load average value */
Packit 2035a7
    unsigned int loadAverage;
Packit 2035a7
Packit 2035a7
    /** @brief If errors are found, this value is returned from main().
Packit 2035a7
        Default value is 0. */
Packit 2035a7
    int exitCode;
Packit 2035a7
Packit 2035a7
    /** @brief The output format in which the errors are printed in text mode,
Packit 2035a7
        e.g. "{severity} {file}:{line} {message} {id}" */
Packit 2035a7
    std::string outputFormat;
Packit 2035a7
Packit 2035a7
    /** @brief show timing information (--showtime=file|summary|top5) */
Packit 2035a7
    SHOWTIME_MODES showtime;
Packit 2035a7
Packit 2035a7
    /** @brief Using -E for debugging purposes */
Packit 2035a7
    bool preprocessOnly;
Packit 2035a7
Packit 2035a7
    /** @brief List of include paths, e.g. "my/includes/" which should be used
Packit 2035a7
        for finding include files inside source files. (-I) */
Packit 2035a7
    std::list<std::string> includePaths;
Packit 2035a7
Packit 2035a7
    /** @brief Maximum number of configurations to check before bailing.
Packit 2035a7
        Default is 12. (--max-configs=N) */
Packit 2035a7
    unsigned int maxConfigs;
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * @brief Returns true if given id is in the list of
Packit 2035a7
     * enabled extra checks (--enable)
Packit 2035a7
     * @param group group to be enabled
Packit 2035a7
     * @return true if the check is enabled.
Packit 2035a7
     */
Packit 2035a7
    bool isEnabled(EnabledGroup group) const {
Packit 2035a7
        return (_enabled & group) == group;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
    * @brief Returns true if given severity is enabled
Packit 2035a7
    * @return true if the check is enabled.
Packit 2035a7
    */
Packit 2035a7
    bool isEnabled(Severity::SeverityType severity) const;
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
    * @brief Returns true if given value can be shown
Packit 2035a7
    * @return true if the value can be shown
Packit 2035a7
    */
Packit 2035a7
    bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * @brief Enable extra checks by id. See isEnabled()
Packit 2035a7
     * @param str single id or list of id values to be enabled
Packit 2035a7
     * or empty string to enable all. e.g. "style,possibleError"
Packit 2035a7
     * @return error message. empty upon success
Packit 2035a7
     */
Packit 2035a7
    std::string addEnabled(const std::string &str);
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * @brief Disables all severities, except from error.
Packit 2035a7
     */
Packit 2035a7
    void clearEnabled() {
Packit 2035a7
        _enabled = 0;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    enum Language {
Packit 2035a7
        None, C, CPP
Packit 2035a7
    };
Packit 2035a7
Packit 2035a7
    /** @brief Name of the language that is enforced. Empty per default. */
Packit 2035a7
    Language enforcedLang;
Packit 2035a7
Packit 2035a7
    /** @brief suppress message (--suppressions) */
Packit 2035a7
    Suppressions nomsg;
Packit 2035a7
Packit 2035a7
    /** @brief suppress exitcode */
Packit 2035a7
    Suppressions nofail;
Packit 2035a7
Packit 2035a7
    /** @brief defines given by the user */
Packit 2035a7
    std::string userDefines;
Packit 2035a7
Packit 2035a7
    /** @brief undefines given by the user */
Packit 2035a7
    std::set<std::string> userUndefs;
Packit 2035a7
Packit 2035a7
    /** @brief forced includes given by the user */
Packit 2035a7
    std::list<std::string> userIncludes;
Packit 2035a7
Packit 2035a7
    /** @brief include paths excluded from checking the configuration */
Packit 2035a7
    std::set<std::string> configExcludePaths;
Packit 2035a7
Packit 2035a7
Packit 2035a7
    /** @brief --report-progress */
Packit 2035a7
    bool reportProgress;
Packit 2035a7
Packit 2035a7
    /** Library (--library) */
Packit 2035a7
    Library library;
Packit 2035a7
Packit 2035a7
    /** Rule */
Packit 2035a7
    class CPPCHECKLIB Rule {
Packit 2035a7
    public:
Packit 2035a7
        Rule()
Packit 2035a7
            : tokenlist("simple")         // use simple tokenlist
Packit 2035a7
            , id("rule")                  // default id
Packit 2035a7
            , severity(Severity::style) { // default severity
Packit 2035a7
        }
Packit 2035a7
Packit 2035a7
        std::string tokenlist;
Packit 2035a7
        std::string pattern;
Packit 2035a7
        std::string id;
Packit 2035a7
        std::string summary;
Packit 2035a7
        Severity::SeverityType severity;
Packit 2035a7
    };
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * @brief Extra rules
Packit 2035a7
     */
Packit 2035a7
    std::list<Rule> rules;
Packit 2035a7
Packit 2035a7
    /** Is the 'configuration checking' wanted? */
Packit 2035a7
    bool checkConfiguration;
Packit 2035a7
Packit 2035a7
    /** Check for incomplete info in library files? */
Packit 2035a7
    bool checkLibrary;
Packit 2035a7
Packit 2035a7
    /** Struct contains standards settings */
Packit 2035a7
    Standards standards;
Packit 2035a7
Packit 2035a7
    ImportProject project;
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * @brief return true if a included file is to be excluded in Preprocessor::getConfigs
Packit 2035a7
     * @return true for the file to be excluded.
Packit 2035a7
     */
Packit 2035a7
    bool configurationExcluded(const std::string &file) const {
Packit 2035a7
        for (std::set<std::string>::const_iterator i=configExcludePaths.begin(); i!=configExcludePaths.end(); ++i) {
Packit 2035a7
            if (file.length()>=i->length() && file.compare(0,i->length(),*i)==0) {
Packit 2035a7
                return true;
Packit 2035a7
            }
Packit 2035a7
        }
Packit 2035a7
        return false;
Packit 2035a7
    }
Packit 2035a7
};
Packit 2035a7
Packit 2035a7
/// @}
Packit 2035a7
//---------------------------------------------------------------------------
Packit 2035a7
#endif // settingsH