Commit Graph

1764 Commits

Author SHA1 Message Date
Daniel Marjamäki 36297f1025 Tokenizer::varId: don't set varid for function name in code 'bool f(X x, int=3);' 2014-10-14 20:37:32 +02:00
Daniel Marjamäki 30353d4b61 Tokenizer::setVarId: better handling of c++ casts 2014-10-11 18:35:06 +02:00
Simon Martin 70561682eb Tokenizer::simplifyConstTernaryOp: Properly detect the end of the 'false' part of ternary operators when it contains '>'. 2014-10-11 17:01:55 +02:00
Daniel Marjamäki 8c8e85d2db Tokenizer::setVarId: A variable declaration can't start with the typedef keyword 2014-10-11 16:30:51 +02:00
Daniel Marjamäki dd6ae3033f Tokenizer::simplifyRedundantParentheses: dont remove parentheses in 'void * operator new(SIZE_TYPE, int);' 2014-10-11 09:18:43 +02:00
Daniel Marjamäki b0b86f5607 Fixed internal error, use Token::simpleMatch for pattern 'const new' instead of Token::Match 2014-10-10 18:58:04 +02:00
Daniel Marjamäki 19a05b1f53 Tokenizer::setVarId: don't set varid for 'auto' keyword 2014-10-10 16:46:31 +02:00
amai2012 85500dcdbd Merge pull request #453 from simartin/ticket_5625
Ticket #5625: Simplify constant ternary operator in template parameters.
2014-10-06 09:01:08 +02:00
amai2012 cddb4af10b Merge pull request #450 from simartin/ticket_6187
Ticket #6187: Avoid infinite loop if eraseDeadCode does not remove anything
2014-10-06 08:59:56 +02:00
Simon Martin 9ddf857dc7 Ticket #5625: Simplify constant ternary operator in template parameters. 2014-10-04 20:49:57 +02:00
PKEuS a02712cb66 Some small refactorizations:
- Removed redundant calls to std::string constructor
- Use default parameters in some places
2014-10-03 10:02:46 +02:00
PKEuS 14f15d65e7 Support more patterns when replacing stuff like 'or' (#6201) 2014-10-01 08:41:55 +02:00
Simon Martin f088588c88 Ticket #6187: Avoid infinite loop if eraseDeadCode does not remove anything (invalid goto into a dead loop's body). 2014-09-30 19:43:22 +02:00
PKEuS 448195f255 Added variable name to debug message about typeStartToken()
Fixed cppcheck message
2014-09-29 14:36:03 +02:00
PKEuS de13ad7eca Improved simplifications of redundant loops:
- Execute simplifyWhile0 after simplifyKnownVariables (#394)
- Support declaration of variable in loop header in removeRedundantFor
2014-09-26 10:47:05 +02:00
Dmitry-Me b17f2eea16 Cache search result to avoid dual search 2014-09-22 15:54:17 +04:00
Daniel Marjamäki f93cf9d1b7 Fixed #6170 (Tokenizer: sizeof on array in 2d-array is not handled properly) 2014-09-16 17:21:17 +02:00
Dmitry-Me b479948f0f Refactoring: Merge overlapping Token::Match function calls 2014-09-16 06:22:16 +02:00
Daniel Marjamäki 29a49d0641 removed some redundant null pointer checks before calling Token::Match 2014-09-14 11:35:04 +02:00
Simon Martin 53b58f0ed9 Refactoring. Use Token::Match instead of hardcoded patterns to increase readability. 2014-09-14 11:26:16 +02:00
Simon Martin 4b750997cb Ticket #6121: Report a syntax error for invalid enum initializers. 2014-09-13 20:46:53 +02:00
Dmitry-Me 961a1b65ae Merge partially duplicate patterns 2014-09-12 19:10:41 +04:00
Matthias Krüger 323fd1b3dc tokenize.cpp: fix internal warning: Found simple pattern inside Token::Match() call: ") :" 2014-09-08 22:00:57 +02:00
Frank Zingsheim 8c5013adda Fixed #6073 2014-09-07 21:53:32 +02:00
Daniel Marjamäki db929ffd19 Fixed CID 1037074. Useless null pointer check. Created ticket #6144. 2014-09-07 13:50:55 +02:00
PKEuS 35b00a5e05 Support rValue references in typedef (#1823) 2014-09-06 19:00:26 +02:00
Simon Martin eeeb816db9 Ticket #6103: Simplify "new (type)" constructs into "new type" to avoid confusion upon certain input. 2014-09-05 08:02:18 +02:00
PKEuS 8c24553229 Support inherited member variables in setVarId (#4101) 2014-09-04 22:22:09 +02:00
PKEuS a52401cf1b Fixed some compiler warning about signed/unsigned conversions. 2014-09-02 11:44:51 +02:00
PKEuS 3e65cb446e Remove "auto" keyword (storage class specifier) from C++03 and C code (#4990). 2014-09-02 11:21:47 +02:00
PKEuS 80df3dc642 Disabled several checks and simplifications for C code, if they are C++-only. Do not match arguments for C code, since there can't be overloads. 2014-09-01 18:43:24 +02:00
Dmitry-Me 9199dde560 Move declarations closer to where they're first used 2014-09-01 10:05:59 +04:00
PKEuS 3ccdae78ba Support __declspec(property) (#4700) 2014-08-31 20:17:18 +02:00
PKEuS 6a4319f050 Improved simplifications:
- Rearranged their order to solve problems with typedefs. If we simplify chained declarations before typedef parsing, we have less complex expressions to deal with (#4777).
- Fixed detection of variables hiding enums
2014-08-26 15:21:19 +02:00
PKEuS 2326e78381 Fixed #6058: Don't detect class with unknown macro as variable.
Commented out crashing unit test tokenize33() in VS12
2014-08-26 10:40:00 +02:00
amai2012 e02741c82c #5780 Crash on template code below Tokenizer::setVarId(). Fix several crashes with same location. 2014-08-26 09:12:10 +02:00
Dmitry-Me 67ea470275 Break loop early, cleanup declarations 2014-08-24 20:17:41 +02:00
PKEuS 7f2be2f57c Fixed template bracket linkage in while loop simplification
Ran AStyle
2014-08-23 12:28:54 +02:00
PKEuS c678937538 Fixed more false positives of #6056:
- Implemented nextArgument() for usages before < and > are linked
- slightly optimized nextArgument()
2014-08-20 15:02:52 +02:00
PKEuS 5d50e7e9ae Changed heuristics to detect variable constructor initialization syntax (#6071) 2014-08-19 11:06:52 +02:00
PKEuS eac2d58c9e Fixed fix for #6056 2014-08-18 20:40:43 +02:00
Dmitry-Me 120e8c0674 Make loop termination more explicit. 2014-08-18 14:00:25 +04:00
PKEuS e7754be316 Fixed #6056 - properly detect member functions in setVarId() 2014-08-18 11:07:56 +02:00
PKEuS 5c54f8d0d8 Support namespaces and static member variables in setVarId (only one depth) (#6061) 2014-08-18 10:25:30 +02:00
Daniel Marjamäki a52c122229 Tokenizer::createLinks2: set no template-links in 'if (a < b || c > d)' 2014-08-17 19:03:06 +02:00
Daniel Marjamäki 5cdbe0f42d ValueFlow: Improved value flow after for loop 2014-08-17 10:40:22 +02:00
Daniel Marjamäki 75ec97ad23 Tokenizer::simplifyKnownVariables: Fixed bad simplification in for loop header 2014-08-17 07:39:42 +02:00
Daniel Marjamäki 65f10edcb6 Fixed #5866 (False negative: useless condition or null pointer dereference (null object after while loop, method)) 2014-08-16 18:32:25 +02:00
PKEuS e4b55cf843 Fixed a bug and two warnings introduced recently. 2014-08-06 13:35:39 +02:00
PKEuS adcc8b1634 Implement support for __attribute__((used)) (#3408) 2014-08-06 11:13:58 +02:00
PKEuS fd5ff1bb8b Fixed false positive #6030: inheriting classes is not a variable declaration. 2014-08-06 09:04:03 +02:00
PKEuS 83a80cebeb Fixed order of simplifications (#6029) 2014-08-06 08:39:23 +02:00
PKEuS f3e0df7501 Support C++11 style initialization with {}:
-> Support in setVarId and SymbolDatabase (#4344)
-> Fixed false positives in unused variable checking (#5491, #5494)

Side-effect: Support global variables initialized with brackets (C++03 style) in SymbolDatabase
2014-08-05 15:33:57 +02:00
Daniel Marjamäki 4dc73e3a5b Use Token::simpleMatch for simple pattern 2014-08-01 17:47:02 +02:00
Daniel Marjamäki 3f5da22d2b Tokenizer: Added FIXME for keywords handling 2014-08-01 17:27:35 +02:00
Daniel Marjamäki a943a0739a Tokenizer: Don't remove struct member in Tokenizer::simplifyKeyword() 2014-08-01 17:19:08 +02:00
Dmitry-Me dc03b98e60 Run cheaper check first, don't check the same condition twice. 2014-07-28 14:58:19 +04:00
Dmitry-Me 431453f53e Reuse previously computed values, use more const. 2014-07-25 15:05:13 +04:00
Daniel Marjamäki 2e60f30bfc Merge pull request #372 from Dmitry-Me/dontUseArrayAtWhenItWouldntThrow
Use [], not at() when the index is guaranteed to be valid.
2014-07-23 14:15:42 +02:00
Daniel Marjamäki c5e9da2984 xml dump: add more token attributes 2014-07-21 12:44:53 +02:00
Dmitry-Me cd13232062 Use [], not at() when the index is guaranteed to be valid. 2014-07-21 10:37:08 +04:00
Daniel Marjamäki 328cc7b8f5 Fixed #5996 (false positive: Clarify calculation precedence for '+' and '?'.) 2014-07-19 18:29:53 +02:00
Daniel Marjamäki 946c139043 Merge pull request #367 from Dmitry-Me/fixVariableCapitalization
Fix variable capitalization.
2014-07-18 11:15:17 +02:00
Alexander Mai 55e45add4a Fix compiler warnings 2014-07-17 20:04:56 +02:00
Dmitry-Me f995f67a11 Fix variable capitalization. 2014-07-17 12:38:09 +04:00
Daniel Marjamäki b1e5b015df xml dump: output some more info in the dump 2014-07-16 15:27:13 +02:00
orbitcowboy af6f21308f Tokenizer: Added missing comma in string array initialization (This fixes Coverity-ID: 1226263 Missing comma in a string array initialization). 2014-07-12 12:52:49 +02:00
orbitcowboy 6e5a05104b Fixed copy and paste error (Coverity-ID: 1226262 Copy-paste error). 2014-07-12 12:48:05 +02:00
Daniel Marjamäki b6a9c53826 xml dump: fixed some bad xml output in the token list dump 2014-07-14 19:49:31 +02:00
Daniel Marjamäki 8db5836e3f Fixed #5982 (Add xml dump) 2014-07-14 15:51:45 +02:00
Daniel Marjamäki 954400a382 Add simple xml debug output. When both --xml and --debug is used there will be xml debug output. 2014-07-13 17:21:45 +02:00
Dmitry-Me ba3757dfd3 Bring variables decalaration to where they are really needed. 2014-07-10 11:23:14 +04:00
Dmitry-Me d0cbfeb186 Use references instead of deep copying the strings 2014-07-09 11:21:38 +04:00
Daniel Marjamäki 14def42c99 Fixed #5972 (FP: Buffer is accessed out of bounds) 2014-07-08 16:31:08 +02:00
Daniel Marjamäki d40b77dce2 Removed special 'else if' handling. this is redundant since these are simplified. 2014-07-02 16:16:19 +02:00
Zachary D. Blair f6523e384b Fixed 4979 (Doesn't allow any ordering of int modifiers) 2014-07-01 23:59:04 -07:00
Simon Martin 7b942650c2 Ticket #5952: Simplify redundant parentheses in pointer variable declarations. 2014-06-28 09:36:51 +02:00
PKEuS b20f87faf2 Optimized Tokenizer::simplifyPlatformTypes() once more: Another 3% improvement on Windows.
-> All Token::Match strings are uppercase, so check Token::isUpperCaseName() to avoid comparisons with very slow long Token::Match strings (idea from amai)
Removed duplicate Token::Match call in symboldatabase.cpp
2014-06-25 20:42:59 +02:00
PKEuS 360fd4a565 Speedup Tokenizer::simplifyMathFunctions() and Tokenizer::simplifyPlatformTypes()
-> Speedup on entire checking time (TortoiseSVN code) by 3% (MSVC12, x64, not matchcompiled). Probably only measurable when checking code with Windows platform.
2014-06-25 17:00:59 +02:00
Daniel Marjamäki ae81b09b58 Refactoring: Move isScopeNoReturn implementation to library and reuse it both in ValueFlow and Tokenizer 2014-06-22 19:13:15 +02:00
Alexander Mai 2e3f26ba58 Patch from Dmitry-Me: reorder checks so that cheaper ones go first, reuse previously computed values, return early on edge condition 2014-06-16 21:36:31 +02:00
Simon Martin efb12f0409 Ticket #5268: Properly detect function heads when in Tokenizer::simplifyEnum. 2014-06-15 15:52:58 +02:00
Daniel Marjamäki 17f1841fba Merge pull request #339 from simartin/ticket_5868
Ticket #5868: Ignore variables called like a typedef when substituting typedefs
2014-06-14 12:38:02 +02:00
PKEuS 8b9daadd25 Replaced static variable isCPP in Token (was not threadsafe):
- Encapsulate parameters passed through AST compiler functions in a struct
-> Reduces maintenance overhead when changing them
-> Contains parameter indicating if the file is C or C++
- Added eKeyword Token type (at the moment, only true for C++ keyword "delete", but should be set for other keywords as well)
2014-06-14 10:28:12 +02:00
Simon Martin d588ed49b3 Ticket #5868: Ignore variables called like a typedef when substituing typedefs. 2014-06-14 00:50:14 +02:00
Daniel Marjamäki a4a6f3e1be Tokenizer: Removed Tokenizer::simplifyConditionOperator(). Using the AST and ValueFlow, it should be much easier to parse ?: than before. 2014-06-10 19:30:13 +02:00
Simon Martin dc12a73987 Ticket #5907: Properly handle extern declarations in Tokenizer::simplifyVarDecl. 2014-06-08 14:59:58 +02:00
Daniel Marjamäki a41f6077e1 Tokenizer: Use 'podtype' info from library. Partial fix for #5623 2014-06-08 13:28:15 +02:00
Dmitry-Me 7692a306cd Cleanup code - reorder checks and make variable declaration scope narrower. 2014-06-06 18:58:20 +04:00
PKEuS f6c9320aee Fixed incorrect usage of startOfExecutableScope() (Checking time reduced by ~60% (nonlinear) for #5876) 2014-06-05 10:45:26 +02:00
PKEuS 39b64ea5fb Simplify rValue reference arguments without name (&& -> & &) 2014-06-04 18:45:56 +02:00
PKEuS 8db0790407 Tokenizer::tokenize() can now be called without AST being created 2014-06-04 18:45:28 +02:00
PKEuS d93d7401c6 Moved getSourceFilePath(), isC() and isCPP() from Tokenizer to TokenList
Conflicts:
	lib/tokenize.cpp
2014-06-04 18:36:25 +02:00
orbitcowboy 60e80b6fb1 Fixed #5885 - fsanitize=undefined: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' in lib/tokenize.cpp. 2014-05-29 18:25:01 +02:00
Simon Martin c027c526a9 Remove unnecessary declaration (one line before the actual definition... 2014-05-25 22:04:51 +02:00
PKEuS 38aaa46804 Stabilized AST:
- Fixed broken simplification causing crashs when cast was followed by unary minus (real world examples from arch/parisc/math-emu/ (linux-kernel))
- Stabilized determination of unary and binary operators
2014-05-24 19:05:04 +02:00
Simon Martin fcff8d39d9 Ticket #5816: Properly handle template'd template parameters in enum initializers. 2014-05-23 21:25:42 +02:00
orbitcowboy 6183f21070 Fixed CID 1037088 Dereference after null check in Tokenizer::simplifyLabelsCaseDefault. 2014-05-23 21:38:56 +02:00
orbitcowboy d19f676547 Fixed travis build warning (Check Internal). 2014-05-22 18:00:06 +02:00
orbitcowboy 031020ae4a #Fixed 5485: Wrong simplification of numbers like 1e+007 to 1e+007.0 2014-05-22 17:40:15 +02:00
PKEuS d19eabde42 New Check: Compare pointer with '\0' (#4070) 2014-05-21 19:12:07 +02:00
PKEuS 7b1eca700b Fixed bug in setVarId: VarIds for member functions defined inline in class were not properly set 2014-05-21 17:30:58 +02:00
orbitcowboy e3009bdd0b Tokenizer:simplifyKeyword(): Improved matching when the static keyword is removed. 2014-05-13 16:47:55 +02:00
orbitcowboy 90c1016c74 Fixed #5842: remove C99 static keyword between [] in tokenizer. 2014-05-13 16:28:28 +02:00
Alexander Mai be9a566d48 Refactoring/small corrections to fix warnings from clang -fsanitize=undefined 'member call on null pointer' 2014-05-20 21:55:08 +02:00
PKEuS 8cb1f09fc2 Silenced travis errors (avoid false positive) 2014-05-19 20:56:05 +02:00
PKEuS 5fbd58d98d Fixed messages of CheckInternal, fixed a false positive. 2014-05-18 20:39:52 +02:00
PKEuS b162560755 Refactorizations:
- Removed some duplicate nullpointer checks
- Simplified tok->link() on '<' usage.
2014-05-18 17:07:21 +02:00
Simon Martin 69d294c6c4 Ticket #5816: Skip typename in template arguments for enum initializers. 2014-05-17 08:50:12 +02:00
Simon Martin 92cc17110d Ticket #5814: Handle A::B as template parameter for enum initializers. 2014-05-15 21:52:57 +02:00
Daniel Marjamäki 0dfbbd0f80 Fixed #5479 (Tokenizer: don't remove parentheses in code 'a<b<c>>(2)') 2014-05-11 08:22:28 +02:00
PKEuS edd84c0906 Fixed #5773: Don't prepend "std::" to function definitions 2014-05-09 21:58:28 +02:00
Daniel Marjamäki 1541e27e4a Fixed #5533 (False positive: 'Assignment of function parameter has no effect outside the function.') 2014-05-09 18:43:29 +02:00
Simon Martin 512e22d1ba Ticket #5315: Memory leak analysis confused by ((variable).attribute) notation. 2014-05-08 20:58:24 +02:00
Robert Reif ae96491d6c Fixed #5756 (declspec(nothrow) not supported) 2014-05-04 20:47:20 +02:00
Daniel Marjamäki 7d583e639c AST: Fixed handling of '(((typeof(x))*)0)' 2014-05-04 18:36:04 +02:00
Simon Martin b03f36cd71 Ticket #5709: Comma operator not properly tokenized. 2014-05-03 21:35:04 +02:00
Alexander Mai 4815e3c4c5 Fix some segmentation faults seen while reducing #5743 (sorry, no test cases supplied) 2014-04-29 20:16:50 +02:00
Daniel Marjamäki 36895674ce Refactoring. Simplified condition using Token::Match. 2014-04-29 04:45:45 +02:00
Robert Reif 4de9e29adc Fixed #5706 (operators with noexcept broken) 2014-04-29 04:37:13 +02:00
Daniel Marjamäki 9c74d914d7 Fixed #5667 (Tokenizer: simplify 'void (X::*f)()' to 'void *f') 2014-04-27 19:49:21 +02:00
Robert Reif ca9386859b Tokenizer: replace ') const| {' pattern to detect function start 2014-04-26 18:31:56 +02:00
Robert Reif cd6332d960 Tokenizer: replace ') const| {' pattern to detect function start 2014-04-26 18:30:09 +02:00
Daniel Marjamäki 9406f3428a IncompleteStatement: Fixed false positive when '({..})' blocks are used 2014-04-24 06:32:29 +02:00
Daniel Marjamäki aea528c763 enum: don't simplify enum constant that is assigned 2014-04-23 17:10:17 +02:00
Daniel Marjamäki 272fcc18d8 Don't warn about redundant number statement in '({ do_something(); 0; })' 2014-04-23 16:23:19 +02:00
Daniel Marjamäki 52e0e4453b Fixed #5646 (FP: pointer to array is not assigned a value.) 2014-04-21 16:14:49 +02:00
Robert Reif 6ff5de2118 Fixed #5697 (Check for throw in __attribute__((nothrow)) function) 2014-04-20 20:40:55 +02:00
Daniel Marjamäki 6146c8f5bb Tokenizer: Fixed bad simplifyComma for code 'return a ? b = c , d : e ;' 2014-04-18 13:38:48 +02:00
Daniel Marjamäki 064844f8db Tokenizer: Fixed bad simplifyComma for code 'a ? b = c , d : e ;' 2014-04-17 18:47:55 +02:00
PKEuS 076f7a7542 Fixed some coverity findings about dead code, fixed a misleading comment 2014-04-14 22:46:51 +02:00
Philipp Kloke dfd9d32c4b Refactorization: Removed whitespaces at the end of a token
Removed a redundant 'void'
2014-04-12 23:41:46 +02:00
Daniel Marjamäki 9d51bfd015 Fixed #5397 (False positive: Same expression on both sides of '&') 2014-04-12 16:06:31 +02:00
PKEuS 7ffc313748 Save "->" in Token::originalName if simplified to "."; Fix false positive #4890. 2014-04-12 12:04:56 +02:00
PKEuS 9c921ab657 Fixed handling of member function pointers in setVarId and SymbolDatabase (#4577) 2014-04-12 12:04:55 +02:00
PKEuS 83f4657e69 Fixed remaining issue in #3503: Member function taking a function pointer must not be "simplified" to a variable initialization 2014-04-12 12:04:55 +02:00
PKEuS 92839ab4d2 Refactorizations:
- Rearranged members of Value to reduce structures size
- Removed redundant ctor of Value
- Fixed VS warning in tokenize.cpp
2014-04-12 12:04:55 +02:00
Robert Reif 847d28d283 Fixed #5638 (is there any plan to check noexcept correctness?) 2014-04-10 16:17:10 +02:00
Daniel Marjamäki 225fb96554 Fixed #5627 (False positive assignBoolToPointer) 2014-03-31 15:55:54 +02:00
Daniel Marjamäki 088664d626 Fixed compiler warning 'conversion from unsigned long to unsigned int, may loose value' 2014-03-31 06:50:59 +02:00
PKEuS 060f9035c9 Fixed crashs on garbage code (#5604) 2014-03-30 11:38:01 +02:00
PKEuS aa527cb408 Refactorization: Store sizes as int, not as string in Tokenizer::simplifySizeof(). 2014-03-30 11:21:40 +02:00
PKEuS 4e19645d62 Added C++11 keywords / C11 types 'char16_t' and 'char32_t' (#3301) 2014-03-28 18:24:39 +01:00
PKEuS a16d631813 Further improvements to setVarId and function/array pointer detection in SymbolDatabase (#2872) 2014-03-28 17:43:40 +01:00
PKEuS 1c58628223 Handle pointer/reference to array in setVarId (#2645) 2014-03-28 16:10:27 +01:00
PKEuS efe3f834be Refactorized handling of syntaxError: Print debug output, removed a few return values that are no longer required 2014-03-27 18:41:52 +01:00
PKEuS e8c7a723f5 Fixed five new true positives in cppcheck, silenced one new false positive (see #5618) 2014-03-27 15:50:30 +01:00
PKEuS 7e4081f7f5 Treat syntaxError and cppcheckError as InternalErrors (throw as exception, #4268) 2014-03-27 13:15:21 +01:00
PKEuS 379807a8ea Fixed TODO_ASSERT_EQUAL and #5614 caused by bad simplification of return values. 2014-03-27 11:04:31 +01:00
PKEuS 5f2067e401 Refactorized dead code elimination:
- Use library to get noreturn functions
- Fixed do-while simplification (#4940)
2014-03-23 10:59:41 +01:00