Tokenizer::setVarId : small optimisations

This commit is contained in:
Daniel Marjamäki 2008-12-24 07:46:57 +00:00
parent 6472588ddd
commit a65a66bee0
2 changed files with 22 additions and 18 deletions

View File

@ -4,33 +4,33 @@ TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivis
BIN = ${DESTDIR}/usr/bin BIN = ${DESTDIR}/usr/bin
all: ${OBJS} main.o all: ${OBJS} main.o
g++ -Wall -g -o cppcheck $^ g++ -Wall -g -pg -o cppcheck $^
test: ${OBJS} testrunner.o testsuite.o ${TESTS} test: ${OBJS} testrunner.o testsuite.o ${TESTS}
g++ -Wall -g -o testrunner $^ g++ -Wall -g -o testrunner $^
cppcheckexecutor.o: cppcheckexecutor.cpp cppcheckexecutor.h cppcheck.h errorlogger.h cppcheckexecutor.o: cppcheckexecutor.cpp cppcheckexecutor.h cppcheck.h errorlogger.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
cppcheck.o: cppcheck.cpp cppcheck.h settings.h errorlogger.h preprocessor.h tokenize.h token.h checkmemoryleak.h checkbufferoverrun.h checkclass.h checkheaders.h checkother.h checkfunctionusage.h filelister.h cppcheck.o: cppcheck.cpp cppcheck.h settings.h errorlogger.h preprocessor.h tokenize.h token.h checkmemoryleak.h checkbufferoverrun.h checkclass.h checkheaders.h checkother.h checkfunctionusage.h filelister.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
main.o: main.cpp cppcheck.h settings.h errorlogger.h main.o: main.cpp cppcheck.h settings.h errorlogger.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
checkbufferoverrun.o: checkbufferoverrun.cpp checkbufferoverrun.h tokenize.h settings.h errorlogger.h token.h checkbufferoverrun.o: checkbufferoverrun.cpp checkbufferoverrun.h tokenize.h settings.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
checkclass.o: checkclass.cpp checkclass.h tokenize.h settings.h errorlogger.h token.h checkclass.o: checkclass.cpp checkclass.h tokenize.h settings.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
checkfunctionusage.o: checkfunctionusage.cpp checkfunctionusage.h tokenize.h settings.h errorlogger.h token.h checkfunctionusage.o: checkfunctionusage.cpp checkfunctionusage.h tokenize.h settings.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
checkheaders.o: checkheaders.cpp checkheaders.h tokenize.h settings.h errorlogger.h token.h checkheaders.o: checkheaders.cpp checkheaders.h tokenize.h settings.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
checkmemoryleak.o: checkmemoryleak.cpp checkmemoryleak.h tokenize.h settings.h errorlogger.h token.h checkmemoryleak.o: checkmemoryleak.cpp checkmemoryleak.h tokenize.h settings.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
checkother.o: checkother.cpp checkother.h tokenize.h settings.h errorlogger.h token.h checkother.o: checkother.cpp checkother.h tokenize.h settings.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
filelister.o: filelister.cpp filelister.h filelister.o: filelister.cpp filelister.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
preprocessor.o: preprocessor.cpp preprocessor.h errorlogger.h preprocessor.o: preprocessor.cpp preprocessor.h errorlogger.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
settings.o: settings.cpp settings.h settings.o: settings.cpp settings.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
testbufferoverrun.o: testbufferoverrun.cpp tokenize.h settings.h errorlogger.h token.h checkbufferoverrun.h testsuite.h testbufferoverrun.o: testbufferoverrun.cpp tokenize.h settings.h errorlogger.h token.h checkbufferoverrun.h testsuite.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testcharvar.o: testcharvar.cpp tokenize.h settings.h errorlogger.h token.h checkother.h testsuite.h testcharvar.o: testcharvar.cpp tokenize.h settings.h errorlogger.h token.h checkother.h testsuite.h
@ -72,9 +72,9 @@ testunusedvar.o: testunusedvar.cpp testsuite.h errorlogger.h tokenize.h settings
testfilelister.o: testfilelister.cpp filelister.h testfilelister.o: testfilelister.cpp filelister.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
token.o: token.cpp token.h token.o: token.cpp token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
tokenize.o: tokenize.cpp tokenize.h settings.h errorlogger.h token.h filelister.h tokenize.o: tokenize.cpp tokenize.h settings.h errorlogger.h token.h filelister.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp
clean: clean:
rm -f *.o testrunner cppcheck rm -f *.o testrunner cppcheck

View File

@ -638,14 +638,18 @@ void Tokenizer::setVarId()
++_varId; ++_varId;
int indentlevel = 0; int indentlevel = 0;
int parlevel = 0; int parlevel = 0;
for ( tok2 = tok->next(); tok2 && indentlevel >= 0; tok2 = tok2->next() ) for ( tok2 = tok->next(); tok2; tok2 = tok2->next() )
{ {
if ( tok2->str() == varname ) if ( tok2->str() == varname )
tok2->varId( _varId ); tok2->varId( _varId );
else if ( tok2->str() == "{" ) else if ( tok2->str() == "{" )
++indentlevel; ++indentlevel;
else if ( tok2->str() == "}" ) else if ( tok2->str() == "}" )
{
--indentlevel; --indentlevel;
if ( indentlevel < 0 )
break;
}
else if ( tok2->str() == "(" ) else if ( tok2->str() == "(" )
++parlevel; ++parlevel;
else if ( tok2->str() == ")" ) else if ( tok2->str() == ")" )
@ -659,8 +663,8 @@ void Tokenizer::setVarId()
// Struct/Class members // Struct/Class members
for ( TOKEN *tok = _tokens; tok; tok = tok->next() ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( TOKEN::Match(tok, "%var% . %var%") && if ( tok->varId() != 0 &&
tok->varId() != 0 && TOKEN::Match(tok, "%var% . %var%") &&
tok->tokAt(2)->varId() == 0 ) tok->tokAt(2)->varId() == 0 )
{ {
++_varId; ++_varId;