HP UX Web Development Tools manual Source structure in the rules library

Page 18

Table 2 Source structure in the rules library

include/

HPCodeGuideConstructs.h

 

 

Contains the APIs required for (re)writing the rules to enforce coding guidelines.

 

HPCodeGuideDiagnosticTags.h

 

 

Contains the various diagnostic tags that you can use to emit the diagnostics

 

 

from the rules library.

lib/

src/

libcodeguide.a

This is provided to fill in the implementation stubs for recompilation of the rules' library, and must be linked in while compiling the rules' library.

librules.s[lo]

This is the default rules' library that is available with cadvise.

HPCodeGuideRules.C

The file where all rules are implemented. You can modify this file to incorporate more rules and/or modify the existing ones.

HPCodeGuideRulesDriver.C

The driver from where the rules are invoked on the various program constructs.

Makefile

The default makefile for rebuilding the rules' library from the above sources.

The sample rules towards naming convention that are available with the current release are as follows:

1.Functions that returns a bool must start with is.

2.Names of abstract classes should begin with Interface.

3.Class names should start with a capital letter.

4.Names of global variables should start with a capital letter.

5.Names of local variables should start with a small letter.

An example of writing a rule to enforce the naming convention of private data members being suffixed with an '_' is as follows:

Example 5 Writing a rule to enforce naming convention

void Field::checkNamingConventions() {

//Private data members of class should end with "_" if(name() && isPrivate()) {

char ch = *name() + strlen(name()); if(ch != '_')

warning("Private data member \"%s\" not suffixed with \"_\"", 2000053, name());

}

}

NOTE: Cadvise reports do not currently have support for Coding Guideline diagnostics. Use the -teeoption to view these messages.

18 Using Cadvise

Image 18
Contents HP Code Advisor C.02.20 User Guide Page Contents Contents Intended audience Document conventions and symbolsAbout this document Related informationHP encourages your comments Cadvise-help@lists.hp.comIntroduction FeaturesCadvise user interface Features Cadvise user interfaceAdvanced static code analysis $ cadvise cc -c hello.cSupported compilers $ cadvise -pdb ./mypdb +wlint aCC hello.cppSupported platforms Installing Cadvise Using CadviseSteps in using cadvise Getting startedInvoking Cadvise See the following makefile content Using Cadvise as a wrapper around Compiler or LinkerFor information on PDB, see Using the Program Database PDB Integrating Cadvise with the makefiles and build processEnabling different categories of diagnostic messages Generating code complexity metricsExample 2 Sample wrapper script Example 3 Generating code complexity metrics Objfile.metricsGenerating code complexity metrics Example 4 Code complexity metrics $ cat /tmp/example.c+wcodeguide=rules-library Source structure in the rules library Example 5 Writing a rule to enforce naming conventionUsing the Program Database PDB Deleting PDB PDB options tableSpecifying the PDB location Disabling locks in PDB operationsExample 8 Removing object file information from the PDB Creating a PDB snapshot at a specified locationDisplaying PDB version Example 9 Creating a PDB snapshotUsing cross-file analysis UsageCross-file analysis options Crossfile=auto Example 15 Specifying the location of object files Suppressing warnings selectively Configuring diagnostic messagesDiagnostic configuration options table Enabling warnings selectivelyInterpreting selective warnings as errors Disabling warnings in a macroManaging warnings in a source file Cadvise report report-options -pdb pdbdir Generating reportsReport generation options table Cadvise report report-options logfileGenerating detailed report Generating summary reportsGenerating file summary report $cadvise report -summary -pdb testpdb -noheaderExample 23 Generating detailed report To save reports, run the following commandGenerating Html report $ cadvise report -pdb testpdb -allGenerating XML report Printing diagnostics with specific diagnostic numbersFollowing example shows the command to generate XML report Example 24 Generating an XML report$ cadvise report -pdb testpdb -diag Suppressing diagnostics for specific filesGenerating reports based on severity Example 26 Generating reports based on severity$ cadvise report -pdb test.pdb -summary -exclude inflate.c Reporting diagnostics from specific filesReporting program complexity metrics $ cadvise report -pdb test.pdb -summary -include inflate.cGenerating report for a module Example 29 Reporting program complexity metrics$ cadvise report -pdb gzip.pdb +metrics -include inflate.c Generating PDB comparison report Modifying the default severity level of a diagnosticSuppressing report header $ cadvise report -pdb test.pdb -summary -module test1Example 34 Generating detailed diff report with the header $ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -allExample 35 Generating diff report for any particular warning $ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -diag$ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -severity $ cadvise -pdb pdb1 cc one.c two.cReport options file $ cadvise report -pdb new.pdb -basepdb old.pdb -allGenerating consolidated report from multiple PDBs Example 42 Generating a report using -migration optionGenerate report for migration related warnings Example 41 Report options fileReport options interoperability Recommended process for analyzing the diagnostic messagesGenerating PDB diffs with multiple PDBs $ cadvise report -pdb 1.pdb2.pdb3.pdb4.pdb -allExample 45 Ignoring the -includeoption Example 44 Reporting options interoperability$ cadvise report -pdb test.pdb -diag 2549 -exclude b.c $ cadvise report -pdb test.pdb -summary -include a.cb.cHelp-h-H Example 48 Using -noabortMiscellaneous driver options Example 47 Displaying the list of cadvise optionsExample 51 Using -tee option Example 49 Using -nobuild optionFollowing command creates the file cadvdir/foo.cad Following example shows the usage of -nobuildoptionExample 52 Using +opts filename option Line generates the following messagesCategories of diagnostics with examples Categories of diagnostics tableDetecting generic programming errors Categories of diagnostics with examples Example 53 Null pointer dereference check Such cases, cadvise generates the following warningExample 54 Potential memory leak check Such cases, cadvise generates the following warningsExample 55 Out of bound access Example 56 Out of scope accessSuch cases, cadvise generates the following error Example 57 Use of pointer after freeExample 58 Allocator/deallocator mismatch Example 60 Detecting 32-bit to 64-bit migraton issues Detecting 32-bit to 64-bit migraton issuesDetecting endianness migration issues Example 59 Signed bit field of lengthDetecting potential security vulnerabilities Example 61 Detecting endian dependent code fragmentsConsider the following code fragment Detecting multi-threaded programming issues This case, cadvise generates the following errorExample 63 Detecting multi-threaded programming issues Running cadvise generates the following errorDetecting potential performance improvement opportunities Detecting potential performance improvement opportunities Fixing the warnings by source change Incompatibilities on PA-RISC based systems AC++ standard conformance and compatibility changesSymbols Index