Commit Graph

230 Commits

Author SHA1 Message Date
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
Stefan Weil 675e63b6a7 Spell checks 2011-03-30 16:45:31 +02:00
Robert Reif 3529014924 expose number of variables found by Tokenizer 2011-02-26 08:42:19 -05:00
Daniel Marjamäki 63c003f92e Tokenizer: fixed so that 'p=&x; if(p)' is simplified to 'p=&x;if(&x)'. Ticket: #2596 2011-02-20 18:18:27 +01:00
Daniel Marjamäki de75bdfed5 Tokenizer: comments/refactorings 2011-02-12 21:11:20 +01:00
Daniel Marjamäki 4d1aae5859 Tokenizer::simplifyTemplates: Broke out the functionality that instantiates a template 2011-02-12 20:58:45 +01:00
Daniel Marjamäki 9021f0f180 Tokenizer::simplifyTemplates: Broke out the functionality that handles default template arguments 2011-02-12 20:27:44 +01:00
Daniel Marjamäki 00bdf618f2 Tokenizer::simplifyTemplates: Broke out the functionality that extract a list of template instantiations 2011-02-12 20:17:58 +01:00
Daniel Marjamäki 25d6bfe3c4 Tokenizer::simplifyTemplates: broke out the functionality that extract a list of template declarations 2011-02-12 20:12:07 +01:00
Daniel Marjamäki 654116af61 Tokenizer::simplifyTemplates: Broke out handling for 'template<>..' 2011-02-12 19:43:33 +01:00
Daniel Marjamäki 63ade3e4f6 Tokenizer::simplifyKnownVariables: Split up the function into smaller functions. Broke out ..GetData function that extracts info about assigned variable before the simplification is made. 2011-02-12 09:24:20 +01:00
Robert Reif 78b5361ec8 fix #2568 (False positive: (style) Union 'A_t' hides typedef with same name (forward declaration)) 2011-02-11 19:09:24 -05:00
Daniel Marjamäki 951a81d0d2 Tokenizer::simplifyKnownVariables: Broke out the simplification into a separate function 2011-02-11 20:12:51 +01:00
Robert Reif e6848aef98 Tokenizer: refactor duplicated token copy code info function 2011-02-09 22:02:17 -05:00
Robert Reif 8eb92001b3 Fixed #2530 (Tokenizer: Remove redundant 'MyClass::' inside MyClass class declaration) 2011-02-02 07:40:08 +01:00