9. Tool Integrations

9.1. Pretty Printer

The command “Pretty Print” allows you to format Ada source files using a number of language-specific options. The command is provided in the Ada menu on the menubar and in the contextual menus of the editor and the GNAT Project Explorer.

Note that in addition to formatting individual files, you can format all the files in an entire project by selecting the project node in the GNAT Project Explorer.

The actual formatting is provided by the external tool “gnatpp”, with switches specified in the GNAT project file. You can either edit the project file manually, as usual, or use the GNAT Project GUI properties editor to set them.

If you edit the GNAT project file manually, the package corresponding to the tool is named “Pretty_Printer” and it uses the Default_Switches attribute for language “Ada”. The following GNAT project file fragment provides an example:

pretty printer switches in gpr file

As usual it will be easier to use the interactive dialog to set the switches. To invoke the dialog, select GNAT Project -> Edit Properties from the GNAT Project Explorer’s contextual menu. The dialog will appear as follows:

pretty printer switches in project editor

9.2. Metrics Analysis

The command “Compute Metrics” allows you to analyze Ada source files using several different metric quantifiers. The command is provided in the Ada & Analyze menus on the menubar and in the contextual menus of the editor and the GNAT Project Explorer.

Note that in addition to analyzing individual files, you can analyze all the files in an entire project by selecting the project node in the GNAT Project Explorer. This option is illustrated below:

invoking metrics on a project

9.2.1. Controls

The actual analysis is provided by the external tool “gnatmetric”. See the GNAT User’s Guide for the details of using the tool. The specific switches applied are controlled via the “Metrics” package in the project’s GNAT project file (the “gpr file”).

Note that re-issuing the command only performs the analysis again if necessary; specifically, if the GNAT project file has changed or if there are no prior results in the first place.

9.2.2. Results

Analysis results are displayed in the Metrics view, with an overall summary in the Console view.

metrics summary in console

The Metrics view shows the results in a tree format, with an overall project summary provided first. Results for each file then follow the project summary. In the figure below, the view has been maximized to show more of the results, and both the summary and the results for one of the subprograms have been expanded.

metrics view showing results

The Metrics view will be opened automatically after the analysis completes. You can open the view manually, using the shortcut:

showing metrics view via shortcut

9.3. Style Checking

The command “Check Style” allows you to analyze Ada source files using several different coding style rules. The command is provided in the Ada & Analyze menus on the menubar and in the contextual menus of the editor and the GNAT Project Explorer.

Note that in addition to analyzing individual files, you can analyze all the files in an entire project by choosing the command from the contextual menu when the project node in the GNAT Project Explorer is selected. This approach is illustrated below:

invoking style checks on project

9.3.1. Controls

The actual analysis is provided by the external tool “gnatcheck”. See the GNAT User’s Guide for the details of using the tool.

The specific switches applied are controlled by means of a “rules” file. The name and location of this file can be specified in the package Check in the GNAT project file. The various switches may be specified there as well.

To specify the rules files, within the package Check specify the Default_Switches attribute for language “Ada”. In that attribute, you must specify both the “-rules” switch as well as the name of the rules file itself using the “-from=” switch. For example, in the following GNAT project file fragment we specify the switch file name “ms1553.rules”:

specifying package check switches

If you don’t specify a rules file in the project file, the command will open a dialog box to prompt you for the file name and location:

no rules file dialog

In addition to setting the individual rules switches manually in the project file, you can also set the rules switches via a multipage graphical editor. The editor will be opened whenever you double-click on a file with the extension “rules”, such as “ada.rules” or any similarly named file. To create a new rules file, just use the new-file wizard to create a file with an extension of ”.rules” and the editor will open for it automatically.

In the following, the file “ms1553.rules” has been opened:

rules file editor 1

Note the tabs at the bottom. The rules are separated into logical sections, based in part on their point of origin (e.g., the Ada 95 Quality and Style Guide, or the GNAT style warnings provided by the compiler). Each tabbed page contains options to be enabled or disabled by check-boxes, except for the last page on the far right. That page, labeled with the file name itself, contains the file in textual form.

9.3.2. Results

The results of the analysis appear in a text file. By default the file is named “gnatcheck.out”, but you can specify the name in the GNAT project file.

sample check result file