Merge pull request #71 from neuschaefer/tokenizer
Refactoring: Do language detection in one place, instead of spreading it around the code. (There are still locations that need to be fixed to use the new functions.)
This commit is contained in:
commit
8cb53107dd
|
@ -196,10 +196,8 @@ public:
|
|||
/** @brief run all simplified checks */
|
||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) {
|
||||
// Don't use these check for Java and C# programs..
|
||||
if (tokenizr->getFiles()->at(0).find(".java") != std::string::npos ||
|
||||
tokenizr->getFiles()->at(0).find(".cs") != std::string::npos) {
|
||||
if (tokenizr->isJavaOrCSharp())
|
||||
return;
|
||||
}
|
||||
|
||||
CheckMemoryLeakInFunction checkMemoryLeak(tokenizr, settings, errLog);
|
||||
checkMemoryLeak.checkReallocUsage();
|
||||
|
@ -367,10 +365,8 @@ public:
|
|||
|
||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) {
|
||||
// Don't use these check for Java and C# programs..
|
||||
if (tokenizr->getFiles()->at(0).find(".java") != std::string::npos ||
|
||||
tokenizr->getFiles()->at(0).find(".cs") != std::string::npos) {
|
||||
if (tokenizr->isJavaOrCSharp())
|
||||
return;
|
||||
}
|
||||
|
||||
CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog);
|
||||
checkMemoryLeak.check();
|
||||
|
|
|
@ -1982,6 +1982,8 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
}
|
||||
|
||||
// Convert C# code
|
||||
// FIXME: This should be if(isCSharp()), but that makes the lines 5931 and
|
||||
// 5932 of test/testtokenize.cpp fail.
|
||||
if (_files[0].find(".cs")) {
|
||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%type% [ ] %var% [=;]") &&
|
||||
|
@ -2005,9 +2007,10 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
|
||||
// Simplify JAVA/C# code
|
||||
if (isJavaOrCSharp()) {
|
||||
const bool isJava(_files[0].find(".java") != std::string::npos);
|
||||
// better don't call isJava in the loop
|
||||
bool isJava_ = isJava();
|
||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||
if (isJava && Token::Match(tok, ") throws %var% {")) {
|
||||
if (isJava_ && Token::Match(tok, ") throws %var% {")) {
|
||||
tok->deleteNext(2);
|
||||
} else if (tok->str() == "private")
|
||||
tok->str("private:");
|
||||
|
|
|
@ -47,25 +47,35 @@ public:
|
|||
Tokenizer(const Settings * settings, ErrorLogger *errorLogger);
|
||||
virtual ~Tokenizer();
|
||||
|
||||
/** Is the code JAVA/C#. Used for bailouts */
|
||||
bool isJavaOrCSharp() const {
|
||||
if (_files.size() != 1)
|
||||
return false;
|
||||
/** The file extension. Used by isC() etc. */
|
||||
std::string fileExtension() const {
|
||||
if (_files.empty())
|
||||
return std::string("");
|
||||
const std::string::size_type pos = _files[0].rfind('.');
|
||||
if (pos != std::string::npos)
|
||||
return (_files[0].substr(pos) == ".java" ||
|
||||
_files[0].substr(pos) == ".cs");
|
||||
return false;
|
||||
return _files[0].substr(pos);
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
/** Is the code JAVA. Used for bailouts */
|
||||
bool isJava() const {
|
||||
return fileExtension() == ".java";
|
||||
}
|
||||
|
||||
/** Is the code C#. Used for bailouts */
|
||||
bool isCSharp() const {
|
||||
return fileExtension() == ".cs";
|
||||
}
|
||||
|
||||
/** Is the code JAVA/C#. Used for bailouts */
|
||||
bool isJavaOrCSharp() const {
|
||||
return isJava() || isCSharp();
|
||||
}
|
||||
|
||||
/** Is the code C. Used for bailouts */
|
||||
bool isC() const {
|
||||
if (_files.empty())
|
||||
return false;
|
||||
const std::string::size_type pos = _files[0].rfind('.');
|
||||
if (pos != std::string::npos)
|
||||
return (_files[0].substr(pos) == ".c") || (_files[0].substr(pos) == ".C");
|
||||
return false;
|
||||
std::string ext = fileExtension();
|
||||
return (ext == ".c" || ext == ".C");
|
||||
}
|
||||
|
||||
/** Is the code CPP. Used for bailouts */
|
||||
|
|
Loading…
Reference in New Issue