From 19c7550ae009f6a1dcc59d06ccfd323755f90730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 30 Dec 2010 10:11:33 +0100 Subject: [PATCH] writing rules: more tweaks --- man/writing-rules-1.docbook | 4 +- man/writing-rules-2.docbook | 90 ++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 53 deletions(-) diff --git a/man/writing-rules-1.docbook b/man/writing-rules-1.docbook index 11a5eef77..e94758da6 100644 --- a/man/writing-rules-1.docbook +++ b/man/writing-rules-1.docbook @@ -3,7 +3,9 @@ "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
- Writing Cppcheck rules - Part 1 + Writing Cppcheck rules + + Part 1 - Getting started Daniel diff --git a/man/writing-rules-2.docbook b/man/writing-rules-2.docbook index e3199292e..c82fc23f5 100644 --- a/man/writing-rules-2.docbook +++ b/man/writing-rules-2.docbook @@ -3,7 +3,9 @@ "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
- Writing Cppcheck rules - Part 2 + Writing Cppcheck rules + + Part 2 - The Cppcheck data representation Daniel @@ -49,31 +51,37 @@ variable ids (Cppcheck gives each variable a unique id). You can ignore these if you only plan to write rules with regular expressions, you can't use variable ids with regular expressions. + + In general, I will use the --rule=.+ output in + this article because it is more compact.
- Simplifications + Some of the simplifications - This is not intended to be a complete reference for all - simplifications. It is mostly intended to show that the data is simplified - in many ways. + The data is simplified in many ways. The intention with the + simplifications is to remove all information that the rules don't + use. - The intention with the simplifications is to remove all information - that the rules don't use. + The best way to see what simplifications there are is to look at the + doxygen documentation for the Tokenizer. Some developer information such + as doxygen output is available online at + http://cppcheck.sf.net/devinfo.html
- Preprocessing (Preprocessor) + Preprocessing The Cppcheck data is preprocessed. There are no comments, #define, #include, etc. + Original source code: + #define SIZE 123 char a[SIZE]; - Debug output: + The Cppcheck data for that is: - 1: -2: char a@1 [ 123 ] ; + char a [ 123 ] ;
@@ -84,10 +92,9 @@ char a[SIZE]; typedef char s8; s8 x; - Debug output: + The Cppcheck data for that is: - 1: ; -2: char x@1 ; + ; char x ;
@@ -95,11 +102,7 @@ s8 x; Calculations are simplified. - int a[10 + 4]; - - Debug output: - - 1: int a@1 [ 14 ] ; + int a[10 + 4]; => int a [ 14 ] ;
@@ -112,11 +115,10 @@ s8 x; declared at a time. The initialization is also broken out into a separate statement. - int *a=0, b=2; + int *a=0, b=2; => int * a ; a = 0 ; int b ; b = 2 ; - Debug output: - - 1: int * a@1 ; a@1 = 0 ; int b@2 ; b@2 = 2 ; + This is even done in the global scope. Even though that is + invalid in C/C++.
@@ -132,7 +134,7 @@ s8 x; array[x + 2] = 0; } - Debug output: + The --debug output for that is: 1: void f ( ) 2: { @@ -156,7 +158,7 @@ s8 x; free(b); } - Debug output: + The --debug output for that is: 1: void f ( ) 2: { @@ -174,15 +176,10 @@ s8 x; Braces in if/for/while-body (Tokenizer::simplifyIfAddBraces) - There are always braces in if/for/while bodies. + Cppcheck makes sure that there are always braces in if/for/while + bodies. - if (x) - f1(); - - Debug output: - - 1: if ( x ) { -2: f1 ( ) ; } + if (x) f1(); => if ( x ) { f1 ( ) ; }
@@ -199,7 +196,7 @@ s8 x; f2(); } - Debug output: + The --debug output: 1: void f ( int x@1 ) 2: { @@ -223,14 +220,9 @@ s8 x; } } - Debug output: + The Cppcheck data is: - 1: void f ( ) -2: { -3: { -4: f1 ( ) ; -5: } -6: } + void f ( ) { { f1 ( ) ; } } Another example: @@ -243,12 +235,7 @@ s8 x; The debug output: - 1: void f ( ) -2: { -3: -4: -5: -6: } + void f ( ) { }
@@ -265,7 +252,8 @@ s8 x; } } - The "x = f1()" is broken out. Debug output: + The "x = f1()" is broken out. The --debug + output: 1: void f ( ) 2: { @@ -285,7 +273,8 @@ s8 x; } } - The "x = f1()" is broken out twice. Debug output: + The "x = f1()" is broken out twice. The + --debug output: 1: void f ( ) 2: { @@ -295,9 +284,6 @@ s8 x; 5: 6: } 7: } - - An interesting thing here is that "f2 ( ) ;" is written on line - 5. But the "x@1 = f1 ( ) ;" after it is written on line 4.