Various code cleanups
This commit is contained in:
parent
e2dd085b60
commit
167a7e3e51
|
@ -159,7 +159,7 @@ void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, std::map
|
||||||
|
|
||||||
oss << cleanedPath;
|
oss << cleanedPath;
|
||||||
|
|
||||||
if (MyIsDirectory(cleanedPath.c_str())) {
|
if (MyIsDirectory(cleanedPath)) {
|
||||||
char c = cleanedPath[ cleanedPath.size()-1 ];
|
char c = cleanedPath[ cleanedPath.size()-1 ];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\\':
|
case '\\':
|
||||||
|
@ -175,8 +175,7 @@ void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, std::map
|
||||||
bdir << cleanedPath << '\\';
|
bdir << cleanedPath << '\\';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::string::size_type pos;
|
std::string::size_type pos = cleanedPath.find_last_of('\\');
|
||||||
pos = cleanedPath.find_last_of('\\');
|
|
||||||
if (std::string::npos != pos) {
|
if (std::string::npos != pos) {
|
||||||
bdir << cleanedPath.substr(0, pos + 1);
|
bdir << cleanedPath.substr(0, pos + 1);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +201,7 @@ void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, std::map
|
||||||
#endif // defined(UNICODE)
|
#endif // defined(UNICODE)
|
||||||
|
|
||||||
std::ostringstream fname;
|
std::ostringstream fname;
|
||||||
fname << bdir.str().c_str() << ansiFfd;
|
fname << bdir.str() << ansiFfd;
|
||||||
|
|
||||||
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||||
// File
|
// File
|
||||||
|
@ -236,10 +235,7 @@ bool FileLister::isDirectory(const std::string &path)
|
||||||
|
|
||||||
bool FileLister::fileExists(const std::string &path)
|
bool FileLister::fileExists(const std::string &path)
|
||||||
{
|
{
|
||||||
if (MyFileExists(path) == TRUE)
|
return (MyFileExists(path) == TRUE);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,8 @@ namespace {
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
|
static void makeArrayIndexOutOfBoundsError(std::ostream& oss, const CheckBufferOverrun::ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
|
||||||
oss << "Array '" << arrayInfo.varname();
|
oss << "Array '" << arrayInfo.varname();
|
||||||
for (unsigned int i = 0; i < arrayInfo.num().size(); ++i)
|
for (unsigned int i = 0; i < arrayInfo.num().size(); ++i)
|
||||||
oss << "[" << arrayInfo.num(i) << "]";
|
oss << "[" << arrayInfo.num(i) << "]";
|
||||||
|
@ -61,24 +60,18 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
|
||||||
oss << "[" << index[i] << "]";
|
oss << "[" << index[i] << "]";
|
||||||
}
|
}
|
||||||
oss << " out of bounds";
|
oss << " out of bounds";
|
||||||
|
}
|
||||||
|
void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
makeArrayIndexOutOfBoundsError(oss, arrayInfo, index);
|
||||||
reportError(tok, Severity::error, "arrayIndexOutOfBounds", oss.str());
|
reportError(tok, Severity::error, "arrayIndexOutOfBounds", oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::arrayIndexOutOfBoundsError(const std::list<const Token *> &callstack, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
|
void CheckBufferOverrun::arrayIndexOutOfBoundsError(const std::list<const Token *> &callstack, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Array '" << arrayInfo.varname();
|
makeArrayIndexOutOfBoundsError(oss, arrayInfo, index);
|
||||||
for (unsigned int i = 0; i < arrayInfo.num().size(); ++i)
|
|
||||||
oss << "[" << arrayInfo.num(i) << "]";
|
|
||||||
oss << "' index ";
|
|
||||||
if (index.size() == 1)
|
|
||||||
oss << index[0];
|
|
||||||
else {
|
|
||||||
oss << arrayInfo.varname();
|
|
||||||
for (unsigned int i = 0; i < index.size(); ++i)
|
|
||||||
oss << "[" << index[i] << "]";
|
|
||||||
}
|
|
||||||
oss << " out of bounds";
|
|
||||||
reportError(callstack, Severity::error, "arrayIndexOutOfBounds", oss.str());
|
reportError(callstack, Severity::error, "arrayIndexOutOfBounds", oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +535,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
|
||||||
total_size["fwrite"] = 1001; // parameter 2 * parameter 3
|
total_size["fwrite"] = 1001; // parameter 2 * parameter 3
|
||||||
}
|
}
|
||||||
|
|
||||||
if (par == 2) {
|
else if (par == 2) {
|
||||||
total_size["read"] = 3;
|
total_size["read"] = 3;
|
||||||
total_size["pread"] = 3;
|
total_size["pread"] = 3;
|
||||||
total_size["write"] = 3;
|
total_size["write"] = 3;
|
||||||
|
@ -928,7 +921,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
||||||
(varid == 0 && Token::Match(tok, ("strcpy|strcat ( " + varnames + " , %str% )").c_str()))) {
|
(varid == 0 && Token::Match(tok, ("strcpy|strcat ( " + varnames + " , %str% )").c_str()))) {
|
||||||
const std::size_t len = Token::getStrLength(tok->tokAt(varc + 4));
|
const std::size_t len = Token::getStrLength(tok->tokAt(varc + 4));
|
||||||
if (total_size > 0 && len >= (unsigned int)total_size) {
|
if (total_size > 0 && len >= (unsigned int)total_size) {
|
||||||
bufferOverrunError(tok, varid > 0 ? "" : varnames.c_str());
|
bufferOverrunError(tok, varid > 0 ? std::string("") : varnames);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if ((varid > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %var% )", varid)) ||
|
} else if ((varid > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %var% )", varid)) ||
|
||||||
|
@ -1653,7 +1646,7 @@ void CheckBufferOverrun::checkSprintfCall(const Token *tok, const MathLib::bigin
|
||||||
std::list<const Token*> parameters;
|
std::list<const Token*> parameters;
|
||||||
const Token* vaArg = tok->tokAt(2)->nextArgument()->nextArgument();
|
const Token* vaArg = tok->tokAt(2)->nextArgument()->nextArgument();
|
||||||
while (vaArg) {
|
while (vaArg) {
|
||||||
if (Token::Match(vaArg, "%any% [,)]")) {
|
if (Token::Match(vaArg->next(), "[,)]")) {
|
||||||
if (Token::Match(vaArg, "%str%"))
|
if (Token::Match(vaArg, "%str%"))
|
||||||
parameters.push_back(vaArg);
|
parameters.push_back(vaArg);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include "symboldatabase.h"
|
#include "symboldatabase.h"
|
||||||
|
|
||||||
#include <locale>
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -487,7 +485,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok2, "%any% ="))
|
if (tok2 && tok2->strAt(1) == "=")
|
||||||
assignVar(ftok->str(), scope, usage);
|
assignVar(ftok->str(), scope, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -833,7 +831,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
|
||||||
tok = tok->tokAt(4);
|
tok = tok->tokAt(4);
|
||||||
|
|
||||||
// check if a function is called
|
// check if a function is called
|
||||||
if (Token::Match(tok->next(), "%any% (") &&
|
if (tok->strAt(2) == "(" &&
|
||||||
tok->linkAt(2)->next()->str() == ";") {
|
tok->linkAt(2)->next()->str() == ";") {
|
||||||
std::list<Function>::const_iterator it;
|
std::list<Function>::const_iterator it;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
@ -314,9 +313,9 @@ void CheckMemoryLeak::memoryLeak(const Token *tok, const std::string &varname, A
|
||||||
alloctype == CheckMemoryLeak::Pipe ||
|
alloctype == CheckMemoryLeak::Pipe ||
|
||||||
alloctype == CheckMemoryLeak::Fd ||
|
alloctype == CheckMemoryLeak::Fd ||
|
||||||
alloctype == CheckMemoryLeak::Dir)
|
alloctype == CheckMemoryLeak::Dir)
|
||||||
resourceLeakError(tok, varname.c_str());
|
resourceLeakError(tok, varname);
|
||||||
else
|
else
|
||||||
memleakError(tok, varname.c_str());
|
memleakError(tok, varname);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -2553,7 +2552,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
|
||||||
|
|
||||||
// Function call .. possible deallocation
|
// Function call .. possible deallocation
|
||||||
else if (Token::Match(tok->previous(), "[{};] %var% (")) {
|
else if (Token::Match(tok->previous(), "[{};] %var% (")) {
|
||||||
if (!CheckMemoryLeakInFunction::test_white_list(tok->str().c_str())) {
|
if (!CheckMemoryLeakInFunction::test_white_list(tok->str())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2562,9 +2561,9 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allocInConstructor && !deallocInDestructor) {
|
if (allocInConstructor && !deallocInDestructor) {
|
||||||
memoryLeak(tokVarname, (classname + "::" + varname).c_str(), Alloc);
|
memoryLeak(tokVarname, classname + "::" + varname, Alloc);
|
||||||
} else if (Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No) {
|
} else if (Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No) {
|
||||||
memoryLeak(tokVarname, (classname + "::" + varname).c_str(), Alloc);
|
memoryLeak(tokVarname, classname + "::" + varname, Alloc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2707,7 +2706,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Token * const vartok
|
||||||
|
|
||||||
else if (tok3->str() == "}") {
|
else if (tok3->str() == "}") {
|
||||||
if (indentlevel3 == 0) {
|
if (indentlevel3 == 0) {
|
||||||
memoryLeak(tok3, (vartok->str() + "." + tok2->strAt(2)).c_str(), Malloc);
|
memoryLeak(tok3, vartok->str() + "." + tok2->strAt(2), Malloc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
--indentlevel3;
|
--indentlevel3;
|
||||||
|
@ -2739,7 +2738,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Token * const vartok
|
||||||
|
|
||||||
// Deallocating the struct..
|
// Deallocating the struct..
|
||||||
else if (indentlevel2 == 0 && Token::Match(tok3, "free|kfree ( %varid% )", structid)) {
|
else if (indentlevel2 == 0 && Token::Match(tok3, "free|kfree ( %varid% )", structid)) {
|
||||||
memoryLeak(tok3, (vartok->str() + "." + tok2->strAt(2)).c_str(), Malloc);
|
memoryLeak(tok3, vartok->str() + "." + tok2->strAt(2), Malloc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2785,7 +2784,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Token * const vartok
|
||||||
// Returning from function without deallocating struct member?
|
// Returning from function without deallocating struct member?
|
||||||
if (!Token::Match(tok3, "return %varid% ;", structid) &&
|
if (!Token::Match(tok3, "return %varid% ;", structid) &&
|
||||||
!Token::Match(tok3, "return & %varid% .", structid)) {
|
!Token::Match(tok3, "return & %varid% .", structid)) {
|
||||||
memoryLeak(tok3, (vartok->str() + "." + tok2->strAt(2)).c_str(), Malloc);
|
memoryLeak(tok3, vartok->str() + "." + tok2->strAt(2), Malloc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -789,14 +789,11 @@ bool CheckStl::isStlContainer(unsigned int varid)
|
||||||
if (Token::simpleMatch(type, "std ::"))
|
if (Token::simpleMatch(type, "std ::"))
|
||||||
type = type->tokAt(2);
|
type = type->tokAt(2);
|
||||||
|
|
||||||
// all possible stl containers
|
// all possible stl containers as a token
|
||||||
static const char STL_CONTAINER_LIST[] = "bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|vector";
|
static const char STL_CONTAINER_LIST[] = "bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|vector <";
|
||||||
|
|
||||||
// container template string
|
|
||||||
const std::string checkStr(std::string(STL_CONTAINER_LIST) + " <");
|
|
||||||
|
|
||||||
// check if it's an stl template
|
// check if it's an stl template
|
||||||
if (Token::Match(type, checkStr.c_str()))
|
if (Token::Match(type, STL_CONTAINER_LIST))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,7 +858,7 @@ void CheckStl::size()
|
||||||
|
|
||||||
void CheckStl::sizeError(const Token *tok)
|
void CheckStl::sizeError(const Token *tok)
|
||||||
{
|
{
|
||||||
const std::string varname(tok ? tok->str().c_str() : "list");
|
const std::string varname(tok ? tok->str() : std::string("list"));
|
||||||
reportError(tok, Severity::performance, "stlSize",
|
reportError(tok, Severity::performance, "stlSize",
|
||||||
"Possible inefficient checking for '" + varname + "' emptiness.\n"
|
"Possible inefficient checking for '" + varname + "' emptiness.\n"
|
||||||
"Checking for '" + varname + "' emptiness might be inefficient. "
|
"Checking for '" + varname + "' emptiness might be inefficient. "
|
||||||
|
|
|
@ -417,7 +417,7 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
|
||||||
if (Token::Match(tok->tokAt(start), "&| %var%") ||
|
if (Token::Match(tok->tokAt(start), "&| %var%") ||
|
||||||
Token::Match(tok->tokAt(start), "( const| struct|union| %type% *| ) &| %var%") ||
|
Token::Match(tok->tokAt(start), "( const| struct|union| %type% *| ) &| %var%") ||
|
||||||
Token::Match(tok->tokAt(start), "( const| struct|union| %type% *| ) ( &| %var%") ||
|
Token::Match(tok->tokAt(start), "( const| struct|union| %type% *| ) ( &| %var%") ||
|
||||||
Token::Match(tok->tokAt(start), "%any% < const| struct|union| %type% *| > ( &| %var%")) {
|
Token::Match(tok->tokAt(start+1), "< const| struct|union| %type% *| > ( &| %var%")) {
|
||||||
unsigned char offset = 0;
|
unsigned char offset = 0;
|
||||||
unsigned int varid2;
|
unsigned int varid2;
|
||||||
bool addressOf = false;
|
bool addressOf = false;
|
||||||
|
|
|
@ -21,10 +21,8 @@
|
||||||
#include "mathlib.h"
|
#include "mathlib.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
@ -70,7 +68,7 @@ double MathLib::toDoubleNumber(const std::string &str)
|
||||||
else if (isNullValue(str))
|
else if (isNullValue(str))
|
||||||
return 0.0;
|
return 0.0;
|
||||||
// otherwise, convert to double
|
// otherwise, convert to double
|
||||||
std::istringstream istr(str.c_str());
|
std::istringstream istr(str);
|
||||||
double ret;
|
double ret;
|
||||||
istr >> ret;
|
istr >> ret;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -590,7 +589,7 @@ std::string Preprocessor::removeParentheses(const std::string &str)
|
||||||
if (str.find("\n#if") == std::string::npos && str.compare(0, 3, "#if") != 0)
|
if (str.find("\n#if") == std::string::npos && str.compare(0, 3, "#if") != 0)
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
std::istringstream istr(str.c_str());
|
std::istringstream istr(str);
|
||||||
std::ostringstream ret;
|
std::ostringstream ret;
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(istr, line)) {
|
while (std::getline(istr, line)) {
|
||||||
|
@ -836,7 +835,7 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
|
||||||
|
|
||||||
// Replace "defined A" with "defined(A)"
|
// Replace "defined A" with "defined(A)"
|
||||||
{
|
{
|
||||||
std::istringstream istr(processedFile.c_str());
|
std::istringstream istr(processedFile);
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(istr, line)) {
|
while (std::getline(istr, line)) {
|
||||||
|
@ -1183,7 +1182,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
||||||
|
|
||||||
if (s.find("&&") != std::string::npos) {
|
if (s.find("&&") != std::string::npos) {
|
||||||
Tokenizer tokenizer(_settings, _errorLogger);
|
Tokenizer tokenizer(_settings, _errorLogger);
|
||||||
std::istringstream tempIstr(s.c_str());
|
std::istringstream tempIstr(s);
|
||||||
if (!tokenizer.tokenize(tempIstr, filename.c_str(), "", true)) {
|
if (!tokenizer.tokenize(tempIstr, filename.c_str(), "", true)) {
|
||||||
std::ostringstream lineStream;
|
std::ostringstream lineStream;
|
||||||
lineStream << __LINE__;
|
lineStream << __LINE__;
|
||||||
|
@ -1300,7 +1299,7 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &c
|
||||||
{
|
{
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, NULL);
|
Tokenizer tokenizer(&settings, NULL);
|
||||||
std::istringstream istr(("(" + condition + ")").c_str());
|
std::istringstream istr("(" + condition + ")");
|
||||||
if (!tokenizer.tokenize(istr, "", "", true)) {
|
if (!tokenizer.tokenize(istr, "", "", true)) {
|
||||||
// If tokenize returns false, then there is syntax error in the
|
// If tokenize returns false, then there is syntax error in the
|
||||||
// code which we can't handle. So stop here.
|
// code which we can't handle. So stop here.
|
||||||
|
@ -1519,7 +1518,7 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
|
||||||
if (line.find("=") != std::string::npos) {
|
if (line.find("=") != std::string::npos) {
|
||||||
Tokenizer tokenizer(settings, NULL);
|
Tokenizer tokenizer(settings, NULL);
|
||||||
line.erase(0, sizeof("#pragma endasm"));
|
line.erase(0, sizeof("#pragma endasm"));
|
||||||
std::istringstream tempIstr(line.c_str());
|
std::istringstream tempIstr(line);
|
||||||
tokenizer.tokenize(tempIstr, "");
|
tokenizer.tokenize(tempIstr, "");
|
||||||
if (Token::Match(tokenizer.tokens(), "( %var% = %any% )")) {
|
if (Token::Match(tokenizer.tokens(), "( %var% = %any% )")) {
|
||||||
ret << "asm(" << tokenizer.tokens()->strAt(1) << ");";
|
ret << "asm(" << tokenizer.tokens()->strAt(1) << ");";
|
||||||
|
@ -2210,7 +2209,7 @@ public:
|
||||||
tokenizer.setSettings(&settings);
|
tokenizer.setSettings(&settings);
|
||||||
|
|
||||||
// Tokenize the macro to make it easier to handle
|
// Tokenize the macro to make it easier to handle
|
||||||
std::istringstream istr(macro.c_str());
|
std::istringstream istr(macro);
|
||||||
tokenizer.createTokens(istr);
|
tokenizer.createTokens(istr);
|
||||||
|
|
||||||
// macro name..
|
// macro name..
|
||||||
|
@ -2481,7 +2480,7 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
|
|
||||||
// read code..
|
// read code..
|
||||||
std::istringstream istr(code.c_str());
|
std::istringstream istr(code);
|
||||||
std::string line;
|
std::string line;
|
||||||
while (getlines(istr, line)) {
|
while (getlines(istr, line)) {
|
||||||
// defining a macro..
|
// defining a macro..
|
||||||
|
|
|
@ -129,7 +129,7 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tokensBack) {
|
if (_tokensBack) {
|
||||||
_tokensBack->insertToken(str2.str().c_str());
|
_tokensBack->insertToken(str2.str());
|
||||||
} else {
|
} else {
|
||||||
_tokens = new Token(&_tokensBack);
|
_tokens = new Token(&_tokensBack);
|
||||||
_tokensBack = _tokens;
|
_tokensBack = _tokens;
|
||||||
|
@ -145,20 +145,12 @@ void Tokenizer::addtoken(const Token * tok, const unsigned int lineno, const uns
|
||||||
if (tok == 0)
|
if (tok == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Replace hexadecimal value with decimal
|
|
||||||
std::ostringstream str2;
|
|
||||||
if (strncmp(tok->str().c_str(), "0x", 2) == 0) {
|
|
||||||
str2 << std::strtoul(tok->str().c_str() + 2, NULL, 16);
|
|
||||||
} else {
|
|
||||||
str2 << tok->str();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_tokensBack) {
|
if (_tokensBack) {
|
||||||
_tokensBack->insertToken(str2.str().c_str());
|
_tokensBack->insertToken(tok->str());
|
||||||
} else {
|
} else {
|
||||||
_tokens = new Token(&_tokensBack);
|
_tokens = new Token(&_tokensBack);
|
||||||
_tokensBack = _tokens;
|
_tokensBack = _tokens;
|
||||||
_tokensBack->str(str2.str());
|
_tokensBack->str(tok->str());
|
||||||
}
|
}
|
||||||
|
|
||||||
_tokensBack->linenr(lineno);
|
_tokensBack->linenr(lineno);
|
||||||
|
@ -330,7 +322,7 @@ void Tokenizer::createTokens(std::istream &code)
|
||||||
bool foundOurfile = false;
|
bool foundOurfile = false;
|
||||||
fileIndexes.push_back(FileIndex);
|
fileIndexes.push_back(FileIndex);
|
||||||
for (unsigned int i = 0; i < _files.size(); ++i) {
|
for (unsigned int i = 0; i < _files.size(); ++i) {
|
||||||
if (Path::sameFileName(_files[i].c_str(), line.c_str())) {
|
if (Path::sameFileName(_files[i], line)) {
|
||||||
// Use this index
|
// Use this index
|
||||||
foundOurfile = true;
|
foundOurfile = true;
|
||||||
FileIndex = i;
|
FileIndex = i;
|
||||||
|
@ -759,7 +751,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
|
||||||
static unsigned int count = 0;
|
static unsigned int count = 0;
|
||||||
name = "Unnamed" + MathLib::toString<unsigned int>(count++);
|
name = "Unnamed" + MathLib::toString<unsigned int>(count++);
|
||||||
}
|
}
|
||||||
tok->next()->insertToken(name.c_str());
|
tok->next()->insertToken(name);
|
||||||
} else
|
} else
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (tok->strAt(3) == ":") {
|
} else if (tok->strAt(3) == ":") {
|
||||||
|
@ -798,7 +790,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
|
||||||
}
|
}
|
||||||
tok1->insertToken(tok->next()->str()); // struct, union or enum
|
tok1->insertToken(tok->next()->str()); // struct, union or enum
|
||||||
tok1 = tok1->next();
|
tok1 = tok1->next();
|
||||||
tok1->insertToken(name.c_str());
|
tok1->insertToken(name);
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok = tok3;
|
tok = tok3;
|
||||||
}
|
}
|
||||||
|
@ -1849,7 +1841,7 @@ void Tokenizer::simplifyTypedef()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tokenizer::simplifyMulAnd(void)
|
void Tokenizer::simplifyMulAnd()
|
||||||
{
|
{
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "[;{}] *")) {
|
if (Token::Match(tok, "[;{}] *")) {
|
||||||
|
@ -5141,10 +5133,10 @@ void Tokenizer::simplifyConditionOperator()
|
||||||
while (pos1 != std::string::npos) {
|
while (pos1 != std::string::npos) {
|
||||||
std::string::size_type pos2 = str.find(" ", pos1);
|
std::string::size_type pos2 = str.find(" ", pos1);
|
||||||
if (pos2 == std::string::npos) {
|
if (pos2 == std::string::npos) {
|
||||||
tok->insertToken(str.substr(pos1).c_str());
|
tok->insertToken(str.substr(pos1));
|
||||||
pos1 = pos2;
|
pos1 = pos2;
|
||||||
} else {
|
} else {
|
||||||
tok->insertToken(str.substr(pos1, pos2 - pos1).c_str());
|
tok->insertToken(str.substr(pos1, pos2 - pos1));
|
||||||
pos1 = pos2 + 1;
|
pos1 = pos2 + 1;
|
||||||
}
|
}
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
@ -5661,7 +5653,7 @@ bool Tokenizer::simplifyFunctionReturn()
|
||||||
static void incdec(std::string &value, const std::string &op)
|
static void incdec(std::string &value, const std::string &op)
|
||||||
{
|
{
|
||||||
int ivalue = 0;
|
int ivalue = 0;
|
||||||
std::istringstream istr(value.c_str());
|
std::istringstream istr(value);
|
||||||
istr >> ivalue;
|
istr >> ivalue;
|
||||||
if (op == "++")
|
if (op == "++")
|
||||||
++ivalue;
|
++ivalue;
|
||||||
|
@ -6311,7 +6303,7 @@ void Tokenizer::simplifyIfNot()
|
||||||
// if( foo(x) == 0 )
|
// if( foo(x) == 0 )
|
||||||
if (Token::Match(tok->link()->tokAt(-2), "( %var%")) {
|
if (Token::Match(tok->link()->tokAt(-2), "( %var%")) {
|
||||||
tok->deleteNext(2);
|
tok->deleteNext(2);
|
||||||
tok->link()->previous()->insertToken(tok->link()->previous()->str().c_str());
|
tok->link()->previous()->insertToken(tok->link()->previous()->str());
|
||||||
tok->link()->tokAt(-2)->str("!");
|
tok->link()->tokAt(-2)->str("!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7649,7 +7641,7 @@ void Tokenizer::simplifyGoto()
|
||||||
if (indentlevel == 1 && lev == 0)
|
if (indentlevel == 1 && lev == 0)
|
||||||
ret2 = true;
|
ret2 = true;
|
||||||
}
|
}
|
||||||
token->insertToken(tok2->str().c_str());
|
token->insertToken(tok2->str());
|
||||||
token = token->next();
|
token = token->next();
|
||||||
token->linenr(tok2->linenr());
|
token->linenr(tok2->linenr());
|
||||||
token->varId(tok2->varId());
|
token->varId(tok2->varId());
|
||||||
|
@ -8140,7 +8132,7 @@ void Tokenizer::simplifyEnum()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enumType) {
|
if (enumType) {
|
||||||
const std::string pattern(className.empty() ? "" : (className + " :: " + enumType->str()).c_str());
|
const std::string pattern(className.empty() ? std::string("") : (className + " :: " + enumType->str()));
|
||||||
|
|
||||||
// count { and } for tok2
|
// count { and } for tok2
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
@ -9117,7 +9109,7 @@ void Tokenizer::simplifyStructDecl()
|
||||||
tok->insertToken("static");
|
tok->insertToken("static");
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
tok->insertToken(type->str().c_str());
|
tok->insertToken(type->str());
|
||||||
}
|
}
|
||||||
|
|
||||||
tok = restart;
|
tok = restart;
|
||||||
|
@ -9138,11 +9130,11 @@ void Tokenizer::simplifyStructDecl()
|
||||||
|
|
||||||
name = "Anonymous" + MathLib::toString<unsigned int>(count++);
|
name = "Anonymous" + MathLib::toString<unsigned int>(count++);
|
||||||
|
|
||||||
tok1->insertToken(name.c_str());
|
tok1->insertToken(name);
|
||||||
|
|
||||||
tok->insertToken(";");
|
tok->insertToken(";");
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
tok->insertToken(name.c_str());
|
tok->insertToken(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unnamed anonymous struct/union so possibly remove it
|
// unnamed anonymous struct/union so possibly remove it
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code.c_str());
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
tokenizer.simplifyTokenList();
|
tokenizer.simplifyTokenList();
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
extern std::ostringstream errout;
|
extern std::ostringstream errout;
|
||||||
extern std::ostringstream output;
|
extern std::ostringstream output;
|
||||||
|
@ -2294,7 +2293,7 @@ private:
|
||||||
|
|
||||||
void unicodeInComment() {
|
void unicodeInComment() {
|
||||||
const std::string filedata("//\xC8");
|
const std::string filedata("//\xC8");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2302,7 +2301,7 @@ private:
|
||||||
|
|
||||||
void unicodeInString() {
|
void unicodeInString() {
|
||||||
const std::string filedata("\"\xC8\"");
|
const std::string filedata("\"\xC8\"");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2716,7 +2715,7 @@ private:
|
||||||
|
|
||||||
void testPreprocessorRead1() {
|
void testPreprocessorRead1() {
|
||||||
const std::string filedata("/*\n*/ # /*\n*/ defi\\\nne FO\\\nO 10\\\n20");
|
const std::string filedata("/*\n*/ # /*\n*/ defi\\\nne FO\\\nO 10\\\n20");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS("#define FOO 1020", preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS("#define FOO 1020", preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2724,7 +2723,7 @@ private:
|
||||||
|
|
||||||
void testPreprocessorRead2() {
|
void testPreprocessorRead2() {
|
||||||
const std::string filedata("\"foo\\\\\nbar\"");
|
const std::string filedata("\"foo\\\\\nbar\"");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS("\"foo\\bar\"", preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS("\"foo\\bar\"", preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2732,7 +2731,7 @@ private:
|
||||||
|
|
||||||
void testPreprocessorRead3() {
|
void testPreprocessorRead3() {
|
||||||
const std::string filedata("#define A \" a \"\n\" b\"");
|
const std::string filedata("#define A \" a \"\n\" b\"");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2742,7 +2741,7 @@ private:
|
||||||
{
|
{
|
||||||
// test < \\> < > (unescaped)
|
// test < \\> < > (unescaped)
|
||||||
const std::string filedata("#define A \" \\\\\"/*space*/ \" \"");
|
const std::string filedata("#define A \" \\\\\"/*space*/ \" \"");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS("#define A \" \\\\\" \" \"", preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS("#define A \" \\\\\" \" \"", preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2751,7 +2750,7 @@ private:
|
||||||
{
|
{
|
||||||
// test <" \\\" "> (unescaped)
|
// test <" \\\" "> (unescaped)
|
||||||
const std::string filedata("#define A \" \\\\\\\" \"");
|
const std::string filedata("#define A \" \\\\\\\" \"");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS("#define A \" \\\\\\\" \"", preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS("#define A \" \\\\\\\" \"", preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2760,7 +2759,7 @@ private:
|
||||||
{
|
{
|
||||||
// test <" \\\\"> <" "> (unescaped)
|
// test <" \\\\"> <" "> (unescaped)
|
||||||
const std::string filedata("#define A \" \\\\\\\\\"/*space*/ \" \"");
|
const std::string filedata("#define A \" \\\\\\\\\"/*space*/ \" \"");
|
||||||
std::istringstream istr(filedata.c_str());
|
std::istringstream istr(filedata);
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
ASSERT_EQUALS("#define A \" \\\\\\\\\" \" \"", preprocessor.read(istr, "test.cpp", 0));
|
ASSERT_EQUALS("#define A \" \\\\\\\\\" \" \"", preprocessor.read(istr, "test.cpp", 0));
|
||||||
|
@ -2775,7 +2774,7 @@ private:
|
||||||
std::string processedFile;
|
std::string processedFile;
|
||||||
std::list<std::string> cfg;
|
std::list<std::string> cfg;
|
||||||
std::list<std::string> paths;
|
std::list<std::string> paths;
|
||||||
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
||||||
}
|
}
|
||||||
|
|
||||||
void missingInclude() {
|
void missingInclude() {
|
||||||
|
|
|
@ -127,7 +127,7 @@ private:
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code.c_str());
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
tokenizer.simplifyTokenList();
|
tokenizer.simplifyTokenList();
|
||||||
|
|
||||||
|
|
|
@ -5101,7 +5101,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code.c_str());
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
|
|
Loading…
Reference in New Issue