Home
RuleWizard User's Guide
Contents
1. 9 Creating a rule generally involves the follovving steps 1 Using plain English define the rule that you want to create and enforce For example Begin class names with an uppercase letter 2 Express this concept in terms of RuleWizard elements Create the parent rule node that is the subject of your rule a Inthe Node tab select the node that is the sub ject of your rule Tip For a description of a certain node right click the node and choose View Documenta tion from the shortcut menu that opens b Right click the selected node then choose Cre ate Rule from the shortcut menu A rule node will appear in the GUI s right panel e Add further qualifications to your node until it fully expresses your rule Overview How to Create a Rule a Right click any of your rule s nodes All available options for the chosen node will be displayed in the shortcut menu that opens Any options that are not programming elements or concepts are explained in the RuleWizard Commands topic of this User s Guide b Choose a command from the shortcut menu Depending on the command that you choose RuleWizard will add a rule element modify a rule element or open a dialog box that lets you add or modify a rule element c If you want to continue adding to and modifying the rule you can do so by right clicking any rule node or rule element then choosing one of the available commands C D
2. O 8 c 0 D _ DC RuleWizard Commands 62 Context are inverse operations For example an expression can be in the context of an statement but be contained in the condi tion rather than the body of the statement Condition Lets you create a rule condition about the parent node s condition statement The condition of Node A returns node A s condition statement Expressions and Regular Expressions Expressions and Regular Expressions Expressions Expressions are used to match values is used with expressions to indicate a variable You can enter expressions in the Modify Expression window A few examples of valid expressions that you could enter in this window include Expression Matches Example a value equal 1 matches values ton equal to 1 lt n a value less lt 100 matches val thann ues less than 100 gt n a value greater gt 100 matches val thann ues greater than 100 lt n a value less lt 550 matches val than or equalto ues less than or equal n to 550 gt n a value greater gt 1 matches values than or equalto greater than or equal to n 1 63 J o gt OH o Expressions and Regular Expressions Regular Expressions Regular expressions are used to match strings A regular expression is similar to a Perl expression You can enter regular expressions in Regexp fields
3. return true a gt b Greater than or equals expression Example bool func int x LE XS 3 1 a gt b return false return true Logical Comparison expressions expressions involving logical operators la Logical not expression Example bool func int x DE tX la return false return true a amp amp b Logical and expression Example 75 J o O 8 c 0 Dec DC Available Rule Nodes 76 bool func int x int y if x amp amp y a amp amp b return false return true alip Logical or expression Example bool func int x int y if x Il y allb return false return true Miscellaneous Miscellaneous expressions which don t fit in other categories ellipses Ellipses expression used for catch parameter Example void func try catch catch parameter is a b Dot operator expression Example class Foo public void func int 222 T int bar Foo f f func tf cb Available Rule Nodes return f z2zz ab a b Scope reference expression Example class Foo public static void func T void bar Foo func ff ash amp a Address of expression Example int i 0 int j amp i Ka a Dereference expression Example int i new int XL 5 a a b Dot star expression used in pointers
4. L 5 DC Rule Properties Panel 54 Header Determines the name that CodeWizard assigns to this rule Severity Choose the severity category in which you want CodeWizard to classify the rule CodeWizard classifies rules into groups based on the severity of violating the rule e Severe Violation e Possible Severe Violation e Violation e Possible Violation e Informational The Severe Violation category should contain rules whose viola tion will definitely result in a bug Each category below Severe Violation should contain rules whose violations have a progres sively lower probability of resulting in an error CodeWizard users can suppress rules according to their severity so it is important to classify each error appropriately If a violation of this rule will very likely lead to an error give it a high severity if you classify a severe rule as Informational a violation of that rule may be overlooked by a user suppressing Informational viola tions Note If you do not specify the rule s severity it will be catego rized as a Violation the default setting Language Selections Determines which language s this rule applies to Rule Properties Panel Es Rule Properties xi Codewizard Rule ID Header Severity Viotation Language Selections vic Vi C Info Tab The Info tab allows you to specify the following properties e Author Indicates the name of
5. Sal a D N Q G Help Menu Help Menu The Help menu contains the following commands e RuleWizard Documentation Displays the RuleWizard User s Guide e Rule Documentation Displays the documentation that RuleWiz ard automatically generates for custom rules To update this doc umentation choose Rule gt Update Documentation e About Displays RuleWizard s version number gt 0 D e N x 5 DC 48 Nodes Tab Nodes Tab The Nodes tab contains the main elements of C and C code You can use the Nodes tab to start creating rules by right clicking the node that you want to be your parent rule node and choosing Create Rule from the shortcut menu that opens CH C C 1 Constants Declarations Q C Expressions C Assignment CI Bitwise C a C alb C agb IN a b CI Comparison Logical Cf Miscellaneou CH Numerical L Name Spaces Cf Protection Specifi CJ Statements CI Types 4 A nones leet Sal N DA Q G 49 0 D e N L 5 DC Results Tab 50 Results Tab Clicking the Results tab opens the results tree which displays all mes sages that RuleWizard has generated To view the results tree click the Results tab at the bottom of the left GUI pane To view RuleWizard Mes sages simply click on that category all results will be displa
6. c 0 Dec DC Available Rule Nodes 84 Miscellaneous Various nodes not fitting in other categories File File containing source code Used for rules about relationships of nodes within a files Protection Specifiers Nodes which specify access accessibility public Public accessibility Example class Foo public public Foo T protected Protected accessibility Example class Foo protected protected Foo T private Private accessibility Example class Foo private private Foo T Statements General node for all types of statements break Break statement Example bool bar void func while 1 if bar break break case Case statement Example void func int i switch i case 1 break case case 2 break case catch Catch statement used for exception handling Example void bar void func int i try bar h Gateh Cetin A catch continue Continue statement used in loops Example Available Rule Nodes 85 J o gt O Available Rule Nodes bool bar int void func int i while i if bar i continue continue default Default statement used inside switch statement Example void func int i switch i case 1 break case 2 break default break default do while do while lo
7. associated with the rule s that you want CodeWizard to enforce 5 Click Apply and or OK 6 Run CodeWizard as normal to automatically enforce these rules Suppressing and Disabling Rules If a custom rule is not relevant to a particular situation you may want to suppress reporting of that rule s violations Rules created in RuleWizard can be suppressed in the same way that built in CodeWizard rules are suppressed For information about suppressions refer to the CodeWizard User s Guide When suppressing custom rules be aware that these rules are categorized as User RulelD Rule ID is specified in the Rule Proper ties panel When you suppress a rule CodeWizard checks for violations but does not report them If you do not want violations of a particular rule reported under most circumstances you may improve testing performance by dis abling the rule then enabling the rule only when you want to enforce it If you never enabled a rule the rule is already disabled To disable a previously enabled rule perform the following steps O gt Ve Sal D Vu o 2 5 cc D c 9 How to Automatically Enforce Your Custom Coding Standards UNIX Open the text file that tells CodeVVizard to enforce that rule 2 In that text file remove or comment out the names of the rule file i e IfAssign rule that you do not want enforced 3 Save the text file Windows 1 Open the CodeWizard
8. Control Panel 2 Click the Rules Tab 3 Inthe Rules Directory List select the entry for the file that tells CodeWizard to enforce this rule 4 Clear the check box associated with the rule that you want to dis able 5 Click Apply and or OK Enforcing Multiple Rule Sets In some cases you may want to have multiple rule sets For example you might want a company set a team set and a project set To create such a rule set 1 UNIX 12 In the directory where the rules are saved create a text file that contains the names of the rule files i e IfAssign rule that you want enforced When you add the rule files names do not use any spaces or indentation Add only one rule file s name per line Save that text file Tell CodeWizard which rule set s you want it to enforce by per forming the appropriate procedure below In your psrc file enter the name and path of the rule set s that you want to enforce How to Automatically Enforce Your Custom Coding Standards e For example if you wanted to enforce directory1 site_rules txt directory2 proj_rules txt and directory3 user_rules txt you would enter CodeWizard ruledirlist directoryl site_rules txt CodeWizard ruledirlist directory2 proj_rules txt CodeWizard ruledirlist directory3 user_rules txt e If all three lines are in a psrc file all the rules listed in these three files will be enforced e Ifyou want to temporarily disable a rule set
9. Properties To specify such rule properties as Rule ID header severity author and description choose Rule gt Properties then enter the desired properties in the Rule Properties panel How to Save a Rule How to Save a Rule In order to enforce a rule you must save it To save your rule choose Rule gt Save or Rule gt Save As This command will invoke a file chooser in which you can specify the rule s filename and path Be sure to give each rule a rule extension If you do not use this exact exten sion CodeWizard will not load your rules properly After you have saved your rule s you can exit RuleWizard then enable your rule You can determine if RuleWizard automatically enables saved rules with out asking if it asks you about enforcing each rule you save or if it does not enforce saved rules by choosing one of the options available in the RuleWizard Preferences panel C D gt Ke Sal D Vu o 2 5 cc D c 9 How to Automatically Enforce Your Custom Coding Standards Hovv to Automatically Enforce Your Custom Coding Standards To have CodeWizard enforce an enabled coding standard run CodeWiz ard as normal If you want CodeWizard to enforce a rule that you have not yet enabled perform the following steps UNIX 1 If the rule that you want to enforce is saved in the default direc tory lt codewizard_install_dir gt rules open the cwrules txt file in that direc
10. a green bar indicates that the rule is valid The messages in the status bar tell you how make an invalid rule valid The rule needs an output with a non empty message i Rule Properties Panel Rule Properties Panel The Rule Properties panel allows you to specify the following rule proper ties e Rule ID e Header e Severity e Language Selection e Author e Description To open the Rule Properties panel choose Rule gt Properties The Rule Properties panel has two tabs e CodeWizard Determines properties that will be used within CodeWizard e Info Lets you store general information about the rule CodeWizard Tab The CodeWizard tab allows you to specify the following properties e Rule ID Type the number that you want CodeWizard to assign to this rule Each rule should have a unique Rule ID When this rule is violated CodeWizard will report a violation of rule user Rule IDI Note CodeWizard assigns Rule IDs from 100 699 to built in user rules If you assign your custom rule a Rule ID that is also assigned to a built in rule CodeWizard will report violations of both of these rules as violations of the same Rule ID For exam ple if you have two different rules whose Rule ID is 101 a viola tion of either rule will be flagged as a violation of user_101 You can prevent such confusing output by ensuring that every rule has a unique Rule ID 53 Sal a o N Q G 0 D e
11. i Assignment a b a b Plus equals operator expression Example int i 1 int j 0 j i Plus equals at b a b Minus equals operator expression Example int i 1 int j 0 j i Minus equals a b a b Divide equals operator expression Example int i 4 int j 2 j i Divide equals a b a b Multiply equals operator expression Example int i 2 int j 3 j i Multiply equals a b a b Mod equals operator expression Example int i int j j i Mod equals a b 2 3 a amp b Bitwise and equals operator expression Example int i 2 int j 3 j amp i Bitwise and equals a b a4 b Bitwise xor equals operator expression Example int i 2 int j 3 j i Bitwise xor equals a b al b Bitwise or equals operator expression Example int i 2 Int g 3 j I i Bitwise or equals a b a lt lt b Left shift equals operator expression Available Rule Nodes 71 J o gt O 8 c 0 Dec DC Available Rule Nodes 72 Example int i 2 int j 3 j lt lt i Left shift equals a b a gt gt b Right shift equals operator expression Example int i 2 int CR j gt gt i Right shift equals a b Wel Predecrement expression Example int i 1 i Predecrement a a Preincrement expression Example int i 1
12. i Preincrement ta a Postdecrement expression Example int i 1 i Postdecrement a a Postincrement expression Example int i 1 Available Rule Nodes i Postincrement att Bitwise Expressions involving non assignment bitwise operators va Bitwise mot expression Example int a 3 Bitwise not a alb Bitwise or expression Example int x 73 y 0 y x 4 Bitwise or alb a amp b Bitwise and expression Example int z 73 y 0 y z amp Ox0f Bitwise and a amp b a b Bitwise XOR expression Example int z 73 y 0 y z Ox0f Bitwise XOR ab Comparison Expressions which compare values a Equality operator expression 73 J o mg gt O Available Rule Nodes Example bool func int x if x 3 1 a b return false return true al b Not equal operator expression Example bool func int x if x 3 at b return false return true a lt b Less than expression Example bool func int x if x lt 3 ach return false return true a lt b Less than or equals expression Example bool func int x LES 3 d a lt b return false 8 c 0 Dec GU DC return true 74 Available Rule Nodes a gt b Greater than expression Example bool func int x LE XS 3 f a gt b return false
13. set operator that it is attached to When you choose this type of output the viola tion output can contain properties of the collector but not properties of nodes contained in the set operator Currently the only variable you can use here is count Indirect Direct Check When an indirect check is performed CodeWizard searches for the specified condition in all nodes that have the specified relationship to the given node When a direct check is performed CodeWizard searches for the specified condition only in the first node that has the specified relationship to the given node J o O 59 8 c 0 Dec DC RuleWizard Commands 60 e Create Set Operator Creates a set operator Set operators are used to specify relationships between set components Available options include e Union The set of nodes that are in either the attached set component or the operand including the nodes that are in both e Intersection The set of nodes that are in both the attached set component and the operand e Difference The set of nodes that are in the attached set component but not in the operand or the set of nodes that are in the operand but not in the attached set compo nent e Left minus Right The set of nodes that are in the attached set component to the left of the set operator but which are not in the operand as indicated in the circle attached to the right of t
14. to member functions Example class Foo public void func J o mg gt O Ir typedef void Foo mpf void bar Foo f mpf ampf amp Foo func ampf a b 77 8 c 0 Dec DC Available Rule Nodes 78 a gt b Arrow star expression used in pointers to member function Example class Foo public void func T typedef void Foo mpf void bar Foo f mpf ampf amp Foo func f gt ampf a gt b a b Array reference char array John Doe char c array 0 array reference a b a b Compound statement list Example void func for int i 0 i gt 0 i lt 10 i a b in for condition a b Function call expression Example void foo int i void bar int x foo x Function call a b Left Hand Side is Function foo Right Hand Side is Parameter x Available Rule Nodes a b c Ternary operator expression Example bool func int x return x 2 true false Ternary operator a2bic typeid typeid operator expression used for RTTI Example class Shape void f Shape amp r typeid r typeid sizeof sizeof operator expression Example int ti malloc 20 sizeof int sizeof new new operator expression Example int i new int 20 new delete delete operator expression Example int i new int delete i delete thr
15. RuleWizard User s Guide RuleWizard User s Guide Introducing RuleWizard Welcome T 1 Contacting ee testes catia aliens ceed 2 Creating Custom Coding Balas Overview How to Create a Rule see ee eee eee How to Customize Rule Properties eee eee eee ee eee How to Save and Enable a Rule eee eee eee 9 How to Automatically Enforce Your Custom Coding Standards 10 Tutorial Creating and Enforcing Custom Coding Standards 14 Lesson 1 Do not use the 2 operaior eee eee 15 Lesson 2 Function Names Must Begin With a Capital Letter 21 How to Modify an Existing Rule AA 31 Working With Node Sets AA 32 RuleWizard GUI Help FE Mentee diner Seed Ee E ees ed ebe 44 Nodes Mentre ai tc eege el 45 R le MENU oe sl ideas deed eege AEN EEN sates AUER 46 VIE 47 OID MENU cient ee eene Eet nt 48 Nodes Tabien deee eeeeeegee eeENN NENNEN e N EEN 49 Results Tabria aa a aa a eeneg da aa aeaaea Tata deS 50 Files Tabs EE 51 EIN EE 52 Rule Properties Panel sse esse esse esec eeee eenn neee 53 RuleWizard Preferences PDanel eee 56 Reference Guide RuleWizard Commande sss eee eee 58 RuleWizard User s Guide Expressions and Regular Expressions 63 Available Rule Nodes AAA 67 Index RuleWizard User s Guide Welcome Welcome Welcome to RuleWizard a feature that allows you to create custom cod ing standards CodeWizard can automatically enforce any rule created in RuleWizard By allowi
16. With Collectors Counts and Trigger Points About Trigger Points RuleWizard s Collector and Count commands let you create a rule con dition that restricts a node or node set s quantity To create such a rule condition you would first create a collector then right click the collector and choose Count The collector keeps track of the number of times that the specified pattern is found Count places a condition on what number of instances constitutes a rule violation When a rule that restricts a node s quantity is enforced the number of instances of the pattern are collected in the collector the count is checked and a violation is reported if the count falls within the parameters specified in the rule By specifying when CodeWizard should empty the collector you can determine precisely how the count is determined This is done through the use of trigger points Trigger points determine the node at which CodeWizard starts and stops counting the number of instances that occur The correct trigger point number to use is determined by counting back from the node to which the collector is attached to the node at which you want the collector emptied and a violation reported if the specified pat tern is found Working With Node Sets For example consider the following example trigger point indicator In this example a trigger point of 1 indicates to empty the collector after each switch statement is searched The swit
17. a tion output can contain properties of the collector but not properties of nodes contained in the set operator Currently the only variable you can use here is count Working With Node Sets If your rule includes a collector you can have your output include the number of hits that the collector has accumulated To do this enter COUNT A where A is the label of the collector whose count you want reported in the appropriate output message You can also have your output message list the items that a collector has accumulated To do this enter LIST A where A is the label of the col lector whose list you want reported in the appropriate output message These two variables COUNT and LIST are called set references O gt Ve Sal D Vu 41 File Menu File Menu The File menu contains the following commands e Customize Preferences Opens the RuleWizard Preferences panel which allows you to customize such RuleWizard options as rule view and rule file directory e Save Preferences Saves the current RuleWizard Preferences e Print Prints the contents of the current window How well this works depends on your Java implementation e Exit Closes RuleWizard Any rules that were open will be saved as you exit gt 0 D e N x 5 DC A4 Nodes Menu Nodes Menu The Nodes menu contains the following commands Properties Indicates which Node Dictionary you a
18. a rule node or other rule element a shortcut menu containing all available commands for that node or element will open Most commands are programming elements or concepts The following commands are unique to RuleWizard Create Collector Adds a collector displayed as a pentagon to the selected rule node The collector allows you to place numeri cal stipulations on the outcome of a rule Works with the Count command available by right clicking the collector The collector keeps track of the number of times a pattern is found Count places a condition on what number of instances constitutes a rule violation Create Output Adds an output arrow to the selected rule node The output arrow is the essential closing to any rule An output arrow tells RuleWizard to report an error if the specified pattern is found if no output arrow is included no violations of this rule can be reported The placement of the arrow determines what line number is reported in the error message For example if you have a rule with nodes A B and C and you attach the output arrow to node C the line number will reference the line where C occurs if you attach the output to node A the line number will ref erence the line where A occurs If you are adding an output arrow to a set component a collector or set operator you must choose between the following two types of output arrows e Hits Output Choose this output to indicate that e One output message sho
19. ant a rule to check if the total number of hits in two different sets of nodes is greater than 0 In such cases you would create a rule that includes one or more set components Set components are a category of components that represent sets of nodes These components include collectors and set operators Collec tors let you restrict a node or node sets quantity Set operators let you specify a relationship between two or more set components for example they could be used to create a rule that checks that the total number of hits in two rule conditions is less than 1 Working With Node Sets Set operators Reference Variable Collectors O D DA gt Ve Sal Gi D Vu Using Set Operators to Specify Relationships Between Set Components You can use set operators to create rule segments that collect the number of hits of a specific relationship between two set components For exam 33 o 2 5 cc o D 9 Working With Node Sets 34 ple you could use set operators to create a rule segment that collects the number of hits of the pattern of nodes that are in either set component A or in set component B Set operators are rule elements that indicate two things e Which two set components you want to represent a relationship between e What type of relationship you want to establish between the two associated set components Because set operators establish relationships
20. ate directory e Rule file enabling Determines how rule files are enabled Avail able options include e Ask me whenever save a rule that is not enabled e Do not enable rules automatically do not ask me e Enable rules automatically do not ask me Browser Tab The Browser tab lets you configure the following preferences e Browser Determines what browser RuleWizard uses e Command Determines browser commands such as executable name and any arguments that you want RuleWizard to pass to that browser If you select a browser name that is provided RuleWizard will automatically fill in both Executable and Argu ments If you select Other you can click Browse to navigate to the appropriate Executable settings For Arguments enter 1 e Use DDE Determines whether or not Dynamic Data Exchange DDE lets programs share information If you select Use DDE the changes you make to files as you are using RuleWizard will automatically be applied to other programs that use those same files Use DDE is selected by default and may not be disabled for the Automatic option in the Browser field It is selected by default but may be disabled for Netscape Navigator and Inter net Explorer When Other is selected in the Browser field Use DDE is disabled by default and may not be enabled Sal a o N Q G 57 8 c 0 Dec DC RuleWizard Commands 58 RuleWizard Commands When you right click
21. ber of nodes from the node with the attached collector to the top node of the rule then add 1 You cannot place a trigger point on a node for which a direct check is performed You cannot add an output arrow between the collector and the node applied node that the trigger point number points to Determining the Output Type of a Set Component If you place an output arrow on a set component you will be asked to determine when the output fires reports that the pattern has been vio lated The available output options for set components are Hits Output Fires on each hit or each node contained in the set This type of output arrow is placed below the center of the set operator that it is attached to When you choose this type of out put the violation output can contain fields of nodes contained in the set operator For example if you have a collector that con tains variables in Java or C and you select a Hits Output you can use an output message such as Initialize all variables in con structor Variable name is not initialized When this rule is actu ally violated the name variable will be replaced with the name of the uninitialized variable Trigger Output Fires once for the set when the set is triggered at the trigger point This type of output arrow is placed below the left side of the set operator that it is attached to or below the trig ger point number When you choose this type of output the viol
22. between set components they must be connected to one set component the set component that the set operator is attached to and reference another set component the operand of the set operator i e the other set component that this set operator works with Set operators can be used to establish four types of relationships e a union of two set components an intersection of two set components an exclusive or relationship between two set components e adifference between two set components A union is the set of nodes that are e inthe attached collector or e in the operand or e in both the attached collector and the operand For example if A represents a set component that contains nodes xx yy and zz and B represents a set component that contains nodes ww xx and yy a union between A and B would match xx yy zz and ww CH Working With Node Sets An intersection is the set of nodes that are in both the attached set com ponent and the operand For example if A represents a set component that contains nodes xx yy and zz and B represents a set component that contains nodes ww xx and yy an intersection between A and B would match xx and yy A difference is the set of nodes that are either e Inthe attached set component the left side but not in the oper and the right side or e Inthe operand the right side but not in the attached set com ponent the left side Thus a r
23. buf is Variable of Type Array or Type char Builtin Non primitive type builtin for a given compiler Class User defined class type Example class Foo class Enum User defined enum type Example enum E Enum type Function Function type Used for function pointers Example void foo void ptr int ptr is Pointer of Type Function ptr 3 Reference Reference type Used for passing by reference Example 89 J o mg O 8 c 0 Dec DC Available Rule Nodes 90 void func int amp i i is Parameter of Type Reference to Type int i 3 Struct Struct type Example struct Foo Z struct Typedef typedef type Example typedef int INT INT x x is Variable of Type Typedef to Type int Union Union type Example union MyUnion union ine x char y T Primitive All primitive types bool Primitive type bool Example bool b b is Variable of Type bool char Primitive type char Example Available Rule Nodes char c c is Variable of Type char vvehar t Primitive type wchar_t Example wchar_t c c is Variable of Type wchar_t short Primitive type short Example short x x is Variable of Type short int Primitive type int Example Intis i is Variable of Type int long Primitive type long Example long x x is Variable of Type long float Prim
24. ch node is one node back from the Body node to which the collector and trigger point are attached When enforced this rule would for each file look for a switch statement then look for default statements in that switch statement s body The num ber of expressions that met this criteria would be placed in the collector the count would be checked and a violation would be reported if the count were zero When another switch statement was parsed the collec tor would then be emptied and this process would be repeated for that switch statement If you had a trigger point of 2 the highest possible value in this example CodeWizard would empty the collector only after the entire file was searched The collector accumulates all values found from the file node 1 actual and one applied node the file is an applied node back from the node to which the trigger point and collector are attached and the collec tor would not be emptied until a new file was parsed Creating a Trigger Point 39 O D DA gt Ve Sal Gi D Vu o 2 5 cc D c 9 Working With Node Sets 40 When you create a collector it is assigned a number 1 trigger point by default To change the trigger point value right click the trigger point num ber and choose the desired value from the shortcut menu that opens Guidelines for using trigger points To get the maximum value for a particular trigger point count the num
25. check the 23 O D DA gt Ve Sal Gi D Vu o 2 5 cc o 9 Lesson 2 Function Names Must Begin VVith a Capital Letter Negate check box This tells CodeWizard to report an error if the specified value is not present e In our example we want the function name to begin with a capital letter Thus we would enter A Z in the Regexp field then check the Negate check box ES Modify Sting E Regexp A Z vi Negate OK Cancel indicates the beginning of an expression A Z indicates uppercase let ters from A to Z After you have typed this value and checked the check box click OK Optional Additions e If you want to exempt operator functions from this rule Right click the Function rule node Choose IsOperator from the shortcut menu Oe NO ee Right click the IsOperator rule node 4 Choose Toggle from the shortcut menu e If you want to exempt constructor functions from this rule 1 Right click the Function rule node 2 Choose Member Function gt IsConstructor from the shortcut menu 3 Right click the IsConstructor rule node 4 Choose Toggle from the shortcut menu e If you want to exempt destructor functions from this rule 1 Right click the Function rule node 24 Lesson 2 Function Names Must Begin With a Capital Letter 2 Choose Member Function gt IsDestructor from the shortcut menu 3 Right click the IsDestructor rule node Choo
26. comment out the line that contains the rule set that you want to skip 2 Save your psrc file 3 Run CodeWizard as normal Windows 1 Open the CodeWizard Control Panel 2 Click the Rules Tab 3 Click Add then specify the path to one of the text files that con tains a rule set that you want to enforce 4 If you want to add additional rule sets repeat the previous step for all additional rule sets 5 If you do not want to enforce a rule set listed in the Rules Direc tory List select that entry then click Remove 6 Click Apply 7 Run CodeWizard as normal O S D S 5 Gi J D o o 2 5 DC o E D 9 Tutorial Creating and Enforcing Custom Coding Standards Tutorial Creating and Enforcing Custom Coding Standards This tutorial will walk you through the steps required to compose and automatically enforce two basic rules 1 Do not use the operator Lesson 1 2 Function names should begin with a capital letter Lesson 2 Lesson 1 Do not use the operator Lesson 1 Do not use the operator Getting Started When you first open Rule Wizard you will see the following GUI File Nodes Rule View Help icc SC Constants Declarations CI Expressions C Name Spaces C Protection Specifiers Statements SD Types a D D Si Gi ES E o Nodes The nodes with which you b
27. ction declarations Global Function Global function declaration Example void globalFuncl Global Function IsDecl is true Is Implementation is false void globalFunc2 Global Function IsDecl is true Is Implementation is true Member Function Member function declaration Example class Foo public void func Member Function f Parameter Function parameter declaration Example Available Rule Nodes void func int i i is parameter whose type is int Template Parameter Template parameter declaration Example class lt class T gt void func T t Template Parameter Variables Variables Global Variable Global Variable Example int global Global Variable IsDecl is true global 3 Global Variable IsDecl is false Local Variable Local Variable Example void func int local Local Variable IsDecl is true local 3 Local Variable IsDecl is false Member Variable Member Variable Example class Foo public Foo member 0 Member Variable IsDecl is false private J o mg gt O int member Member Variable IsDecl is true T Expressions 69 8 c 0 Dec DC Available Rule Nodes 70 Includes all types of expression nodes Assignment Includes all expression nodes used for assignment a b Assignment operator expression Example int i 1 int j 0 j
28. ed Some of these commands that you may not be familiar with include e Count Lets you create a rule condition that restricts a node s quantity Must be used in conjunction with the Create Collector command First create a collector then right click the collector and choose Count The collector keeps track of the number of times a pattern is found Count places a condition on what num ber of instances constitutes a rule violation For information on determining exactly how counts are calculated see Working With Node Sets on page 32 e Body Lets you create a rule condition about the code element that is a subnode of the parent node The body of Node A returns a body that is A s subnode the exact definition of the body depends on the node itself e Context Lets you create a rule condition about the code element that contains the parent node The context of Node A returns the node that contains Node A For example if you wanted to create a rule that said always put X inside of Y you would create a par ent node for X use Context to attach Y create a collector then use Count to specify that a count of 0 constitutes a violation Note Some rules can use only Body some can use only Con text some can use neither and some can use both If you have a choice choose Body because Body will result in better perfor mance than Context In many but not all cases Body and 61 J o mg
29. el command 60 language selection for rule 54 Left minus Right command 60 LIST 43 menus File 44 Help 48 Nodes 45 Rule 46 View 47 93 Index Move Down One command 7 Move Up One command 7 multiple rule sets 12 N Nodes menu 45 Nodes tab 49 nodes available 67 O output creating and customizing 5 6 placement in rules with trigger points 42 set component output options 42 P panels Rule Properties 53 RuleWizard Preferences 56 ParaSoft contacting 2 Preferences Panel 56 Properties Panel 53 properties customizing 8 Q Quality Consulting 2 R regexp 64 regular expressions 64 Results tab 50 Right minus Left command 60 Rule Files tab 56 Rule ID 53 Rule menu 46 94 Rule Properties panel 53 rule sets 12 rules author 55 creating demonstration 14 overview 4 tips 6 customizing rule properties 8 53 description 55 disabling 11 documentation for custom rules 46 48 enabling 9 10 57 header 54 language 54 modifying existing 31 multiple rule sets 12 Rule ID 53 saving 9 severity 54 suppressing 11 RuleWizard about 1 commands 58 customizing 56 launching 4 RuleWizard Preferences Panel 56 S saving a rule 9 set components 32 output options 42 set references 43 severity of rule 54 status bar 6 52 suppressing rules 11 suppressions 54 T tabs File 51 Nodes 49 Results 50 Rule Files 56 View 56 technical support 2 Trigger Output command 42 59 trigger points 40 U Unio
30. for example C Style Sheet Next indicate that this rule is of Informational severity by choosing Informational from the Severity box When you have entered all of these values click OK to close this panel For more information on any of the fields in the Rule Properties panel see the Rule Properties Panel topic Saving and Enabling Your Rule Before you begin composing another rule or before you exit the program you will want to save your rule CodeWizard only enforces rules that have been saved To tell RuleWizard to automatically enforce all rules that you save choose File gt Customize Preferences click the Rule Files tab then choose the Enable rules automatically do not ask me option This will prompt RuleWizard to automatically enable all rules that you save To save and enable your rule choose Rule gt Save or Rule gt Save As This command will invoke a file chooser in which you can specify the rule s filename and path Be sure to give each rule a rule extension If you 29 a D D Si Gi ES E o o 2 5 DC D c 9 Lesson 2 Function Names Must Begin VVith a Capital Letter 30 do not use this exact extension CodeWizard will not load your rules prop erly Viewing Rule Documentation Information about the rule will be included in RuleWizard s Rules Docu mentation files To view this documentation choose Help gt Rules Docu mentation To refresh this documentat
31. from 0 to 9 sion that begins with rule and ends with an integer 2 ignore case i ParaSoft matches Para Soft PARASOFT parasoft or paraSOFT D like but the a 2 matches aaa string it a 3 matches at least 3 occur matches must be of the length specified in the braces rences of the preceding charac ter aaaaaa or aaaaaaaa but not aa a 2 5 matches between 2 and 5 occurrences of the pre ceding character aaa aaaaaa but not aa or aaaaaaaaaaaaaaaaaa 65 J o mg O Expressions and Regular Expressions character Matches Examples metacharacter matches the rulewizard codewizard string before matches rulewizard codewiz the the ard or both string after the TT or both al Tips indicates the beginning of a string in parentheses indicates the end of a string in parentheses Thus to get an exact match for a string use the format STRING For example soft would only flag soft e Ifyou want CodeWizard to report an error if the expression is detected leave the Regexp window s Negate check box empty e If you want CodeWizard to report an error if the expression is not detected check the Regexp window s Negate check box e Regular expressions searches are case sensitive by default e When using regular ee is an escape character that you can use to match a
32. gt Ke Sal D Vu e Determine what error message will be displayed when this rule is violated a Create an output arrow by right clicking a rule node the placement of the output arrow deter mines what line number is used for the output message to have the line number of node C included in the output message place the output arrow on node C then choosing Create Output from the shortcut menu The Customize Output window will open b In the Customize Output window enter a brief explanation of the violation c Click OK An output arrow will then be added to your rule The rule is complete once it e Expresses the pattern that you want CodeWizard to search for and Contains an output arrow and message Overview How to Create a Rule After you customize this rule s properties you must at least enter a rule header and save the rule you can enforce it with CodeWizard Information about the rule will be included in RuleWizard s Rules Docu mentation files To view this documentation choose Help gt Rules Docu mentation To refresh this documentation choose Rule gt Update Documentation Tips General e Remember that you are trying to express a pattern that consti tutes a violation of the rule e As you create your rule look at the status bar for tips on creating a valid rule The color of the bar in the right side of the status bar indicates whether or not a rule is valid a red bar indicates that
33. gt About e Ifthe problem is not urgent report it by e mail or by fax e Ifyou call please use a phone near your computer The Quality Consultant may need you to try things while you are on the phone Contact Information e USA Headquarters Tel 888 305 0041 Fax 626 305 9048 Email quality parasoft com Web Site http www parasoft com e ParaSoft France Tel 33 0 1 60 79 51 51 Fax 33 0 1 60 79 51 50 Email quality parasoft fr com e ParaSoft Germany Tel 49 0 78 05 95 69 60 Fax 449 0 78 05 95 69 19 Email quality parasoft de com Contacting ParaSoft ParaSoft UK Tel 44 171 288 66 00 Fax 44 171 288 66 02 Email quality parasoft uk com 5 pmm O Q E O 9 gt Overview How to Create a Rule Overview How to Create a Rule When you create a rule your goal is to graphically express the pattern that you do not want to appear in your code When CodeWizard enforces a rule it searches for instances where the specified pattern occurs then flags any violations that it finds To open RuleWizard click the RuleWizard button in the CodeWizard Visual C tool bar for Windows or enter rulewizard atthe prompt for UNIX When the RuleWizard GUI opens you will see two main panels The Node tab on the left side of the GUI contains the nodes that you can use as rule subjects The right side of the GUI is the area where your rule pat terns will be displayed o 2 5 DC D c
34. he set operator e Right minus Left The set of nodes that are in the operand as indicated in the circle attached to the right of the set operator but which are not in the attached set component to the left of the set operator e XOR The set of nodes that are either in the attached set component the operand but not in both For information on set components and set operators see Work ing With Node Sets on page 32 e Label Labels a set component so that it can be used as the operand of a set operator RuleWizard commands will be displayed at the top of the shortcut menu options that pertain to programming elements and concepts are displayed below the menu s line Each non RuleWizard command in the shortcut menu is followed by a symbol that describes the function of the item indicates an item which can have either a direct or indirect check RuleWizard Commands S indicates an item that takes a string input T F indicates an item that lets you toggle between true and false inputs M indicates an item that lets you choose between predetermined input options indicates an item that takes a numerical input indicates a property node that is available from more than one com mand For example if you can choose the Body property from more than one of the available commands the Body command will contain an aster isk The commands available depend on which node or rule element was select
35. ight left difference represents the nodes in the operand but not the set operator while a left right difference represents the nodes that are in the set operator but not in the operand For example if A repre sents a set component that contains nodes xx yy and zz and B repre sents a set component that contains nodes ww xx and yy an A B difference between A and B would match zz while a B A difference would match ww An XOR exclusive or relationship is the set of nodes that are in either the attached set component or the operand but not the nodes that are in both For example if A represents a set component that contains nodes XX yy and zz and B represents a set component that contains nodes ww xx and yy a XOR between A and B would match zz and ww 35 O D DA gt Ve Sal Gi D Vu o 2 5 cc o 9 Working With Node Sets 36 To establish such relationships between two set components X and Y you would 1 Attach a set operator to one set component X by right clicking it and choosing Set Operator gt lt desired relation gt from the short cut menu that opens Attach a label to the other set component Y Specify that you want Y to be the set operator s operand by selecting Y s label as the set Components operand value Working With Node Sets Functions set operator One common reason that you might use set operators is to create a rule that
36. ion choose Rule gt Update Documentation Enforcing Your Rule Automatically To have CodeWizard enforce an enabled custom coding standard simply run CodeWizard as normal How to Modify an Existing Rule How to Modify an Existing Rule RuleWizard can be used to modify two types of rules e All rules that you created can be modified in RuleWizard e CodeWizard rules that are in the User category and have a cor responding rule file For more information about these rules refer to the CodeWizard User s Guide To modify a rule perform the following steps 1 In RuleWizard choose Rule gt Open then open the rule file for the rule that you want to modify By default all rule files for built in user rules are located at lt codewizard_install_dir gt rules O gt Ve Sal D Vu 2 Modify the rule until it fully expresses the pattern that you want CodeWizard to search for 3 Save your rule by choosing Rule gt Save 31 o 2 5 DC D c 9 Working With Node Sets 32 Working With Node Sets About Node Sets When creating complex rules you may want to create conditions that depend on specific attributes or relationships between multiple nodes For example if you have multiple nodes in a rule condition you may want to specify exactly where CodeWizard starts and stops counting the number of hits instances where the specified conditions are met Or you may w
37. itive type float Example float fy is Variable of Type float double Primitive type double Example double d a is Variable of Type double 91 J o O Available Rule Nodes long double Primitive type long double Example long double d d is Variable of Type long double void Primitive type void Used for void pointers Example wold pi p is Variable of Type pointer to type void pointer Pointer type Example char name name is Variable of Type pointer to type char 8 c 0 D _ DC 92 Index A author of rule 55 B Body command 61 Browser tab 57 C C indicating that a rule applies to 54 C indicating that a rule applies to 54 CodeWizard enforcing rules with 10 items 31 Collector 40 commands 58 Condition command 7 62 contacting ParaSoft 2 Context command 7 61 COUNT 43 Count command 7 61 customizing 40 Create Collector command 40 58 Create Output command 6 58 Create Set Operator command 60 D description of rule 55 Difference command 60 differences 36 Direct Check command 7 59 disabling rules 11 documentation for custom rules 6 46 Index 48 E enabling rules 9 10 57 expressions 63 F File menu 44 Files tab 51 H header of rule 54 Help menu 48 Hits Output command 42 58 Indirect Check command 7 59 Info tab 55 Intersection command 60 intersections 35 L Lab
38. n command 60 unions 35 User items 31 V View menu 47 View tab 56 X xor 36 XOR command 60 Index 95
39. ng you to easily create and enforce standards that are perfectly tailored to your personal project team and company needs RuleWizard and CodeWizard provide the most effective and efficient error prevention solution available 5 mmp G Q E O 9 gt With RuleWizard you create custom rules by graphically expressing the pattern that you want CodeWizard to look for when it parses code during static analysis Rules are created by selecting a main node then adding additional elements until the rule expresses the pattern that you want CodeWizard to check for Rule elements are added by pointing clicking and entering values into dialog boxes No knowledge of the parser is required to write or modify a rule ES RuleWizard C C cast unsigned rule File Nodes Rule View Help C C gt E Constants C Declarations CJ Expressions CI Name Spaces E Protection Specifiers E Statements EI Types Nodes Files Resurs Contacting ParaSoft Contacting ParaSoft ParaSoft is committed to providing you with the best possible product support for RuleWizard If you have any trouble installing or using RuleWizard please follow the procedure below in contacting our Quality Consulting department e Check the manual E 9 8 kel 9 e Be prepared to recreate your problem e Know your RuleWizard version You can find it in Help
40. of Modify String windows Here are some guidelines for entering regular expressions character Matches Examples metacharacter anystring an occurrence soft matches parasoft soft of the string ware soften etc anystring exactly one at matches hat cat bat fat non null char etc but not at acter w ing matches webking work ing but not what a king or wing 0 or 1 occur j test matches either jtest or rences of the test preceding character S 0 or more a soft matches asoft or occurrences of aaaaasoft preceding ing matches webking wan EN character ing wing what was that thing 8 E 1 or more a soft matches aaaaasoft or occurrences of aaasoft but not asoft C the preceding character x Expressions and Regular Expressions character Matches Examples metacharacter I matches one cpy up matches cup pup or occurrence of yup any character ruleO 1 4 matches rule01 inside the rule02 rule 03 rule 04 brackets Achjat matches all 3 letter inverts the words ending with at except brackets meta for cat and hat character A Z any uppercase A Z matches any uppercase letters from A letter from A to Z to Z a z any lowercase a z matches any lowercase letters from a z letter from a z 0 9 any integer rule 0 9 matches any expres
41. op statement Example void func int i do do while i while i D for for loop statement o Example D KZ void bar L void func for int i 0 i lt 10 i for bar 86 Available Rule Nodes goto goto statement Example void func bool done if done goto end goto end if if statement Example void func bool done if done if return return return statement Example int func return 07 return switch switch statement Example void func int i switch i switch case 1 break case 2 break default break J o gt O 87 8 c 0 Dec DC Available Rule Nodes 88 try try statement Example void bar void func int i try try bar eaten saw 1 while while statement Example void func int i while i while Block Block statement Normally contains other statements Begins and ends with curly braces Example void func block Simple A statement which does not fall into any other statement category The simple statement s body usually contains an expression Example void func int amp i i Simple statement Types Available Rule Nodes All types which can be used for variable declaration Complex Non primitive types Array Array type Example char buf 1024
42. or another character that has a non literal meaning 8 c 0 Dec DC 66 Available Rule Nodes Available Rule Nodes The nodes that you can use to create your rule are listed below in the order in which they appear in a fully expanded node tree Constants Constant value of any type bool Constant A constant value of true or false enum Constant An enum identifier declared in body of enum declaration Example enum E A B C enum Constant A B C Integer Constant Constant integer expression Example int i 10 Integer Constant Value is 10 Real Constant Constant expression vvhich is a real number Example double d 34 75 Real Constant Representation is 34 75 String Constant Constant string expression Example char tpc John Doe String Constant Value is John Doe Declarations Nodes representing various declarations in user code 67 J o mg gt O 8 c 0 Dec DC Available Rule Nodes 68 Some declaration nodes can be accessed from both their declaration and expressions which reference that declaration In these cases the IsDecl property returns a boolean allowing users to distinguish between the actual declaration and references to that declaration Friend friend function declaration Example void friendFunc class Foo public friend void friendFunc Friend T Functions Fun
43. ow throw operator expression 79 J o mg gt O Available Rule Nodes Example void func throw throw asm Inlined assembly expression Example void func asm mov eax ebp asm Cast Expression which casts from one type to another Kind of cast indicated by Kind which include the following normal implicit e dynamic_cast const cast e static_cast e reinterpret_cast Example class Base public virtual Base T class Derived public Base void func char c c int i int normal C style cast float f i implicit cast Base pb new Derived 8 c 0 Dec DC Derived pd dynamic_cast lt Derived gt pb dynamic_cast const char pname John Doe char pc const_cast lt char gt pname const_cast static_cast lt char gt i static cast 80 Available Rule Nodes int pi reinterpret_cast lt int gt pc reinterpret cast Overloaded An expression using an overloaded operator Example include lt iostream h gt void func cout lt lt Hello how old are you Overloaded lt lt lt lt endl Overloaded lt lt int age cin gt gt age Overloaded gt gt ab string concat Expression of strings being concatenated Example char tpc ab cd ab string concat Initializer List Expression containing initializations used in member f
44. pecify the rule s filename and path Be sure to give each rule a rule extension If you do not use this exact extension CodeWizard will not load your rules prop erly Viewing Rule Documentation Information about the rule will be included in RuleWizard s Rules Docu mentation files To view this documentation choose Help gt Rules Docu mentation To refresh this documentation choose Rule gt Update Documentation Enforcing Your Rule Automatically To have CodeWizard enforce an enabled custom coding standard simply run CodeWizard as normal Lesson 2 Function Names Must Begin With a Capital Letter Lesson 2 Function Names Must Begin With a Capital Letter We will now demonstrate how to build a rule that flags instances where function names do not begin with a capital letter Designing the Rule Pattern Creating the Parent Node First open RuleWizard if it is not already open To start creating this rule open Declarations right click the Functions folder then choose Create Rule from the shortcut menu Note Because we want this rule to apply to both member and global func tion we selected the general Function node not Global Functions or Member Functions Tal C C Constants Q Declarations IN Friend CH Functions TN Paramete p Create Rule TN Template Ehe C Variables F Fenreescinne After you choose Create Rule you will see the following parent rule node in
45. perator a b Modify Delete Create Collector Create Output Condition Context LJ FalseChoice Filename S lie KH You will then see the following Customize Output window CH D DA gt Ve Sal Gi D Vu Le D E Customize Output OK Cancel In the Customize Output window that appears type Do not use the operator ES Customize Output Eg Do not use the operator OK Cancel 17 o 2 5 cc o 9 Lesson 1 Do not use the operator 18 Next click OK Your rule should now look like this Your rule now tells CodeWizard to report the specified error message when the operator is used Your rule is now complete After you cus tomize this rule s properties and save it CodeWizard will be able to enforce it Customizing Rule Properties You can customize rule properties in the Rule Properties panel To access this panel choose Rule gt Properties You will then see the Rule Properties panel F Rule Properties B CodeWizard Info Rule ID Header Severity Violation Language Selections MC Vi Car The Rule Properties panel allovvs you to determine the rule s properties In the CodeWizard tab type the Rule ID the number that you want CodeWizard to assign to this rule the header the name that you want CodeWizard to assign to this rule then choose the
46. port the specified error message when a function s name does not begin with a capital letter Your rule is now complete After you customize this rule s properties and save it CodeWizard will be able to enforce it Customizing Rule Properties Rule properties can be customized via the Rule Properties panel To access this panel choose Rule gt Properties 27 o 2 5 cc o 9 Lesson 2 Function Names Must Begin VVith a Capital Letter 28 You will then see the Rule Properties panel ES Rule Properties xi CodeWvizard Info Rule ID Header Severity Viotation v Language Selections WiC V C This panel lets you determine the rule s properties In the CodeWizard tab type the Rule ID the number that you want CodeWizard to assign to this rule the header the name that you want CodeWizard to assign to this rule then choose the rule s severity the severity category in which CodeWizard will classify the rule For this rule you might enter the fol lowing properties in the CodeWizard tab Lesson 2 Function Names Must Begin With a Capital Letter Es Rule Properties B CodeWizard Info Rule ID hon Header Begin all function names with a capital letter Severity informational lt Selections OK Cancel Click the Info tab then enter the name of the rule s author your name and or development group and a description of the rule
47. re currently using C This menu item check box is filled with red color as default It indicates that all C specific elements in the Node Dictionary are shown When this check box is toggled to empty RuleWizard will hide all C specific elements in the Node Dictionary C This menu item check box is filled with red color as default It indicates that all C specific elements in the Node Dictionary are shown When this check box is toggled to empty RuleWizard will hide all C specific elements in the Node Dictionary 45 Sal a o N Q G 0 D e L 5 DC Rule Menu 46 Rule Menu The Rule menu contains the following commands New Rule Closes the current rule and adds the first node of a new rule Open Rule Opens a saved rule Close Closes the current rule Save Saves the current rule Save As Saves the current rule lets specify rule name and loca tion Properties Allows you to describe the properties of the current rule including Rule ID Header Severity Author and Description fields Update Documentation Updates automatically generated docu mentation for custom rules Rules documentation is accessible by choosing Help gt Rules Documentation View Menu View Menu The View menu contains the following commands e Show Hide status bar Displays hides the status bar at the bot tom of the GUI e Show Hide file viewer Displays hides the file tab 47
48. restricts the number of hits for a union intersection difference or XOR node set To create a rule that counts and restricts the total number of hits that occur for a specific type of relationship between two node sets 1 Create a rule condition that contains a set component such as a collector 2 Label the set component by right clicking it then choosing Label gt lt label name gt from the shortcut menu that opens Once you have done this you can make this component an operand of a set operator 3 Create another rule condition that contains a set component 37 O D DA gt Ve Sal Gi D Vu o 2 5 cc o E D 9 Working With Node Sets 38 4 Right click the newly added set component then choose Create Set Operator gt lt desired type of relationship gt from the shortcut menu that opens A set operator will then be attached to this set component 5 Indicate the operand of this set operator by right clicking the cir cle on the top right of the set operator and choosing the label of the first set component from the shortcut menu 6 Restrict the number of hits allowed for the specified relationship by right clicking the set operator choosing Count from the short cut menu then if necessary modifying the value included in the count node Once you have added an output arrow to your rule and specified rule properties your rule will be complete Customizing Counts
49. rule s severity the Lesson 1 Do not use the operator severity category in which CodeWizard will classify the rule For this rule you might enter the following properties in the CodeWizard tab ES Rule Properties xi CaodeWizard Info Rule ID i001 Header Do not use the operator Severity informational x Language Selections OK Cancel Now click the Info tab then enter the name of the rule s author your name and or development group and a description of the rule for exam ple C Style Sheet When you have entered all of these values click OK to close this panel For more information on any of the fields in the Rule Properties panel see the Rule Properties Panel topic Saving and Enabling Your Rule Before you begin composing another rule or before you exit the program you will want to save your rule CodeWizard only enforces rules that have been saved To tell RuleWizard to automatically enforce all rules that you save choose File gt Customize Preferences click the Rule Files tab then choose the Enable rules automatically do not ask me option This will prompt RuleWizard to automatically enable all rules that you save 19 O D DA gt Ve Sal Gi D Vu o 2 5 DC D c 9 Lesson 1 Do not use the 2 operator 20 To save and enable your rule choose Rules Save or Rules Save As This command will invoke a file chooser in which you can s
50. s to match strings For guidelines on using expressions and regular expressions see Expressions and Regular Expressions on page 63 Rule Conditions e To create a rule that whose pattern involves a union intersection or difference of multiple nodes see Working With Node Sets on page 32 O S D S 5 Gi J D o e To create a rule condition that restricts the number of a certain element that can appear in a block like a file or a class create a collector to track the number of instances of that pattern then use Count to specify the number of instances that constitutes a viola tion For information on determining exactly how counts are cal culated see Working With Node Sets on page 32 e To create a rule condition about the code element that contains the parent node use Context e To create a rule condition about the parent node s condition state ment use Condition e To create a rule condition about the code element that is a subn ode of the parent node use Body e To indicate whether or not CodeWizard searches nodes recur sively when it searches for the rule condition use Indirect Check and Direct Check e Indirect Check is the default setting to use a Direct Check right click the node whose checking type you want to change then choose Direct Check from the shortcut menu o 2 5 cc o E D 9 How to Customize Rule Properties How to Customize Rule
51. se Toggle from the shortcut menu Functions When you enter these conditions CodeWizard will not check whether or not the names of operator functions constructor functions or destructor functions begin with a capital letter Specifying an Error Message Finally we need to specify what text CodeWizard should print when this rule is violated The first step in doing this is right clicking the parent rule node here the Functions rule node then choosing Create Output from the shortcut menu 25 O D DA gt Ve Sal Gi D Vu o 2 5 cc o 9 Lesson 2 Function Names Must Begin VVith a Capital Letter Functions Modify Delete Create Collector Create Body LJ Context Filename S Is Implementation TE leNacl TE The action will invoke the following Customize Output window E Customize Output Es x 1 OK Cancel In the Customize Output window enter the message that you want CodeWizard to deliver when this rule is violated In this example you might enter A function name should begin with a capital letter 26 Lesson 2 Function Names Must Begin With a Capital Letter ES Customize Output A function name should begin with a capital letter Ok Cancel Click OK Your rule should now look like this O D DA gt Ve Sal Gi D Vu Functions Your rule now tells CodeWizard to re
52. the rule is not yet valid a green bar indicates that the rule is valid The messages in the status bar tell you how to make an invalid rule valid o 2 5 DC D c 9 e Be sure to include at least one output arrow in each rule If a rule does not have an output arrow CodeWizard will not report an error if this pattern is found in the code under test To include an output arrow right click a rule node the placement of the output arrow determines what line number is used for the output mes sage to have the line number of node C included in the output message place the output arrow on node C then choose Cre ate Output from the shortcut menu e Be sure to enter a header when you customize this rule s proper ties rules without headers are not valid e Both nodes such as bool Constant and folders containing nodes such as Constants can be used as rule nodes e TO view a description of a node in the Node tab right click the node that you want more information about then choose View Documentation from the shortcut menu Overview How to Create a Rule e Be aware that RuleWizard is order specific If your rule has more than one child node you can move the child up or down one posi tion by right clicking the vertical line common to all children then choosing Move up one or Move down one from the shortcut menu Expressions and Regular Expressions e Use expressions to match values and regular expression
53. the right pane of the GUI 21 O D D gt Ve Sal D Vu o 2 5 cc o 9 Lesson 2 Function Names Must Begin VVith a Capital Letter 22 Functions We now have the basic building block for a rule about some aspect of function declarations Adding Further Qualifications to the Parent Rule Node To specify that this rule will be about function naming conventions right click the Functions rule node and choose Name from the shortcut menu that opens Modify Delete Create Collector Create Output Body Functions Context Filename S Is Implementation TF IsDecl T F Isinline TF IsOperator TF IsStatic TF Line 8 Name s A Parameter Return Type A rule node with the content Name none will now be attached to your parent rule node Lesson 2 Function Names Must Begin With a Capital Letter To continue developing the rule right click the Name rule node then choose Modify from the shortcut menu Functions You will then see the following Modify String window ES Modify Sting E Regexp _ Negate OK Cancel In the Regexp field of the Modify String Window specify what value CodeWizard should look for e Ifyou want CodeWizard to report an error if a certain value is not present in the function s name as we do in our example enter the value that you want to require the presence of then
54. the rule s author Description Contains a description of this rule This description will be displayed when you open a Message Window from Insra 55 Sal D N DA Q Q 0 D e N L 5 DC RuleWizard Preferences Panel 56 RuleWizard Preferences Panel The RuleWizard Preferences panel lets you specify RuleWizard options related to e How rules are displayed e Where rules are stored e How rule files are enabled e The web browser to be used To open the RuleWizard Preferences panel select File gt Customize Preferences The Rule Properties panel has three tabs e View Determines how rules are displayed e Rule Files Determines where rule files are stored e Browser Sets browser related options such as browser used browser commands etc View Tab The View Tab allows you to specify the following preferences e Pixel spacing between components Determines the space between rule nodes Available options include e Horizontal Determines the horizontal spacing between rule nodes e Vertical Determines the vertical spacing between rule nodes e Reset to defaults Returns spacing settings to their default values Rule Files Tab RuleWizard Preferences Panel The Rule Files tab lets you configure the following preferences e Rule File Directory Determines where your rule files are stored You can either choose the default directory or specify an alter n
55. tory If the rule that you want to enforce is saved in a different directory create a text file in that directory In the open text file add the names of the rule files i e IfAs sign rule that you want CodeWizard to enforce When you add the rule files names do not use any spaces or indentation Add only one rule file s name per line Save the text file If your text file is not lt codewizard_install_dir gt rules cwrules txt open your psrc file enter a rulesdirlist option that specifies the path to the text file you just saved then save your psrc file For example if your rules and text file named rules txt were saved in home user rules you would enter CodeWizard ruledirlist home user rules rules txt 5 Run CodeWizard as normal to automatically enforce these rules Windows 1 10 If your rules are saved in the default directory lt codewizard_install_dir rules gt proceed to step 2 How to Automatically Enforce Your Custom Coding Standards If your rules are stored in a different directory perform the follow ing steps e Create an empty text file in the directory that contains the rule s that you want to enforce e Save the text file e Open the CodeWizard Control Panel e Click the Rules Tab e Click Add then specify the path to the text file that you just saved e Click Apply e Proceed to step 4 Open the CodeWizard Control Panel Click the Rules Tab Check the check box es
56. uild your rules are displayed on the left pane of the GUI The gray pane on the right of the GUI will be your workspace for composing rules Creating the Rule Let s start by walking you through the steps required to build a simple rule Do not use the operator Designing the Rule Pattern o 2 5 cc o 9 Lesson 1 Do not use the operator 16 Creating a Parent Rule Node Whenever you create a rule the first thing that you need to do is right click the node that you want to be the subject of your rule then select Create Rule from the shortcut menu To begin creating this rule right click the a b c node in under Expressions gt Miscellaneous then choose Create Rule from the shortcut menu CA miscellaneous IN ab IN ah C ga Da IN a b C a b C sai IN ab C ab DD a2b e C typeil Greate Rule IN aeai 7 e S Adding Further Qualifications to the Parent Rule Node The rule already expresses the pattern that we want CodeWizard to search for the presence of the operator in a file Thus no further qual ifications are required Specifying an Error Message Now that your rule fully expresses the pattern you need to specify what text CodeWizard should print when this rule is violated The first step in doing this is right clicking the parent rule node here the a b c rule node then choosing Create Output from the shortcut menu Lesson 1 Do not use the o
57. uld be reported each time that the attached node is matched e The output message should reference the line number of the node to which the collector is attached For example if you have a collector that contains variables in Java or C and you select a Hits Output you can use an output mes sage such as Initialize all variables in construc tor Variable name is not initialized When this RuleWizard Commands rule is actually violated the name variable will be replaced with the name of the uninitialized variable When you choose this type of output the viola tion output can contain variables such as tag or value for nodes contained in the set collec tor or operator For example if you have a collec tor that contains variables in Java or C and you select a Hits Output you can use an output message such as Initialize all variables in con structor Variable name is not initialized When this rule is actually violated the name variable will be replaced with the name of the uninitialized variable e Trigger Output Choose this output to indicate that e One output message should be reported each time that the trigger point is matched for exam ple if the trigger point references a file one mes sage will be reported for each file e The output message s line number should refer ence the line number of the trigger point node This type of output arrow is placed below the center of the
58. unctions Example class Foo public Foo _x 0 _y 0 Initializer list private int _x int _y T Numerical Numerical expressions which are not assignments a Positive signed expression Example 81 J o mg O 8 c 0 Dec DC Available Rule Nodes 82 int func int num return num a Negative signed expression Example int func int num return num a b Addition expression Example int gesi int k 3 3 a b Subtraction expression Example int 3 1 int k 3 j a b Multiplication expression Example int j 1 int Ros 38 j a b Division expression Example int j 2 int k 5 3 ta a Addition atb Subtraction a b Multiplication a b Division a b a b Modulo expression Example H 8 j Mod a b int j int k 2 5 a lt lt b Left shift expression Example int El Re 1 k i lt lt j Left shift a gt gt b a gt gt b Right shift expression Example int is 1 j sl k 1 RE dS ge Right shift a gt gt b Name Spaces Nodes involving the use of namespaces namespace Namespace declaration Example namespace ns Name Space class Foo T using Use of using namespace keyword Example include lt vector gt using namespace std using Available Rule Nodes 83 J o OH 8
59. yed in the right GUI pane Clicking the RuleWizard Messages results category will allow you to access all messages that have appeared on the status bar This feature provides you with a convenient way to go back and review a message that is no longer visible To clear the RuleWizard Messages right click that category and then click Clear in the shortcut menu CH Result Windows J TN RuleWizard Messages Nodes Fies Results Files Tab Files Tab The Files tab displays the structure of your directories You can use it to open rule files to do this right click the rule file that you want to open then choose Open Rule from the shortcut menu If you do not see the Files tab you may enable it by choosing View gt Show File Viewer LJ Ws C CONE Tore NAMI z Zeie Noog SANPF rule IN OOP_LEVEL rule IN OPT_UEQ rule IN OPT_UISO rule IN OPT_UNC tule CY PT_ASlrule Cy PT UEl rule IN StringAppend rule SuperFinalize rule C UC AUV rule C UC DIL rule A UC PE rule ES UC PM rule C UC UP rule 4 S CES Sal N DA Q G 51 0 D e N L 5 DC Status Bar 52 Status Bar The status bar displays RuleWizard messages including tips on how to make the rule in progress valid The color of the bar in the right side of the status bar indicates whether or not a rule is valid a red bar indicates that the rule is not yet valid
Download Pdf Manuals
Related Search
Related Contents
M15 Camera Manual Kenroy Home 32622ORB Installation Guide manual - Amazon Web Services 名前とはたらき① MS International THDW3-T-MC4X4T Instructions / Assembly Epson Artisan 700 All-in-One Printer Installation Guide BOVILOR® I/Se Copyright © All rights reserved.
Failed to retrieve file