Commit Graph

933 Commits

Author SHA1 Message Date
PKEuS 167a7e3e51 Various code cleanups 2011-12-08 21:28:34 +01:00
PKEuS 1bef8d1247 Tokenizer: Code cleanups 2011-12-08 17:42:26 +01:00
Edoardo Prezioso 149ff355e2 Add more kind of code to process for 'removeExceptionSpecifications' (unions, anonymous unions and structs). 2011-12-08 02:50:05 +01:00
Edoardo Prezioso 4de5d87078 1)Remove newly copy of 'eraseTokens' and replace every occurrence with 'deleteNext' with right parameter.
2)General improvements to code.
2011-12-08 01:44:18 +01:00
PKEuS 1c1c31bea0 Tokenizer: Refactorings and improvements. Better handling of [] 2011-12-07 21:15:00 +01:00
Edoardo Prezioso 612b3c59ca 1)Implement another declaration of 'Token::eraseTokens' with parameters: the starting token and the number of times needed to call 'deleteNext'.
2)Use the overloaded 'eraseTokens' where needed instead of using consecutively 'deleteNext'.
3)Tokenizer: general optimizations about the deletion of some tokens.
4)Run astyle.
2011-12-07 02:29:03 +01:00
Edoardo Prezioso b9224439c1 Add 'exit' and 'abort' to the flow control list in order to simplify code after them. 2011-12-06 22:56:12 +01:00
Edoardo Prezioso eb5fe250ab Partial fix ticket #3385 ('throw' isn't removed if the argument of the function is type 'struct|class'). 2011-12-06 21:02:26 +01:00
Edoardo Prezioso 0504952950 Remove some redundant parenthesis - part 9 2011-12-06 16:53:57 +01:00
Edoardo Prezioso 1b4b8fbefe Tokenizer: use more 'deleteNext' instead of 'eraseTokens' where possible. 2011-12-05 18:52:34 +01:00
Edoardo Prezioso 186ab3645e Oops. I should eventually keep ';', not 'typedef'. 2011-12-05 00:26:08 +01:00
Edoardo Prezioso 65213772df Tokenizer: use 'deleteNext()' or, even better, 'eraseTokens' instead of 'deleteThis()' where possible. 2011-12-05 00:08:50 +01:00
Edoardo Prezioso 9cadd7c17a Remove some redundant semicolons - part 8 2011-12-04 19:11:51 +01:00
Edoardo Prezioso 4946b036ad Remove some redundant semicolons - part 7 2011-12-04 18:08:35 +01:00
Edoardo Prezioso 52a174fa9d Remove some redundant semicolons - part 6 2011-12-04 17:30:25 +01:00
Edoardo Prezioso b45d63a10a Remove some redundant semicolons - part 5 2011-12-04 17:15:53 +01:00
Edoardo Prezioso 2fc067e6ab Tokenizer::simplifyConst : handle also '%type% const' when the 'type' token is the first one in the list. 2011-12-04 16:59:19 +01:00
Edoardo Prezioso a363749a17 1) Remove some redundant semicolons - part 4 ('typedef' != _tokens.str());
2) Tokenizer: Use Token::eraseTokens instead of using the same instructions as the ones inside such function.
2011-12-04 15:40:05 +01:00
Daniel Marjamäki eeb6dc48a5 Fixed #3359 (False positive: array[idx++] += val triggers unexpected 'Array index out of bounds' error) 2011-12-04 12:22:21 +01:00
Daniel Marjamäki 49784a44e1 Tokenizer: improved handling of inner templates. Partial fix for #3226 2011-12-04 11:38:41 +01:00
Edoardo Prezioso f47ac539d6 Tokenizer::simplifyFlowControl: 1) remove consecutive 'break' or 'continue', since they don't influence the CheckOther results; 2) improve the code speed where possible;
Tokenizer::eraseDeadCode: Ditto.
2011-12-03 17:15:19 +01:00
Thomas Jarosch fcb6759f43 The usual astyle run 2011-12-03 17:01:56 +01:00
Daniel Marjamäki 50dfdf7c2e Fixed #3350 (Analysis failed) 2011-12-03 15:15:15 +01:00
Edoardo Prezioso 00bae586e9 Add 'throw' to the flow control statements list for simplification of dead code. 2011-12-03 02:04:29 +01:00
Edoardo Prezioso 42a557432d Remove some redundant semicolons - part 3 2011-12-02 23:04:06 +01:00
Edoardo Prezioso c2ddb67316 Remove some redundant semicolons - part 2 2011-12-02 22:58:29 +01:00
Edoardo Prezioso ff1cb241a8 Remove some redundant semicolons - part 1 2011-12-02 22:39:33 +01:00
Edoardo Prezioso 767413adad 1)internal check found a 'findmatch' with simple string argument;
2)Style: uniform 'while (...)' when inside it there's an assignment;
3)Replace '0' with 'NULL' where there's comparison with a pointer.
2011-12-01 12:04:47 +01:00
Edoardo Prezioso 1084e4bece 1) Shut up GCC compiler for 'missing braces around assignment';
2) Tokenizer::simplifyGoto: Code refactoring in order to skip code inside '()|[]' parentheses without counting.
2011-11-30 20:58:39 +01:00
PKEuS 6b6f780057 code cleanups and refactorings 2011-11-26 21:02:04 +01:00
Marek Zmysłowski 3ae96600b5 Fixed #3212 (Simplify the double pointer cast) 2011-11-25 07:23:54 +01:00
Thomas Jarosch 5025d1019f Use Token::simpleMatch instead of Token::Match
"--enable=internal" reported:
[lib/tokenize.cpp:3563]: (warning) Found simple pattern inside Token::Match() call: ") ;"
2011-11-24 10:11:45 +01:00
Daniel Marjamäki 17f891ad34 Tokenizer::setVarId: Fixed problem with class declarations with inheritance. skip them. 2011-11-21 21:18:56 +01:00
Daniel Marjamäki 9aa8a49677 Tokenizer::setVarId: fixed 'using' bug 2011-11-21 18:04:42 +01:00
Daniel Marjamäki 004dcf834b Fixed #3281 (Tokenizer::simplifyKnownVariables : static constant value is not used) 2011-11-20 21:50:26 +01:00
Edoardo Prezioso 6889a28d31 1) Run runastyle;
2) Clarify some comments in 'Tokenizer::simplifyFlowControl' and in 'Tokenizer::eraseDeadCode';
3) Add some 'const' variables inside 'Tokenizer::eraseDeadCode'.
2011-11-20 19:06:55 +01:00
Edoardo Prezioso d0d5a2fcd8 Completed ticket #3230 (Refactoring: add function to remove tokens when a label is found.) and fixed ticket #3264 (False positive: Variable is assigned a value that is never used). 2011-11-20 18:37:00 +01:00
Daniel Marjamäki 097637a66c Fixed #3316 (Cppcheck reporting internal errors - code compiles cleanly) 2011-11-20 16:22:21 +01:00
Edoardo Prezioso 42e369a4b4 Change every 'tokAt(..)->link()' to 'linkAt(..)'. 2011-11-20 14:24:27 +01:00
Daniel Marjamäki 1cf45a5cde Fixed #3280 (False positive: assigned value that is never used) 2011-11-20 12:09:07 +01:00
Daniel Marjamäki 8c091ff968 Fixed #3340 (Internal error. Token::Match called with varid 0... union is causing problems) 2011-11-20 08:13:28 +01:00
Thomas Jarosch c317c8979c Run astyle 2011-11-14 09:21:42 +01:00
Edoardo Prezioso 2c64d299ca Change every 'tokAt(...)->str()' to 'strAt(...)'. 2011-11-13 13:10:59 +01:00
Edoardo Prezioso b28a44dc3b Change: 'next()->next()'->'tokAt(2)', 'previous()->previous()'->'tokAt(-2)'. 2011-11-12 22:33:03 +01:00
Edoardo Prezioso ed6a0e14c4 Add simplification of the consecutive braces before the end of 'tokenize()' function. 2011-11-12 16:59:20 +01:00
Edoardo Prezioso 5cbfbe31c1 Add removal of consecutive braces, i.e.: '{ { ... } }'->'{ ... }'.
Changed a little bit the dead code tests.
2011-11-12 12:07:10 +01:00
Daniel Marjamäki 5a35beebf7 added todo comment 2011-11-11 11:07:03 +01:00
Daniel Marjamäki 34e40502c6 Fixed #3314 (cppcheck incorrectly reporting Syntax error.) 2011-11-11 10:53:49 +01:00
Richard Quirk f56aa19fac Fix varid 0 with function pointer and virtual methods 2011-11-09 21:07:55 +01:00
Daniel Marjamäki 2d00cabee1 Fixed #3279 (Token::Match called with varid 0) 2011-11-09 18:49:17 +01:00
Edoardo Prezioso 0569953753 Fixed ticket #3309 (false positive: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses) 2011-11-08 22:48:14 +01:00
Edoardo Prezioso 3cc9a333c9 Fixed tokenizer: don't change '*(str+num)' if '*' means a product with a previous variable or number.
Ditto for '&str[num]' (still commented).
2011-11-08 18:14:43 +01:00
Edoardo Prezioso a546fc6e9d Fixed ticket #3310 (segmentation fault of cppcheck) 2011-11-08 17:37:24 +01:00
Edoardo Prezioso aaa77c4709 Improve tokenizer: remove more redundant parenthesis and add a prototype code for: '&str[num]'=>'(str+num)' with reporting non obvious test failures. 2011-11-07 23:40:06 +01:00
Edoardo Prezioso 6e2f2816de Improve same expression check: remove '%op%' pattern and add ',' for the same expressions as an argument inside a function.
Improve compound assignment simplification: use already defined 'isAssignmentOp' and extend the adding parenthesis to a generic operator, not only to the arithmetical ones. See: http://en.cppreference.com/w/cpp/language/operator_precedence
2011-11-06 14:35:53 +01:00
Daniel Marjamäki 5edf153602 Fixed #3294 (Token::Match multi compare false negative) 2011-11-05 19:24:21 +01:00
Daniel Marjamaki b96ab6ba26 Fixed #3188 (Function parser false positive) 2011-11-05 12:23:05 +01:00
Daniel Marjamäki 085a6285fa Fixed #3117 (Tokenizer::simplifyKnownVariables : Don't simplify static variable that is changed) 2011-11-05 08:30:11 +01:00
Daniel Marjamäki 9b8ffe7219 Fixed #3248 (Tokenizer: better handling of char constants that are compared with numeric constants) 2011-11-03 20:03:31 +01:00
Daniel Marjamaki b6b5416b42 Tokenizer: Fixed failed unit test 2011-11-02 20:42:38 +01:00
Daniel Marjamaki 0884204c2f Fixed #3279 (Token::Match called with varid 0) 2011-11-02 18:31:13 +01:00
Daniel Marjamaki 937a4497ca Fixed #3272 (Internal error) 2011-11-01 18:03:32 +01:00
Edoardo Prezioso 9dd3360cd6 Fix some complainted choices made in my older commits.
Note: probably you should do 'make clean' before using 'make' to rebuild it again. Maybe it's me but 'make' reports various errors when linking.
2011-11-01 13:23:47 +01:00
Daniel Marjamäki a7f27a83a7 Fixed #3271 (Regression: something related to symbol database / varid) 2011-10-31 18:33:15 +01:00
Edoardo Prezioso ba5909ef1d General code tweaking, nothing strange. 2011-10-31 02:24:59 +01:00
Edoardo Prezioso 433f4640a9 Fix some GCC warnings regarding the sign conversion. 2011-10-30 18:34:49 +01:00
Edoardo Prezioso 42fd4e2f52 Tokenizer: Change 'var++|--;' into '++|--var;' and remove redundant 'tokAt(0)'. 2011-10-29 22:25:49 +02:00
Daniel Marjamäki 92333b585a Fixed #3092 (Tokenizer::setVarId : shadow variable in member function gets the wrong varid) 2011-10-29 21:25:58 +02:00
Daniel Marjamäki a809bb3471 astyle formatting 2011-10-29 19:51:11 +02:00
Daniel Marjamäki acaa9c456f Fixed #3152 (Tokenizer: template constructor is removed) 2011-10-29 19:45:47 +02:00
Daniel Marjamäki 8f49eb6a7e Tokenizer: Make sure that friend classes don't get varid. Ticket: #2962 2011-10-29 18:22:58 +02:00
Edoardo Prezioso 5d868766c7 Tokenizer time improvements (time says real: -1 second)
1)change tokAt(1|-1) with next()|previous() with conditions where necessary;
2)change strAt(1|-1) with next()|previous()->str() with conditions where necessary;
3)change tokAt(n)->str(), with n != -1,1, to strat(n);
4)change simplifyFuncInWhile implementation because it was too slow and stupid.
2011-10-29 01:57:53 +02:00
Edoardo Prezioso dd719b41bf Definitely check correctly 'sizeof %num%' when '%num%' has '-' sign. 2011-10-29 00:11:38 +02:00
Thomas Jarosch ef8f49bbf3 Use new findsimplematch API for simple patterns 2011-10-28 12:49:03 +02:00
Edoardo Prezioso bab740289c Complete todo: convert 'for' into 'while'.
It's not possible to enable this code because of the disaster it will be created for all the checks with the 'for' pattern.
2011-10-28 00:50:54 +02:00
PKEuS 49fd057e17 Tokenizer: Simplify 'foo(void)' to 'foo()' 2011-10-27 19:56:59 +02:00
Thomas Jarosch 22251d50bb Bugfix: Use Token::Match instead of Token::simpleMatch because it's a complex pattern
This bug was in here before my recent refactoring.

(And yes, I wrote a check for cppcheck's Token::Match invocation ;))
2011-10-27 16:43:04 +02:00
Thomas Jarosch 434fb933a8 Implement Token::findsimplematch und use it for simple patterns 2011-10-27 15:59:22 +02:00
Thomas Jarosch 54adb910ec Use Token::simpleMatch instead of Token::Match for simple patterns 2011-10-27 15:59:22 +02:00
Edoardo Prezioso 9bb1a1b7a5 Added code for simplification of 'for ( a; b; c;); -> '{ a; for (; b; c;) ; }'.
It's not enabled because it fails many tests with testrunner.
2011-10-27 02:59:50 +02:00
Edoardo Prezioso 1be1af4afb Move the simplification of 'strlen' in simplifyTokenList.
This way it's possible to omit the call to simplifyKnownVariables before 'strlen'.
2011-10-27 01:24:35 +02:00
Edoardo Prezioso df5d26901c Add new warning option to check for dead code and change the order of some struct members to reduce structure padding. 2011-10-24 03:02:00 +02:00
Thomas Jarosch db8c7deb30 Fixed #3232 (Check if container is modified inside BOOST_FOREACH) 2011-10-23 13:07:43 +02:00
Erik Lax b7ab1e7d7e Fixed #3237 (Bug in parser of class operator functions) 2011-10-23 10:25:14 +02:00
Johan Samuelson 3d8fa2f76e Fixed #3123 ([False Positive] Shadowed enum) 2011-10-22 13:43:53 +02:00
Daniel Marjamäki 32e20d4e31 made 'variableHidingTypedef' inconclusive. See ticket #3199 2011-10-22 13:26:33 +02:00
Marek Zmysłowski b332ea8222 Fixed #3204 (Refactor standards support in Settings) 2011-10-22 09:45:48 +02:00
Edoardo Prezioso 9257e82475 Improve tokenizer: don't confuse between a label and the case/default statements. 2011-10-19 18:49:02 +02:00
Edoardo Prezioso 882b0c15a0 Improve tokenizing of "do{ ... } while(0)".
The simplification will be the same for every combination, except for the 'continue' and the 'break'. In that case, keep the block braces.
2011-10-19 18:20:29 +02:00
Edoardo Prezioso 4f256ef314 Runastyle + removal of useless conditions after previous commit. 2011-10-19 14:48:08 +02:00
Edoardo Prezioso 73f0e2c5b9 Fixed ticket #3227 (Improve tokenizer: labels are not handled correctly after a case or another label instruction)
Moved the labels simplification after combining the tokens and moved the case/default simplification inside the labels.
2011-10-19 14:20:09 +02:00
Edoardo Prezioso f4cdf57955 Fixed ticket #3229 (Segfault with goto):
Don't handle labels, gotos, returns and indentations inside the round braces. This is applied not only for simplifyGoto, but also to simplifyFlowControl.
Rewrite enum badly handled by astyle inside mathlib.cpp and move simplifyFlowControl at the end of the simplifyTokenList in order to catch more dead code, not related to the ticket.
2011-10-18 23:56:35 +02:00
Edoardo Prezioso de8eb48a5c Remove redundant function findmatch inside tokenize.cpp.
There's Token::findmatch which is already used inside other Tokenizer functions.
2011-10-17 13:46:27 +02:00
Edoardo Prezioso c3caade3ca - Fixed mispelled function name;
changed variable name inside simplifyFlowControl for consistency;
improved simplifyFlowControl to handle better this kind of code:
"return; { { } { label : ; ok ( ) ; } }"->"return ; { { label: ok ( ) ; } }".
2011-10-17 02:16:49 +02:00
Ettl Martin 1a710e5761 fixed regression on linux due to missing include 2011-10-16 14:16:35 +02:00
PKEuS f8074b71d2 Fixed #2470 (False negative: Possible null pointer dereference (C++0x keyword 'nullptr')) 2011-10-16 12:54:58 +02:00
Thomas Jarosch a52b73f9f9 Fix #3208 (Simplify pointer to standard type, C only)
The symbol database is unavailable during token simplification
and &data[0] might return something completely different for C++.

Moved code_is_c() from checkOther to Tokenizer.
2011-10-16 08:09:57 +02:00
Edoardo Prezioso 8afc1b6f2d Changed the name of the removal of dead code after flow control statements for consistency (simplifyDeadCode is too generalized as name) 2011-10-15 12:45:48 +02:00
Edoardo Prezioso 57ead6988e Fixed ticket #3138 (Tokenizer: remove unreachable code below goto inside a namespace|class|struct block) 2011-10-15 11:35:45 +02:00
Edoardo Prezioso f95b692a69 Fixed ticket #3113 (complete simplification of dead code after control flow statements) 2011-10-15 01:34:07 +02:00