From bfb4d79d63bd462a12344f541a5da6620c4821bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 30 Dec 2010 20:54:52 +0100 Subject: [PATCH] writing rules #2: tweaks. published --- man/writing-rules-2.docbook | 107 ++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 22 deletions(-) diff --git a/man/writing-rules-2.docbook b/man/writing-rules-2.docbook index c82fc23f5..dffe6d605 100644 --- a/man/writing-rules-2.docbook +++ b/man/writing-rules-2.docbook @@ -59,14 +59,7 @@
Some of the simplifications - The data is simplified in many ways. 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 + The data is simplified in many ways.
Preprocessing @@ -85,7 +78,7 @@ char a[SIZE];
- typedef (Tokenizer::simplifyTypedef) + typedef The typedefs are simplified. @@ -98,32 +91,39 @@ s8 x;
- Calculations (Tokenizer::simplifyCalculations) + Calculations Calculations are simplified. - int a[10 + 4]; => int a [ 14 ] ; + int a[10 + 4]; + + The Cppcheck data for that is: + + int a [ 14 ] ;
Variables
- Variable declarations (Tokenizer::simplifyVarDecl) + Variable declarations Variable declarations are simplified. Only one variable can be declared at a time. The initialization is also broken out into a separate statement. - int *a=0, b=2; => int * a ; a = 0 ; int b ; b = 2 ; + int *a=0, b=2; + + The Cppcheck data for that is: + + int * a ; a = 0 ; int b ; b = 2 ; This is even done in the global scope. Even though that is invalid in C/C++.
- Known variable values - (Tokenizer::simplifyKnownVariables) + Known variable values Known variable values are simplified. @@ -173,13 +173,17 @@ s8 x; if/for/while
- Braces in if/for/while-body - (Tokenizer::simplifyIfAddBraces) + Braces in if/for/while-body Cppcheck makes sure that there are always braces in if/for/while bodies. - if (x) f1(); => if ( x ) { f1 ( ) ; } + if (x) + f1(); + + The Cppcheck data for that is: + + if ( x ) { f1 ( ) ; }
@@ -239,7 +243,7 @@ s8 x;
- Assignments (Tokenizer::simplifyIfAssign) + Assignments Assignments within conditions are broken out from the condition. @@ -252,8 +256,8 @@ s8 x; } } - The "x = f1()" is broken out. The --debug - output: + The x=f1() is broken out. The + --debug output: 1: void f ( ) 2: { @@ -273,7 +277,7 @@ s8 x; } } - The "x = f1()" is broken out twice. The + The x=f1() is broken out twice. The --debug output: 1: void f ( ) @@ -285,6 +289,65 @@ s8 x; 6: } 7: }
+ +
+ Comparison with > + + Comparisons are simplified. The two conditions in this example + are logically the same: + + void f() +{ + if (x < 2); + if (2 > x); +} + + Cppcheck data doesn't use > for + comparisons. It is converted into < instead. In + the Cppcheck data there is no difference for 2>x + and x<2. + + 1: +2: void f ( ) +3: { +4: if ( x < 2 ) { ; } +5: if ( x < 2 ) { ; } +6: } + + A similar conversion happens when >= is + used. +
+ +
+ if (x) and if (!x) + + If possible a condition will be reduced to x or !x. Here is an + example code: + + void f() +{ + if (!x); + if (NULL == x); + if (x == 0); + + if (x); + if (NULL != x); + if (x != 0); +} + + The --debug output is: + + 1: void f ( ) +2: { +3: if ( ! x ) { ; } +4: if ( ! x ) { ; } +5: if ( ! x ) { ; } +6: +7: if ( x ) { ; } +8: if ( x ) { ; } +9: if ( x ) { ; } +10: } +