Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ static std::string executeAddon(const AddonInfo &addonInfo,
return result;
}

static std::string getDefinesFlags(const std::string &semicolonSeparatedString)
{
std::string flags;
for (const std::string &d: split(semicolonSeparatedString, ";"))
flags += "-D" + d + " ";
return flags;
}

CppCheck::CppCheck(ErrorLogger &errorLogger,
bool useGlobalSuppressions,
std::function<bool(std::string,std::vector<std::string>,std::string,std::string*)> executeCommand)
Expand Down Expand Up @@ -350,6 +358,9 @@ unsigned int CppCheck::check(const std::string &path)
for (const std::string &i: mSettings.includePaths)
flags += "-I" + i + " ";

flags += getDefinesFlags(mSettings.userDefines);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm .. an alternative could be to reuse split.

for (const std::string &d: split(mSettings.userDefines, ";"))
    flags += "-D" + d + " ";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please reuse split.. if you do it here like my code or rewrite your getDefinesFlags that is up to you :-)



const std::string args2 = "-cc1 -ast-dump " + flags + path;
const std::string redirect2 = analyzerInfo.empty() ? std::string("2>&1") : ("2> " + clangStderr);
if (!mSettings.buildDir.empty()) {
Expand Down Expand Up @@ -1407,16 +1418,11 @@ void CppCheck::getErrorMessages()
void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
{
std::string allIncludes = "";
std::string allDefines = "-D"+fileSettings.defines;
for (const std::string &inc : fileSettings.includePaths) {
allIncludes = allIncludes + "-I\"" + inc + "\" ";
}

std::string::size_type pos = 0u;
while ((pos = allDefines.find(";", pos)) != std::string::npos) {
allDefines.replace(pos, 1, " -D");
pos += 3;
}
const std::string allDefines = getDefinesFlags(fileSettings.defines);

#ifdef _WIN32
const char exe[] = "clang-tidy.exe";
Expand Down