From a1d0defbc0e8012d100c3e90161ef14435f15a86 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Fri, 2 Apr 2010 21:42:06 +0300 Subject: [PATCH 1/2] astyle fix --- lib/checkother.cpp | 6 +++--- lib/mathlib.cpp | 10 +++++----- test/testmathlib.cpp | 8 ++++---- test/testother.cpp | 4 ++-- test/testsuite.h | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 155d0ea9d..78f77d164 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2474,9 +2474,9 @@ void CheckOther::checkMathFunctions() { mathfunctionCallError(tok); } - // acos( x ) x is defined for intervall [-1,+1], but not beyound - else if(Token::Match(tok, "acos ( %num% )") && - fabs(MathLib::toDoubleNumber(tok->tokAt(2)->str())) > 1.0) + // acos( x ) x is defined for intervall [-1,+1], but not beyound + else if (Token::Match(tok, "acos ( %num% )") && + fabs(MathLib::toDoubleNumber(tok->tokAt(2)->str())) > 1.0) { mathfunctionCallError(tok); } diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 006e41a7e..18f055262 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -55,11 +55,11 @@ double MathLib::toDoubleNumber(const std::string &str) { return std::strtoul(str.c_str(), '\0', 16); } - // nullcheck - else if (str == "-0" || str == "-0.0" || str == "-0." - || str == "+0" || str == "+0.0" || str == "+0.") - return 0.0; - // otherwise, convert to double + // nullcheck + else if (str == "-0" || str == "-0.0" || str == "-0." + || str == "+0" || str == "+0.0" || str == "+0.") + return 0.0; + // otherwise, convert to double std::istringstream istr(str.c_str()); double ret; istr >> ret; diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index c59d75682..a682be854 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -116,9 +116,9 @@ private: ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.0E+1")); ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.0E-1")); - // ----------------- - // to double number: - // ----------------- + // ----------------- + // to double number: + // ----------------- ASSERT_EQUALS(10.0 , MathLib::toDoubleNumber("10")); ASSERT_EQUALS(1000.0, MathLib::toDoubleNumber("10E+2")); ASSERT_EQUALS(100.0 , MathLib::toDoubleNumber("1.0E+2")); @@ -135,7 +135,7 @@ private: ASSERT_EQUALS(0.0 , MathLib::toDoubleNumber("+0.")); ASSERT_EQUALS(0.0 , MathLib::toDoubleNumber("-0.0")); ASSERT_EQUALS(0.0 , MathLib::toDoubleNumber("+0.0")); - + } void isint() diff --git a/test/testother.cpp b/test/testother.cpp index 229ad3c58..990bf3b02 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2169,7 +2169,7 @@ private: void mathfunctionCall1() { - // log|log10 + // log|log10 check("void foo()\n" "{\n" " std::cout << log(-2) << std::endl;\n" @@ -2230,7 +2230,7 @@ private: "}"); TODO_ASSERT_EQUALS("", errout.str()); - // acos + // acos check("void foo()\n" "{\n" " std::cout << acos(1) << std::endl;\n" diff --git a/test/testsuite.h b/test/testsuite.h index 1eb5af95f..b872d15b9 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -43,9 +43,9 @@ protected: void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual); - // the vars expected and actual need to be of type double, in order to avoid overflow of unsigned int - // e.g: ASSERT_EQUALS(-100.0, MathLib::toDoubleNumber("-1.0E+2")); whould not work without this. - void assertEquals(const char *filename, int linenr, double expected, double actual); + // the vars expected and actual need to be of type double, in order to avoid overflow of unsigned int + // e.g: ASSERT_EQUALS(-100.0, MathLib::toDoubleNumber("-1.0E+2")); whould not work without this. + void assertEquals(const char *filename, int linenr, double expected, double actual); void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual); void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual); From ff38bbf468fd0cd68bc85f2cb0c8969cd0c62cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 2 Apr 2010 20:48:32 +0200 Subject: [PATCH 2/2] Cleanup: The Tokenizer doesn't need to handle UTF in code nor multiline string. That is handled in the Preprocessor. --- lib/tokenize.cpp | 8 +------- lib/tokenize.h | 6 +++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2edae2696..b8d7a81f8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -230,11 +230,8 @@ void Tokenizer::createTokens(std::istream &code) // Read one byte at a time from code and create tokens for (char ch = (char)code.get(); code.good(); ch = (char)code.get()) { - // We are not handling UTF and stuff like that. Code is supposed to plain simple text. - if (ch < 0) - continue; - // char/string.. + // multiline strings are not handled. The preprocessor should handle that for us. if (ch == '\'' || ch == '\"') { std::string line; @@ -247,9 +244,6 @@ void Tokenizer::createTokens(std::istream &code) // Append token.. line += c; - if (c == '\n') - ++lineno; - // Special sequence '\.' if (special) special = false; diff --git a/lib/tokenize.h b/lib/tokenize.h index 8664d0854..c38587464 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -71,7 +71,11 @@ public: /** * Create tokens from code. - * @param code input stream for code, same as what tokenize() + * The code must be preprocessed first: + * - multiline strings are not handled. + * - UTF in the code are not handled. + * - comments are not handled. + * @param code input stream for code */ void createTokens(std::istream &code);