cmdlineparser: Added -E option
This commit is contained in:
parent
ee5a5e8bb5
commit
599327bfb1
|
@ -384,6 +384,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
_settings->userUndefs.insert(undef);
|
||||
}
|
||||
|
||||
// -E
|
||||
else if (std::strcmp(argv[i], "-E") == 0) {
|
||||
_settings->preprocessOnly = true;
|
||||
}
|
||||
|
||||
// Include paths
|
||||
else if (std::strncmp(argv[i], "-I", 2) == 0) {
|
||||
std::string path;
|
||||
|
@ -729,12 +734,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (def && !_settings->_force && !maxconfigs)
|
||||
_settings->_maxConfigs = 1U;
|
||||
|
||||
if (_settings->_force)
|
||||
_settings->_maxConfigs = ~0U;
|
||||
|
||||
else if ((def || _settings->preprocessOnly) && !maxconfigs)
|
||||
_settings->_maxConfigs = 1U;
|
||||
|
||||
if (_settings->isEnabled("unusedFunction") && _settings->_jobs > 1) {
|
||||
PrintMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
|
||||
}
|
||||
|
@ -799,6 +804,8 @@ void CmdLineParser::PrintHelp()
|
|||
" -U<ID> Undefine preprocessor symbol. Use -U to explicitly\n"
|
||||
" hide certain #ifdef <ID> code paths from checking.\n"
|
||||
" Example: '-UDEBUG'\n"
|
||||
" -E Print preprocessor output on stdout and don't do any\n"
|
||||
" further processing.\n"
|
||||
" --enable=<id> Enable additional checks. The available ids are:\n"
|
||||
" * all\n"
|
||||
" Enable all checks. It is recommended to only\n"
|
||||
|
|
|
@ -187,6 +187,22 @@ unsigned int CppCheck::processFile(const std::string& filename, std::istream& fi
|
|||
|
||||
codeWithoutCfg += _settings.append();
|
||||
|
||||
if (_settings.preprocessOnly) {
|
||||
if (codeWithoutCfg.compare(0,5,"#file") == 0)
|
||||
codeWithoutCfg.insert(0U, "//");
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = codeWithoutCfg.find("\n#file",pos)) != std::string::npos)
|
||||
codeWithoutCfg.insert(pos+1U, "//");
|
||||
pos = 0;
|
||||
while ((pos = codeWithoutCfg.find("\n#endfile",pos)) != std::string::npos)
|
||||
codeWithoutCfg.insert(pos+1U, "//");
|
||||
pos = 0;
|
||||
while ((pos = codeWithoutCfg.find(Preprocessor::macroChar,pos)) != std::string::npos)
|
||||
codeWithoutCfg[pos] = ' ';
|
||||
reportOut(codeWithoutCfg);
|
||||
continue;
|
||||
}
|
||||
|
||||
Tokenizer _tokenizer(&_settings, this);
|
||||
if (_settings._showtime != SHOWTIME_NONE)
|
||||
_tokenizer.setTimerResults(&S_timerResults);
|
||||
|
|
|
@ -43,6 +43,7 @@ Settings::Settings()
|
|||
_loadAverage(0),
|
||||
_exitCode(0),
|
||||
_showtime(SHOWTIME_NONE),
|
||||
preprocessOnly(false),
|
||||
_maxConfigs(12),
|
||||
enforcedLang(None),
|
||||
reportProgress(false),
|
||||
|
|
|
@ -138,6 +138,9 @@ public:
|
|||
/** @brief show timing information (--showtime=file|summary|top5) */
|
||||
SHOWTIME_MODES _showtime;
|
||||
|
||||
/** @brief Using -E for debugging purposes */
|
||||
bool preprocessOnly;
|
||||
|
||||
/** @brief List of include paths, e.g. "my/includes/" which should be used
|
||||
for finding include files inside source files. (-I) */
|
||||
std::list<std::string> _includePaths;
|
||||
|
|
Loading…
Reference in New Issue