Add support for user defined rules

This commit is contained in:
Daniel Marjamäki 2010-12-12 11:56:22 +01:00
parent 1ece516816
commit 2d3865a671
17 changed files with 258 additions and 68 deletions

107
Makefile
View File

@ -86,22 +86,23 @@ TESTOBJ = test/options.o \
test/testuninitvar.o \ test/testuninitvar.o \
test/testunusedfunctions.o \ test/testunusedfunctions.o \
test/testunusedprivfunc.o \ test/testunusedprivfunc.o \
test/testunusedvar.o \ test/testunusedvar.o
test/tinyxml/tinystr.o \
test/tinyxml/tinyxml.o \ EXTOBJ = externals/tinyxml/tinystr.o \
test/tinyxml/tinyxmlerror.o \ externals/tinyxml/tinyxml.o \
test/tinyxml/tinyxmlparser.o externals/tinyxml/tinyxmlerror.o \
externals/tinyxml/tinyxmlparser.o
###### Targets ###### Targets
cppcheck: $(LIBOBJ) $(CLIOBJ) cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)
$(CXX) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(LDFLAGS) $(CXX) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)
all: cppcheck testrunner all: cppcheck testrunner
testrunner: $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o
$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS) $(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS)
test: all test: all
./testrunner ./testrunner
@ -210,125 +211,113 @@ lib/tokenize.o: lib/tokenize.cpp lib/tokenize.h lib/token.h lib/filelister.h lib
$(CXX) $(CXXFLAGS) -Ilib -c -o lib/tokenize.o lib/tokenize.cpp $(CXX) $(CXXFLAGS) -Ilib -c -o lib/tokenize.o lib/tokenize.cpp
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/timer.h cli/cmdlineparser.h cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/timer.h cli/cmdlineparser.h
$(CXX) $(CXXFLAGS) -Ilib -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp $(CXX) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h cli/cmdlineparser.h lib/filelister.h cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h cli/cmdlineparser.h lib/filelister.h
$(CXX) $(CXXFLAGS) -Ilib -c -o cli/cppcheckexecutor.o cli/cppcheckexecutor.cpp $(CXX) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/cppcheckexecutor.o cli/cppcheckexecutor.cpp
cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -c -o cli/main.o cli/main.cpp $(CXX) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/main.o cli/main.cpp
cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h
$(CXX) $(CXXFLAGS) -Ilib -c -o cli/threadexecutor.o cli/threadexecutor.cpp $(CXX) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/threadexecutor.o cli/threadexecutor.cpp
test/options.o: test/options.cpp test/options.h test/options.o: test/options.cpp test/options.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/options.o test/options.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/options.o test/options.cpp
test/testautovariables.o: test/testautovariables.cpp lib/tokenize.h lib/checkautovariables.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testautovariables.o: test/testautovariables.cpp lib/tokenize.h lib/checkautovariables.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testautovariables.o test/testautovariables.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testautovariables.o test/testautovariables.cpp
test/testbufferoverrun.o: test/testbufferoverrun.cpp lib/tokenize.h lib/checkbufferoverrun.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h lib/mathlib.h test/testsuite.h test/redirect.h test/testbufferoverrun.o: test/testbufferoverrun.cpp lib/tokenize.h lib/checkbufferoverrun.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h lib/mathlib.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testbufferoverrun.o test/testbufferoverrun.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testbufferoverrun.o test/testbufferoverrun.cpp
test/testcharvar.o: test/testcharvar.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testcharvar.o: test/testcharvar.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testcharvar.o test/testcharvar.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -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/errorlogger.h lib/symboldatabase.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/errorlogger.h lib/symboldatabase.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testclass.o test/testclass.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testclass.o test/testclass.cpp
test/testcmdlineparser.o: test/testcmdlineparser.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/settings.h test/testcmdlineparser.o: test/testcmdlineparser.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testcmdlineparser.o test/testcmdlineparser.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -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/errorlogger.h lib/symboldatabase.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/errorlogger.h lib/symboldatabase.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testconstructors.o test/testconstructors.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testconstructors.o test/testconstructors.cpp
test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.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 test/tinyxml/tinyxml.h test/tinyxml/tinystr.h test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.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
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testcppcheck.o test/testcppcheck.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testcppcheck.o test/testcppcheck.cpp
test/testdivision.o: test/testdivision.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testdivision.o: test/testdivision.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testdivision.o test/testdivision.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testdivision.o test/testdivision.cpp
test/testerrorlogger.o: test/testerrorlogger.cpp test/testsuite.h lib/errorlogger.h test/redirect.h test/testerrorlogger.o: test/testerrorlogger.cpp test/testsuite.h lib/errorlogger.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testerrorlogger.o test/testerrorlogger.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testerrorlogger.o test/testerrorlogger.cpp
test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/tokenize.h lib/checkexceptionsafety.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/tokenize.h lib/checkexceptionsafety.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp
test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testincompletestatement.o test/testincompletestatement.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testincompletestatement.o test/testincompletestatement.cpp
test/testmathlib.o: test/testmathlib.cpp lib/mathlib.h test/testsuite.h lib/errorlogger.h test/redirect.h test/testmathlib.o: test/testmathlib.cpp lib/mathlib.h test/testsuite.h lib/errorlogger.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testmathlib.o test/testmathlib.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -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/errorlogger.h lib/symboldatabase.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/errorlogger.h lib/symboldatabase.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testmemleak.o test/testmemleak.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testmemleak.o test/testmemleak.cpp
test/testnullpointer.o: test/testnullpointer.cpp lib/tokenize.h lib/checknullpointer.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testnullpointer.o: test/testnullpointer.cpp lib/tokenize.h lib/checknullpointer.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testnullpointer.o test/testnullpointer.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testnullpointer.o test/testnullpointer.cpp
test/testobsoletefunctions.o: test/testobsoletefunctions.cpp lib/tokenize.h lib/checkobsoletefunctions.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testobsoletefunctions.o: test/testobsoletefunctions.cpp lib/tokenize.h lib/checkobsoletefunctions.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testobsoletefunctions.o test/testobsoletefunctions.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testobsoletefunctions.o test/testobsoletefunctions.cpp
test/testoptions.o: test/testoptions.cpp test/options.h test/testsuite.h lib/errorlogger.h test/redirect.h test/testoptions.o: test/testoptions.cpp test/options.h test/testsuite.h lib/errorlogger.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testoptions.o test/testoptions.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testoptions.o test/testoptions.cpp
test/testother.o: test/testother.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testother.o: test/testother.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testother.o test/testother.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testother.o test/testother.cpp
test/testpath.o: test/testpath.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/path.h test/testpath.o: test/testpath.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/path.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testpath.o test/testpath.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpath.o test/testpath.cpp
test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/tokenize.h lib/checkpostfixoperator.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/tokenize.h lib/checkpostfixoperator.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testpostfixoperator.o test/testpostfixoperator.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpostfixoperator.o test/testpostfixoperator.cpp
test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/preprocessor.h lib/tokenize.h lib/token.h lib/settings.h test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/preprocessor.h lib/tokenize.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testpreprocessor.o test/testpreprocessor.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpreprocessor.o test/testpreprocessor.cpp
test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h test/redirect.h test/options.h test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h test/redirect.h test/options.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testrunner.o test/testrunner.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testrunner.o test/testrunner.cpp
test/testsettings.o: test/testsettings.cpp lib/settings.h test/testsuite.h lib/errorlogger.h test/redirect.h test/testsettings.o: test/testsettings.cpp lib/settings.h test/testsuite.h lib/errorlogger.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsettings.o test/testsettings.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testsettings.o test/testsettings.cpp
test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsimplifytokens.o test/testsimplifytokens.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -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/errorlogger.h test/testsuite.h test/redirect.h test/teststl.o: test/teststl.cpp lib/tokenize.h lib/checkstl.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/teststl.o test/teststl.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/teststl.o test/teststl.cpp
test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h test/redirect.h test/options.h test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h test/redirect.h test/options.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsuite.o test/testsuite.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testsuite.o test/testsuite.cpp
test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h test/redirect.h test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp
test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testtoken.o test/testtoken.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testtoken.o test/testtoken.cpp
test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testtokenize.o test/testtokenize.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -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/errorlogger.h test/testsuite.h test/redirect.h test/testuninitvar.o: test/testuninitvar.cpp lib/tokenize.h lib/checkuninitvar.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testuninitvar.o test/testuninitvar.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testuninitvar.o test/testuninitvar.cpp
test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h test/testsuite.h lib/errorlogger.h test/redirect.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/settings.h test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h test/testsuite.h lib/errorlogger.h test/redirect.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedfunctions.o test/testunusedfunctions.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -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/errorlogger.h lib/symboldatabase.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/errorlogger.h lib/symboldatabase.h test/testsuite.h test/redirect.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp
test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedvar.o test/testunusedvar.cpp $(CXX) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testunusedvar.o test/testunusedvar.cpp
test/tinyxml/tinystr.o: test/tinyxml/tinystr.cpp test/tinyxml/tinystr.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/tinyxml/tinystr.o test/tinyxml/tinystr.cpp
test/tinyxml/tinyxml.o: test/tinyxml/tinyxml.cpp test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/tinyxml/tinyxml.o test/tinyxml/tinyxml.cpp
test/tinyxml/tinyxmlerror.o: test/tinyxml/tinyxmlerror.cpp test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/tinyxml/tinyxmlerror.o test/tinyxml/tinyxmlerror.cpp
test/tinyxml/tinyxmlparser.o: test/tinyxml/tinyxmlparser.cpp test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/tinyxml/tinyxmlparser.o test/tinyxml/tinyxmlparser.cpp

36
build.txt Normal file
View File

@ -0,0 +1,36 @@
Some temporary build instructions. This is work in progress.
The tinyxml and pcre libraries are needed. The tinyxml is not really needed, these
files could be integrated into the CLI instead.
Windows
Visual Studio
To build pcre I downloaded the sourcecode from www.pcre.org. I downloaded cmake 2.8.
Then I built the lib with:
cmake .
nmake
To build tinyxml I just built all the files in externals/tinyxml
MINGW (Qt 4.7 SDK)
I downloaded pcre-8.0-lib.zip from here: http://software-download.name/pcre-library-windows/
I build libtinyxml.a with:
cd externals/tinyxml
qmake
jom
Linux
The normal Makefile should work
Install pcre on ubuntu might be needed:
sudo apt-get install libpcre3 libpcre3-dev

View File

@ -1,18 +1,21 @@
TEMPLATE = app TEMPLATE = app
TARGET = cppcheck TARGET = cppcheck
DEPENDPATH += . DEPENDPATH += .
INCLUDEPATH += . ../lib INCLUDEPATH += . ../lib ../externals
OBJECTS_DIR = temp OBJECTS_DIR = temp
CONFIG += warn_on CONFIG += warn_on
CONFIG -= qt app_bundle CONFIG -= qt app_bundle
include($$PWD/../externals/tinyxml/tinyxml.pri)
include($$PWD/../lib/lib.pri) include($$PWD/../lib/lib.pri)
SOURCES += main.cpp \ SOURCES += main.cpp \
cppcheckexecutor.cpp \ cppcheckexecutor.cpp \
cmdlineparser.cpp \
threadexecutor.cpp threadexecutor.cpp
HEADERS += cppcheckexecutor.cpp \ HEADERS += cppcheckexecutor.h \
threadexecutor.cpp cmdlineparser.h \
threadexecutor.h
CONFIG(release, debug|release) { CONFIG(release, debug|release) {
DEFINES += NDEBUG DEFINES += NDEBUG

View File

@ -26,6 +26,8 @@
#include "settings.h" #include "settings.h"
#include "cmdlineparser.h" #include "cmdlineparser.h"
// xml is used in rules
#include "tinyxml/tinyxml.h"
static void AddFilesToList(const std::string& FileList, std::vector<std::string>& PathNames) static void AddFilesToList(const std::string& FileList, std::vector<std::string>& PathNames)
{ {
@ -387,6 +389,56 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->_showtime = SHOWTIME_NONE; _settings->_showtime = SHOWTIME_NONE;
} }
// Rules are a debug feature
#ifndef NDEBUG
// Rule given at command line
else if (strncmp(argv[i], "--rule=", 7) == 0)
{
Settings::Rule rule;
rule.pattern = 7 + argv[i];
_settings->rules.push_back(rule);
}
// Rule file
else if (strncmp(argv[i], "--rule-file=", 12) == 0)
{
TiXmlDocument doc;
if (doc.LoadFile(12+argv[i]))
{
TiXmlElement *root = doc.FirstChildElement();
if (root && root->ValueStr() == "rule")
{
Settings::Rule rule;
TiXmlElement *pattern = root->FirstChildElement("pattern");
if (pattern)
{
rule.pattern = pattern->GetText();
}
TiXmlElement *message = root->FirstChildElement("message");
if (message)
{
TiXmlElement *severity = message->FirstChildElement("severity");
if (severity)
rule.severity = severity->GetText();
TiXmlElement *id = message->FirstChildElement("id");
if (id)
rule.id = id->GetText();
TiXmlElement *summary = message->FirstChildElement("summary");
if (summary)
rule.summary = summary->GetText();
}
if (!rule.pattern.empty())
_settings->rules.push_back(rule);
}
}
}
#endif
// Print help // Print help
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{ {

3
externals/tinyxml/tinyxml.pri vendored Normal file
View File

@ -0,0 +1,3 @@
HEADERS += $$PWD/tinystr.h $$PWD/tinyxml.h
SOURCES += $$PWD/tinystr.cpp $$PWD/tinyxml.cpp $$PWD/tinyxmlerror.cpp $$PWD/tinyxmlparser.cpp

View File

@ -6,6 +6,7 @@ DEPENDPATH += . \
../lib ../lib
INCLUDEPATH += . \ INCLUDEPATH += . \
../lib ../lib
LIBS+=-L../externals
DESTDIR = . DESTDIR = .
RCC_DIR = temp RCC_DIR = temp

View File

@ -32,6 +32,9 @@
#include <ctime> #include <ctime>
#include "timer.h" #include "timer.h"
#define PCRE_STATIC
#include <pcre.h>
static TimerResults S_timerResults; static TimerResults S_timerResults;
CppCheck::CppCheck(ErrorLogger &errorLogger) CppCheck::CppCheck(ErrorLogger &errorLogger)
@ -297,6 +300,76 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
Timer timerSimpleChecks((*it)->name() + "::runSimplifiedChecks", _settings._showtime, &S_timerResults); Timer timerSimpleChecks((*it)->name() + "::runSimplifiedChecks", _settings._showtime, &S_timerResults);
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this); (*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
} }
// Are there extra rules?
if (!_settings.rules.empty())
{
std::ostringstream ostr;
for (const Token *tok = _tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
const std::string str(ostr.str());
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it)
{
const Settings::Rule &rule = *it;
if (rule.pattern.empty() || rule.id.empty() || rule.severity.empty())
continue;
const char *error = 0;
int erroffset = 0;
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,NULL);
if (!re && error)
{
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
Severity::error,
error,
"pcre_compile");
reportErr(errmsg);
}
if (re)
{
int pos = 0;
int ovector[30];
if (0 <= pcre_exec(re, NULL, str.c_str(), str.size(), pos, 0, ovector, 30))
{
unsigned int pos1 = (unsigned int)ovector[0];
unsigned int pos2 = (unsigned int)ovector[1];
// determine location..
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(_tokenizer.getFiles()->front());
loc.line = 0;
unsigned int len = 0;
for (const Token *tok = _tokenizer.tokens(); tok; tok = tok->next())
{
len = len + 1 + tok->str().size();
if (len > pos1)
{
loc.setfile(_tokenizer.getFiles()->at(tok->fileIndex()));
loc.line = tok->linenr();
break;
}
}
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack(1, loc);
// Create error message
std::string summary;
if (rule.summary.empty())
summary = "found '" + str.substr(pos1, pos2 - pos1) + "'";
else
summary = rule.summary;
ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id);
// Report error
reportErr(errmsg);
}
pcre_free(re);
}
}
}
} }
Settings CppCheck::settings() const Settings CppCheck::settings() const

View File

@ -1,5 +1,6 @@
# no manual edits - this file is autogenerated by dmake # no manual edits - this file is autogenerated by dmake
LIBS += -L../externals -lpcre
HEADERS += $$PWD/check.h \ HEADERS += $$PWD/check.h \
$$PWD/checkautovariables.h \ $$PWD/checkautovariables.h \
$$PWD/checkbufferoverrun.h \ $$PWD/checkbufferoverrun.h \

View File

@ -185,6 +185,30 @@ public:
* As usual, include guards are not counted. * As usual, include guards are not counted.
*/ */
bool ifcfg; bool ifcfg;
/** Rule */
class Rule
{
public:
Rule()
{
// default id
id = "rule";
// default severity
severity = "style";
}
std::string pattern;
std::string id;
std::string severity;
std::string summary;
};
/**
* @brief Extra rules
*/
std::list<Rule> rules;
}; };
/// @} /// @}

View File

@ -128,6 +128,9 @@ int main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::vector<std::string> externalfiles;
getCppFiles(externalfiles, "externals/");
// QMAKE - lib/lib.pri // QMAKE - lib/lib.pri
{ {
@ -135,6 +138,7 @@ int main(int argc, char **argv)
if (fout1.is_open()) if (fout1.is_open())
{ {
fout1 << "# no manual edits - this file is autogenerated by dmake\n\n"; fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
fout1 << "LIBS += -lpcre\n";
fout1 << "HEADERS += $$PWD/check.h \\\n"; fout1 << "HEADERS += $$PWD/check.h \\\n";
for (unsigned int i = 0; i < libfiles.size(); ++i) for (unsigned int i = 0; i < libfiles.size(); ++i)
{ {
@ -215,14 +219,18 @@ int main(int argc, char **argv)
for (unsigned int i = 1; i < testfiles.size(); ++i) for (unsigned int i = 1; i < testfiles.size(); ++i)
fout << " \\" << std::endl << std::string(14, ' ') << objfile(testfiles[i]); fout << " \\" << std::endl << std::string(14, ' ') << objfile(testfiles[i]);
fout << "\n\n"; fout << "\n\n";
fout << "EXTOBJ = " << objfile(externalfiles[0]);
for (unsigned int i = 1; i < externalfiles.size(); ++i)
fout << " \\" << std::endl << std::string(14, ' ') << objfile(externalfiles[i]);
fout << "\n\n";
fout << "\n###### Targets\n\n"; fout << "\n###### Targets\n\n";
fout << "cppcheck:\t$(LIBOBJ)\t$(CLIOBJ)\n"; fout << "cppcheck:\t$(LIBOBJ)\t$(CLIOBJ)\t$(EXTOBJ)\n";
fout << "\t$(CXX) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(LDFLAGS)\n\n"; fout << "\t$(CXX) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)\n\n";
fout << "all:\tcppcheck\ttestrunner\n\n"; fout << "all:\tcppcheck\ttestrunner\n\n";
fout << "testrunner:\t$(TESTOBJ)\t$(LIBOBJ)\tcli/threadexecutor.o\tcli/cmdlineparser.o\tcli/cppcheckexecutor.o\n"; fout << "testrunner:\t$(TESTOBJ)\t$(LIBOBJ)\t$(EXTOBJ)\tcli/threadexecutor.o\tcli/cmdlineparser.o\tcli/cppcheckexecutor.o\n";
fout << "\t$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS)\n\n"; fout << "\t$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS)\n\n";
fout << "test:\tall\n"; fout << "test:\tall\n";
fout << "\t./testrunner\n\n"; fout << "\t./testrunner\n\n";
fout << "check:\tall\n"; fout << "check:\tall\n";
@ -247,8 +255,8 @@ int main(int argc, char **argv)
fout << "\n###### Build\n\n"; fout << "\n###### Build\n\n";
compilefiles(fout, libfiles, "-Ilib"); compilefiles(fout, libfiles, "-Ilib");
compilefiles(fout, clifiles, "-Ilib"); compilefiles(fout, clifiles, "-Ilib -Iexternals");
compilefiles(fout, testfiles, "-Ilib -Icli"); compilefiles(fout, testfiles, "-Ilib -Icli -Iexternals");
return 0; return 0;
} }