From aa927d5aa382efeb98c381be684639812c8b1305 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 1 Jan 2012 22:55:05 +0200 Subject: [PATCH] Refactoring: Add new file lib/templatesimplifier.cpp The plan is to move template simplification into this new class to take some lines from 10 000 line tokenizer. --- Makefile | 62 ++++++++++++++++++----------------- cppcheck.cbp | 2 ++ lib/lib.pri | 2 ++ lib/templatesimplifier.cpp | 67 ++++++++++++++++++++++++++++++++++++++ lib/templatesimplifier.h | 50 ++++++++++++++++++++++++++++ lib/tokenize.cpp | 34 ++----------------- lib/tokenize.h | 7 ---- 7 files changed, 156 insertions(+), 68 deletions(-) create mode 100644 lib/templatesimplifier.cpp create mode 100644 lib/templatesimplifier.h diff --git a/Makefile b/Makefile index 86bae037e..ead084a1b 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,7 @@ LIBOBJ = lib/check64bit.o \ lib/settings.o \ lib/suppressions.o \ lib/symboldatabase.o \ + lib/templatesimplifier.o \ lib/timer.o \ lib/token.o \ lib/tokenize.o @@ -214,7 +215,7 @@ lib/checkassignif.o: lib/checkassignif.cpp lib/checkassignif.h lib/check.h lib/t lib/checkautovariables.o: lib/checkautovariables.cpp lib/checkautovariables.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/symboldatabase.h lib/mathlib.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/checkautovariables.o lib/checkautovariables.cpp -lib/checkboost.o: lib/checkboost.cpp lib/checkboost.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/symboldatabase.h lib/mathlib.h +lib/checkboost.o: lib/checkboost.cpp lib/checkboost.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/checkboost.o lib/checkboost.cpp lib/checkbufferoverrun.o: lib/checkbufferoverrun.cpp lib/checkbufferoverrun.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/mathlib.h lib/symboldatabase.h lib/executionpath.h @@ -250,7 +251,7 @@ lib/checkpostfixoperator.o: lib/checkpostfixoperator.cpp lib/checkpostfixoperato lib/checkstl.o: lib/checkstl.cpp lib/checkstl.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/executionpath.h lib/symboldatabase.h lib/mathlib.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/checkstl.o lib/checkstl.cpp -lib/checkuninitvar.o: lib/checkuninitvar.cpp lib/checkuninitvar.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h lib/checknullpointer.h +lib/checkuninitvar.o: lib/checkuninitvar.cpp lib/checkuninitvar.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h lib/checknullpointer.h lib/symboldatabase.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/checkuninitvar.o lib/checkuninitvar.cpp lib/checkunusedfunctions.o: lib/checkunusedfunctions.cpp lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h @@ -262,7 +263,7 @@ lib/checkunusedvar.o: lib/checkunusedvar.cpp lib/checkunusedvar.h lib/check.h li lib/cppcheck.o: lib/cppcheck.cpp lib/cppcheck.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/preprocessor.h lib/path.h lib/timer.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/cppcheck.o lib/cppcheck.cpp -lib/errorlogger.o: lib/errorlogger.cpp lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h lib/path.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h +lib/errorlogger.o: lib/errorlogger.cpp lib/errorlogger.h lib/suppressions.h lib/path.h lib/cppcheck.h lib/settings.h lib/standards.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/errorlogger.o lib/errorlogger.cpp lib/executionpath.o: lib/executionpath.cpp lib/executionpath.h lib/token.h @@ -274,7 +275,7 @@ lib/mathlib.o: lib/mathlib.cpp lib/mathlib.h lib/tokenize.h lib/path.o: lib/path.cpp lib/path.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/path.o lib/path.cpp -lib/preprocessor.o: lib/preprocessor.cpp lib/preprocessor.h lib/tokenize.h lib/token.h lib/path.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h +lib/preprocessor.o: lib/preprocessor.cpp lib/preprocessor.h lib/tokenize.h lib/token.h lib/path.h lib/errorlogger.h lib/suppressions.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/preprocessor.o lib/preprocessor.cpp lib/settings.o: lib/settings.cpp lib/settings.h lib/suppressions.h lib/standards.h lib/path.h lib/preprocessor.h @@ -286,31 +287,34 @@ lib/suppressions.o: lib/suppressions.cpp lib/suppressions.h lib/settings.h lib/s lib/symboldatabase.o: lib/symboldatabase.cpp lib/symboldatabase.h lib/token.h lib/mathlib.h lib/tokenize.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/check.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/symboldatabase.o lib/symboldatabase.cpp +lib/templatesimplifier.o: lib/templatesimplifier.cpp lib/token.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/templatesimplifier.o lib/templatesimplifier.cpp + lib/timer.o: lib/timer.cpp lib/timer.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/timer.o lib/timer.cpp -lib/token.o: lib/token.cpp lib/token.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h lib/check.h lib/tokenize.h +lib/token.o: lib/token.cpp lib/token.h lib/errorlogger.h lib/suppressions.h lib/check.h lib/tokenize.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/token.o lib/token.cpp -lib/tokenize.o: lib/tokenize.cpp lib/tokenize.h lib/token.h lib/mathlib.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/check.h lib/path.h lib/symboldatabase.h +lib/tokenize.o: lib/tokenize.cpp lib/tokenize.h lib/token.h lib/mathlib.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/check.h lib/path.h lib/symboldatabase.h lib/templatesimplifier.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_LIB} -c -o lib/tokenize.o lib/tokenize.cpp cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cppcheck.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/timer.h cli/cmdlineparser.h lib/path.h cli/filelister.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_CLI} -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp -cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h lib/preprocessor.h cli/cmdlineparser.h cli/filelister.h lib/path.h cli/pathmatch.h +cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/suppressions.h lib/settings.h lib/standards.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h lib/preprocessor.h cli/cmdlineparser.h cli/filelister.h lib/path.h cli/pathmatch.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_CLI} -c -o cli/cppcheckexecutor.o cli/cppcheckexecutor.cpp cli/filelister.o: cli/filelister.cpp cli/filelister.h lib/path.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_CLI} -c -o cli/filelister.o cli/filelister.cpp -cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h +cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/suppressions.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_CLI} -c -o cli/main.o cli/main.cpp cli/pathmatch.o: cli/pathmatch.cpp cli/pathmatch.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_CLI} -c -o cli/pathmatch.o cli/pathmatch.cpp -cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h cli/threadexecutor.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h +cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/suppressions.h lib/settings.h lib/standards.h cli/threadexecutor.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_CLI} -c -o cli/threadexecutor.o cli/threadexecutor.cpp test/options.o: test/options.cpp test/options.h @@ -334,13 +338,13 @@ test/testbufferoverrun.o: test/testbufferoverrun.cpp lib/tokenize.h lib/checkbuf test/testcharvar.o: test/testcharvar.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testcharvar.o test/testcharvar.cpp -test/testclass.o: test/testclass.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/symboldatabase.h lib/mathlib.h test/testsuite.h test/redirect.h +test/testclass.o: test/testclass.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testclass.o test/testclass.cpp -test/testcmdlineparser.o: test/testcmdlineparser.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h +test/testcmdlineparser.o: test/testcmdlineparser.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testcmdlineparser.o test/testcmdlineparser.cpp -test/testconstructors.o: test/testconstructors.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/symboldatabase.h lib/mathlib.h test/testsuite.h test/redirect.h +test/testconstructors.o: test/testconstructors.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testconstructors.o test/testconstructors.cpp test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h test/redirect.h lib/path.h @@ -355,19 +359,19 @@ test/testerrorlogger.o: test/testerrorlogger.cpp lib/cppcheck.h lib/settings.h l test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/tokenize.h lib/checkexceptionsafety.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp -test/testfilelister.o: test/testfilelister.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h +test/testfilelister.o: test/testfilelister.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testfilelister.o test/testfilelister.cpp -test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h +test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testincompletestatement.o test/testincompletestatement.cpp test/testinternal.o: test/testinternal.cpp lib/tokenize.h lib/checkinternal.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testinternal.o test/testinternal.cpp -test/testmathlib.o: test/testmathlib.cpp lib/mathlib.h test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h +test/testmathlib.o: test/testmathlib.cpp lib/mathlib.h test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testmathlib.o test/testmathlib.cpp -test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/checkmemoryleak.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/symboldatabase.h lib/mathlib.h test/testsuite.h test/redirect.h +test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/checkmemoryleak.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testmemleak.o test/testmemleak.cpp test/testnonreentrantfunctions.o: test/testnonreentrantfunctions.cpp lib/tokenize.h lib/checknonreentrantfunctions.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h @@ -379,60 +383,60 @@ test/testnullpointer.o: test/testnullpointer.cpp lib/tokenize.h lib/checknullpoi test/testobsoletefunctions.o: test/testobsoletefunctions.cpp lib/tokenize.h lib/checkobsoletefunctions.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testobsoletefunctions.o test/testobsoletefunctions.cpp -test/testoptions.o: test/testoptions.cpp test/options.h test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h +test/testoptions.o: test/testoptions.cpp test/options.h test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testoptions.o test/testoptions.cpp test/testother.o: test/testother.cpp lib/preprocessor.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testother.o test/testother.cpp -test/testpath.o: test/testpath.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/path.h +test/testpath.o: test/testpath.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/path.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testpath.o test/testpath.cpp -test/testpathmatch.o: test/testpathmatch.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h +test/testpathmatch.o: test/testpathmatch.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testpathmatch.o test/testpathmatch.cpp test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/tokenize.h lib/checkpostfixoperator.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testpostfixoperator.o test/testpostfixoperator.cpp -test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/preprocessor.h lib/tokenize.h lib/token.h +test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/preprocessor.h lib/tokenize.h lib/token.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testpreprocessor.o test/testpreprocessor.cpp -test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h test/options.h +test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h test/options.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testrunner.o test/testrunner.cpp -test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/tokenize.h lib/token.h +test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testsimplifytokens.o test/testsimplifytokens.cpp test/teststl.o: test/teststl.cpp lib/tokenize.h lib/checkstl.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/teststl.o test/teststl.cpp -test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h test/options.h +test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h test/options.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testsuite.o test/testsuite.cpp test/testsuppressions.o: test/testsuppressions.cpp lib/cppcheck.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testsuppressions.o test/testsuppressions.cpp -test/testsymboldatabase.o: test/testsymboldatabase.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h test/testutils.h lib/tokenize.h lib/token.h lib/symboldatabase.h lib/mathlib.h +test/testsymboldatabase.o: test/testsymboldatabase.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h test/testutils.h lib/settings.h lib/standards.h lib/tokenize.h lib/symboldatabase.h lib/token.h lib/mathlib.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testsymboldatabase.o test/testsymboldatabase.cpp test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp -test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h test/testutils.h lib/tokenize.h lib/token.h +test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h test/testutils.h lib/settings.h lib/standards.h lib/tokenize.h lib/token.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testtoken.o test/testtoken.cpp -test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/tokenize.h lib/token.h +test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testtokenize.o test/testtokenize.cpp test/testuninitvar.o: test/testuninitvar.cpp lib/tokenize.h lib/checkuninitvar.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testuninitvar.o test/testuninitvar.cpp -test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/checkunusedfunctions.h lib/check.h lib/token.h +test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testunusedfunctions.o test/testunusedfunctions.cpp -test/testunusedprivfunc.o: test/testunusedprivfunc.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/symboldatabase.h lib/mathlib.h test/testsuite.h test/redirect.h +test/testunusedprivfunc.o: test/testunusedprivfunc.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp -test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/suppressions.h lib/standards.h test/redirect.h lib/tokenize.h lib/checkunusedvar.h lib/check.h lib/token.h +test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h lib/tokenize.h lib/checkunusedvar.h lib/check.h lib/token.h lib/settings.h lib/standards.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testunusedvar.o test/testunusedvar.cpp diff --git a/cppcheck.cbp b/cppcheck.cbp index ccb1c5d78..e79b38d0d 100644 --- a/cppcheck.cbp +++ b/cppcheck.cbp @@ -159,6 +159,8 @@ + + diff --git a/lib/lib.pri b/lib/lib.pri index bdf7db8f2..5234324e0 100644 --- a/lib/lib.pri +++ b/lib/lib.pri @@ -30,6 +30,7 @@ HEADERS += $${BASEPATH}check.h \ $${BASEPATH}settings.h \ $${BASEPATH}suppressions.h \ $${BASEPATH}symboldatabase.h \ + $${BASEPATH}templatesimplifier.h \ $${BASEPATH}timer.h \ $${BASEPATH}token.h \ $${BASEPATH}tokenize.h @@ -61,6 +62,7 @@ SOURCES += $${BASEPATH}check64bit.cpp \ $${BASEPATH}settings.cpp \ $${BASEPATH}suppressions.cpp \ $${BASEPATH}symboldatabase.cpp \ + $${BASEPATH}templatesimplifier.cpp \ $${BASEPATH}timer.cpp \ $${BASEPATH}token.cpp \ $${BASEPATH}tokenize.cpp diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp new file mode 100644 index 000000000..245e6f2fa --- /dev/null +++ b/lib/templatesimplifier.cpp @@ -0,0 +1,67 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "templatesimplifier.h" +#include "token.h" + +//--------------------------------------------------------------------------- +#ifdef _MSC_VER +#pragma warning(disable: 4503) +#endif + + + +//--------------------------------------------------------------------------- + +TemplateSimplifier::TemplateSimplifier() +{ +} + +TemplateSimplifier::~TemplateSimplifier() +{ +} + +void TemplateSimplifier::cleanupAfterSimplify(Token *tokens) +{ + bool goback = false; + for (Token *tok = tokens; tok; tok = tok->next()) { + if (goback) { + tok = tok->previous(); + goback = false; + } + if (tok->str() == "(") + tok = tok->link(); + + else if (Token::Match(tok, "%type% <") && + (!tok->previous() || tok->previous()->str() == ";")) { + const Token *tok2 = tok->tokAt(2); + std::string type; + while (Token::Match(tok2, "%type% ,") || Token::Match(tok2, "%num% ,")) { + type += tok2->str() + ","; + tok2 = tok2->tokAt(2); + } + if (Token::Match(tok2, "%type% > (") || Token::Match(tok2, "%num% > (")) { + type += tok2->str(); + tok->str(tok->str() + "<" + type + ">"); + Token::eraseTokens(tok, tok2->tokAt(2)); + if (tok == tokens) + goback = true; + } + } + } +} diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h new file mode 100644 index 000000000..c93207bc3 --- /dev/null +++ b/lib/templatesimplifier.h @@ -0,0 +1,50 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +//--------------------------------------------------------------------------- +#ifndef templatesimplifierH +#define templatesimplifierH +//--------------------------------------------------------------------------- + + + +class Token; + + +/// @addtogroup Core +/// @{ + +/** @brief Simplify templates from the preprocessed and partially simplified code. */ +class TemplateSimplifier { +public: + TemplateSimplifier(); + virtual ~TemplateSimplifier(); + + /** + * Used after simplifyTemplates to perform a little cleanup. + * Sometimes the simplifyTemplates isn't fully successful and then + * there are function calls etc with "wrong" syntax. + */ + static void cleanupAfterSimplify(Token *tokens); +}; + +/// @} + +//--------------------------------------------------------------------------- +#endif diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 314e96e81..b29da75f8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -30,6 +30,7 @@ #include "check.h" #include "path.h" #include "symboldatabase.h" +#include "templatesimplifier.h" #include #include @@ -2324,7 +2325,7 @@ bool Tokenizer::tokenize(std::istream &code, // then unsimplified function calls etc remain. These have the // "wrong" syntax. So this function will just fix so that the // syntax is corrected. - simplifyTemplates2(); + TemplateSimplifier::cleanupAfterSimplify(_tokens); // Simplify the operator "?:" simplifyConditionOperator(); @@ -3519,37 +3520,6 @@ void Tokenizer::simplifyTemplates() } //--------------------------------------------------------------------------- -void Tokenizer::simplifyTemplates2() -{ - bool goback = false; - for (Token *tok = _tokens; tok; tok = tok->next()) { - if (goback) { - tok = tok->previous(); - goback = false; - } - if (tok->str() == "(") - tok = tok->link(); - - else if (Token::Match(tok, "%type% <") && - (!tok->previous() || tok->previous()->str() == ";")) { - const Token *tok2 = tok->tokAt(2); - std::string type; - while (Token::Match(tok2, "%type% ,") || Token::Match(tok2, "%num% ,")) { - type += tok2->str() + ","; - tok2 = tok2->tokAt(2); - } - if (Token::Match(tok2, "%type% > (") || Token::Match(tok2, "%num% > (")) { - type += tok2->str(); - tok->str(tok->str() + "<" + type + ">"); - Token::eraseTokens(tok, tok2->tokAt(2)); - if (tok == _tokens) - goback = true; - } - } - } -} -//--------------------------------------------------------------------------- - std::string Tokenizer::getNameForFunctionParams(const Token *start) { if (start->next() == start->link()) diff --git a/lib/tokenize.h b/lib/tokenize.h index 94d080f66..cbb819d9f 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -543,13 +543,6 @@ public: */ int simplifyTemplatesGetTemplateNamePosition(const Token *tok); - /** - * Used after simplifyTemplates to perform a little cleanup. - * Sometimes the simplifyTemplates isn't fully successful and then - * there are function calls etc with "wrong" syntax. - */ - void simplifyTemplates2(); - /** * Simplify e.g. 'atol("0")' into '0' */