Commit Graph

1342 Commits

Author SHA1 Message Date
Thomas Jarosch 7f0bc73e8e Simple constification (needed by the match compiler) 2013-01-04 03:17:52 +01:00
Edoardo Prezioso 1affb0c96b Use more Effective C++ code style in Token class:
1)The non-const version of Token::tokAt and Token::linkAt now will use a combination of const_cast and static_cast to remove duplicate code.
2)The non-const versions of Token::find(simple)match are added, in order to avoid the usage of const_cast outside the Token code.
3)As a consequence of 2), an useless const_cast applied to a call of Token::findsimplematch in Tokenizer code is removed.
2013-01-03 22:35:34 +01:00
Daniel Marjamäki a3ee72a51d Fixed #4409 (Cppcheck 1.58 dev hangs when checking mhz.c of lmbench3 (attached code)) 2013-01-03 19:14:44 +01:00
Daniel Marjamäki ded0d50591 Tokenizer: add reportProgress to Tokenizer::simplifyKnownVariables. Ticket: #4409 2013-01-03 15:22:06 +01:00
Reijo Tomperi 5d5f7085bf Updating year 2012 -> 2013 to .cpp and .h files and man page. 2013-01-01 18:29:08 +02:00
Edoardo Prezioso 6612952dd4 Use 'simple' matching with normal patterns. 2012-12-31 13:30:06 +01:00
Daniel Marjamäki 4378357d7e Fixed #4372 (Tokenizer misidentifying which function a variable belongs to) 2012-12-29 21:07:41 +01:00
Daniel Marjamäki 4d085dd3fd Fixed #4316 (False positive: (constStatement) Redundant code) 2012-12-29 17:13:06 +01:00
Daniel Marjamäki 9af51a75e6 Tokenizer::setVarId: Proper handling of 'void f(struct foobar). Ticket: #4444' 2012-12-29 08:54:39 +01:00
Daniel Marjamäki bf9b900c30 Tokenizer::setVarId: Fixed problem with initializer lists (#4436) 2012-12-27 18:15:00 +01:00
Robert Reif 3e6d601982 Fixed #4436 (FP: Member variable is not initialized in the constructor. (with two parameters)) 2012-12-27 17:15:38 +01:00
acm4me 7da155c8ba Support for Sun Studio C++ compiler 2012-12-27 11:51:12 +01:00
Daniel Marjamäki b3301a9ef9 Fixed #4433 (Wrong array size for string with \0) 2012-12-26 12:10:09 +01:00
Daniel Marjamäki db2a129557 Tokenizer: Improved handling of '\0' in strings 2012-12-25 08:56:12 +01:00
Daniel Marjamäki 56b7670468 Tokenizer::setVarId: Fixed problem in initializer list when parameter and class member has same name 2012-12-23 19:55:09 +01:00
Robert Reif dae232015e Fixed #4430 (FP: Member variable is not initialized in the constructor.) 2012-12-23 08:04:44 +01:00
Daniel Marjamäki 47e1a571f7 Tokenizer: Fixed goto problems 2012-12-22 19:28:53 +01:00
Daniel Marjamäki d3f5fd4e59 Tokenizer: Fixed Token::Match pattern 2012-12-10 20:38:07 +01:00
Daniel Marjamäki df03e3a8d2 Fixed #4395 (Wrong simplification of known variables in nested assignment) 2012-12-10 06:08:33 +01:00
Daniel Marjamäki c91250cd6e Fixed #4277 (duplicateExpression finds false positive for floats in a union as a member of a class) 2012-12-03 17:05:37 +01:00
Robert Reif b216639069 Fixed #4378 (simplifyEnum doesn't simplify enum type within open and close parenthisis) 2012-12-02 07:22:55 +01:00
Edoardo Prezioso 5101f3c029 Use the new pattern: '%comp%' where possible.
Change also the description comment of the Token::Match by adding the new pattern and the forgotten '%op%'.
2012-12-01 01:31:35 +01:00
Edoardo Prezioso f3782935c2 Tokenizer: improve code and change name of +- concatenation function. 2012-12-01 00:43:23 +01:00
Edoardo Prezioso 3d1d983251 Tokenizer: simplify also __FILE__ together with __LINE__. 2012-12-01 00:37:10 +01:00
Daniel Marjamäki 672831f41a Fixed #4187 (False positive: Variable inside a lambda is reported as uninitialized) 2012-11-30 10:30:26 +01:00
Edoardo Prezioso a219ed313b Fixed again #2963 (FP: Typedef names considered duplicate because __LINE__ not expanded).
It is caused by a regression introduced with commit 75fbe310ff. Add also a TODO in the non working detection inside TestSimplifyTokens::simplifyTypedef98.
2012-11-30 00:00:44 +01:00
Edoardo Prezioso e214d94589 Tokenizer: use list.back() when we start the loop backwards. 2012-11-29 17:42:31 +01:00
Daniel Marjamäki 3372657a07 Fixed #4227 (False positive: Comparison of a boolean with an integer (double dResult=false)) 2012-11-29 09:29:25 +01:00
Daniel Marjamäki 509721d6d0 Fixed #4304 (False positive during an array declaration) 2012-11-29 08:44:12 +01:00
Edoardo Prezioso 6b40d93f6f Try to fix Visual Studio compiler warning.
Related to commit 119ab519a4.
2012-11-28 12:06:27 +01:00
Daniel Marjamäki 5d1b4e6dbb Tokenizer: Remove redundant '+' 2012-11-28 07:09:56 +01:00
Edoardo Prezioso f3029ce6bb Fixed a bug in Tokenizer::simplifyKnownVariables.
When we find constant variables, check if there's a usage of its reference in the code (for example: don't simplify 'f(&x)' to 'f(&100)').
2012-11-26 17:06:52 +01:00
Edoardo Prezioso 76639578ad Improve Tokenizer::simplifyFuncInWhile.
Differentiate between the new cppcheck:r variables by appending a number to the name, like 'cppcheck:r1', 'cppcheck:r2' and more.
2012-11-26 02:19:35 +01:00
Edoardo Prezioso 5fb2115e9d Fixed a bug in Tokenizer::concatenateNegativeNumber.
The first negative number inside a '{}' list was not simplified correctly.
2012-11-20 19:14:58 +01:00
Edoardo Prezioso c5e5ee9ed2 Adapt %var%|%num% changes with Tokenizer, final. 2012-11-17 22:44:31 +01:00
Edoardo Prezioso 1bf003389e Adapt %var%|%num% changes with Tokenizer, part 4. 2012-11-17 22:43:42 +01:00
Edoardo Prezioso f8e4af9ce2 Adapt %var%|%num% changes with Tokenizer, part 3. 2012-11-17 22:42:24 +01:00
Edoardo Prezioso bd63db62af Adapt %var%|%num% changes with Tokenizer, part 2. 2012-11-17 22:40:44 +01:00
Edoardo Prezioso 2b4215ea7a Adapt %var%|%num% changes with Tokenizer, part 1. 2012-11-17 22:39:02 +01:00
PKEuS e5ebb49312 Added support for sizeof(wchar_t). Improved <Windows.h> type testing for Win64 platform. 2012-11-11 16:16:17 +01:00
PKEuS 5555e055f1 Refactorized <Windows.h> type support:
- Changed some more Win32 simplifications of wide-character/string types to use wchar_t
- Added support for LPWSTR
- Fixed test case to ensure that simplifications also work for Win32W
2012-11-11 15:40:06 +01:00
PKEuS 4ea2df8671 Changed handling of type wchar_t:
- Don't simplify wchar_t to unsigned short on Win32 platforms to ensure that checking of strings and nullpointer dereferences works.
- Added it as standard type
2012-11-11 14:47:16 +01:00
PKEuS 58fe7105f4 Remove C++11 keywords "override", "final" and "constexpr" 2012-11-09 19:53:10 +01:00
Edoardo Prezioso 119ab519a4 Support GNU extension of '?:' operator:
"x ? : y" is equivalent to "x ? x : y". I found a lot of code with this extension, probably we should warn a user to not use this.
2012-11-08 17:49:43 +01:00
Edoardo Prezioso 9556634ee7 Revert 1c0617c504. 2012-11-07 18:34:25 +01:00
Edoardo Prezioso 061a5e1ad7 Run astyle. 2012-11-07 02:24:46 +01:00
Edoardo Prezioso 1c0617c504 change some Token::Match patterns used in code:
replace '||' with '%oror%', where possible.
2012-11-07 02:23:09 +01:00
Edoardo Prezioso 63307c5db2 Remove the now useless fix for #4245.
The fix for #4276 made completely useless that branch, so remove it until someone shows a testcase which breaks this commit.
2012-11-05 00:13:04 +01:00
Edoardo Prezioso 7293fcfa9b Remove redundant code in simplifyVarDecl:
TokenList::insertTokens adds the missing braces links when needed. The function does not add links to '<>', though, hence the TODO.
2012-11-05 00:12:22 +01:00
Edoardo Prezioso 4e25ffa948 Remove unexecuted branch in duplicateTypedef:
If the code is intended to be used, please revert + provide a valid testcase.
2012-11-04 23:03:14 +01:00
Edoardo Prezioso 333711ae4f Remove dead branch in simplifySizeof:
the code in that branch won't ever be executed because simplifySizeOf is called after arraySize, which adds the string length inside the '[]' parenthesis.
2012-11-04 22:41:38 +01:00
Edoardo Prezioso 24bf6f99e1 More simplifyRedundantParenthesis changes:
simplify also '( var . var . ... . var )' parenthesis.
2012-11-04 22:38:18 +01:00
Edoardo Prezioso b6b359d1c6 Tokenizer::simplifyRedundantParenthesis refactor:
Change useless 'while' to 'if' where possible; unify duplicate 'delete [| ]| var' handling code.
2012-11-04 20:51:40 +01:00
Edoardo Prezioso 93f1fed205 Tokenizer '?:' handling code refactorization:
move '=|,|(|[|{|}|;|case|return (%bool%) ?' code handling from simplifyConditionOperator in simplifyConstTernaryOp in order to use a more efficient code, thus to remove code duplication.
2012-11-04 19:18:11 +01:00
Edoardo Prezioso 18e1eb7c70 Add missing hunks in the previous commit. 2012-11-04 19:08:54 +01:00
Edoardo Prezioso c54eafdf69 Use '%char%' matching in the tokenizer file. 2012-11-04 17:22:38 +01:00
PKEuS 1c399c86ca Improved fix for #4311; Added back support for "this." (fixes again #4291)
Added TODO unit test for missing varid.
2012-11-03 21:16:05 +01:00
Daniel Marjamäki 6c2563c467 Fixed #4311 (False positive: warning (selfAssignment): Redundant assignment of 'm_bar' to itself. 2012-11-03 13:18:43 +01:00
Edoardo Prezioso c9e0089546 Change Tokenizer member function name.
From 'simplifyQuestionMark' to 'simplifyConstTernaryOp' (the older name was not clear). Adjusted the doxy comment.
2012-11-02 14:57:12 +01:00
Edoardo Prezioso 8271d63744 Forgot to fix another clang analyzer message.
I don't understand why here there is a loop 'break' after a token stepping forward and a bool assignment.
2012-10-24 15:30:40 +02:00
Edoardo Prezioso 11b0047063 Fix some clang analyzer messages.
CheckMemoryLeak: two redundant assignments, should be clarified;
TemplateSimplifier: same;
Tokenizer: same.
2012-10-24 03:17:56 +02:00
Edoardo Prezioso f0f216390e Fixed #4276 (segmentation fault of cppcheck (invalid code)) 2012-10-20 21:40:51 +02:00
Edoardo Prezioso 4ddcde1e6f CheckMemoryLeak: add '?1:0' to clarify the value of the argument to 'deleteNext'; Tokenize.cpp: in simplifyCompoundAssignment(), remove ':' odd code used to fix a weird test case ('case' code not inside a function body), remove useless 'tok->next() != NULL' check (already true by previous condition); in simplifyConditionOperator(), handle better the parenthesis skipping code and remove useless ')'check; in simplifyQuestionMark(), remove useless 'tok->tokAt(-2)' check (Token::Match returns false if the token is NULL), add more patterns to Token::Match to handle more test cases; in simplifyBitFields(), add 'const' to 'offset' bool. RedirectOutputError: style nitpick change to declaration of a pointer. 2012-10-19 14:19:52 +02:00
Baris Demiray d84d360afc Fixed #4291 (Variable ID is not set when variable is accessed through 'this') 2012-10-19 06:18:13 +02:00
Edoardo Prezioso 61365ea0e5 Fixed #4293 (FP: Variable is not simplified, causing a false positive). 2012-10-17 00:25:20 +02:00
Daniel Marjamäki 562291477d Fixed #4226 (False positive: Uninitialized variable (problem with namespace ::rtl)) 2012-10-15 06:53:38 +02:00
Edoardo Prezioso 64b4960acc Tokenizer: simplify GCC '({ %var%|%num% ; })' to '%var%|%num%'.
Remove useless brace around condition in simplifyFlowControl.
2012-10-13 13:24:41 +02:00
Edoardo Prezioso 1951d1cdc5 Tokenizer: improve the new 'skipTernaryOp' function by supporting GCC '{(var|num;)}' statement expression extension; improve 'Tokenizer::simplifyQuestionMark' by supporting simplification with 'case' before ternary operation, using skipTernaryOp to get colon and, most importantly, supporting indented '?:' operations. 2012-10-13 02:32:43 +02:00
Edoardo Prezioso d4a3c1617a Fixed: Tokenizer::simplifyLabelCaseDefault was careless with '?:' operator near 'case' adding the semicolon after the ternary colon. 2012-10-12 20:51:13 +02:00
Edoardo Prezioso c42facae1f Tokenizer::simplifyLabelsCaseDefault: jump '(' and '[' parenthesis.
TestTokenizer: add simple test cases with some correct and wrong syntax concerning 'case'.
2012-10-12 17:08:21 +02:00
Edoardo Prezioso 1e4b080737 Fixed #4278 (syntax error). 2012-10-11 13:35:20 +02:00
Edoardo Prezioso e62e03ab31 Fixed #4267 (segmentation fault of cppcheck (invalid code)). 2012-10-09 20:44:30 +02:00
Edoardo Prezioso 3703e71f82 Related to previous commit: if the '{}' parenthesis are found after 'case', don't skip them after continuing to the main loop or it will cause indentlevel mismatching. 2012-10-09 18:24:21 +02:00
Edoardo Prezioso 9668508b32 Tokenizer::simplifyLabelsCaseDefault:
use more efficient check for 'const' token;
remove redundant NULL checks thanks to commit e3bbcf501f.
2012-10-09 17:52:20 +02:00
Ettl Martin 2cf75d5339 astyle run 2012-10-08 21:50:21 +02:00
Ettl Martin 0879bb5825 #4245: Segmentation fault (invalid code); Applied patch from amai. 2012-10-08 21:49:25 +02:00
Daniel Marjamäki 6a37942431 Fixed #3935 (False report for accessing array out of bounds after casting to short) 2012-10-07 18:38:05 +02:00
Daniel Marjamäki 4c1abde48e Reverted 107b3b44. Write syntax error for 'if MACRO()'. We can't know if MACRO() is supposed to be used in the condition or if it is some annotation that should be removed. Ticket #4171 2012-10-06 19:12:39 +02:00
Edoardo Prezioso e3bbcf501f Fixed #4234 (segmentation fault of cppcheck in Tokenizer::simplifyFlowControl() (invalid code)) 2012-10-06 13:37:44 +02:00
Daniel Marjamäki c2b61030a8 Fixed #4254 (Tokenizer::simplifyIfAssign: varids not preserved) 2012-10-06 12:49:24 +02:00
Daniel Marjamäki 2f069f550f Removed Java/C# handling 2012-10-02 18:44:36 +02:00
Daniel Marjamäki 9a462d8a0a Fixed #4225 (False positive: uninitialized variable (assignemnt in ternary expression with cast)) 2012-09-30 18:49:25 +02:00
PKEuS c4b881f844 Refactorizations in tokenize.cpp and testsimplifytokens.cpp:
- Avoid const_cast in testsimplifytokens.cpp
- Removed redundant null-check (VS11 code analysis)
- Fixed MSVC compiler warning
- Replaced some indentation counters
2012-09-29 14:10:41 +02:00
Daniel Marjamäki ff4f8b58f3 Disable checkComparisonOfFuncReturningBool check because of false warnings. Ticket #2617 2012-09-28 18:51:10 +02:00
Alexander Mai 074b7781b2 Fixed #4239 (segmentation fault of cppcheck (invalid code)) 2012-09-27 06:35:36 +02:00
Mohit Mate 9e297c95f2 Fixed #2617 (improve check: comparing boolean with '<') 2012-09-26 18:18:36 +02:00
Daniel Marjamäki 2e3a7db4eb Fixed #4115 (Incorrect uninitialized variable error message with realloc macro) 2012-09-22 18:41:33 +02:00
Daniel Marjamäki 6c25f3662e Tokenizer::simplifyEnum: Don't simplify enums in function heads. Ticket #3953 2012-09-21 16:17:20 +02:00
Edoardo Prezioso 8e1e8525a3 Partial rewrite of Tokenizer::simplifyComma:
skip '= { .. }' where possible;
hence remove '%num% after comma' check because it's redundant now;
replace round braces counter method with faster 'link skip';
if 'endAt' is 'NULL' after finding the ';' token, exit the function;
hence remove redundant 'tok != NULL' check after simplifying 'return' code.
2012-09-20 21:45:16 +02:00
Edoardo Prezioso eb5a61edfe Tokenizer: some changes to the code:
be sure '?:' ternary operation has whitespaces around the operators;
remove useless loop to get the 6 next tokens, use tokAt(6);
add '?1:0' to bool values when doing a sum with them.
remove useless 'enum' pattern checking in code executed after simplifyEnum;
after being sure the 'tok' is a standard type, begin the loop with the token next to it;
it's possible to remove two tokens before the current one without moving this.
2012-09-20 01:07:50 +02:00
Daniel Marjamäki aa3cdc6b6f Fixed #3565 (Variable hides enumerator (attached code example)) 2012-09-19 19:19:13 +02:00
Ettl Martin 3f89e38275 fixed #4195 segmentation fault of cppcheck (invalid code); Added a testcase 2012-09-19 10:37:30 +02:00
Daniel Marjamäki 07d2935e81 Fixed #4164 (False positive: (error) Uninitialized variable: min) 2012-09-18 20:55:37 +02:00
Daniel Marjamäki 1f7d9ca22c Fixed #4211 (Tokenizer::simplifyVarDecl: Improved handling of >> in templates) 2012-09-17 19:45:42 +02:00
Daniel Marjamäki a99515ca91 Fixed #3933 (Negative array index issue (because sizeof struct is assumed to be 100)) 2012-09-16 08:20:43 +02:00
Daniel Marjamäki f1ebd99dc2 Fixed #3507 (false positive: comma-separated statements before return in methods) 2012-09-15 11:55:08 +02:00
Daniel Marjamäki 9f2e1ab98d Fixed #4048 (Tokenizer::simplifyVarDecl: Improve handling of 'a::b const * p = 0;') 2012-09-14 16:46:45 +02:00
Daniel Marjamäki 19fdbf0fd0 Fixed #4185 (Incorrect 'Found duplicate if expressions' for strings with high bit set) 2012-09-13 16:44:10 +02:00
PKEuS 22a8e3f4e6 Replaced Tokenizer::getFunctionTokenByName() by SymbolDatabase::findFunctionByName(), which handles scopes slightly better. 2012-09-11 18:03:47 +02:00
Daniel Marjamäki 64faa780fe Fixed #4087 (div by zero check is invalid for floats) 2012-09-11 16:50:42 +02:00