ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


CodeWizard

Quick facts

Items enforced

Technical Papers

Support & Manuals

Recent Reviews

User Testimonials

Press Releases

Send us feedback

CodeWizard

CodeWizard: a tool to enforce C++ coding standards





Contents  Previous  Next  Index

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 function, we selected the general Function node, not Global Functions or Member Functions.

After you choose Create Rule, you will see the following parent rule node in the right pane of the GUI:

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.

A rule node with the content Name: -none- will now be attached to your parent rule node.

To continue developing the rule, right-click the Name rule node, then choose Modify from the shortcut menu.

You will then see the following Modify String window:

In the Regexp field of the Modify String Window, specify what value CodeWizard should look for.

  • If you 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 check the Negate check box. This tells CodeWizard to report an error if the specified value is not present.
  • 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:

^ indicates the beginning of an expression; [A-Z] indicates uppercase letters from A to Z.

After you have typed this value and checked the check box, click OK.

Optional Additions

  • If you want to exempt operator functions from this rule:
    1. Right-click the Function rule node.
    2. Choose IsOperator from the shortcut menu.
    3. Right-click the IsOperator rule node.
    4. Choose Toggle from the shortcut menu.
  • If you want to exempt constructor functions from this rule:
    1. Right-click the Function rule node.
    2. Choose Member Function> IsConstructor from the shortcut menu.
    3. Right-click the IsConstructor rule node.
    4. Choose Toggle from the shortcut menu.
  • If you want to exempt destructor functions from this rule:
    1. Right-click the Function rule node.
    2. Choose Member Function> IsDestructor from the shortcut menu.
    3. Right-click the IsDestructor rule node.
    4. Choose Toggle from the shortcut menu.

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.

The action will invoke the following Customize Output window:

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."

Click OK.

Your rule should now look like this:

Your rule now tells CodeWizard to report 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> Properties.

You will then see the Rule Properties panel.

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 following properties in the CodeWizard tab:

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 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> 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> Save or Rule> 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 extension, CodeWizard will not load your rules properly.

Viewing Rule Documentation

Information about the rule will be included in RuleWizard's Rules Documentation files. To refresh this documentation, choose Rule> Update Documentation. To view this documentation, choose Rule> Rules Documentation.

Enforcing Your Rule Automatically

To have CodeWizard enforce an enabled custom coding standard, simply run CodeWizard as normal.


Contents  Previous  Next  Index

Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft