tokenize: use mathlib when simplifying calculations (ticket: 236)
This commit is contained in:
parent
97f5380a2c
commit
638d18cfc8
2
Makefile
2
Makefile
|
@ -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
|
src/token.o: src/token.cpp src/token.h
|
||||||
$(CXX) $(CXXFLAGS) -c -o src/token.o src/token.cpp
|
$(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
|
$(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
|
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
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "filelister.h"
|
#include "filelister.h"
|
||||||
|
#include "mathlib.h"
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -2109,36 +2110,26 @@ bool Tokenizer::simplifyCalculations()
|
||||||
// (1-2)
|
// (1-2)
|
||||||
if (Token::Match(tok, "[[,(=<>] %num% [+-*/] %num% [],);=<>]"))
|
if (Token::Match(tok, "[[,(=<>] %num% [+-*/] %num% [],);=<>]"))
|
||||||
{
|
{
|
||||||
int i1 = std::atoi(tok->strAt(1));
|
tok = tok->next();
|
||||||
int i2 = std::atoi(tok->strAt(3));
|
|
||||||
if (i2 == 0 && *(tok->strAt(2)) == '/')
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (*(tok->strAt(2)))
|
switch (*(tok->strAt(1)))
|
||||||
{
|
{
|
||||||
case '+':
|
case '+':
|
||||||
i1 += i2;
|
tok->str(MathLib::add(tok->str(), tok->strAt(2)).c_str());
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
i1 -= i2;
|
tok->str(MathLib::subtract(tok->str(), tok->strAt(2)).c_str());
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
i1 *= i2;
|
tok->str(MathLib::multiply(tok->str(), tok->strAt(2)).c_str());
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
i1 /= i2;
|
tok->str(MathLib::divide(tok->str(), tok->strAt(2)).c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tok = tok->next();
|
|
||||||
std::ostringstream str;
|
tok->deleteNext();
|
||||||
str << i1;
|
|
||||||
tok->str(str.str().c_str());
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue