Fix more -Wshadow compile warnings

This commit is contained in:
Reijo Tomperi 2010-04-09 22:40:37 +03:00
parent f77dbbb14b
commit 6dc3860ae9
8 changed files with 85 additions and 85 deletions

View File

@ -156,9 +156,9 @@ unsigned int ThreadExecutor::check()
CppCheck fileChecker(*this); CppCheck fileChecker(*this);
fileChecker.settings(_settings); fileChecker.settings(_settings);
fileChecker.addFile(_filenames[i]); fileChecker.addFile(_filenames[i]);
unsigned int result = fileChecker.check(); unsigned int resultOfCheck = fileChecker.check();
std::ostringstream oss; std::ostringstream oss;
oss << result; oss << resultOfCheck;
writeToPipe('3', oss.str()); writeToPipe('3', oss.str());
exit(0); exit(0);
} }

View File

@ -533,9 +533,9 @@ std::string Preprocessor::replaceIfDefined(const std::string &str)
return ret; return ret;
} }
void Preprocessor::preprocess(std::istream &istr, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths) void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths)
{ {
processedFile = read(istr, filename, _settings); processedFile = read(srcCodeStream, filename, _settings);
// Replace all tabs with spaces.. // Replace all tabs with spaces..
std::replace(processedFile.begin(), processedFile.end(), '\t', ' '); std::replace(processedFile.begin(), processedFile.end(), '\t', ' ');
@ -707,8 +707,8 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
} }
if (par != 0) if (par != 0)
{ {
std::ostringstream line; std::ostringstream lineStream;
line << __LINE__; lineStream << __LINE__;
ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage errmsg;
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
@ -717,7 +717,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
errmsg._callStack.push_back(loc); errmsg._callStack.push_back(loc);
errmsg._severity = "error"; errmsg._severity = "error";
errmsg._msg = "mismatching number of '(' and ')' in this line: " + def; errmsg._msg = "mismatching number of '(' and ')' in this line: " + def;
errmsg._id = "preprocessor" + line.str(); errmsg._id = "preprocessor" + lineStream.str();
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
ret.clear(); ret.clear();
return ret; return ret;
@ -783,9 +783,9 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
} }
else else
{ {
std::string def((deflist.back() == "1") ? "0" : "1"); std::string tempDef((deflist.back() == "1") ? "0" : "1");
deflist.pop_back(); deflist.pop_back();
deflist.push_back(def); deflist.push_back(tempDef);
} }
} }
@ -848,11 +848,11 @@ 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 istr(s.c_str()); std::istringstream tempIstr(s.c_str());
if (!tokenizer.tokenize(istr, filename.c_str())) if (!tokenizer.tokenize(tempIstr, filename.c_str()))
{ {
std::ostringstream line; std::ostringstream lineStream;
line << __LINE__; lineStream << __LINE__;
ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage errmsg;
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
@ -861,7 +861,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
errmsg._callStack.push_back(loc); errmsg._callStack.push_back(loc);
errmsg._severity = "error"; errmsg._severity = "error";
errmsg._msg = "Error parsing this: " + s; errmsg._msg = "Error parsing this: " + s;
errmsg._id = "preprocessor" + line.str(); errmsg._id = "preprocessor" + lineStream.str();
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
} }
@ -1148,8 +1148,8 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
{ {
Tokenizer tokenizer; Tokenizer tokenizer;
line.erase(0, sizeof("#pragma endasm")); line.erase(0, sizeof("#pragma endasm"));
std::istringstream istr(line.c_str()); std::istringstream tempIstr(line.c_str());
tokenizer.tokenize(istr, ""); 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) << ");";
@ -1291,11 +1291,11 @@ static int tolowerWrapper(int c)
} }
void Preprocessor::handleIncludes(std::string &code, const std::string &filename, const std::list<std::string> &includePaths) void Preprocessor::handleIncludes(std::string &code, const std::string &filePath, const std::list<std::string> &includePaths)
{ {
std::list<std::string> paths; std::list<std::string> paths;
std::string path; std::string path;
path = filename; path = filePath;
path.erase(1 + path.find_last_of("\\/")); path.erase(1 + path.find_last_of("\\/"));
paths.push_back(path); paths.push_back(path);
std::string::size_type pos = 0; std::string::size_type pos = 0;
@ -1623,11 +1623,11 @@ public:
const std::string &s(params2[i]); const std::string &s(params2[i]);
std::ostringstream ostr; std::ostringstream ostr;
ostr << "\""; ostr << "\"";
for (std::string::size_type i = 0; i < s.size(); ++i) for (std::string::size_type j = 0; j < s.size(); ++j)
{ {
if (s[i] == '\\' || s[i] == '\"') if (s[j] == '\\' || s[j] == '\"')
ostr << '\\'; ostr << '\\';
ostr << s[i]; ostr << s[j];
} }
str = ostr.str() + "\""; str = ostr.str() + "\"";
} }
@ -2027,9 +2027,9 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
"syntaxError", "syntaxError",
std::string("Syntax error. Not enough parameters for macro '") + macro->name() + "'."); std::string("Syntax error. Not enough parameters for macro '") + macro->name() + "'.");
std::map<std::string, PreprocessorMacro *>::iterator it; std::map<std::string, PreprocessorMacro *>::iterator iter;
for (it = macros.begin(); it != macros.end(); ++it) for (iter = macros.begin(); iter != macros.end(); ++iter)
delete it->second; delete iter->second;
return ""; return "";
} }

View File

@ -54,7 +54,7 @@ public:
* Extract the code for each configuration. Use this with getcode() to get the * Extract the code for each configuration. Use this with getcode() to get the
* file data for each individual configuration. * file data for each individual configuration.
* *
* @param istr The (file/string) stream to read from. * @param srcCodeStream The (file/string) stream to read from.
* @param processedFile Give reference to empty string as a parameter, * @param processedFile Give reference to empty string as a parameter,
* function will fill processed file here. Use this also as a filedata parameter * function will fill processed file here. Use this also as a filedata parameter
* to getcode() if you recieved more than once configurations. * to getcode() if you recieved more than once configurations.
@ -67,7 +67,7 @@ public:
* Note that if path from given filename is also extracted and that is used as * Note that if path from given filename is also extracted and that is used as
* a last include path if include file was not found from earlier paths. * a last include path if include file was not found from earlier paths.
*/ */
void preprocess(std::istream &istr, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths); void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths);
/** Just read the code into a string. Perform simple cleanup of the code */ /** Just read the code into a string. Perform simple cleanup of the code */
static std::string read(std::istream &istr, const std::string &filename, Settings *settings); static std::string read(std::istream &istr, const std::string &filename, Settings *settings);
@ -185,7 +185,7 @@ private:
* Search includes from code and append code from the included * Search includes from code and append code from the included
* file * file
* @param code The source code to modify * @param code The source code to modify
* @param filename The name of the file to check e.g. "src/main.cpp" * @param filePath Relative path to file to check e.g. "src/main.cpp"
* @param includePaths List of paths where incude files should be searched from, * @param includePaths List of paths where incude files should be searched from,
* single path can be e.g. in format "include/". * single path can be e.g. in format "include/".
* There must be a path separator at the end. Default parameter is empty list. * There must be a path separator at the end. Default parameter is empty list.
@ -193,7 +193,7 @@ private:
* a last include path if include file was not found from earlier paths. * a last include path if include file was not found from earlier paths.
* @return modified source code * @return modified source code
*/ */
void handleIncludes(std::string &code, const std::string &filename, const std::list<std::string> &includePaths); void handleIncludes(std::string &code, const std::string &filePath, const std::list<std::string> &includePaths);
Settings *_settings; Settings *_settings;
ErrorLogger *_errorLogger; ErrorLogger *_errorLogger;

View File

@ -595,10 +595,10 @@ const Token *Token::findmatch(const Token *tok, const char pattern[], unsigned i
return 0; return 0;
} }
void Token::insertToken(const std::string &str) void Token::insertToken(const std::string &tokenStr)
{ {
Token *newToken = new Token(tokensBack); Token *newToken = new Token(tokensBack);
newToken->str(str); newToken->str(tokenStr);
newToken->_linenr = _linenr; newToken->_linenr = _linenr;
newToken->_fileIndex = _fileIndex; newToken->_fileIndex = _fileIndex;
if (this->next()) if (this->next())
@ -658,38 +658,38 @@ std::string Token::stringifyList(bool varid, const char *title, const std::vecto
if (title) if (title)
ret << "\n### " << title << " ###\n"; ret << "\n### " << title << " ###\n";
unsigned int linenr = 0; unsigned int lineNumber = 0;
int fileIndex = -1; int fileInd = -1;
std::map<unsigned int, unsigned int> lineNumbers; std::map<unsigned int, unsigned int> lineNumbers;
for (const Token *tok = this; tok; tok = tok->next()) for (const Token *tok = this; tok; tok = tok->next())
{ {
bool fileChange = false; bool fileChange = false;
if (static_cast<int>(tok->_fileIndex) != fileIndex) if (static_cast<int>(tok->_fileIndex) != fileInd)
{ {
if (fileIndex != -1) if (fileInd != -1)
{ {
lineNumbers[fileIndex] = tok->_fileIndex; lineNumbers[fileInd] = tok->_fileIndex;
} }
fileIndex = static_cast<int>(tok->_fileIndex); fileInd = static_cast<int>(tok->_fileIndex);
ret << "\n\n##file "; ret << "\n\n##file ";
if (fileNames.size() > static_cast<unsigned int>(fileIndex)) if (fileNames.size() > static_cast<unsigned int>(fileInd))
ret << fileNames.at(fileIndex); ret << fileNames.at(fileInd);
else else
ret << fileIndex; ret << fileInd;
linenr = lineNumbers[fileIndex]; lineNumber = lineNumbers[fileInd];
fileChange = true; fileChange = true;
} }
if (linenr != tok->linenr() || fileChange) if (lineNumber != tok->linenr() || fileChange)
{ {
while (linenr < tok->linenr()) while (lineNumber < tok->linenr())
{ {
++linenr; ++lineNumber;
ret << "\n" << linenr << ":"; ret << "\n" << lineNumber << ":";
} }
linenr = tok->linenr(); lineNumber = tok->linenr();
} }
ret << " " << tok->str(); ret << " " << tok->str();

View File

@ -228,9 +228,9 @@ public:
/** /**
* Insert new token after this token. This function will handle * Insert new token after this token. This function will handle
* relations between next and previous token also. * relations between next and previous token also.
* @param str String for the new token. * @param tokenStr String for the new token.
*/ */
void insertToken(const std::string &str); void insertToken(const std::string &tokenStr);
Token *previous() const Token *previous() const
{ {

View File

@ -126,35 +126,35 @@ private:
void xml() void xml()
{ {
// Test the errorlogger.. // Test the errorlogger..
ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage errorMessage;
errmsg._msg = "ab<cd>ef"; errorMessage._msg = "ab<cd>ef";
ASSERT_EQUALS("<error id=\"\" severity=\"\" msg=\"ab&lt;cd&gt;ef\"/>", errmsg.toXML()); ASSERT_EQUALS("<error id=\"\" severity=\"\" msg=\"ab&lt;cd&gt;ef\"/>", errorMessage.toXML());
} }
void include() void include()
{ {
ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage errorMessage;
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
loc.file = "ab/cd/../ef.h"; loc.file = "ab/cd/../ef.h";
errmsg._callStack.push_back(loc); errorMessage._callStack.push_back(loc);
ASSERT_EQUALS("<error file=\"ab/ef.h\" line=\"0\" id=\"\" severity=\"\" msg=\"\"/>", errmsg.toXML()); ASSERT_EQUALS("<error file=\"ab/ef.h\" line=\"0\" id=\"\" severity=\"\" msg=\"\"/>", errorMessage.toXML());
ASSERT_EQUALS("[ab/ef.h:0]: ", errmsg.toText()); ASSERT_EQUALS("[ab/ef.h:0]: ", errorMessage.toText());
} }
void templateFormat() void templateFormat()
{ {
ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage errorMessage;
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
loc.file = "some/{file}file.cpp"; loc.file = "some/{file}file.cpp";
loc.line = 10; loc.line = 10;
errmsg._callStack.push_back(loc); errorMessage._callStack.push_back(loc);
errmsg._id = "testId"; errorMessage._id = "testId";
errmsg._severity = "testSeverity"; errorMessage._severity = "testSeverity";
errmsg._msg = "long testMessage"; errorMessage._msg = "long testMessage";
ASSERT_EQUALS("<error file=\"some/{file}file.cpp\" line=\"10\" id=\"testId\" severity=\"testSeverity\" msg=\"long testMessage\"/>", errmsg.toXML()); ASSERT_EQUALS("<error file=\"some/{file}file.cpp\" line=\"10\" id=\"testId\" severity=\"testSeverity\" msg=\"long testMessage\"/>", errorMessage.toXML());
ASSERT_EQUALS("[some/{file}file.cpp:10]: (testSeverity) long testMessage", errmsg.toText()); ASSERT_EQUALS("[some/{file}file.cpp:10]: (testSeverity) long testMessage", errorMessage.toText());
ASSERT_EQUALS("testId-some/{file}file.cpp,testSeverity.10?{long testMessage}", errmsg.toText("{id}-{file},{severity}.{line}?{{message}}")); ASSERT_EQUALS("testId-some/{file}file.cpp,testSeverity.10?{long testMessage}", errorMessage.toText("{id}-{file},{severity}.{line}?{{message}}"));
} }
void getErrorMessages() void getErrorMessages()

View File

@ -393,7 +393,7 @@ private:
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
const unsigned int varid(Token::findmatch(tokenizer.tokens(), varname)->varId()); const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId());
// getcode.. // getcode..
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, 0, 0); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, 0, 0);
@ -403,7 +403,7 @@ private:
CheckMemoryLeak::AllocType allocType, deallocType; CheckMemoryLeak::AllocType allocType, deallocType;
allocType = deallocType = CheckMemoryLeak::No; allocType = deallocType = CheckMemoryLeak::No;
bool all = false; bool all = false;
Token *tokens = checkMemoryLeak.getcode(tokenizer.tokens(), callstack, varid, allocType, deallocType, false, all, 1); Token *tokens = checkMemoryLeak.getcode(tokenizer.tokens(), callstack, varId, allocType, deallocType, false, all, 1);
// stringify.. // stringify..
std::ostringstream ret; std::ostringstream ret;

View File

@ -246,20 +246,20 @@ private:
tokenizer.validate(); tokenizer.validate();
std::string ret; std::string ret;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
{ {
if (tok != tokenizer.tokens()) if (tok1 != tokenizer.tokens())
ret += " "; ret += " ";
if (!simplify) if (!simplify)
{ {
if (tok->isUnsigned()) if (tok1->isUnsigned())
ret += "unsigned "; ret += "unsigned ";
else if (tok->isSigned()) else if (tok1->isSigned())
ret += "signed "; ret += "signed ";
} }
if (tok->isLong()) if (tok1->isLong())
ret += "long "; ret += "long ";
ret += tok->str(); ret += tok1->str();
} }
return ret; return ret;
@ -701,13 +701,13 @@ private:
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
{ {
if (tok->previous()) if (tok1->previous())
{ {
ostr << " "; ostr << " ";
} }
ostr << tok->str(); ostr << tok1->str();
} }
return ostr.str(); return ostr.str();
@ -719,9 +719,9 @@ private:
std::istringstream istr(""); std::istringstream istr("");
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
Token tok(0); Token tok1(0);
tok.str(type); tok1.str(type);
return tokenizer.sizeOfType(&tok); return tokenizer.sizeOfType(&tok1);
} }
void sizeof1() void sizeof1()
@ -1839,8 +1839,8 @@ private:
tokenizer.simplifyIfAssign(); tokenizer.simplifyIfAssign();
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
ostr << (tok->previous() ? " " : "") << tok->str(); ostr << (tok1->previous() ? " " : "") << tok1->str();
return ostr.str(); return ostr.str();
} }
@ -1883,8 +1883,8 @@ private:
tokenizer.simplifyIfNot(); tokenizer.simplifyIfNot();
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
ostr << (tok->previous() ? " " : "") << tok->str(); ostr << (tok1->previous() ? " " : "") << tok1->str();
return ostr.str(); return ostr.str();
} }
@ -1916,8 +1916,8 @@ private:
tokenizer.simplifyLogicalOperators(); tokenizer.simplifyLogicalOperators();
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
ostr << (tok->previous() ? " " : "") << tok->str(); ostr << (tok1->previous() ? " " : "") << tok1->str();
return ostr.str(); return ostr.str();
} }
@ -2478,11 +2478,11 @@ private:
tokenizer.simplifyTypedef(); tokenizer.simplifyTypedef();
std::string ret; std::string ret;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
{ {
if (tok != tokenizer.tokens()) if (tok1 != tokenizer.tokens())
ret += " "; ret += " ";
ret += tok->str(); ret += tok1->str();
} }
return ret; return ret;