本文整理汇总了C++中errorlogger::errormessage::FileLocation类的典型用法代码示例。如果您正苦于以下问题:C++ FileLocation类的具体用法?C++ FileLocation怎么用?C++ FileLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileLocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: file
QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc)
: file(QString::fromStdString(loc.getfile(false)))
, line(loc.line)
, col(loc.col)
, info(QString::fromStdString(loc.getinfo()))
{
}
开发者ID:imasaaki,项目名称:cppcheck,代码行数:7,代码来源:erroritem.cpp
示例2: FileLocationSetFile
void FileLocationSetFile()
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
ASSERT_EQUALS("foo.cpp", loc.getfile());
ASSERT_EQUALS(0, loc.line);
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:7,代码来源:testerrorlogger.cpp
示例3: ToVerboseXml
void ToVerboseXml()
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:12,代码来源:testerrorlogger.cpp
示例4: ErrorMessageConstruct
void ErrorMessageConstruct()
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(true));
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:14,代码来源:testerrorlogger.cpp
示例5: msg
void CustomFormat2()
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("Programming error. - foo.cpp(5):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})"));
ASSERT_EQUALS("Verbose error - foo.cpp(5):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})"));
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:14,代码来源:testerrorlogger.cpp
示例6: unusedFunctionError
void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger, const std::string &filename, const std::string &funcname)
{
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
if (!filename.empty())
{
ErrorLogger::ErrorMessage::FileLocation fileLoc;
fileLoc.setfile(filename);
fileLoc.line = 1;
locationList.push_back(fileLoc);
}
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction", false);
if (errorLogger)
errorLogger->reportErr(errmsg);
else
reportError(errmsg);
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:17,代码来源:checkunusedfunctions.cpp
示例7: errmsg
Token *Token::linkAt(int index)
{
Token *tok = this->tokAt(index);
if (!tok) {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("");
loc.line = this->linenr();
locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error,
"Internal error. Token::linkAt called with index outside the tokens range.",
"cppcheckError",
false);
Check::reportError(errmsg);
}
return tok ? tok->link() : 0;
}
开发者ID:Rajkishor,项目名称:cppcheck,代码行数:18,代码来源:token.cpp
示例8: InconclusiveXml
void InconclusiveXml()
{
// Location
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
// Inconclusive error message
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
// Don't save inconclusive messages if the xml version is 1
ASSERT_EQUALS("", msg.toXML(false, 1));
// TODO: how should inconclusive messages be saved when the xml version is 2?
ASSERT_EQUALS("", msg.toXML(false, 2));
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:18,代码来源:testerrorlogger.cpp
示例9: CustomFormatLocations
void CustomFormatLocations()
{
// Check that first location from location stack is used in template
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
ErrorLogger::ErrorMessage::FileLocation loc2;
loc2.setfile("bar.cpp");
loc2.line = 8;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
locs.push_back(loc2);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(2, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("Programming error. - bar.cpp(8):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})"));
ASSERT_EQUALS("Verbose error - bar.cpp(8):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})"));
}
开发者ID:applsdev,项目名称:cppcheck,代码行数:19,代码来源:testerrorlogger.cpp
示例10: tooManyConfigsError
void CppCheck::tooManyConfigsError(const std::string &file, const std::size_t numberOfConfigurations)
{
if (!_settings.isEnabled(Settings::INFORMATION) && !tooManyConfigs)
return;
tooManyConfigs = false;
if (_settings.isEnabled(Settings::INFORMATION) && file.empty())
return;
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
if (!file.empty()) {
ErrorLogger::ErrorMessage::FileLocation location;
location.setfile(file);
loclist.push_back(location);
}
std::ostringstream msg;
msg << "Too many #ifdef configurations - cppcheck only checks " << _settings.maxConfigs;
if (numberOfConfigurations > _settings.maxConfigs)
msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n";
if (file.empty())
msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n";
msg << "The checking of the file will be interrupted because there are too many "
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
"by --force command line option or from GUI preferences. However that may "
"increase the checking time.";
if (file.empty())
msg << " For more details, use --enable=information.";
ErrorLogger::ErrorMessage errmsg(loclist,
emptyString,
Severity::information,
msg.str(),
"toomanyconfigs", CWE398,
false);
reportErr(errmsg);
}
开发者ID:Dmitry-Me,项目名称:cppcheck,代码行数:40,代码来源:cppcheck.cpp
示例11: purgedConfigurationMessage
void CppCheck::purgedConfigurationMessage(const std::string &file, const std::string& configuration)
{
tooManyConfigs = false;
if (_settings.isEnabled("information") && file.empty())
return;
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
if (!file.empty()) {
ErrorLogger::ErrorMessage::FileLocation location;
location.setfile(file);
loclist.push_back(location);
}
ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information,
"The configuration '" + configuration + "' was not checked because its code equals another one.",
"purgedConfiguration",
false);
reportErr(errmsg);
}
开发者ID:HeisSpiter,项目名称:cppcheck,代码行数:23,代码来源:cppcheck.cpp
示例12: executeRules
void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &tokenizer)
{
(void)tokenlist;
(void)tokenizer;
#ifdef HAVE_RULES
// Are there rules to execute?
bool isrule = false;
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
if (it->tokenlist == tokenlist)
isrule = true;
}
// There is no rule to execute
if (isrule == false)
return;
// Write all tokens in a string that can be parsed by pcre
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
const std::string str(ostr.str());
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
const Settings::Rule &rule = *it;
if (rule.pattern.empty() || rule.id.empty() || rule.severity == Severity::none || rule.tokenlist != tokenlist)
continue;
const char *error = nullptr;
int erroffset = 0;
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,nullptr);
if (!re) {
if (error) {
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
Severity::error,
error,
"pcre_compile",
false);
reportErr(errmsg);
}
continue;
}
int pos = 0;
int ovector[30]= {0};
while (pos < (int)str.size() && 0 <= pcre_exec(re, nullptr, str.c_str(), (int)str.size(), pos, 0, ovector, 30)) {
const unsigned int pos1 = (unsigned int)ovector[0];
const unsigned int pos2 = (unsigned int)ovector[1];
// jump to the end of the match for the next pcre_exec
pos = (int)pos2;
// determine location..
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(tokenizer.list.getSourceFilePath());
loc.line = 0;
std::size_t len = 0;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
len = len + 1U + tok->str().size();
if (len > pos1) {
loc.setfile(tokenizer.list.getFiles().at(tok->fileIndex()));
loc.line = tok->linenr();
break;
}
}
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack(1, loc);
// Create error message
std::string summary;
if (rule.summary.empty())
summary = "found '" + str.substr(pos1, pos2 - pos1) + "'";
else
summary = rule.summary;
const ErrorLogger::ErrorMessage errmsg(callStack, rule.severity, summary, rule.id, false);
// Report error
reportErr(errmsg);
}
pcre_free(re);
}
#endif
}
开发者ID:HeisSpiter,项目名称:cppcheck,代码行数:86,代码来源:cppcheck.cpp
示例13: processFile
unsigned int CppCheck::processFile(const std::string& filename)
{
exitcode = 0;
// only show debug warnings for accepted C/C++ source files
if (!Path::acceptFile(filename))
_settings.debugwarnings = false;
if (_settings.terminated())
return exitcode;
if (_settings._errorsOnly == false) {
std::string fixedpath = Path::simplifyPath(filename.c_str());
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + std::string("..."));
}
try {
Preprocessor preprocessor(&_settings, this);
std::list<std::string> configurations;
std::string filedata = "";
if (!_fileContent.empty()) {
// File content was given as a string
std::istringstream iss(_fileContent);
preprocessor.preprocess(iss, filedata, configurations, filename, _settings._includePaths);
} else {
// Only file name was given, read the content from file
std::ifstream fin(filename.c_str());
Timer t("Preprocessor::preprocess", _settings._showtime, &S_timerResults);
preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths);
}
if (_settings.checkConfiguration) {
return 0;
}
if (!_settings.userDefines.empty()) {
configurations.clear();
configurations.push_back(_settings.userDefines);
}
if (!_settings._force && configurations.size() > _settings._maxConfigs) {
const std::string fixedpath = Path::toNativeSeparators(filename);
ErrorLogger::ErrorMessage::FileLocation location;
location.setfile(fixedpath);
const std::list<ErrorLogger::ErrorMessage::FileLocation> loclist(1, location);
std::ostringstream msg;
msg << "Too many #ifdef configurations - cppcheck will only check " << _settings._maxConfigs << " of " << configurations.size() << ".\n"
"The checking of the file will be interrupted because there are too many "
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
"by --force command line option or from GUI preferences. However that may "
"increase the checking time.";
ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information,
msg.str(),
"toomanyconfigs",
false);
reportErr(errmsg);
}
unsigned int checkCount = 0;
for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it) {
// Check only a few configurations (default 12), after that bail out, unless --force
// was used.
if (!_settings._force && checkCount >= _settings._maxConfigs) {
const std::string fixedpath = Path::toNativeSeparators(filename);
ErrorLogger::ErrorMessage::FileLocation location;
location.setfile(fixedpath);
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
loclist.push_back(location);
ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information,
"Interrupted checking because of too many #ifdef configurations.",
"toomanyconfigs",
false);
reportInfo(errmsg);
break;
}
cfg = *it;
// If only errors are printed, print filename after the check
if (_settings._errorsOnly == false && it != configurations.begin()) {
std::string fixedpath = Path::simplifyPath(filename.c_str());
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + ": " + cfg + std::string("..."));
}
Timer t("Preprocessor::getcode", _settings._showtime, &S_timerResults);
const std::string codeWithoutCfg = preprocessor.getcode(filedata, *it, filename, _settings.userDefines.empty());
t.Stop();
const std::string &appendCode = _settings.append();
if (_settings.debugFalsePositive) {
if (findError(codeWithoutCfg + appendCode, filename.c_str())) {
//.........这里部分代码省略.........
开发者ID:steeveeet,项目名称:cppcheck,代码行数:101,代码来源:cppcheck.cpp
示例14: checkFile
void CppCheck::checkFile(const std::string &code, const char FileName[])
{
if (_settings.terminated() || _settings.checkConfiguration)
return;
Tokenizer _tokenizer(&_settings, this);
bool result;
// Tokenize the file
std::istringstream istr(code);
Timer timer("Tokenizer::tokenize", _settings._showtime, &S_timerResults);
result = _tokenizer.tokenize(istr, FileName, cfg);
timer.Stop();
if (!result)
{
// File had syntax errors, abort
return;
}
Timer timer2("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
_tokenizer.fillFunctionList();
timer2.Stop();
// call all "runChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
if (_settings.terminated())
return;
Timer timerRunChecks((*it)->name() + "::runChecks", _settings._showtime, &S_timerResults);
(*it)->runChecks(&_tokenizer, &_settings, this);
}
Timer timer3("Tokenizer::simplifyTokenList", _settings._showtime, &S_timerResults);
result = _tokenizer.simplifyTokenList();
timer3.Stop();
if (!result)
return;
Timer timer4("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
_tokenizer.fillFunctionList();
timer4.Stop();
if (_settings.isEnabled("unusedFunction") && _settings._jobs == 1)
_checkUnusedFunctions.parseTokens(_tokenizer);
// call all "runSimplifiedChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
if (_settings.terminated())
return;
Timer timerSimpleChecks((*it)->name() + "::runSimplifiedChecks", _settings._showtime, &S_timerResults);
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
}
#ifdef HAVE_RULES
// Are there extra rules?
if (!_settings.rules.empty())
{
std::ostringstream ostr;
for (const Token *tok = _tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
const std::string str(ostr.str());
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it)
{
const Settings::Rule &rule = *it;
if (rule.pattern.empty() || rule.id.empty() || rule.severity.empty())
continue;
const char *error = 0;
int erroffset = 0;
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,NULL);
if (!re && error)
{
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
Severity::error,
error,
"pcre_compile",
false);
reportErr(errmsg);
}
if (!re)
continue;
int pos = 0;
int ovector[30];
while (0 <= pcre_exec(re, NULL, str.c_str(), (int)str.size(), pos, 0, ovector, 30))
{
unsigned int pos1 = (unsigned int)ovector[0];
unsigned int pos2 = (unsigned int)ovector[1];
// jump to the end of the match for the next pcre_exec
pos = (int)pos2;
// determine location..
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(_tokenizer.getFiles()->front());
//.........这里部分代码省略.........
开发者ID:zblair,项目名称:cppcheck,代码行数:101,代码来源:cppcheck.cpp
示例15: processFile
unsigned int CppCheck::processFile()
{
exitcode = 0;
// TODO: Should this be moved out to its own function so all the files can be
// analysed before any files are checked?
if (_settings.test_2_pass && _settings._jobs == 1)
{
const std::string printname = Path::toNativeSeparators(_filename);
reportOut("Analysing " + printname + "...");
std::ifstream f(_filename.c_str());
analyseFile(f, _filename);
}
_errout.str("");
if (_settings.terminated())
return exitcode;
if (_settings._errorsOnly == false)
{
std::string fixedpath(_filename);
fixedpath = Path::simplifyPath(fixedpath.c_str());
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + std::string("..."));
}
try
{
Preprocessor preprocessor(&_settings, this);
std::list<std::string> configurations;
std::string filedata = "";
if (!_fileContent.empty())
{
// File content was given as a string
std::istringstream iss(_fileContent);
preprocessor.preprocess(iss, filedata, configurations, _filename, _settings._includePaths);
}
else
{
// Only file name was given, read the content from file
std::ifstream fin(_filename.c_str());
Timer t("Preprocessor::preprocess", _settings._showtime, &S_timerResults);
preprocessor.preprocess(fin, filedata, configurations, _filename, _settings._includePaths);
}
if (_settings.checkConfiguration)
{
return 0;
}
_settings.ifcfg = bool(configurations.size() > 1);
if (!_settings.userDefines.empty())
{
configurations.clear();
configurations.push_back(_settings.userDefines);
}
int checkCount = 0;
for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it)
{
// Check only 12 first configurations, after that bail out, unless --force
// was used.
if (!_settings._force && checkCount > 11)
{
const std::string fixedpath = Path::toNativeSeparators(_filename);
ErrorLogger::ErrorMessage::FileLocation location;
location.setfile(fixedpath);
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
loclist.push_back(location);
const std::string msg("Interrupted checking because of too many #ifdef configurations.\n"
"The checking of the file was interrupted because there were too many "
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
"by --force command line option or from GUI preferences. However that may "
"increase the checking time.");
ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information,
msg,
"toomanyconfigs",
false);
_errorLogger.reportErr(errmsg);
break;
}
cfg = *it;
Timer t("Preprocessor::getcode", _settings._showtime, &S_timerResults);
const std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, _filename, &_settings, &_errorLogger);
t.Stop();
// If only errors are printed, print filename after the check
if (_settings._errorsOnly == false && it != configurations.begin())
{
std::string fixedpath = Path::simplifyPath(_filename.c_str());
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + ": " + cfg + std::string("..."));
}
//.........这里部分代码省略.........
开发者ID:zblair,项目名称:cppcheck,代码行数:101,代码来源:cppcheck.cpp
示例16: processFile
unsigned int CppCheck::processFile()
{
exitcode = 0;
// only show debug warnings for C/C++ source files (don't fix
// debug warnings for java/c#/etc files)
if (!Path::acceptFile(_filename))
_settings.debugwarnings = false;
// TODO: Should this be moved out to its own function so all the files can be
// analysed before any files are checked?
if (_settings.test_2_pass && _settings._jobs == 1) {
const std::string printname = Path::toNativeSeparators(_filename);
reportOut("Analysing " + printname + "...");
std::ifstream f(_filename.c_str());
analyseFile(f, _filename);
}
_errout.str("");
if (_settings.terminated())
return exitcode;
if (_settings._errorsOnly == false) {
std::string fixedpath(_filename);
fixedpath = Path::simplifyPath(fixedpath.c_str());
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + std::string("..."));
}
try {
Preprocessor preprocessor(&_settings, this);
std::list<std::string> configurations;
std::string filedata = "";
if (!_fileContent.empty()) {
// File content was given as a string
std::istringstream iss(_fileContent);
preprocessor.preprocess(iss, filedata, configurations, _filename, _settings._includePaths);
} else {
// Only file name was given, read the content from file
std::ifstream fin(_filename.c_str());
Timer t("Preprocessor::preprocess", _settings._showtime, &S_timerResults);
preprocessor.preprocess(fin, filedata, configurations, _filename, _settings._includePaths);
}
if (_settings.checkConfiguration) {
return 0;
}
_settings.ifcfg = bool(configurations.size() > 1);
if (!_settings.userDefines.empty()) {
configurations.clear();
configurations.push_back(_settings.userDefines);
}
int checkCount = 0;
for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it) {
// Check only a few configurations (default 12), after that bail out, unless --force
// was used.
if (!_settings._force && checkCount >= _settings._maxConfigs) {
const std::string fixedpath = Path::toNativeSeparators(_filename);
ErrorLogger::ErrorMessage::FileLocation location;
location.setfile(fixedpath);
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
loclist.push_back(location);
const std::string msg("Interrupted checking because of too many #ifdef configurations.\n"
"The checking of the file was interrupted because there were too many "
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
"by --force command line option or from GUI preferences. However that may "
"increase the checking time.");
ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information,
msg,
"toomanyconfigs",
false);
if (!_settings.nomsg.isSuppressedLocal(errmsg._id, fixedpath, location.line)) {
reportErr(errmsg);
}
break;
}
cfg = *it;
Timer t("Preprocessor::getcode", _settings._showtime, &S_timerResults);
const std::string codeWithoutCfg = preprocessor.getcode(filedata, *it, _filename);
t.Stop();
// If only errors are printed, print filename after the check
if (_settings._errorsOnly == false && it != configurations.begin()) {
std::string fixedpath = Path::simplifyPath(_filename.c_str());
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + ": " + cfg + std::string("..."));
}
const std::string &appendCode = _settings.append();
//.........这里部分代码省略.........
开发者ID:Drahakar,项目名称:cppcheck,代码行数:101,代码来源:cppcheck.cpp
示例17: checkFile
void CppCheck::checkFile(const std::string &code, const char FileName[])
{
if (_settings.terminated() || _settings.checkConfiguration)
return;
Tokenizer _tokenizer(&_settings, this);
if (_settings._showtime != SHOWTIME_NONE)
_tokenizer.setTimerResults(&S_timerResults);
try {
bool result;
// Execute rules for "raw" code
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
if (it->tokenlist == "raw") {
Tokenizer tokenizer2(&_settings, this);
std::istringstream istr(code);
tokenizer2.list.createTokens(istr, FileName);
executeRules("raw", tokenizer2);
break;
}
}
// Tokenize the file
std::istringstream istr(code);
Timer timer("Tokenizer::tokenize", _settings._showtime, &S_timerResults);
result = _tokenizer.tokenize(istr, FileName, cfg);
timer.Stop();
if (!result) {
// File had syntax errors, abort
return;
}
// dump
if (_settings.dump) {
std::string dumpfile = std::string(FileName) + ".dump";
std::ofstream fdump(dumpfile.c_str());
if (fdump.is_open()) {
fdump << "<?xml version=\"1.0\"?>" << std::endl;
fdump << "<dump cfg=\"" << cfg << "\">" << std::endl;
_tokenizer.dump(fdump);
fdump << "</dump>" << std::endl;
}
return;
}
// call all "runChecks" in all registered Check classes
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
if (_settings.terminated())
return;
Timer timerRunChecks((*it)->name() + "::runChecks", _settings._showtime, &S_timerResults);
(*it)->runChecks(&_tokenizer, &_settings, this);
}
if (_settings.isEnabled("unusedFunction") && _settings._jobs == 1)
CheckUnusedFunctions::instance.parseTokens(_tokenizer, FileName, &_settings);
executeRules("normal", _tokenizer);
if (!_simplify)
return;
Timer timer3("Tokenizer::simplifyTokenList2", _settings._showtime, &S_timerResults);
result = _tokenizer.simplifyTokenList2();
timer3.Stop();
if (!result)
return;
// call all "runSimplifiedChecks" in all registered Check classes
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
if (_settings.terminated())
return;
Timer timerSimpleChecks((*it)->name() + "::runSimplifiedChecks", _settings._showtime, &S_timerResults);
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
}
if (_settings.terminated())
return;
executeRules("simple", _tokenizer);
if (_settings.terminated())
return;
} catch (const InternalError &e) {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
if (e.token) {
loc.line = e.token->linenr();
const std::string fixedpath = Path::toNativeSeparators(_tokenizer.list.file(e.token));
loc.setfile(fixedpath);
} else {
ErrorLogger::ErrorMessage::FileLocation loc2;
loc2.setfile(Path::toNativeSeparators(FileName));
locationList.push_back(loc2);
loc.setfile(_tokenizer.list.getSourceFilePath());
}
locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList,
//.........这里部分代码省略.........
开发者ID:akalenuk,项目名称:cppcheck,代码行数:101,代码来源:cppcheck.cpp
示例18: FileLocationDefaults
void FileLocationDefaults() const {
ErrorLogger::ErrorMessage::FileLocation loc;
ASSERT_EQUALS("", loc.getfile());
ASSERT_EQUALS(0, loc.line);
}
开发者ID:matthiaskrgr,项目名称:cppcheck,代码行数:5,代码来源:testerrorlogger.cpp
示例19: executeRules
void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &tokenizer)
{
(void)tokenlist;
(void)tokenizer;
#ifdef HAVE_RULES
// Are there rules to execute?
bool isrule = false;
for (std::list<Settings::Rule>::const_iterator it = mSettings.rules.begin(); it != mSettings.rules.end(); ++it) {
if (it->tokenlist == tokenlist)
isrule = true;
}
// There is no rule to execute
if (isrule == false)
return;
// Write all tokens in a string that can be parsed by pcre
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
const std::string str(ostr.str());
for (std::list<Settings::Rule>::const_iterator it = mSettings.rules.begin(); it != mSettings.rules.end(); ++it) {
const Settings::Rule &rule = *it;
if (rule.pattern.empty() || rule.id.empty() || rule.severity == Severity::none || rule.tokenlist != tokenlist)
continue;
const char *pcreCompileErrorStr = nullptr;
int erroffset = 0;
pcre * const re = pcre_compile(rule.pattern.c_str(),0,&pcreCompileErrorStr,&erroffset,nullptr);
if (!re) {
if (pcreCompileErrorStr) {
const std::string msg = "pcre_compile failed: " + std::string(pcreCompileErrorStr);
const ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
emptyString,
Severity::error,
msg,
"pcre_compile",
false);
reportErr(errmsg);
}
continue;
}
// Optimize the regex, but only if PCRE_CONFIG_JIT is available
#ifdef PCRE_CONFIG_JIT
const char *pcreStudyErrorStr = nullptr;
pcre_extra * const pcreExtra = pcre_study(re, PCRE_STUDY_JIT_COMPILE, &pcreStudyErrorStr);
// pcre_study() returns NULL for both errors and when it can not optimize the regex.
// The last argument is how one checks for errors.
// It is NULL if everything works, and points to an error string otherwise.
if (pcreStudyErrorStr) {
const std::string msg = "pcre_study failed: " + std::string(pcreStudyErrorStr);
const ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
emptyString,
Severity::error,
msg,
"pcre_study",
false);
reportErr(errmsg);
// pcre_compile() worked, but pcre_study() returned an error. Free the resources allocated by pcre_compile().
pcre_free(re);
continue;
}
#else
const pcre_extra * const pcreExtra = nullptr;
#endif
int pos = 0;
int ovector[30]= {0};
while (pos < (int)str.size()) {
const int pcreExecRet = pcre_exec(re, pcreExtra, str.c_str(), (int)
|
请发表评论