cppcheck/lib/importproject.h

193 lines
7.1 KiB
C
Raw Normal View History

/*
* Cppcheck - A tool for static C/C++ code analysis
2021-03-21 20:58:32 +01:00
* Copyright (C) 2007-2021 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
#ifndef importprojectH
#define importprojectH
//---------------------------------------------------------------------------
2016-12-06 20:02:43 +01:00
#include "config.h"
#include "platform.h"
#include "utils.h"
2017-05-27 04:33:47 +02:00
#include <iosfwd>
#include <list>
#include <map>
#include <set>
2017-05-27 04:33:47 +02:00
#include <string>
#include <vector>
/// @addtogroup Core
/// @{
namespace cppcheck {
2017-09-24 22:57:24 +02:00
struct stricmp {
bool operator()(const std::string &lhs, const std::string &rhs) const {
return caseInsensitiveStringCompare(lhs,rhs) < 0;
}
2017-09-24 22:57:24 +02:00
};
}
class Settings;
/**
* @brief Importing project settings.
*/
class CPPCHECKLIB ImportProject {
public:
enum class Type {
UNKNOWN,
MISSING,
FAILURE,
COMPILE_DB,
VS_SLN,
VS_VCXPROJ,
BORLAND,
CPPCHECK_GUI
};
/** File settings. Multiple configurations for a file is allowed. */
struct CPPCHECKLIB FileSettings {
FileSettings() : platformType(cppcheck::Platform::Unspecified), msc(false), useMfc(false) {}
std::string cfg;
std::string filename;
std::string defines;
std::string cppcheckDefines() const {
return defines + (msc ? ";_MSC_VER=1900" : "") + (useMfc ? ";__AFXWIN_H__=1" : "");
}
std::set<std::string> undefs;
std::list<std::string> includePaths;
2017-08-03 20:38:24 +02:00
std::list<std::string> systemIncludePaths;
std::string standard;
cppcheck::Platform::PlatformType platformType;
bool msc;
bool useMfc;
void parseCommand(std::string command);
void setDefines(std::string defs);
void setIncludePaths(const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string, cppcheck::stricmp> &variables);
};
std::list<FileSettings> fileSettings;
Type projectType;
ImportProject();
void selectOneVsConfig(cppcheck::Platform::PlatformType platform);
std::list<std::string> getVSConfigs();
// Cppcheck GUI output
struct {
std::string analyzeAllVsConfigs;
std::vector<std::string> pathNames;
std::list<std::string> libraries;
std::list<std::string> excludedPaths;
std::list<std::string> checkVsConfigs;
std::string projectFile;
std::string platform;
} guiProject;
2016-12-06 20:02:43 +01:00
void ignorePaths(const std::vector<std::string> &ipaths);
void ignoreOtherConfigs(const std::string &cfg);
2019-01-31 23:52:48 +01:00
Type import(const std::string &filename, Settings *settings=nullptr);
protected:
bool importCompileCommands(std::istream &istr);
bool importCppcheckGuiProject(std::istream &istr, Settings *settings);
virtual bool sourceFileExists(const std::string &file);
private:
bool importSln(std::istream &istr, const std::string &path, const std::vector<std::string> &fileFilters);
bool importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::vector<std::string> &fileFilters);
bool importBcb6Prj(const std::string &projectFilename);
void printError(const std::string &message);
2019-04-11 18:46:57 +02:00
void setRelativePaths(const std::string &filename);
2019-04-11 18:46:57 +02:00
std::string mPath;
std::set<std::string> mAllVSConfigs;
};
namespace CppcheckXml {
2019-08-12 12:54:25 +02:00
const char ProjectElementName[] = "project";
const char ProjectVersionAttrib[] = "version";
const char ProjectFileVersion[] = "1";
const char BuildDirElementName[] = "builddir";
const char ImportProjectElementName[] = "importproject";
const char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
const char Parser[] = "parser";
const char BugHunting[] = "bug-hunting";
2019-08-12 12:54:25 +02:00
const char IncludeDirElementName[] = "includedir";
const char DirElementName[] = "dir";
const char DirNameAttrib[] = "name";
const char DefinesElementName[] = "defines";
const char DefineName[] = "define";
const char DefineNameAttrib[] = "name";
const char UndefinesElementName[] = "undefines";
const char UndefineName[] = "undefine";
const char PathsElementName[] = "paths";
const char PathName[] = "dir";
const char PathNameAttrib[] = "name";
const char RootPathName[] = "root";
const char RootPathNameAttrib[] = "name";
const char IgnoreElementName[] = "ignore";
const char IgnorePathName[] = "path";
const char IgnorePathNameAttrib[] = "name";
const char ExcludeElementName[] = "exclude";
const char ExcludePathName[] = "path";
const char ExcludePathNameAttrib[] = "name";
const char FunctionContracts[] = "function-contracts";
const char FunctionContract[] = "contract";
const char ContractFunction[] = "function";
const char ContractExpects[] = "expects";
2020-08-22 11:37:44 +02:00
const char VariableContractsElementName[] = "variable-contracts";
const char VariableContractItemElementName[] = "var";
const char VariableContractVarName[] = "name";
const char VariableContractMin[] = "min";
const char VariableContractMax[] = "max";
2019-08-12 12:54:25 +02:00
const char LibrariesElementName[] = "libraries";
const char LibraryElementName[] = "library";
const char PlatformElementName[] = "platform";
const char SuppressionsElementName[] = "suppressions";
const char SuppressionElementName[] = "suppression";
const char AddonElementName[] = "addon";
const char AddonsElementName[] = "addons";
const char ToolElementName[] = "tool";
const char ToolsElementName[] = "tools";
const char TagsElementName[] = "tags";
const char TagElementName[] = "tag";
const char TagWarningsElementName[] = "tag-warnings";
const char TagAttributeName[] = "tag";
const char WarningElementName[] = "warning";
2020-07-21 11:27:03 +02:00
const char HashAttributeName[] = "hash";
2019-08-12 12:54:25 +02:00
const char CheckHeadersElementName[] = "check-headers";
const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
const char MaxCtuDepthElementName[] = "max-ctu-depth";
const char MaxTemplateRecursionElementName[] = "max-template-recursion";
2019-08-12 12:54:25 +02:00
const char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values";
2020-01-30 07:14:17 +01:00
const char ClangTidy[] = "clang-tidy";
2019-08-12 12:54:25 +02:00
const char Name[] = "name";
const char VSConfigurationElementName[] = "vs-configurations";
const char VSConfigurationName[] = "config";
}
/// @}
//---------------------------------------------------------------------------
#endif // importprojectH