Refactorization: Simplified code in tokenlist.cpp, token.cpp and testthreadexecutor.cpp

This commit is contained in:
Philipp Kloke 2015-10-18 20:28:17 +02:00
parent 5d12471caa
commit a837cc48e0
4 changed files with 50 additions and 85 deletions

View File

@ -191,43 +191,17 @@ void Token::deleteNext(unsigned long index)
void Token::swapWithNext() void Token::swapWithNext()
{ {
if (_next) { if (_next) {
Token temp(0); std::swap(_str, _next->_str);
std::swap(_tokType, _next->_tokType);
temp._str = _next->_str; std::swap(_flags, _next->_flags);
temp._tokType = _next->_tokType; std::swap(_varId, _next->_varId);
temp._flags = _next->_flags; std::swap(_fileIndex, _next->_fileIndex);
temp._varId = _next->_varId; std::swap(_link, _next->_link);
temp._fileIndex = _next->_fileIndex; std::swap(_scope, _next->_scope);
temp._link = _next->_link; std::swap(_function, _next->_function);
temp._scope = _next->_scope; std::swap(_originalName, _next->_originalName);
temp._function = _next->_function; std::swap(values, _next->values);
temp._originalName = _next->_originalName; std::swap(_progressValue, _next->_progressValue);
temp.values = _next->values;
temp._progressValue = _next->_progressValue;
_next->_str = _str;
_next->_tokType = _tokType;
_next->_flags = _flags;
_next->_varId = _varId;
_next->_fileIndex = _fileIndex;
_next->_link = _link;
_next->_scope = _scope;
_next->_function = _function;
_next->_originalName = _originalName;
_next->values = values;
_next->_progressValue = _progressValue;
_str = temp._str;
_tokType = temp._tokType;
_flags = temp._flags;
_varId = temp._varId;
_fileIndex = temp._fileIndex;
_link = temp._link;
_scope = temp._scope;
_function = temp._function;
_originalName = temp._originalName;
values = temp.values;
_progressValue = temp._progressValue;
} }
} }

View File

@ -108,7 +108,7 @@ void TokenList::deleteTokens(Token *tok)
// add a token. // add a token.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void TokenList::addtoken(const std::string & str, const unsigned int lineno, const unsigned int fileno, bool split) void TokenList::addtoken(std::string str, const unsigned int lineno, const unsigned int fileno, bool split)
{ {
if (str.empty()) if (str.empty())
return; return;
@ -129,23 +129,20 @@ void TokenList::addtoken(const std::string & str, const unsigned int lineno, con
} }
// Replace hexadecimal value with decimal // Replace hexadecimal value with decimal
std::string str2;
if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) { if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
std::ostringstream str2stream; std::ostringstream str2stream;
str2stream << MathLib::toULongNumber(str); str2stream << MathLib::toULongNumber(str);
str2 = str2stream.str(); str = str2stream.str();
} else if (str.compare(0, 5, "_Bool") == 0) { } else if (str.compare(0, 5, "_Bool") == 0) {
str2 = "bool"; str = "bool";
} else {
str2 = str;
} }
if (_back) { if (_back) {
_back->insertToken(str2); _back->insertToken(str);
} else { } else {
_front = new Token(&_back); _front = new Token(&_back);
_back = _front; _back = _front;
_back->str(str2); _back->str(str);
} }
if (isCPP() && str == "delete") if (isCPP() && str == "delete")

View File

@ -59,7 +59,7 @@ public:
*/ */
static void deleteTokens(Token *tok); static void deleteTokens(Token *tok);
void addtoken(const std::string & str, const unsigned int lineno, const unsigned int fileno, bool split = false); void addtoken(std::string str, const unsigned int lineno, const unsigned int fileno, bool split = false);
void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno); void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno);
static void insertTokens(Token *dest, const Token *src, unsigned int n); static void insertTokens(Token *dest, const Token *src, unsigned int n);

View File

@ -84,60 +84,54 @@ private:
} }
void many_threads() { void many_threads() {
std::ostringstream oss; check(20, 100, 100,
oss << "int main()\n" "int main()\n"
<< "{\n"; "{\n"
oss << " char *a = malloc(10);\n"; " char *a = malloc(10);\n"
oss << " return 0;\n" " return 0;\n"
<< "}"; "}");
check(20, 100, 100, oss.str());
} }
void no_errors_more_files() { void no_errors_more_files() {
std::ostringstream oss; check(2, 3, 0,
oss << "int main()\n" "int main()\n"
<< "{\n" "{\n"
<< " return 0;\n" " return 0;\n"
<< "}\n"; "}");
check(2, 3, 0, oss.str());
} }
void no_errors_less_files() { void no_errors_less_files() {
std::ostringstream oss; check(2, 1, 0,
oss << "int main()\n" "int main()\n"
<< "{\n" "{\n"
<< " return 0;\n" " return 0;\n"
<< "}\n"; "}");
check(2, 1, 0, oss.str());
} }
void no_errors_equal_amount_files() { void no_errors_equal_amount_files() {
std::ostringstream oss; check(2, 2, 0,
oss << "int main()\n" "int main()\n"
<< "{\n" "{\n"
<< " return 0;\n" " return 0;\n"
<< "}\n"; "}");
check(2, 2, 0, oss.str());
} }
void one_error_less_files() { void one_error_less_files() {
std::ostringstream oss; check(2, 1, 1,
oss << "int main()\n" "int main()\n"
<< "{\n" "{\n"
<< " {char *a = malloc(10);}\n" " {char *a = malloc(10);}\n"
<< " return 0;\n" " return 0;\n"
<< "}\n"; "}");
check(2, 1, 1, oss.str());
} }
void one_error_several_files() { void one_error_several_files() {
std::ostringstream oss; check(2, 20, 20,
oss << "int main()\n" "int main()\n"
<< "{\n" "{\n"
<< " {char *a = malloc(10);}\n" " {char *a = malloc(10);}\n"
<< " return 0;\n" " return 0;\n"
<< "}\n"; "}");
check(2, 20, 20, oss.str());
} }
}; };