TOC PREV NEXT INDEX DOC LIST MASTER INDEX



C/C++ Code Rule Checker

In team program development, code rules are often used to ensure that programs being developed conform with a `standard' programming style. This makes the collectively developed program more readable and less error-prone. As a result, the cost of development and maintenance are reduced.

The code rule checker operates on the Sienna intermediate representation of the units, so they must already be compiled.

Sienna is a persistent intermediate representation of the C++ source. It is the basis for code rule checking and navigation.

Sienna is generated by default unless the -nosienna switch is passed to the compiler by the build key. It is stored in files in the .Rational/Compilation/cna subdirectory of the view. Sienna generation is the default, and to turn it off it is necessary to create a new build key with -nosienna.

A number of types of warnings can occur if sienna generation is enabled for C/C++. These are described in detail in Sienna Warning Messages.

The following topics are covered in this chapter:


Navigation

For navigation, the fact that Sienna is used is mostly invisible to the user, except that it is better at resolving ambiguities. If there is a reference to an identifier, Navigate > Visit on the identifier will find the correct definition, even if there are multiple definitions of the same name. If the Sienna-based navigation fails, the editor falls back on the current tags-based navigation.


Code Rule Checker Displays

When the code rule checker executes, it examines the file(s) for any code rule violations. If a file violates any of the code rules, the violation(s) are highlighted in the source file. Choose Help > Explain in the editor window and click on the highlighted area for more details on the violations.

If multiple files have violations, a summary window listing all the files with violation is displayed. Use the Visit button on a file name to display the editor window of the corresponding file with all its violations highlighted.


Code Rule Syntax

In Apex, a code rule is represented as a triplet: a name, a switch attribute, and actual code body for checking the rule.

A rule name should be a string with alphanumeric characters and underscores (`_').

The switch attribute of a code rule can be one of the three states:

Uni_State
rule has no associated value (e.g., Use_Clause_In_Use)
Bi_State
rule can be associated with boolean values
Nary_State
rule can be associated with integer values (e.g., Maximum_Loop_Nests)

The Rational Apex code rule checker uses the code rules in the file Policy/Code_Rules.sw in the source view to determine which code rules to check, and the severity level each code rule will be treated on. Each source view can have its own code rule set, so this file can be different from one view to another.


Predefined Code Rules

In Rational Apex, there are predefined code rules for the code rule checker. The values of the switch attributes and severity levels of these rules can be changed by the user. The code rule checker employs the settings and does the checking accordingly.

The format of the Policy/Code_Rules.sw is lines of the form:

Rule_Name: Value [Severity]

where

Value
is "On" or "Off", or a number, as appropriate.
Severity
is "Error", "Warning", or "Informational". [Default: Warning]

Comments are introduced by "#" and continue to the end of the line.

The following is a list of the current rule names and what they check for:


Interface to the Code Rule Checker

You can display the defined code rules or check files against the defined code rules using either the command line interface or the Apex GUI.

Command-Line Interface

To check files against the defined code rules use the check_rules command. It is discussed in detail in the Command Reference.

GUI Interface

From the Apex GUI, the commands Compile > Check Rules and Compile > Show > Code Rules provide access to the code rule checker. Compile > Show > Code Rules simply displays the code rules in effect for the selected object(s). Compile > Check Rules checks the current selection against the predefined code rules. When this command is selected, the Check Code Rules dialog box is displayed.


Sienna Warning Messages

Each of these sienna related warning messages can be suppressed by passing the flag -Wwarning_type to the C/C++ compiler where warning_type is heapmaper, siennaer, siennack, siennard, siennawr, siennanr, or siennanc.

These first three types of warnings don't cause sienna generation to be suppressed (except heapmaper version mismatch). Generally, the generated sienna is nearly or completely intact. Navigation and code rule checking should still work. There may be one or more missing links that prevent navigation from one or more source positions.

heapmaper
siennaer
siennack

The next four types of warnings prevent sienna generation for the compilation. If any of these occur, navigation from the compilation will not work.

siennard

The last three types of errors mean the compiler is not able to read/write the specified file. There could be file permission problems, non-existent directories, or bogus .Rational_Location links someplace in the specified path.

siennawr
siennanr
siennanc


Rational Software Corporation 
http://www.rational.com
support@rational.com
techpubs@rational.com
Copyright © 1993-2002, Rational Software Corporation. All rights reserved.
TOC PREV NEXT INDEX DOC LIST MASTER INDEX TECHNOTES APEX TIPS