dump: output language to dumpfile

This commit is contained in:
Daniel Marjamäki 2022-11-20 12:29:56 +01:00
parent 9f50611a44
commit ad8c1e26f0
5 changed files with 30 additions and 14 deletions

View File

@ -527,9 +527,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}
if (str == "c")
mSettings->enforcedLang = Settings::C;
mSettings->enforcedLang = Settings::Language::C;
else if (str == "c++")
mSettings->enforcedLang = Settings::CPP;
mSettings->enforcedLang = Settings::Language::CPP;
else {
printError("unknown language '" + str + "' enforced.");
return false;

View File

@ -260,8 +260,24 @@ static void createDumpFile(const Settings& settings,
std::ofstream fout(getCtuInfoFileName(dumpFile));
}
std::string language;
switch (settings.enforcedLang) {
case Settings::Language::C:
language = " language=\"c\"";
break;
case Settings::Language::CPP:
language = " language=\"cpp\"";
break;
case Settings::Language::None:
if (Path::isCPP(filename))
language = " language=\"cpp\"";
else if (Path::isC(filename))
language = " language=\"c\"";
break;
}
fdump << "<?xml version=\"1.0\"?>" << std::endl;
fdump << "<dumps>" << std::endl;
fdump << "<dumps" << language << ">" << std::endl;
fdump << " <platform"
<< " name=\"" << settings.platformString() << '\"'
<< " char_bit=\"" << settings.char_bit << '\"'

View File

@ -49,7 +49,7 @@ Settings::Settings()
debugtemplate(false),
debugwarnings(false),
dump(false),
enforcedLang(None),
enforcedLang(Language::None),
exceptionHandling(false),
exitCode(0),
force(false),

View File

@ -121,8 +121,8 @@ void TokenList::determineCppC()
mIsC = Path::isC(getSourceFilePath());
mIsCpp = Path::isCPP(getSourceFilePath());
} else {
mIsC = mSettings->enforcedLang == Settings::C || (mSettings->enforcedLang == Settings::None && Path::isC(getSourceFilePath()));
mIsCpp = mSettings->enforcedLang == Settings::CPP || (mSettings->enforcedLang == Settings::None && Path::isCPP(getSourceFilePath()));
mIsC = mSettings->enforcedLang == Settings::Language::C || (mSettings->enforcedLang == Settings::Language::None && Path::isC(getSourceFilePath()));
mIsCpp = mSettings->enforcedLang == Settings::Language::CPP || (mSettings->enforcedLang == Settings::Language::None && Path::isCPP(getSourceFilePath()));
}
if (mIsCpp) {

View File

@ -418,17 +418,17 @@ private:
REDIRECT;
{
const char * const argv[] = {"cppcheck", "file.cpp"};
settings.enforcedLang = Settings::None;
settings.enforcedLang = Settings::Language::None;
ASSERT(defParser.parseFromArgs(2, argv));
ASSERT_EQUALS(Settings::None, settings.enforcedLang);
ASSERT_EQUALS(Settings::Language::None, settings.enforcedLang);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
CLEAR_REDIRECT_OUTPUT;
{
const char * const argv[] = {"cppcheck", "-x", "c++", "file.cpp"};
settings.enforcedLang = Settings::None;
settings.enforcedLang = Settings::Language::None;
ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
ASSERT_EQUALS(Settings::Language::CPP, settings.enforcedLang);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
CLEAR_REDIRECT_OUTPUT;
@ -446,17 +446,17 @@ private:
CLEAR_REDIRECT_OUTPUT;
{
const char * const argv[] = {"cppcheck", "--language=c++", "file.cpp"};
settings.enforcedLang = Settings::None;
settings.enforcedLang = Settings::Language::None;
ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
ASSERT_EQUALS(Settings::Language::CPP, settings.enforcedLang);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
CLEAR_REDIRECT_OUTPUT;
{
const char * const argv[] = {"cppcheck", "--language=c", "file.cpp"};
settings.enforcedLang = Settings::None;
settings.enforcedLang = Settings::Language::None;
ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(Settings::C, settings.enforcedLang);
ASSERT_EQUALS(Settings::Language::C, settings.enforcedLang);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
CLEAR_REDIRECT_OUTPUT;