tokenize: use mathlib when simplifying calculations (ticket: 236)

This commit is contained in:
Daniel Marjamäki 2009-04-06 19:23:30 +02:00
parent 97f5380a2c
commit 638d18cfc8
2 changed files with 11 additions and 20 deletions

View File

@ -166,7 +166,7 @@ src/threadexecutor.o: src/threadexecutor.cpp src/threadexecutor.h src/settings.h
src/token.o: src/token.cpp src/token.h
$(CXX) $(CXXFLAGS) -c -o src/token.o src/token.cpp
src/tokenize.o: src/tokenize.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/filelister.h
src/tokenize.o: src/tokenize.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/filelister.h src/mathlib.h
$(CXX) $(CXXFLAGS) -c -o src/tokenize.o src/tokenize.cpp
test/testautovariables.o: test/testautovariables.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkautovariables.h src/check.h test/testsuite.h

View File

@ -21,6 +21,7 @@
//---------------------------------------------------------------------------
#include "tokenize.h"
#include "filelister.h"
#include "mathlib.h"
#include <locale>
#include <fstream>
@ -2109,36 +2110,26 @@ bool Tokenizer::simplifyCalculations()
// (1-2)
if (Token::Match(tok, "[[,(=<>] %num% [+-*/] %num% [],);=<>]"))
{
int i1 = std::atoi(tok->strAt(1));
int i2 = std::atoi(tok->strAt(3));
if (i2 == 0 && *(tok->strAt(2)) == '/')
{
continue;
}
tok = tok->next();
switch (*(tok->strAt(2)))
switch (*(tok->strAt(1)))
{
case '+':
i1 += i2;
tok->str(MathLib::add(tok->str(), tok->strAt(2)).c_str());
break;
case '-':
i1 -= i2;
tok->str(MathLib::subtract(tok->str(), tok->strAt(2)).c_str());
break;
case '*':
i1 *= i2;
tok->str(MathLib::multiply(tok->str(), tok->strAt(2)).c_str());
break;
case '/':
i1 /= i2;
tok->str(MathLib::divide(tok->str(), tok->strAt(2)).c_str());
break;
}
tok = tok->next();
std::ostringstream str;
str << i1;
tok->str(str.str().c_str());
for (int i = 0; i < 2; i++)
{
tok->deleteNext();
}
tok->deleteNext();
tok->deleteNext();
ret = true;
}