Commit Graph

244 Commits

Author SHA1 Message Date
PKEuS 22a8e3f4e6 Replaced Tokenizer::getFunctionTokenByName() by SymbolDatabase::findFunctionByName(), which handles scopes slightly better. 2012-09-11 18:03:47 +02:00
Daniel Marjamäki 853c6522dc Tokenizer::simplifyEnum: Readded refactorings. Tickets 3949,3950,4025,4053 has been solved as far as I see. 2012-09-08 12:42:24 +02:00
PKEuS 489df29346 Moved Tokenizer::typeConstToConstType() to Tokenizer::simplifyConst() 2012-09-07 11:41:41 +02:00
anuraggarg011 bf11248a09 Fixed #1620 (tokenizer: simplify well known math functions) 2012-09-03 18:51:15 +02:00
Edoardo Prezioso 0d26a79f2c Tokenizer::simplifyEmptyNamespaces: new function.
It removes from the token list, if found, the following tokens: 'namespace %var% { }'. It won't involve C code.
2012-08-28 22:40:25 +02:00
PKEuS 4bab7f0ee2 Removed unused and obsolete functions Tokenizer::getParameterName() and Tokenizer::getNameForFunctionParams() 2012-08-26 16:53:40 +02:00
Daniel Marjamäki 985ac662ee Fixed #4035 (False positive: Memory leak: pTempFile) 2012-08-25 12:00:25 +02:00
Daniel Marjamäki 5051837c1a Reverted last commit. I pushed it by mistake. 2012-08-25 11:00:51 +02:00
Daniel Marjamäki 5e1ccfaf90 Fixed #4035 (False positive: Memory leak: pTempFile) 2012-08-25 10:55:20 +02:00
PKEuS f238f3fad5 Support sizeof in preprocessor directives
Applied "patch" provided by michaeln123 in #4071
2012-08-22 17:28:06 +02:00
PKEuS 35d94c26d5 Changed creation of SymbolDatabase. Database always created after Tokenizer::tokenize() and Tokenizer::simplifyTokenList() instead of on-demand creation by Tokenizer::getSymbolDatabase.
-> With Token::scope() it is possible to access the symboldatabase without having to call getSymbolDatabase(). The change increases safety because it is guaranteed that the database is available in all checks, even if the specific check doesn't call getSymbolDatabase
- Tokenizer::_symbolDatabase does no longer have to be mutable -> Increased const correctness

The change above required two additional changes:
- A bug causing a debug message was fixed in the symboldatabase that became visible in the test suite by the change above.
- Simplify expressions like "struct struct Foo" which might be result of typedef instanciation.
2012-08-12 03:01:24 -07:00
PKEuS 2ab33ef21b Added Pointer to enclosing scope to class Token (Only available when symboldatabase is created). 2012-08-11 11:47:11 -07:00
Daniel Marjamäki 0254344df5 Tokenizer::simplifyEnum: Reverted refactorings/optimisations as there were regressions (#3949, #3950, #4025) 2012-08-10 14:06:24 +02:00
PKEuS c8e40773f1 Fixed cppcheck messagesa about functions that can be const/static:
- Made Tokenizer::getErrorMessages static - Avoids creation of unnecessary instance of Tokenizer
- Changed Tokenizer::removeExceptionSpecifications to common style for simplification functions. In contrast to the comment, this function doesn't call itself recursivly - fixed comment.
- Made Tokenizer::IsScopeNoReturn static.
2012-08-01 12:04:47 -07:00
PKEuS e9182f1fcc Implemented support for 'using namespace std;': Add std:: prefix to names that are known to be in std namespace. Simplify namespace (std::)tr1:: if C++11 flag is set. 2012-07-15 02:05:19 -07:00
Daniel Marjamäki 42e68550fc fixed doxygen errors 2012-07-08 19:32:33 +02:00
Daniel Marjamäki 6ad5fc8456 Refactoring Tokenizer::simplifyEnum. The enum handling is now somewhat faster since all enum values of a enum are simplified at the same time. 2012-07-06 15:43:50 +02:00
Daniel Marjamäki bb9f114d84 Fixed #3924 (False positive: Uninitialized variable (const pointer)) 2012-06-30 12:12:36 +02:00
Daniel Marjamäki 8af044255d Tokenizer: Added new function isFunctionParameterPassedByValue that check if a parameter is passed by value 2012-06-24 13:40:09 +02:00
PKEuS 4b80e91145 Implemented support for building cppcheck lib into a dll
Updated VS9 solution
New VS10 solution that builds cppcheck into a dll used by cli and testrunner.
Functional changes and advantages of new solution:
- Share code between testrunner and cli; ability to share code with gui as well (not yet implemented)
- Files of /lib are no longer compiled twice (should improve build time on single core machines)
- Added configuration for building with PCRE support
- Executables are build into /bin (/bin/debug in debug mode) folder (Should no longer require rebuild when switching between debug and release)
- Completely x64 compatible (contains also x64-debug configuration now)
2012-06-10 05:19:09 -07:00
PKEuS a9cfe2814a Made some functions const according to cppcheck results 2012-05-17 02:54:17 -07:00
PKEuS 4bb2a1b27b Made some functions static or const according to cppcheck results 2012-05-17 01:33:24 -07:00
PKEuS 1a5fbd61d2 Splitted class TokenList from Tokenizer 2012-05-05 09:33:26 -07:00
PKEuS 8cbed66089 Changed relationship between templatesimplifier and tokenizer:
- Pass a tokenizer to templatesimplifier to reduce code duplication (Make use of Tokenizer::reportError; remove redundant TemplateSimplifier::addtoken2) and amount of arguments passed to functions

Removed ctor and dtor implementation from TemplateSimplifier: This class shouldn't be instanciated.
2012-04-23 20:45:36 +02:00
Daniel Marjamäki d5f6cfcfa8 Tokenizer: Use new setVarId function. Removed the old one. 2012-04-22 11:36:31 +02:00
PKEuS 3d2b5a30fe Implemented generic reportError functions in tokenizer (similar to Check::reportError) to reduce code duplication 2012-04-22 11:28:46 +02:00
PKEuS 1c3c94dc67 New simplification: Remove 'extern "C"' from C++ code.
Refactorization in cppcheck.cpp: Catch exception as const reference instead of non-const reference.
2012-04-16 16:25:04 +02:00
Daniel Marjamäki 7669abb170 Tokenizer::setVarId : Starting to rewrite Tokenizer::setVarId. The purpose of the rewrite is to make this function faster. 2012-04-15 11:47:22 +02:00
Daniel Marjamäki c7093ca5d6 Tokenizer: allow that time is measured for certain slow simplifications 2012-04-10 13:45:34 +02:00
Daniel Marjamäki d6c8de104c Revert "Fixed #3648 (Internal error: Token::Match called with varid 0)"
This reverts commit 1fa1ddccba.
2012-03-20 19:00:16 +01:00
Daniel Marjamäki 1fa1ddccba Fixed #3648 (Internal error: Token::Match called with varid 0) 2012-03-20 18:58:27 +01:00
PKEuS cb2a754983 Implemented support for C++11 right angle brackets (>>)
Implemented support for linkage between < and > (Information: It is possible that under certain circumstances comparision operators are linked, since its sometimes difficult to separate between them.)
2012-03-19 18:45:47 +01:00
PKEuS 3af32b0da2 Refactorizations in tokenizer:
- getSourceFilePath returns a const reference now
- Replaced some simple patterns by string comparisions/direct function calls
- Replaced a few indendation counters by easier code
- Replaced one offset variable by token pointer to avoid subsequent calls to tokAt with the same number
2012-03-17 11:48:40 +01:00
PKEuS 1747813a8b Added check for invalid pointer casts (#1255)
Detect sign extension problems when variable is a reference (#3637)
Refactorizations:
- Tokenizer::getFiles returns a reference instead of a pointer, because its guaranteed that no nullpointer is returned
- Remove signed/unsigned in one step for "%type% signed|unsigned"
- Fixed recently introduced compiler warning in symboldatabase.cpp
2012-02-26 11:56:32 +01:00
PKEuS 9431fb1b7e Improved STL checks:
- Added performance checking for .c_str() for return values and function parameters (#1079)
- Added more containers (basic_string, C++11 containers) and more functions to checking (.at, .resize, .reserve, ...)
- Make use of symboldatabase in missingComparision check
2012-02-25 12:43:27 +01:00
PKEuS 9a5f66030c Improved unused private function check:
- Fixed #3628
- Added support for friend
Improved symbol database:
- friend scopes are now set
- Added findScopeByName function
Refactorizations:
- Removed some unnecessary "virtual" keywords
- Removed unnecessary _filename member variable, pass it as argument instead
- Made CppCheck::replaceAll static, since it is independant from a specific CppCheck instance, Pass string to be modified by reference
2012-02-24 20:45:56 +01:00
PKEuS b1ff900aaa Some refactorizations 2012-02-18 23:43:51 +01:00
Daniel Marjamäki 9df6088ddd Revert "really fix #3527 (Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers)"
This reverts commit a37031944e.

I don't want this hard coding of macro names. Feel free to come with a more generic solution if you want.
2012-01-30 06:15:41 +01:00
Robert Reif a37031944e really fix #3527 (Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers) 2012-01-28 20:58:51 -05:00
Edoardo Prezioso ca8e8d26c7 Tokenizer: extract realloc simplification and simplify also when each argument is done by more than one token.
Restyling of a comment in tokenize.h.
2012-01-27 13:56:06 +01:00
Edoardo Prezioso 6e164ae7ed Fixed ticket #3557 (Tokenizer: simplification of '[]' doesn't work well):
extract undefined size array simplification and handle multiple arrays and combos between pointers and arrays, don't handle the definitions as arguments of function.
2012-01-26 17:25:52 +01:00
Edoardo Prezioso b6a0896ce6 Change 'simplifyReturn' to 'simplifyReturnStrncat' because it's not clear what this function does. 2012-01-26 11:49:08 +01:00
Edoardo Prezioso 5953ed7318 Fixed ticket #3528 (Tokenizer: improve simplifyFunctionParameters to take count of square brackets) 2012-01-23 16:10:15 +01:00
Edoardo Prezioso b0dac2fa2e Tokenizer::copyTokens: add optional parameter which preserve the line number differences between tokens to be copied. 2012-01-21 17:18:16 +01:00
Reijo Tomperi be7691c7b4 Refactoring: Move rest of the template simplification into TemplateSimplifier
simplifyCalculations() was temporarily moved into TemplateSimplifier also, it should be moved to a better place.
2012-01-09 21:33:11 +02:00
Reijo Tomperi e91d239ea5 Refactor: Move file extension checks from Tokenizer to Path class. This has also functional change as now also file.JAVA is considered a Java file. 2012-01-06 21:56:28 +02:00
Daniel Marjamäki de4a64332e Refactoring: Copy FileLister::acceptFile to Path::acceptFile. Use Path::getFilenameExtension and Path::acceptFile in Tokenizer. Use Path::acceptFile in CppCheck::processFile instead of hardcoded handling. 2012-01-06 17:31:10 +01:00
Reijo Tomperi eda04ad906 Refactoring: Move template code into templatesimplifier: simplifyTemplatesExpandTemplate() 2012-01-05 22:45:19 +02:00
Edoardo Prezioso 75fbe310ff Extract various functions inside the Tokenizer class and fix tokenization of 'return __LINE__ ;'. 2012-01-04 12:57:58 +01:00
Reijo Tomperi 0369681a2c Refactoring: Move template code into templatesimplifier: simplifyTemplatesGetTemplateNamePosition() 2012-01-03 23:49:50 +02:00
Reijo Tomperi ac290b1a8a Refactoring: Move template code into templatesimplifier: simplifyTemplatesUseDefaultArgumentValues(), simplifyTemplatesInstantiateMatch() 2012-01-03 23:35:06 +02:00
Reijo Tomperi 16fb1801e1 Refactoring: Move template code into templatesimplifier: simplifyTemplatesGetTemplateDeclarations(), simplifyTemplatesGetTemplateInstantiations() 2012-01-02 23:05:27 +02:00
Reijo Tomperi 37269d0c28 Refactoring: Move template code into templatesimplifier: simplifyTemplatesExpandSpecialized() 2012-01-02 22:53:13 +02:00
Reijo Tomperi aa927d5aa3 Refactoring: Add new file lib/templatesimplifier.cpp
The plan is to move template simplification into this new class to take some lines from 10 000 line tokenizer.
2012-01-01 22:55:05 +02:00
Reijo Tomperi 8cae17fda8 Update year to 2012 2012-01-01 01:05:37 +02:00
Reijo Tomperi 90e1a397a2 Refactoring: Remove duplicate function from tokenizer: code_is_c() -> isC() 2011-12-29 00:36:16 +02:00
Edoardo Prezioso ec0badb651 By pressing request, extract method: simplifyJavaAndCSharp. 2011-12-28 22:44:53 +01:00
Jonathan Neuschäfer 7a5627029f tokenizer: proper checks for Java and C# 2011-12-27 18:01:39 +01:00
Jonathan Neuschäfer 103588c5bc Refactoring: tokenizer: factor out fileExtension 2011-12-27 18:01:39 +01:00
Daniel Marjamäki 91874214d8 Refactoring: Added utility function that determine if scope ends with a call to a noreturn function 2011-12-27 18:00:12 +01:00
Daniel Marjamäki 385afffb14 Null pointers: show inconclusive errors if functions are called. Assume they won't assign the pointer. Ticket: #3443 2011-12-26 07:13:10 +01:00
Reijo Tomperi e112bfdd47 Refactoring: Rename some variables and funtions in tokenizer.
Small logic change also for count variable to make new name more logical.
2011-12-26 00:06:27 +02:00
Reijo Tomperi 347982a347 Refactoring: Extract several methods from tokenize() 2011-12-24 23:23:08 +02:00
Reijo Tomperi 8e6ebd4a22 Refactoring: Extract method: simplifyDoublePlusAndDoubleMinus() 2011-12-24 22:51:55 +02:00
Reijo Tomperi 00cbf02d84 Refactoring: Rename variable used -> templateInstantiations 2011-12-24 00:03:03 +02:00
Reijo Tomperi 70c4bb54b4 Refactoring: Split long function in tokenizer.
simplifyTemplatesInstantiate()
2011-12-22 23:13:45 +02:00
Reijo Tomperi 1c12d04d0d Refactoring: Make a 300 line function a little smaller.
simplifyTemplatesInstantiate()
2011-12-22 22:39:15 +02:00
Edoardo Prezioso 52620e6493 Tokenizer::simplifyDoWhileAddBraces:
1)rewrite fix for ticket #988 (just don't simplify inside macro parenthesis);
2)use a different organization of the code: start from last token and proceed backwards. This way 'simplifyDoWhileAddBracesHelper' can be called just once, hence the 'Helper' code can be improved and moved in the main function.
2011-12-12 00:20:46 +01:00
Edoardo Prezioso bf815ac1e4 Improve labels simplification code, remove redundant checking. 2011-12-10 14:13:48 +01:00
Edoardo Prezioso 7d12951da0 1)Fixed ticket #3184 (Improve Tokenizer: improve simplifyMulAnd to simplify weirder code);
2)Fix a test case inside TestSimplifyTokens::flowControl.
2011-12-09 20:47:51 +01:00
PKEuS 1bef8d1247 Tokenizer: Code cleanups 2011-12-08 17:42:26 +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 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 Marjamaki b96ab6ba26 Fixed #3188 (Function parser false positive) 2011-11-05 12:23:05 +01:00
PKEuS 845e5d259a Improved isJavaOrCSharp, isC and isCPP. Fixed isC for files with includes. 2011-10-27 19:18:54 +02:00
seb777 aa74761e8d fix isC method (.C files are C code files) 2011-10-26 22:54:00 +02:00
Thomas Jarosch 84a763d3b0 Run astyle 2011-10-26 21:15:44 +02:00
seb777 de71c41379 Fixed Ticket 2144 (false negatives: Old Style Pointer Cast apply only on .cpp files) 2011-10-26 21:17:27 +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
Benjamin Goose 7d6b76e1d1 Include <iosfwd> for std::istream. 2011-10-20 08:46:29 +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
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 f95b692a69 Fixed ticket #3113 (complete simplification of dead code after control flow statements) 2011-10-15 01:34:07 +02:00
Daniel Marjamäki 6f8e42a5af changed the astyle formatting flags 2011-10-13 20:53:06 +02:00
Robert Reif 7dd001c9a9 run astyle 2011-10-06 21:10:20 -04:00
Edoardo Prezioso fe4ce594ce Renamed the function 'removeRedundantCodeAfterReturn' with 'simplifyDeadCode'.
This is a preparation in order to add new features to this function (see the @todo in the tokenize header file, ticket #3113 and #3175 for details).
2011-10-06 22:40:39 +02:00
Robert Reif 9994218aa2 refactor last commit to move unknown type output to seperate function 2011-09-28 07:36:48 -04:00
Robert Reif f97424b242 start adding Windows ASCII TCHAR conversion support 2011-09-24 14:51:03 -04:00
Robert Reif 97d4277854 add Microsoft memory function conversions to standard cstring functions 2011-09-22 19:59:56 -04:00
Robert Reif 66eb37c135 convert size_t to standard type 2011-09-18 10:31:31 -04:00
Edoardo Prezioso 1ff7410f4f Fixed #3075 (False positive => Improve tokenizer: remove redundant code after a 'return' state) 2011-09-13 07:55:47 +02:00
Daniel Marjamäki 46b5d5bd00 Fixed #3069 (False positive: Memory leak: data) 2011-09-03 20:45:48 +02:00
Robert Reif 389ab80b63 fix #2999 (false positive: (style) Struct 'Fred' hides typedef with same name) 2011-08-14 18:06:05 -04:00
Robert Reif 1286898fa0 fix #2864 (--errorlist missing errors: variableHidingTypedef and Extra qualification) 2011-06-28 21:46:54 -04:00
Reijo Tomperi 918b4d859f Fixed #2860, False positive: Returning value of strncat() reported as memory leak
http://sourceforge.net/apps/trac/cppcheck/ticket/2860
2011-06-26 23:53:16 +03:00
Robert Reif 5e3263235b fix #2739 (segmentation fault of cppcheck ( if()x )) 2011-06-11 15:51:12 -04:00
WenChung Chiu 1ea52cfa02 Fixed #2784 (Pointer issue: *&f=open()) 2011-05-18 07:25:30 +02:00
Daniel Marjamäki 739b6a93e2 Fixed #2713 (False positive (Redundant assignment)) 2011-04-16 12:07:56 +02:00