Refactorized inefficient usage of std::string and const char[].

This commit is contained in:
PKEuS 2014-04-02 13:56:34 +02:00
parent 3c64c70ce2
commit e9411e05ba
13 changed files with 265 additions and 268 deletions

View File

@ -483,7 +483,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (!path.empty()) {
path = Path::fromNativeSeparators(path);
path = Path::simplifyPath(path.c_str());
path = Path::simplifyPath(path);
path = Path::removeQuotationMarks(path);
if (FileLister::isDirectory(path)) {

View File

@ -138,7 +138,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
return exitcode;
if (_settings._errorsOnly == false) {
std::string fixedpath = Path::simplifyPath(filename.c_str());
std::string fixedpath = Path::simplifyPath(filename);
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + std::string("..."));
}
@ -209,7 +209,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
// 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());
std::string fixedpath = Path::simplifyPath(filename);
fixedpath = Path::toNativeSeparators(fixedpath);
_errorLogger.reportOut(std::string("Checking ") + fixedpath + ": " + cfg + std::string("..."));
}

View File

@ -365,7 +365,7 @@ void ErrorLogger::ErrorMessage::FileLocation::setfile(const std::string &file)
{
_file = file;
_file = Path::fromNativeSeparators(_file);
_file = Path::simplifyPath(_file.c_str());
_file = Path::simplifyPath(_file);
}
std::string ErrorLogger::ErrorMessage::FileLocation::stringify() const

View File

@ -203,25 +203,23 @@ public:
}
std::string blockstart(const std::string &file) const {
std::string start;
const std::map<std::string, CodeBlock>::const_iterator map_it
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
if (map_it != _executableblocks.end()) {
start = map_it->second.start();
return map_it->second.start();
}
return start;
return std::string();
}
std::string blockend(const std::string &file) const {
std::string end;
const std::map<std::string, CodeBlock>::const_iterator map_it
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
if (map_it != _executableblocks.end()) {
end = map_it->second.end();
return map_it->second.end();
}
return end;
return std::string();
}
bool iskeyword(const std::string &file, const std::string &keyword) const {
@ -305,10 +303,10 @@ private:
void addBlock(const std::string& blockName) {
_blocks.insert(blockName);
}
std::string start() const {
const std::string& start() const {
return _start;
}
std::string end() const {
const std::string& end() const {
return _end;
}
int offset() const {

View File

@ -58,26 +58,26 @@ std::string Path::fromNativeSeparators(std::string path)
return path;
}
std::string Path::simplifyPath(const char *originalPath)
std::string Path::simplifyPath(std::string originalPath)
{
// Skip ./ at the beginning
if (std::strlen(originalPath) > 2 && originalPath[0] == '.' &&
if (originalPath.size() > 2 && originalPath[0] == '.' &&
originalPath[1] == '/') {
originalPath += 2;
originalPath = originalPath.erase(0, 2);
}
std::string subPath = "";
std::vector<std::string> pathParts;
for (; *originalPath; ++originalPath) {
if (*originalPath == '/' || *originalPath == '\\') {
for (std::size_t i = 0; i < originalPath.size(); ++i) {
if (originalPath[i] == '/' || originalPath[i] == '\\') {
if (subPath.length() > 0) {
pathParts.push_back(subPath);
subPath = "";
}
pathParts.push_back(std::string(1 , *originalPath));
pathParts.push_back(std::string(1 , originalPath[i]));
} else
subPath.append(1, *originalPath);
subPath.append(1, originalPath[i]);
}
if (subPath.length() > 0)

View File

@ -57,7 +57,7 @@ public:
* @param originalPath path to be simplified, must have / -separators.
* @return simplified path
*/
static std::string simplifyPath(const char *originalPath);
static std::string simplifyPath(std::string originalPath);
/**
* @brief Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')

View File

@ -2308,7 +2308,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
const bool fileOpened(openHeader(filename, includePaths, filepath, fin));
if (fileOpened) {
filename = Path::simplifyPath(filename.c_str());
filename = Path::simplifyPath(filename);
std::string tempFile = filename;
std::transform(tempFile.begin(), tempFile.end(), tempFile.begin(), tolowerWrapper);
if (handledFiles.find(tempFile) != handledFiles.end()) {

View File

@ -169,7 +169,7 @@ std::string Suppressions::FileMatcher::addFile(const std::string &name, unsigned
} else if (name.empty()) {
_globs["*"][0U] = false;
} else {
_files[Path::simplifyPath(name.c_str())][line] = false;
_files[Path::simplifyPath(name)][line] = false;
}
return "";
}

View File

@ -62,7 +62,7 @@ unsigned int TokenList::appendFileIfNew(const std::string &fileName)
return i;
// The "_files" vector remembers what files have been tokenized..
_files.push_back(Path::simplifyPath(fileName.c_str()));
_files.push_back(Path::simplifyPath(fileName));
return static_cast<unsigned int>(_files.size() - 1);
}

View File

@ -1372,19 +1372,18 @@ private:
void switch2() {
const std::string code("void f()\n"
"{\n"
" char *str = new char[10];\n"
" switch (abc)\n"
" {\n"
" case 1:\n"
" delete [] str;\n"
" break;\n"
" default:\n"
" break;\n"
" };\n"
"}");
check(code.c_str());
check("void f()\n"
"{\n"
" char *str = new char[10];\n"
" switch (abc)\n"
" {\n"
" case 1:\n"
" delete [] str;\n"
" break;\n"
" default:\n"
" break;\n"
" };\n"
"}");
ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: str\n", errout.str());
}

View File

@ -502,7 +502,7 @@ private:
return tokenizer.tokens()->stringifyList(0, false);
}
std::string tokenizeDebugListing(const std::string &code, bool simplify = false, const char filename[] = "test.cpp") {
std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") {
errout.str("");
Settings settings;

View File

@ -74,7 +74,7 @@ private:
return 0;
}
static const Function *findFunctionByName(const std::string& str, const Scope* startScope) {
static const Function *findFunctionByName(const char str[], const Scope* startScope) {
const Scope* currScope = startScope;
while (currScope && currScope->isExecutable()) {
if (currScope->functionOf)
@ -1301,15 +1301,15 @@ private:
}
void tryCatch1() {
const std::string str("void foo() {\n"
" try { }\n"
" catch (const Error1 & x) { }\n"
" catch (const X::Error2 & x) { }\n"
" catch (Error3 x) { }\n"
" catch (X::Error4 x) { }\n"
"}");
GET_SYMBOL_DB(str.c_str())
check(str.c_str(), false);
const char str[] = "void foo() {\n"
" try { }\n"
" catch (const Error1 & x) { }\n"
" catch (const X::Error2 & x) { }\n"
" catch (Error3 x) { }\n"
" catch (X::Error4 x) { }\n"
"}";
GET_SYMBOL_DB(str);
check(str, false);
ASSERT_EQUALS("", errout.str());
ASSERT(db && db->getVariableListSize() == 5); // index 0 + 4 variables
ASSERT(db && db->scopeList.size() == 7); // global + function + try + 4 catch
@ -1602,23 +1602,23 @@ private:
// #ticket #3561 (throw C++)
void symboldatabase25() {
const std::string str("int main() {\n"
" foo bar;\n"
" throw bar;\n"
"}");
GET_SYMBOL_DB(str.c_str());
check(str.c_str(), false);
const char str[] = "int main() {\n"
" foo bar;\n"
" throw bar;\n"
"}";
GET_SYMBOL_DB(str);
check(str, false);
ASSERT_EQUALS("", errout.str());
ASSERT(db && db->getVariableListSize() == 2); // index 0 + 1 variable
}
// #ticket #3561 (throw C)
void symboldatabase26() {
const std::string str("int main() {\n"
" throw bar;\n"
"}");
GET_SYMBOL_DB_C(str.c_str());
check(str.c_str(), false);
const char str[] = "int main() {\n"
" throw bar;\n"
"}";
GET_SYMBOL_DB_C(str);
check(str, false);
ASSERT_EQUALS("", errout.str());
ASSERT(db && db->getVariableListSize() == 2); // index 0 + 1 variable
}
@ -1958,7 +1958,7 @@ private:
expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl;
std::stringstream actual;
actual << "Function call on line " << tok->linenr() << " calls function on line " << function->tokenDef->linenr() << std::endl;
ASSERT_EQUALS(expected.str().c_str(), actual.str().c_str());
ASSERT_EQUALS(expected.str(), actual.str());
}
index++;
}

View File

@ -603,41 +603,41 @@ private:
void tokenize1() {
const std::string code("void f ( )\n"
"{ if ( p . y ( ) > yof ) { } }");
ASSERT_EQUALS(code, tokenizeAndStringify(code.c_str()));
const char code[] = "void f ( )\n"
"{ if ( p . y ( ) > yof ) { } }";
ASSERT_EQUALS(code, tokenizeAndStringify(code));
}
void tokenize2() {
const std::string code("{ sizeof a, sizeof b }");
ASSERT_EQUALS("{ sizeof ( a ) , sizeof ( b ) }", tokenizeAndStringify(code.c_str()));
const char code[] = "{ sizeof a, sizeof b }";
ASSERT_EQUALS("{ sizeof ( a ) , sizeof ( b ) }", tokenizeAndStringify(code));
}
void tokenize3() {
const std::string code("void foo()\n"
"{\n"
" int i;\n"
" ABC(for(i=0;i<10;i++) x());\n"
"}");
const char code[] = "void foo()\n"
"{\n"
" int i;\n"
" ABC(for(i=0;i<10;i++) x());\n"
"}";
ASSERT_EQUALS("void foo ( )\n"
"{\n"
"int i ;\n"
"ABC ( for ( i = 0 ; i < 10 ; i ++ ) x ( ) ) ;\n"
"}", tokenizeAndStringify(code.c_str()));
"}", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout.str());
}
void tokenize4() {
const std::string code("class foo\n"
"{\n"
"public:\n"
" const int i;\n"
"}");
const char code[] = "class foo\n"
"{\n"
"public:\n"
" const int i;\n"
"}";
ASSERT_EQUALS("class foo\n"
"{\n"
"public:\n"
"const int i ;\n"
"}", tokenizeAndStringify(code.c_str()));
"}", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout.str());
}
@ -691,19 +691,19 @@ private:
}
void tokenize7() {
const std::string code = "void f() {\n"
" int x1 = 1;\n"
" int x2(x1);\n"
"}\n";
const char code[] = "void f() {\n"
" int x1 = 1;\n"
" int x2(x1);\n"
"}\n";
ASSERT_EQUALS("void f ( ) {\nint x1 ; x1 = 1 ;\nint x2 ; x2 = x1 ;\n}",
tokenizeAndStringify(code.c_str(), false));
tokenizeAndStringify(code, false));
}
void tokenize8() {
const std::string code = "void f() {\n"
" int x1(g());\n"
" int x2(x1);\n"
"}\n";
const char code[] = "void f() {\n"
" int x1(g());\n"
" int x2(x1);\n"
"}\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( ) {\n"
"2: int x1@1 ; x1@1 = g ( ) ;\n"
@ -849,25 +849,25 @@ private:
void wrong_syntax1() {
{
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", tokenizeAndStringify(code.c_str(), true));
const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))";
ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", tokenizeAndStringify(code, true));
ASSERT_EQUALS("", errout.str());
}
{
const std::string code("struct A { template<int> struct { }; };");
ASSERT_THROW(tokenizeAndStringify(code.c_str(), true), InternalError);
const char code[] ="struct A { template<int> struct { }; };";
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
}
{
const std::string code("enum ABC { A,B, typedef enum { C } };");
ASSERT_THROW(tokenizeAndStringify(code.c_str(), true), InternalError);
const char code[] ="enum ABC { A,B, typedef enum { C } };";
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
}
{
// #3314 - don't report syntax error.
const std::string code("struct A { typedef B::C (A::*f)(); };");
tokenizeAndStringify(code.c_str(), true);
const char code[] ="struct A { typedef B::C (A::*f)(); };";
tokenizeAndStringify(code, true);
ASSERT_EQUALS("[test.cpp:1]: (debug) Failed to parse 'typedef B :: C ( A :: * f ) ( ) ;'. The checking continues anyway.\n", errout.str());
}
}
@ -1054,8 +1054,8 @@ private:
void foreach() {
// #3690,#5154
const std::string code("void f() { for each ( char c in MyString ) { Console::Write(c); } }");
ASSERT_EQUALS("void f ( ) { asm ( \"char c in MyString\" ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code.c_str()));
const char code[] ="void f() { for each ( char c in MyString ) { Console::Write(c); } }";
ASSERT_EQUALS("void f ( ) { asm ( \"char c in MyString\" ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code));
}
void concatenateNegativeNumber() {
@ -3203,7 +3203,7 @@ private:
}
std::string tokenizeDebugListing(const std::string &code, bool simplify = false, const char filename[] = "test.cpp") {
std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") {
errout.str("");
Settings settings;
@ -3567,11 +3567,11 @@ private:
}
void varid16() {
const std::string code("void foo()\n"
"{\n"
" int x = 1;\n"
" y = (z * x);\n"
"}\n");
const char code[] ="void foo()\n"
"{\n"
" int x = 1;\n"
" y = (z * x);\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: void foo ( )\n"
@ -3584,11 +3584,11 @@ private:
}
void varid17() { // ticket #1810
const std::string code("char foo()\n"
"{\n"
" char c('c');\n"
" return c;\n"
"}\n");
const char code[] ="char foo()\n"
"{\n"
" char c('c');\n"
" return c;\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: char foo ( )\n"
@ -3601,10 +3601,10 @@ private:
}
void varid18() {
const std::string code("char foo(char c)\n"
"{\n"
" bar::c = c;\n"
"}\n");
const char code[] ="char foo(char c)\n"
"{\n"
" bar::c = c;\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: char foo ( char c@1 )\n"
@ -3616,10 +3616,10 @@ private:
}
void varid19() {
const std::string code("void foo()\n"
"{\n"
" std::pair<std::vector<double>, int> x;\n"
"}\n");
const char code[] ="void foo()\n"
"{\n"
" std::pair<std::vector<double>, int> x;\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: void foo ( )\n"
@ -3631,10 +3631,10 @@ private:
}
void varid20() {
const std::string code("void foo()\n"
"{\n"
" pair<vector<int>, vector<double> > x;\n"
"}\n");
const char code[] ="void foo()\n"
"{\n"
" pair<vector<int>, vector<double> > x;\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: void foo ( )\n"
@ -3646,13 +3646,13 @@ private:
}
void varid24() {
const std::string code("class foo()\n"
"{\n"
"public:\n"
" ;\n"
"private:\n"
" static int i;\n"
"};\n");
const char code[] ="class foo()\n"
"{\n"
"public:\n"
" ;\n"
"private:\n"
" static int i;\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class foo ( )\n"
@ -3667,13 +3667,13 @@ private:
}
void varid25() {
const std::string code("class foo()\n"
"{\n"
"public:\n"
" ;\n"
"private:\n"
" mutable int i;\n"
"};\n");
const char code[] ="class foo()\n"
"{\n"
"public:\n"
" ;\n"
"private:\n"
" mutable int i;\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class foo ( )\n"
@ -3688,15 +3688,15 @@ private:
}
void varid26() {
const std::string code("list<int (*)()> functions;\n");
const char code[] ="list<int (*)()> functions;\n";
const std::string expected("\n\n##file 0\n"
"1: list < int ( * ) ( ) > functions@1 ;\n");
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
}
void varid27() {
const std::string code("int fooled_ya;\n"
"fooled_ya::iterator iter;\n");
const char code[] ="int fooled_ya;\n"
"fooled_ya::iterator iter;\n";
const std::string expected("\n\n##file 0\n"
"1: int fooled_ya@1 ;\n"
"2: fooled_ya :: iterator iter@2 ;\n");
@ -3709,9 +3709,9 @@ private:
}
void varid29() {
const std::string code("class A {\n"
" B<C<1>,1> b;\n"
"};\n");
const char code[] ="class A {\n"
" B<C<1>,1> b;\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class A {\n"
"2: B < C < 1 > , 1 > b@1 ;\n"
@ -3720,11 +3720,11 @@ private:
}
void varid30() { // ticket #2614
const std::string code1("void f(EventPtr *eventP, ActionPtr **actionsP)\n"
"{\n"
" EventPtr event = *eventP;\n"
" *actionsP = &event->actions;\n"
"}\n");
const char code1[] = "void f(EventPtr *eventP, ActionPtr **actionsP)\n"
"{\n"
" EventPtr event = *eventP;\n"
" *actionsP = &event->actions;\n"
"}\n";
const std::string expected1("\n\n##file 0\n"
"1: void f ( EventPtr * eventP@1 , ActionPtr * * actionsP@2 )\n"
"2: {\n"
@ -3733,22 +3733,22 @@ private:
"5: }\n");
ASSERT_EQUALS(expected1, tokenizeDebugListing(code1, false, "test.c"));
const std::string code2("void f(int b, int c) {\n"
" x(a*b*c,10);\n"
"}\n");
const char code2[] = "void f(int b, int c) {\n"
" x(a*b*c,10);\n"
"}\n";
const std::string expected2("\n\n##file 0\n"
"1: void f ( int b@1 , int c@2 ) {\n"
"2: x ( a * b@1 * c@2 , 10 ) ;\n"
"3: }\n");
ASSERT_EQUALS(expected2, tokenizeDebugListing(code2, false, "test.c"));
const std::string code3("class Nullpointer : public ExecutionPath\n"
" {\n"
" Nullpointer(Check *c, const unsigned int id, const std::string &name)\n"
" : ExecutionPath(c, id)\n"
" {\n"
" }\n"
"}\n");
const char code3[] = "class Nullpointer : public ExecutionPath\n"
" {\n"
" Nullpointer(Check *c, const unsigned int id, const std::string &name)\n"
" : ExecutionPath(c, id)\n"
" {\n"
" }\n"
"}\n";
const std::string expected3("\n\n##file 0\n"
"1: class Nullpointer : public ExecutionPath\n"
"2: {\n"
@ -3761,31 +3761,31 @@ private:
}
void varid31() { // ticket #2831 (segmentation fault)
const std::string code("z<y<x>");
const char code[] ="z<y<x>";
tokenizeDebugListing(code);
ASSERT_EQUALS("", errout.str());
}
void varid32() { // ticket #2835 (segmentation fault)
const std::string code("><,f<i,");
const char code[] ="><,f<i,";
tokenizeDebugListing(code);
ASSERT_EQUALS("", errout.str());
}
void varid33() { // ticket #2875 (segmentation fault)
const std::string code("0; (a) < (a)");
const char code[] ="0; (a) < (a)";
tokenizeDebugListing(code, true);
ASSERT_EQUALS("", errout.str());
}
void varid34() { // ticket #2825
const std::string code("class Fred : public B1, public B2\n"
"{\n"
"public:\n"
" Fred() { a = 0; }\n"
"private:\n"
" int a;\n"
"};\n");
const char code[] ="class Fred : public B1, public B2\n"
"{\n"
"public:\n"
" Fred() { a = 0; }\n"
"private:\n"
" int a;\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class Fred : public B1 , public B2\n"
"2: {\n"
@ -3799,10 +3799,10 @@ private:
}
void varid35() { // ticket #2937
const std::string code("int foo() {\n"
" int f(x);\n"
" return f;\n"
"}\n");
const char code[] ="int foo() {\n"
" int f(x);\n"
" return f;\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: int foo ( ) {\n"
"2: int f@1 ( x ) ;\n"
@ -3812,25 +3812,25 @@ private:
}
void varid36() { // ticket #2980 (segmentation fault)
const std::string code("#elif A\n"
"A,a<b<x0\n");
const char code[] ="#elif A\n"
"A,a<b<x0\n";
tokenizeDebugListing(code);
ASSERT_EQUALS("", errout.str());
}
void varid37() {
{
const std::string code = "void blah() {"
" Bar bar(*x);"
"}";
const char code[] = "void blah() {"
" Bar bar(*x);"
"}";
ASSERT_EQUALS("\n\n##file 0\n1: "
"void blah ( ) { Bar bar@1 ( * x ) ; }\n",
tokenizeDebugListing(code));
}
{
const std::string code = "void blah() {"
" Bar bar(&x);"
"}";
const char code[] = "void blah() {"
" Bar bar(&x);"
"}";
ASSERT_EQUALS("\n\n##file 0\n1: "
"void blah ( ) { Bar bar@1 ( & x ) ; }\n",
tokenizeDebugListing(code));
@ -3838,7 +3838,7 @@ private:
}
void varid38() {
const std::string code = "FOO class C;\n";
const char code[] = "FOO class C;\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: FOO class C ;\n",
tokenizeDebugListing(code));
@ -3847,13 +3847,13 @@ private:
void varid39() {
// const..
{
const std::string code = "void f(FOO::BAR const);\n";
const char code[] = "void f(FOO::BAR const);\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( FOO :: BAR const ) ;\n",
tokenizeDebugListing(code));
}
{
const std::string code = "static int const SZ = 22;\n";
const char code[] = "static int const SZ = 22;\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: static const int SZ@1 = 22 ;\n",
tokenizeDebugListing(code, false, "test.c"));
@ -3861,30 +3861,30 @@ private:
}
void varid40() {
const std::string code("extern \"C\" int (*a())();");
const char code[] ="extern \"C\" int (*a())();";
ASSERT_EQUALS("\n\n##file 0\n"
"1: int ( * a ( ) ) ( ) ;\n",
tokenizeDebugListing(code));
}
void varid41() {
const std::string code1("union evt; void f(const evt & event);");
const char code1[] = "union evt; void f(const evt & event);";
ASSERT_EQUALS("\n\n##file 0\n"
"1: union evt ; void f ( const evt & event@1 ) ;\n",
tokenizeDebugListing(code1, false, "test.c"));
const std::string code2("struct evt; void f(const evt & event);");
const char code2[] = "struct evt; void f(const evt & event);";
ASSERT_EQUALS("\n\n##file 0\n"
"1: struct evt ; void f ( const evt & event@1 ) ;\n",
tokenizeDebugListing(code2, false, "test.c"));
}
void varid42() {
const std::string code("namespace fruit { struct banana {}; };\n"
"class Fred {\n"
"public:\n"
" struct fruit::banana Bananas[25];\n"
"};");
const char code[] ="namespace fruit { struct banana {}; };\n"
"class Fred {\n"
"public:\n"
" struct fruit::banana Bananas[25];\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: namespace fruit { struct banana { } ; } ;\n"
"2: class Fred {\n"
@ -3895,28 +3895,28 @@ private:
}
void varid43() {
const std::string code("int main(int flag) { if(a & flag) { return 1; } }");
const char code[] ="int main(int flag) { if(a & flag) { return 1; } }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: int main ( int flag@1 ) { if ( a & flag@1 ) { return 1 ; } }\n",
tokenizeDebugListing(code, false, "test.c"));
}
void varid44() {
const std::string code("class A:public B,public C,public D {};");
const char code[] ="class A:public B,public C,public D {};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A : public B , public C , public D { } ;\n",
tokenizeDebugListing(code));
}
void varid45() { // #3466
const std::string code("void foo() { B b(this); A a(this, b); }");
const char code[] ="void foo() { B b(this); A a(this, b); }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void foo ( ) { B b@1 ( this ) ; A a@2 ( this , b@1 ) ; }\n",
tokenizeDebugListing(code));
}
void varid46() { // #3756
const std::string code("void foo() { int t; x = (struct t *)malloc(); f(t); }");
const char code[] ="void foo() { int t; x = (struct t *)malloc(); f(t); }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void foo ( ) { int t@1 ; x = ( struct t * ) malloc ( ) ; f ( t@1 ) ; }\n",
tokenizeDebugListing(code, false, "test.c"));
@ -3925,7 +3925,7 @@ private:
void varid47() { // function parameters
// #3768
{
const std::string code("void f(std::string &string, std::string &len) {}");
const char code[] ="void f(std::string &string, std::string &len) {}";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( std :: string & string@1 , std :: string & len@2 ) { }\n",
tokenizeDebugListing(code, false, "test.cpp"));
@ -3945,37 +3945,37 @@ private:
}
void varid48() { // #3785 - return (a*b)
const std::string code("int X::f(int b) const { return(a*b); }");
const char code[] ="int X::f(int b) const { return(a*b); }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }\n",
tokenizeDebugListing(code, false, "test.c"));
}
void varid49() { // #3799 - void f(std::vector<int>)
const std::string code("void f(std::vector<int>)");
const char code[] ="void f(std::vector<int>)";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( std :: vector < int > )\n",
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid50() { // #3760 - explicit
const std::string code("class A { explicit A(const A&); };");
const char code[] ="class A { explicit A(const A&); };";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A { explicit A ( const A & ) ; } ;\n",
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid51() { // don't set varid on template function
const std::string code("T t; t.x<0>();");
const char code[] ="T t; t.x<0>();";
ASSERT_EQUALS("\n\n##file 0\n"
"1: T t@1 ; t@1 . x < 0 > ( ) ;\n",
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid52() {
const std::string code("A<B<C>::D> e;\n"
"B< C<> > b[10];\n"
"B<C<>> c[10];");
const char code[] ="A<B<C>::D> e;\n"
"B< C<> > b[10];\n"
"B<C<>> c[10];";
ASSERT_EQUALS("\n\n##file 0\n"
"1: A < B < C > :: D > e@1 ;\n"
"2: B < C < > > b@2 [ 10 ] ;\n"
@ -4023,10 +4023,10 @@ private:
}
void varidFunctionCall1() {
const std::string code("void f() {\n"
" int x;\n"
" x = a(y*x,10);\n"
"}");
const char code[] ="void f() {\n"
" int x;\n"
" x = a(y*x,10);\n"
"}";
const std::string expected("\n\n##file 0\n"
"1: void f ( ) {\n"
"2: int x@1 ;\n"
@ -4037,9 +4037,9 @@ private:
void varidFunctionCall2() {
// #2491
const std::string code("void f(int b) {\n"
" x(a*b,10);\n"
"}");
const char code[] ="void f(int b) {\n"
" x(a*b,10);\n"
"}";
const std::string expected1("\n\n##file 0\n"
"1: void f ( int b@1 ) {\n"
"2: x ( a * b");
@ -4050,10 +4050,10 @@ private:
void varidFunctionCall3() {
// Ticket #2339
const std::string code("void f() {\n"
" int a = 0;\n"
" int b = c - (foo::bar * a);\n"
"}");
const char code[] ="void f() {\n"
" int a = 0;\n"
" int b = c - (foo::bar * a);\n"
"}";
const std::string expected("\n\n##file 0\n"
"1: void f ( ) {\n"
@ -4066,14 +4066,14 @@ private:
void varidFunctionCall4() {
// Ticket #3280
const std::string code1("void f() { int x; fun(a,b*x); }");
const char code1[] = "void f() { int x; fun(a,b*x); }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( ) { int x@1 ; fun ( a , b * x@1 ) ; }\n",
tokenizeDebugListing(code1,false,"test.c"));
const std::string code2("void f(int a) { int x; fun(a,b*x); }");
tokenizeDebugListing(code1, false, "test.c"));
const char code2[] = "void f(int a) { int x; fun(a,b*x); }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( int a@1 ) { int x@2 ; fun ( a@1 , b * x@2 ) ; }\n",
tokenizeDebugListing(code2,false,"test.c"));
tokenizeDebugListing(code2, false, "test.c"));
}
@ -4310,12 +4310,12 @@ private:
}
void varid_in_class3() {
const std::string code = "class Foo {\n"
" void blah() {\n"
" Bar x(*this);\n" // <- ..
" }\n"
" int x;\n" // <- .. don't assign same varid
"};";
const char code[] = "class Foo {\n"
" void blah() {\n"
" Bar x(*this);\n" // <- ..
" }\n"
" int x;\n" // <- .. don't assign same varid
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class Foo {\n"
"2: void blah ( ) {\n"
@ -4326,9 +4326,9 @@ private:
}
void varid_in_class4() {
const std::string code = "class Foo {\n"
"public: class C;\n"
"};";
const char code[] = "class Foo {\n"
"public: class C;\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class Foo {\n"
"2: public: class C ;\n"
@ -4980,13 +4980,13 @@ private:
}
void varidclass8() {
const std::string code("class Fred {\n"
"public:\n"
" void foo(int d) {\n"
" int i = bar(x * d);\n"
" }\n"
" int x;\n"
"}\n");
const char code[] ="class Fred {\n"
"public:\n"
" void foo(int d) {\n"
" int i = bar(x * d);\n"
" }\n"
" int x;\n"
"}\n";
const std::string expected("\n\n##file 0\n"
"1: class Fred {\n"
@ -5001,15 +5001,15 @@ private:
}
void varidclass9() {
const std::string code("typedef char Str[10];"
"class A {\n"
"public:\n"
" void f(Str &cl);\n"
" void g(Str cl);\n"
"}\n"
"void Fred::f(Str &cl) {\n"
" sizeof(cl);\n"
"}");
const char code[] ="typedef char Str[10];"
"class A {\n"
"public:\n"
" void f(Str &cl);\n"
" void g(Str cl);\n"
"}\n"
"void Fred::f(Str &cl) {\n"
" sizeof(cl);\n"
"}";
const std::string expected("\n\n"
"##file 0\n"
@ -5026,12 +5026,12 @@ private:
}
void varidclass10() {
const std::string code("class A {\n"
" void f() {\n"
" a = 3;\n"
" }\n"
" int a;\n"
"};\n");
const char code[] ="class A {\n"
" void f() {\n"
" a = 3;\n"
" }\n"
" int a;\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class A {\n"
@ -5044,16 +5044,16 @@ private:
}
void varidclass11() {
const std::string code("class Fred {\n"
" int a;\n"
" void f();\n"
"};\n"
"class Wilma {\n"
" int a;\n"
" void f();\n"
"};\n"
"void Fred::f() { a = 0; }\n"
"void Wilma::f() { a = 0; }\n");
const char code[] ="class Fred {\n"
" int a;\n"
" void f();\n"
"};\n"
"class Wilma {\n"
" int a;\n"
" void f();\n"
"};\n"
"void Fred::f() { a = 0; }\n"
"void Wilma::f() { a = 0; }\n";
const std::string expected("\n\n##file 0\n"
"1: class Fred {\n"
@ -5071,10 +5071,10 @@ private:
}
void varidclass12() {
const std::string code("class Fred {\n"
" int a;\n"
" void f() { Fred::a = 0; }\n"
"};\n");
const char code[] ="class Fred {\n"
" int a;\n"
" void f() { Fred::a = 0; }\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class Fred {\n"
@ -5086,10 +5086,10 @@ private:
}
void varidclass13() {
const std::string code("class Fred {\n"
" int a;\n"
" void f() { Foo::Fred::a = 0; }\n"
"};\n");
const char code[] ="class Fred {\n"
" int a;\n"
" void f() { Foo::Fred::a = 0; }\n"
"};\n";
const std::string expected("\n\n##file 0\n"
"1: class Fred {\n"
@ -5103,9 +5103,9 @@ private:
void varidclass14() {
// don't give friend classes varid
{
const std::string code("class A {\n"
"friend class B;\n"
"}");
const char code[] ="class A {\n"
"friend class B;\n"
"}";
const std::string expected("\n\n##file 0\n"
"1: class A {\n"
@ -5116,9 +5116,9 @@ private:
}
{
const std::string code("class A {\n"
"private: friend class B;\n"
"}");
const char code[] ="class A {\n"
"private: friend class B;\n"
"}";
const std::string expected("\n\n##file 0\n"
"1: class A {\n"