@c o
@c G N A T _ U G N o
@c o
-@c Copyright (C) 1992-2004 Ada Core Technologies, Inc. o
-@c o
-@c GNAT is free software; you can redistribute it and/or modify it under o
-@c terms of the GNU General Public License as published by the Free Soft- o
-@c ware Foundation; either version 2, or (at your option) any later ver- o
-@c sion. GNAT is distributed in the hope that it will be useful, but WITH- o
-@c OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY o
-@c or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License o
-@c for more details. You should have received a copy of the GNU General o
-@c Public License distributed with GNAT; see file COPYING. If not, write o
-@c to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, o
-@c MA 02111-1307, USA. o
+@c GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). o
@c o
@c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
+@setfilename gnat_ugn.info
+
+@copying
+Copyright @copyright{} 1995-2005, 2006, 2007, 2008 Free Software Foundation,
+Inc.
+
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.2 or
+any later version published by the Free Software Foundation; with no
+Invariant Sections, with no Front-Cover Texts and with no Back-Cover
+Texts. A copy of the license is included in the section entitled
+``GNU Free Documentation License''.
+@end copying
+
@c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
@c
@c GNAT_UGN Style Guide
@c
@c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
-@ifset vms
-@setfilename gnat_ugn_vms.info
-@end ifset
-
-@ifset unw
-@setfilename gnat_ugn_unw.info
-@end ifset
+@set NOW January 2007
+@c This flag is used where the text refers to conditions that exist when the
+@c text was entered into the document but which may change over time.
+@c Update the setting for the flag, and (if necessary) the text surrounding,
+@c the references to the flag, on future doc revisions:
+@c search for @value{NOW}.
@set FSFEDITION
@set EDITION GNAT
+@set DEFAULTLANGUAGEVERSION Ada 2005
+@set NONDEFAULTLANGUAGEVERSION Ada 95
@ifset unw
-@set PLATFORM Unix and Windows
-@set FILE gnat_ugn_unw
+@set PLATFORM
@end ifset
@ifset vms
-@set PLATFORM OpenVMS Alpha
-@set FILE gnat_ugn_vms
+@set PLATFORM OpenVMS
@end ifset
+@c @ovar(ARG)
+@c ----------
+@c The ARG is an optional argument. To be used for macro arguments in
+@c their documentation (@defmac).
+@macro ovar{varname}
+@r{[}@var{\varname\}@r{]}@c
+@end macro
-
-@settitle @value{EDITION} User's Guide for Native Platforms / @value{PLATFORM}
+@settitle @value{EDITION} User's Guide @value{PLATFORM}
@dircategory GNU Ada tools
@direntry
-* @value{EDITION} User's Guide (@value{FILE}) for Native Platforms / @value{PLATFORM}
+* @value{EDITION} User's Guide: (gnat_ugn). @value{PLATFORM}
@end direntry
@include gcc-common.texi
@syncodeindex fn cp
@c %**end of header
-@copying
-Copyright @copyright{} 1995-2004, Free Software Foundation
-
-Permission is granted to copy, distribute and/or modify this document
-under the terms of the GNU Free Documentation License, Version 1.2
-or any later version published by the Free Software Foundation;
-with the Invariant Sections being ``GNU Free Documentation License'', with the
-Front-Cover Texts being
-``GNAT User's Guide for Native Platforms / @value{PLATFORM}'',
-and with no Back-Cover Texts.
-A copy of the license is included in the section entitled
-``GNU Free Documentation License''.
-@end copying
-
@titlepage
-
@title @value{EDITION} User's Guide
-@center @titlefont{for Native Platforms}
+@ifset vms
@sp 1
-
@flushright
@titlefont{@i{@value{PLATFORM}}}
@end flushright
-@sp 2
+@end ifset
-@subtitle GNAT, The GNU Ada 95 Compiler
-@subtitle GCC version @value{version-GCC}
+@sp 2
-@author Ada Core Technologies, Inc.
+@subtitle GNAT, The GNU Ada Compiler
+@versionsubtitle
+@author AdaCore
@page
@vskip 0pt plus 1filll
@end titlepage
-
@ifnottex
@node Top, About This Guide, (dir), (dir)
@top @value{EDITION} User's Guide
@noindent
-@value{EDITION} User's Guide for Native Platforms / @value{PLATFORM}
+@value{EDITION} User's Guide @value{PLATFORM}
@noindent
-GNAT, The GNU Ada 95 Compiler@*
+GNAT, The GNU Ada Compiler@*
GCC version @value{version-GCC}@*
@noindent
-Ada Core Technologies, Inc.@*
+AdaCore@*
@menu
* About This Guide::
* GNAT Project Manager::
* The Cross-Referencing Tools gnatxref and gnatfind::
* The GNAT Pretty-Printer gnatpp::
+* The GNAT Metric Tool gnatmetric::
* File Name Krunching Using gnatkr::
* Preprocessing Using gnatprep::
@ifset vms
* GNAT and Libraries::
* Using the GNU make Utility::
@end ifclear
-* Finding Memory Problems::
+* Memory Management Issues::
+* Stack Related Facilities::
+* Verifying Properties Using gnatcheck::
* Creating Sample Bodies Using gnatstub::
+* Generating Ada Bindings for C and C++ headers::
* Other Utility Programs::
* Running and Debugging Ada Programs::
+@ifclear vms
+* Code Coverage and Profiling::
+@end ifclear
@ifset vms
-* Compatibility with DEC Ada::
+* Compatibility with HP Ada::
@end ifset
* Platform-Specific Information for the Run-Time Libraries::
* Example of Binder Output File::
* Elaboration Order Handling in GNAT::
+* Conditional Compilation::
* Inline Assembler::
* Compatibility and Porting Guide::
@ifset unw
@end ifset
@ifclear vms
* Introduction to GPS::
-* Introduction to Glide and GVD::
@end ifclear
The GNAT Compilation Model
* The Ada Library Information Files::
* Binding an Ada Program::
* Mixed Language Programming::
+@ifclear vms
* Building Mixed Ada & C++ Programs::
* Comparison between GNAT and C/C++ Compilation Models::
+@end ifclear
* Comparison between GNAT and Conventional Ada Library Models::
@ifset vms
* Placement of temporary files::
* Validity Checking::
* Style Checking::
* Run-Time Checks::
-* Stack Overflow Checking::
* Using gcc for Syntax Checking::
* Using gcc for Semantic Checking::
-* Compiling Ada 83 Programs::
+* Compiling Different Versions of Ada::
* Character Set Control::
* File Naming Control::
* Subprogram Inlining Control::
* Running gnatlink::
* Switches for gnatlink::
-* Setting Stack Size from gnatlink::
-* Setting Heap Size from gnatlink::
The GNAT Make Program gnatmake
* How gnatmake Works::
* Examples of gnatmake Usage::
-
Improving Performance
* Performance Considerations::
-* Reducing the Size of Ada Executables with gnatelim::
+* Text_IO Suggestions::
+* Reducing Size of Ada Executables with gnatelim::
+* Reducing Size of Executables with unused subprogram/data elimination::
Performance Considerations
* Controlling Run-Time Checks::
* Optimization Levels::
* Debugging Optimized Code::
* Inlining of Subprograms::
+* Other Optimization Switches::
* Optimization and Strict Aliasing::
@ifset vms
* Coverage Analysis::
@end ifset
-Reducing the Size of Ada Executables with gnatelim
+Reducing Size of Ada Executables with gnatelim
* About gnatelim::
* Running gnatelim::
* Correcting the List of Eliminate Pragmas::
* Making Your Executables Smaller::
* Summary of the gnatelim Usage Cycle::
+Reducing Size of Executables with unused subprogram/data elimination
+* About unused subprogram/data elimination::
+* Compilation options::
+
Renaming Files Using gnatchop
* Handling Files with Multiple Units::
* Objects and Sources in Project Files::
* Importing Projects::
* Project Extension::
+* Project Hierarchy Extension::
* External References in Project Files::
* Packages in Project Files::
* Variables from Imported Projects::
* Naming Schemes::
* Library Projects::
-* Using Third-Party Libraries through Projects::
* Stand-alone Library Projects::
* Switches Related to Project Files::
* Tools Supporting Project Files::
* An Extended Example::
* Project File Complete Syntax::
-
The Cross-Referencing Tools gnatxref and gnatfind
* gnatxref Switches::
* Examples of gnatxref Usage::
* Examples of gnatfind Usage::
-
The GNAT Pretty-Printer gnatpp
* Switches for gnatpp::
* Formatting Rules::
+The GNAT Metrics Tool gnatmetric
+
+* Switches for gnatmetric::
File Name Krunching Using gnatkr
* Examples of gnatkr Usage::
Preprocessing Using gnatprep
-
+* Preprocessing Symbols::
* Using gnatprep::
* Switches for gnatprep::
* Form of Definitions File::
* Running gnatclean::
* Switches for gnatclean::
-* Examples of gnatclean Usage::
+@c * Examples of gnatclean Usage::
@ifclear vms
* Overcoming Command Line Length Limits::
@end ifclear
-Finding Memory Problems
+Memory Management Issues
+* Some Useful Memory Pools::
+* The GNAT Debug Pool Facility::
@ifclear vms
* The gnatmem Tool::
@end ifclear
-* The GNAT Debug Pool Facility::
+
+Stack Related Facilities
+
+* Stack Overflow Checking::
+* Static Stack Usage Analysis::
+* Dynamic Stack Usage Analysis::
+
+Some Useful Memory Pools
+
+The GNAT Debug Pool Facility
@ifclear vms
The gnatmem Tool
* Example of gnatmem Usage::
@end ifclear
-The GNAT Debug Pool Facility
+Verifying Properties Using gnatcheck
+
+* Format of the Report File::
+* General gnatcheck Switches::
+* gnatcheck Rule Options::
+* Adding the Results of Compiler Checks to gnatcheck Output::
+* Project-Wide Checks::
+* Predefined Rules::
-Creating Sample Bodies Using gnatstub
+Sample Bodies Using gnatstub
* Running gnatstub::
* Switches for gnatstub::
* Using Other Utility Programs with GNAT::
* The External Symbol Naming Scheme of GNAT::
+* Converting Ada Files to html with gnathtml::
+
@ifclear vms
-* Ada Mode for Glide::
+Code Coverage and Profiling
+
+* Code Coverage of Ada Programs using gcov::
+* Profiling an Ada Program using gprof::
@end ifclear
-* Converting Ada Files to html with gnathtml::
Running and Debugging Ada Programs
@end ifset
@ifset vms
-Compatibility with DEC Ada
+Compatibility with HP Ada
-* Ada 95 Compatibility::
+* Ada Language Compatibility::
* Differences in the Definition of Package System::
* Language-Related Features::
* The Package STANDARD::
* The Package SYSTEM::
* Tasking and Task-Related Features::
-* Implementation of Tasks in DEC Ada for OpenVMS Alpha Systems::
* Pragmas and Pragma-Related Features::
* Library of Predefined Units::
* Bindings::
* Program Compilation and Library Management::
* Input-Output::
* Implementation Limits::
-* Tools::
+* Tools and Utilities::
Language-Related Features
* Address Clauses::
* Other Representation Clauses::
-Implementation of Tasks in DEC Ada for OpenVMS Alpha Systems
+Tasking and Task-Related Features
+* Implementation of Tasks in HP Ada for OpenVMS Alpha Systems::
* Assigning Task IDs::
* Task IDs and Delays::
* Task-Related Pragmas::
* Summary of Run-Time Configurations::
* Specifying a Run-Time Library::
-* Choosing between Native and FSU Threads Libraries::
* Choosing the Scheduling Policy::
* Solaris-Specific Considerations::
-* IRIX-Specific Considerations::
* Linux-Specific Considerations::
* AIX-Specific Considerations::
+* Irix-Specific Considerations::
Example of Binder Output File
Elaboration Order Handling in GNAT
-* Elaboration Code in Ada 95::
-* Checking the Elaboration Order in Ada 95::
-* Controlling the Elaboration Order in Ada 95::
+* Elaboration Code::
+* Checking the Elaboration Order::
+* Controlling the Elaboration Order::
* Controlling Elaboration in GNAT - Internal Calls::
* Controlling Elaboration in GNAT - External Calls::
* Default Behavior in GNAT - Ensuring Safety::
* Summary of Procedures for Elaboration Control::
* Other Elaboration Order Considerations::
+Conditional Compilation
+* Use of Boolean Constants::
+* Debugging - A Special Case::
+* Conditionalizing Declarations::
+* Use of Alternative Implementations::
+* Preprocessing::
+
Inline Assembler
* Basic Assembler Syntax::
* Input Variables in Inline Assembler::
* Inlining Inline Assembler Code::
* Other Asm Functionality::
-* A Complete Example::
Compatibility and Porting Guide
* Compatibility with Ada 83::
+* Compatibility between Ada 95 and Ada 2005::
* Implementation-dependent characteristics::
-* Compatibility with DEC Ada 83::
-* Compatibility with Other Ada 95 Systems::
+@ifclear vms
+@c This brief section is only in the non-VMS version
+@c The complete chapter on HP Ada issues is in the VMS version
+* Compatibility with HP Ada 83::
+@end ifclear
+* Compatibility with Other Ada Systems::
* Representation Clauses::
+@ifset vms
+* Transitioning to 64-Bit GNAT for OpenVMS::
+@end ifset
@ifset unw
Microsoft Windows Topics
* Building DLLs with GNAT::
* GNAT and Windows Resources::
* Debugging a DLL::
-* GNAT and COM/DCOM Objects::
+* Setting Stack Size from gnatlink::
+* Setting Heap Size from gnatlink::
@end ifset
-
* Index::
@end menu
@end ifnottex
@noindent
@ifset vms
-This guide describes the use of of @value{EDITION},
-a full language compiler for the Ada
-95 programming language, implemented on HP OpenVMS Alpha platforms.
+This guide describes the use of @value{EDITION},
+a compiler and software development toolset for the full Ada
+programming language, implemented on OpenVMS for HP's Alpha and
+Integrity server (I64) platforms.
@end ifset
@ifclear vms
This guide describes the use of @value{EDITION},
a compiler and software development
-toolset for the full Ada 95 programming language.
+toolset for the full Ada programming language.
@end ifclear
-It describes the features of the compiler and tools, and details
-how to use them to build Ada 95 applications.
+It documents the features of the compiler and tools, and explains
+how to use them to build Ada applications.
+
+@value{EDITION} implements Ada 95 and Ada 2005, and it may also be invoked in
+Ada 83 compatibility mode.
+By default, @value{EDITION} assumes @value{DEFAULTLANGUAGEVERSION},
+but you can override with a compiler switch
+(@pxref{Compiling Different Versions of Ada})
+to explicitly specify the language version.
+Throughout this manual, references to ``Ada'' without a year suffix
+apply to both the Ada 95 and Ada 2005 versions of the language.
-@ifset PROEDITION
-For ease of exposition, ``GNAT Pro'' will be referred to simply as
+
+@ifclear FSFEDITION
+For ease of exposition, ``@value{EDITION}'' will be referred to simply as
``GNAT'' in the remainder of this document.
-@end ifset
+@end ifclear
+
@item
@ref{Compiling Using gcc}, describes how to compile
-Ada programs with @code{gcc}, the Ada compiler.
+Ada programs with @command{gcc}, the Ada compiler.
@item
@ref{Binding Using gnatbind}, describes how to
@item
@ref{Linking Using gnatlink},
-describes @code{gnatlink}, a
+describes @command{gnatlink}, a
program that provides for linking using the GNAT run-time library to
-construct a program. @code{gnatlink} can also incorporate foreign language
+construct a program. @command{gnatlink} can also incorporate foreign language
object units into the executable.
@item
-@ref{The GNAT Make Program gnatmake}, describes @code{gnatmake}, a
+@ref{The GNAT Make Program gnatmake}, describes @command{gnatmake}, a
utility that automatically determines the set of sources
needed by an Ada compilation unit, and executes the necessary compilations
binding and link.
@ref{Improving Performance}, shows various techniques for making your
Ada program run faster or take less space.
It discusses the effect of the compiler's optimization switch and
-also describes the @command{gnatelim} tool.
+also describes the @command{gnatelim} tool and unused subprogram/data
+elimination.
@item
@ref{Renaming Files Using gnatchop}, describes
version of an Ada source file with control over casing, indentation,
comment placement, and other elements of program presentation style.
+@item
+@ref{The GNAT Metric Tool gnatmetric}, shows how to compute various
+metrics for an Ada source file, such as the number of types and subprograms,
+and assorted complexity measures.
@item
@ref{File Name Krunching Using gnatkr}, describes the @code{gnatkr}
@item
@ref{Preprocessing Using gnatprep}, describes @code{gnatprep}, a
preprocessor utility that allows a single source file to be used to
-generate multiple or parameterized source files, by means of macro
+generate multiple or parameterized source files by means of macro
substitution.
@ifset vms
@end ifclear
@item
-@ref{Finding Memory Problems}, describes
+@ref{Memory Management Issues}, describes some useful predefined storage pools
+and in particular the GNAT Debug Pool facility, which helps detect incorrect
+memory references.
@ifclear vms
-@command{gnatmem}, a utility that monitors dynamic allocation and deallocation
-and helps detect ``memory leaks'', and
+It also describes @command{gnatmem}, a utility that monitors dynamic
+allocation and deallocation and helps detect ``memory leaks''.
@end ifclear
-the GNAT Debug Pool facility, which helps detect incorrect memory references.
+
+@item
+@ref{Stack Related Facilities}, describes some useful tools associated with
+stack checking and analysis.
+
+@item
+@ref{Verifying Properties Using gnatcheck}, discusses @code{gnatcheck},
+a utility that checks Ada code against a set of rules.
@item
@ref{Creating Sample Bodies Using gnatstub}, discusses @code{gnatstub},
a utility that generates empty but compilable bodies for library units.
@item
+@ref{Generating Ada Bindings for C and C++ headers}, describes how to
+generate automatically Ada bindings from C and C++ headers.
+
+@item
@ref{Other Utility Programs}, discusses several other GNAT utilities,
including @code{gnathtml}.
+@ifclear vms
+@item
+@ref{Code Coverage and Profiling}, describes how to perform a structural
+coverage and profile the execution of Ada programs.
+@end ifclear
+
@item
@ref{Running and Debugging Ada Programs}, describes how to run and debug
Ada programs.
@ifset vms
@item
-@ref{Compatibility with DEC Ada}, details the compatibility of GNAT with
-DEC Ada 83 @footnote{``DEC Ada'' refers to the legacy product originally
+@ref{Compatibility with HP Ada}, details the compatibility of GNAT with
+HP Ada 83 @footnote{``HP Ada'' refers to the legacy product originally
developed by Digital Equipment Corporation and currently supported by HP.}
-for OpenVMS Alpha.
+for OpenVMS Alpha. This product was formerly known as DEC Ada,
+@cindex DEC Ada
+and for
+historical compatibility reasons, the relevant libraries still use the
+DEC prefix.
@end ifset
@item
you deal with elaboration order issues.
@item
+@ref{Conditional Compilation}, describes how to model conditional compilation,
+both with Ada in general and with GNAT facilities in particular.
+
+@item
@ref{Inline Assembler}, shows how to use the inline assembly facility
in an Ada program.
@item
-@ref{Compatibility and Porting Guide}, includes sections on compatibility
-of GNAT with other Ada 83 and Ada 95 compilation systems, to assist
-in porting code from other environments.
+@ref{Compatibility and Porting Guide}, contains sections on compatibility
+of GNAT with other Ada development environments (including Ada 83 systems),
+to assist in porting code from those environments.
@ifset unw
@item
@end ifset
@end itemize
-
@c *************************************************
@node What You Should Know before Reading This Guide
@c *************************************************
@unnumberedsec What You Should Know before Reading This Guide
@cindex Ada 95 Language Reference Manual
+@cindex Ada 2005 Language Reference Manual
@noindent
-This user's guide assumes that you are familiar with Ada 95 language, as
+This guide assumes a basic familiarity with the Ada 95 language, as
described in the International Standard ANSI/ISO/IEC-8652:1995, January
1995.
+It does not require knowledge of the new features introduced by Ada 2005,
+(officially known as ISO/IEC 8652:1995 with Technical Corrigendum 1
+and Amendment 1).
+Both reference manuals are included in the GNAT documentation
+package.
@node Related Information
@unnumberedsec Related Information
@itemize @bullet
@item
-@cite{GNAT Reference Manual}, which contains all reference
-material for the GNAT implementation of Ada 95.
+@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, GNAT
+Reference Manual}, which contains all reference material for the GNAT
+implementation of Ada.
@ifset unw
@item
-@cite{Using the GNAT Programming System}, which describes the GPS
-integrated development environment.
+@cite{Using the GNAT Programming Studio}, which describes the GPS
+Integrated Development Environment.
@item
-@cite{GNAT Programming System Tutorial}, which introduces the
+@cite{GNAT Programming Studio Tutorial}, which introduces the
main GPS features through examples.
@end ifset
@item
-@cite{Ada 95 Language Reference Manual}, which contains all reference
+@cite{Ada 95 Reference Manual}, which contains reference
material for the Ada 95 programming language.
@item
-@cite{Debugging with GDB}
+@cite{Ada 2005 Reference Manual}, which contains reference
+material for the Ada 2005 programming language.
+
+@item
+@xref{Top,, Debugging with GDB, gdb, Debugging with GDB},
@ifset vms
-, located in the GNU:[DOCS] directory,
+in the GNU:[DOCS] directory,
@end ifset
-contains all details on the use of the GNU source-level debugger.
+for all details on the use of the GNU source-level debugger.
@item
-@cite{GNU Emacs Manual}
+@xref{Top,, The extensible self-documenting text editor, emacs,
+GNU Emacs Manual},
@ifset vms
-, located in the GNU:[DOCS] directory if the EMACS kit is installed,
+located in the GNU:[DOCS] directory if the EMACS kit is installed,
@end ifset
-contains full information on the extensible editor and programming
+for full information on the extensible editor and programming
environment Emacs.
@end itemize
@itemize @bullet
@item
-@code{Functions}, @code{utility program names}, @code{standard names},
+@code{Functions}, @command{utility program names}, @code{standard names},
and @code{classes}.
@item
-@samp{Option flags}
+@option{Option flags}
@item
-@file{File Names}, @file{button names}, and @file{field names}.
+@file{File names}, @samp{button names}, and @samp{field names}.
@item
-@var{Variables}.
+@code{Variables}, @env{environment variables}, and @var{metasyntactic
+variables}.
@item
@emph{Emphasis}.
@item
-[optional information or parameters]
+@r{[}optional information or parameters@r{]}
@item
Examples are described by text
the ``@code{\}'' character should be used instead.
@end ifset
-
-
@c ****************************
@node Getting Started with GNAT
@chapter Getting Started with GNAT
@ifset unw
@ref{Running GNAT}, through @ref{Using the gnatmake Utility},
show how to use the command line environment.
-@ref{Introduction to Glide and GVD}, provides a brief
-introduction to the visually-oriented IDE for GNAT.
-Supplementing Glide on some platforms is GPS, the
-GNAT Programming System, which offers a richer graphical
-``look and feel'', enhanced configurability, support for
-development in other programming language, comprehensive
-browsing features, and many other capabilities.
+@ref{Introduction to GPS}, provides a brief
+introduction to the GNAT Programming Studio, a visually-oriented
+Integrated Development Environment for GNAT.
+GPS offers a graphical ``look and feel'', support for development in
+other programming languages, comprehensive browsing features, and
+many other capabilities.
For information on GPS please refer to
-@cite{Using the GNAT Programming System}.
+@cite{Using the GNAT Programming Studio}.
@end ifset
@menu
@end ifset
@ifclear vms
* Introduction to GPS::
-* Introduction to Glide and GVD::
@end ifclear
@end menu
@end enumerate
@noindent
-All three steps are most commonly handled by using the @code{gnatmake}
+All three steps are most commonly handled by using the @command{gnatmake}
utility program that, given the name of the main program, automatically
performs the necessary compilation, binding and linking steps.
-
@node Running a Simple Ada Program
@section Running a Simple Ada Program
@noindent
Any text editor may be used to prepare an Ada program.
-@ifclear vms
-If @code{Glide} is
-used, the optional Ada mode may be helpful in laying out the program.
-@end ifclear
+(If @code{Emacs} is
+used, the optional Ada mode may be helpful in laying out the program.)
The
-program text is a normal text file. We will suppose in our initial
+program text is a normal text file. We will assume in our initial
example that you have used your editor to prepare the following
standard format text file:
@end smallexample
@noindent
-@code{gcc} is the command used to run the compiler. This compiler is
-capable of compiling programs in several languages, including Ada 95 and
+@command{gcc} is the command used to run the compiler. This compiler is
+capable of compiling programs in several languages, including Ada and
C. It assumes that you have given it an Ada program if the file extension is
either @file{.ads} or @file{.adb}, and it will then call
the GNAT compiler to compile the specified file.
that an Ada program is consistent.
To build an executable file,
use @code{gnatbind} to bind the program
-and @code{gnatlink} to link it. The
-argument to both @code{gnatbind} and @code{gnatlink} is the name of the
+and @command{gnatlink} to link it. The
+argument to both @code{gnatbind} and @command{gnatlink} is the name of the
@file{ALI} file, but the default extension of @file{.ali} can
be omitted. This means that in the most common case, the argument
is simply the name of the main program:
The result is an executable program called @file{hello}, which can be
run by entering:
-@c The following should be removed (BMB 2001-01-23)
-@c @smallexample
-@c $ ^./hello^$ RUN HELLO^
-@c @end smallexample
-
@smallexample
-$ hello
+$ ^hello^RUN HELLO^
@end smallexample
@noindent
@noindent
appear in response to this command.
-
@c ****************************************
@node Running a Program with Multiple Units
@section Running a Program with Multiple Units
@noindent
Although the compilation can be done in separate steps as in the
above example, in practice it is almost always more convenient
-to use the @code{gnatmake} tool. All you need to know in this case
+to use the @command{gnatmake} tool. All you need to know in this case
is the name of the main program's source file. The effect of the above four
commands can be achieved with a single one:
@end smallexample
@noindent
-In the next section we discuss the advantages of using @code{gnatmake} in
+In the next section we discuss the advantages of using @command{gnatmake} in
more detail.
@c *****************************
@noindent
If you work on a program by compiling single components at a time using
-@code{gcc}, you typically keep track of the units you modify. In order to
+@command{gcc}, you typically keep track of the units you modify. In order to
build a consistent system, you compile not only these units, but also any
units that depend on the units you have modified.
For example, in the preceding case,
sure that the makefile is kept up-to-date manually, which is also an
error-prone process.
-The @code{gnatmake} utility takes care of these details automatically.
+The @command{gnatmake} utility takes care of these details automatically.
Invoke it using either one of the following forms:
@smallexample
@noindent
The argument is the name of the file containing the main program;
-you may omit the extension. @code{gnatmake}
+you may omit the extension. @command{gnatmake}
examines the environment, automatically recompiles any files that need
recompiling, and binds and links the resulting set of object files,
generating the executable file, @file{^gmain^GMAIN.EXE^}.
In a large program, it
-can be extremely helpful to use @code{gnatmake}, because working out by hand
+can be extremely helpful to use @command{gnatmake}, because working out by hand
what needs to be recompiled can be difficult.
-Note that @code{gnatmake}
-takes into account all the Ada 95 rules that
+Note that @command{gnatmake}
+takes into account all the Ada rules that
establish dependencies among units. These include dependencies that result
from inlining subprogram bodies, and from
generic instantiation. Unlike some other
-Ada make tools, @code{gnatmake} does not rely on the dependencies that were
+Ada make tools, @command{gnatmake} does not rely on the dependencies that were
found by the compiler on a previous compilation, which may possibly
-be wrong when sources change. @code{gnatmake} determines the exact set of
+be wrong when sources change. @command{gnatmake} determines the exact set of
dependencies from scratch each time it is run.
@ifset vms
Documentation on Emacs and other tools is available in Emacs under the
pull-down menu button: @code{Help - Info}. After selecting @code{Info},
-use the middle mouse button to select a topic (e.g. Emacs).
+use the middle mouse button to select a topic (e.g.@: Emacs).
In a character cell terminal, do @kbd{C-h i} to invoke info, and then @kbd{m}
(stands for menu) followed by the menu item desired, as in @kbd{m Emacs}, to
@ifclear vms
@node Introduction to GPS
@section Introduction to GPS
-@cindex GPS (GNAT Programming System)
-@cindex GNAT Programming System (GPS)
+@cindex GPS (GNAT Programming Studio)
+@cindex GNAT Programming Studio (GPS)
@noindent
Although the command line interface (@command{gnatmake}, etc.) alone
is sufficient, a graphical Interactive Development
Environment can make it easier for you to compose, navigate, and debug
programs. This section describes the main features of GPS
-(``GNAT Programming System''), the GNAT graphical IDE.
+(``GNAT Programming Studio''), the GNAT graphical IDE.
You will see how to use GPS to build and debug an executable, and
you will also learn some of the basics of the GNAT ``project'' facility.
* Simple Debugging with GPS::
@end menu
-
@node Building a New Program with GPS
@subsection Building a New Program with GPS
@noindent
a collection of properties such
as source directories, identities of main subprograms, tool switches, etc.,
and their associated values.
-(See @ref{GNAT Project Manager}, for details.)
+See @ref{GNAT Project Manager} for details.
In order to run GPS, you will need to either create a new project
or else open an existing one.
The file will be saved in the same directory you specified as the
location of the default project file.
-
@item @emph{Updating the project file}
You need to add the new source file to the project.
terminate this GPS session.
@end enumerate
-
-
@node Simple Debugging with GPS
@subsection Simple Debugging with GPS
@noindent
Select @code{Debug}, then @code{Run}. When the
@code{Program Arguments} window appears, click @code{OK}.
A console window will appear; enter some line of text,
-e.g. @code{abcde}, at the prompt.
+e.g.@: @code{abcde}, at the prompt.
The program will pause execution when it gets to the
breakpoint, and the corresponding line is highlighted.
You will see information about @code{N} appear in the @code{Debugger Data}
pane, showing the value as 5.
-
@item @emph{Assigning a new value to a variable}
Right click on the @code{N} in the @code{Debugger Data} pane, and
The console window will disappear.
@end enumerate
@end enumerate
-
-
-@node Introduction to Glide and GVD
-@section Introduction to Glide and GVD
-@cindex Glide
-@cindex GVD
-@noindent
-This section describes the main features of Glide,
-a GNAT graphical IDE, and also shows how to use the basic commands in GVD,
-the GNU Visual Debugger.
-These tools may be present in addition to, or in place of, GPS on some
-platforms.
-Additional information on Glide and GVD may be found
-in the on-line help for these tools.
-
-@menu
-* Building a New Program with Glide::
-* Simple Debugging with GVD::
-* Other Glide Features::
-@end menu
-
-@node Building a New Program with Glide
-@subsection Building a New Program with Glide
-@noindent
-The simplest way to invoke Glide is to enter @command{glide}
-at the command prompt. It will generally be useful to issue this
-as a background command, thus allowing you to continue using
-your command window for other purposes while Glide is running:
-
-@smallexample
-$ glide&
-@end smallexample
-
-@noindent
-Glide will start up with an initial screen displaying the top-level menu items
-as well as some other information. The menu selections are as follows
-@itemize @bullet
-@item @code{Buffers}
-@item @code{Files}
-@item @code{Tools}
-@item @code{Edit}
-@item @code{Search}
-@item @code{Mule}
-@item @code{Glide}
-@item @code{Help}
-@end itemize
-
-@noindent
-For this introductory example, you will need to create a new Ada source file.
-First, select the @code{Files} menu. This will pop open a menu with around
-a dozen or so items. To create a file, select the @code{Open file...} choice.
-Depending on the platform, you may see a pop-up window where you can browse
-to an appropriate directory and then enter the file name, or else simply
-see a line at the bottom of the Glide window where you can likewise enter
-the file name. Note that in Glide, when you attempt to open a non-existent
-file, the effect is to create a file with that name. For this example enter
-@file{hello.adb} as the name of the file.
-
-A new buffer will now appear, occupying the entire Glide window,
-with the file name at the top. The menu selections are slightly different
-from the ones you saw on the opening screen; there is an @code{Entities} item,
-and in place of @code{Glide} there is now an @code{Ada} item. Glide uses
-the file extension to identify the source language, so @file{adb} indicates
-an Ada source file.
-
-You will enter some of the source program lines explicitly,
-and use the syntax-oriented template mechanism to enter other lines.
-First, type the following text:
-@smallexample
-with Ada.Text_IO; use Ada.Text_IO;
-procedure Hello is
-begin
-@end smallexample
-
-@noindent
-Observe that Glide uses different colors to distinguish reserved words from
-identifiers. Also, after the @code{procedure Hello is} line, the cursor is
-automatically indented in anticipation of declarations. When you enter
-@code{begin}, Glide recognizes that there are no declarations and thus places
-@code{begin} flush left. But after the @code{begin} line the cursor is again
-indented, where the statement(s) will be placed.
-
-The main part of the program will be a @code{for} loop. Instead of entering
-the text explicitly, however, use a statement template. Select the @code{Ada}
-item on the top menu bar, move the mouse to the @code{Statements} item,
-and you will see a large selection of alternatives. Choose @code{for loop}.
-You will be prompted (at the bottom of the buffer) for a loop name;
-simply press the @key{Enter} key since a loop name is not needed.
-You should see the beginning of a @code{for} loop appear in the source
-program window. You will now be prompted for the name of the loop variable;
-enter a line with the identifier @code{ind} (lower case). Note that,
-by default, Glide capitalizes the name (you can override such behavior
-if you wish, although this is outside the scope of this introduction).
-Next, Glide prompts you for the loop range; enter a line containing
-@code{1..5} and you will see this also appear in the source program,
-together with the remaining elements of the @code{for} loop syntax.
-
-Next enter the statement (with an intentional error, a missing semicolon)
-that will form the body of the loop:
-@smallexample
-Put_Line("Hello, World" & Integer'Image(I))
-@end smallexample
-
-@noindent
-Finally, type @code{end Hello;} as the last line in the program.
-Now save the file: choose the @code{File} menu item, and then the
-@code{Save buffer} selection. You will see a message at the bottom
-of the buffer confirming that the file has been saved.
-
-You are now ready to attempt to build the program. Select the @code{Ada}
-item from the top menu bar. Although we could choose simply to compile
-the file, we will instead attempt to do a build (which invokes
-@command{gnatmake}) since, if the compile is successful, we want to build
-an executable. Thus select @code{Ada build}. This will fail because of the
-compilation error, and you will notice that the Glide window has been split:
-the top window contains the source file, and the bottom window contains the
-output from the GNAT tools. Glide allows you to navigate from a compilation
-error to the source file position corresponding to the error: click the
-middle mouse button (or simultaneously press the left and right buttons,
-on a two-button mouse) on the diagnostic line in the tool window. The
-focus will shift to the source window, and the cursor will be positioned
-on the character at which the error was detected.
-
-Correct the error: type in a semicolon to terminate the statement.
-Although you can again save the file explicitly, you can also simply invoke
-@code{Ada} @result{} @code{Build} and you will be prompted to save the file.
-This time the build will succeed; the tool output window shows you the
-options that are supplied by default. The GNAT tools' output (e.g.
-object and ALI files, executable) will go in the directory from which
-Glide was launched.
-
-To execute the program, choose @code{Ada} and then @code{Run}.
-You should see the program's output displayed in the bottom window:
-
-@smallexample
-Hello, world 1
-Hello, world 2
-Hello, world 3
-Hello, world 4
-Hello, world 5
-@end smallexample
-
-@node Simple Debugging with GVD
-@subsection Simple Debugging with GVD
-
-@noindent
-This section describes how to set breakpoints, examine/modify variables,
-and step through execution.
-
-In order to enable debugging, you need to pass the @option{-g} switch
-to both the compiler and to @command{gnatlink}. If you are using
-the command line, passing @option{-g} to @command{gnatmake} will have
-this effect. You can then launch GVD, e.g. on the @code{hello} program,
-by issuing the command:
-
-@smallexample
-$ gvd hello
-@end smallexample
-
-@noindent
-If you are using Glide, then @option{-g} is passed to the relevant tools
-by default when you do a build. Start the debugger by selecting the
-@code{Ada} menu item, and then @code{Debug}.
-
-GVD comes up in a multi-part window. One pane shows the names of files
-comprising your executable; another pane shows the source code of the current
-unit (initially your main subprogram), another pane shows the debugger output
-and user interactions, and the fourth pane (the data canvas at the top
-of the window) displays data objects that you have selected.
-
-To the left of the source file pane, you will notice green dots adjacent
-to some lines. These are lines for which object code exists and where
-breakpoints can thus be set. You set/reset a breakpoint by clicking
-the green dot. When a breakpoint is set, the dot is replaced by an @code{X}
-in a red circle. Clicking the circle toggles the breakpoint off,
-and the red circle is replaced by the green dot.
-
-For this example, set a breakpoint at the statement where @code{Put_Line}
-is invoked.
-
-Start program execution by selecting the @code{Run} button on the top menu bar.
-(The @code{Start} button will also start your program, but it will
-cause program execution to break at the entry to your main subprogram.)
-Evidence of reaching the breakpoint will appear: the source file line will be
-highlighted, and the debugger interactions pane will display
-a relevant message.
-
-You can examine the values of variables in several ways. Move the mouse
-over an occurrence of @code{Ind} in the @code{for} loop, and you will see
-the value (now @code{1}) displayed. Alternatively, right-click on @code{Ind}
-and select @code{Display Ind}; a box showing the variable's name and value
-will appear in the data canvas.
-
-Although a loop index is a constant with respect to Ada semantics,
-you can change its value in the debugger. Right-click in the box
-for @code{Ind}, and select the @code{Set Value of Ind} item.
-Enter @code{2} as the new value, and press @command{OK}.
-The box for @code{Ind} shows the update.
-
-Press the @code{Step} button on the top menu bar; this will step through
-one line of program text (the invocation of @code{Put_Line}), and you can
-observe the effect of having modified @code{Ind} since the value displayed
-is @code{2}.
-
-Remove the breakpoint, and resume execution by selecting the @code{Cont}
-button. You will see the remaining output lines displayed in the debugger
-interaction window, along with a message confirming normal program
-termination.
-
-@node Other Glide Features
-@subsection Other Glide Features
-
-@noindent
-You may have observed that some of the menu selections contain abbreviations;
-e.g., @code{(C-x C-f)} for @code{Open file...} in the @code{Files} menu.
-These are @emph{shortcut keys} that you can use instead of selecting
-menu items. The @key{C} stands for @key{Ctrl}; thus @code{(C-x C-f)} means
-@key{Ctrl-x} followed by @key{Ctrl-f}, and this sequence can be used instead
-of selecting @code{Files} and then @code{Open file...}.
-
-To abort a Glide command, type @key{Ctrl-g}.
-
-If you want Glide to start with an existing source file, you can either
-launch Glide as above and then open the file via @code{Files} @result{}
-@code{Open file...}, or else simply pass the name of the source file
-on the command line:
-
-@smallexample
-$ glide hello.adb&
-@end smallexample
-
-@noindent
-While you are using Glide, a number of @emph{buffers} exist.
-You create some explicitly; e.g., when you open/create a file.
-Others arise as an effect of the commands that you issue; e.g., the buffer
-containing the output of the tools invoked during a build. If a buffer
-is hidden, you can bring it into a visible window by first opening
-the @code{Buffers} menu and then selecting the desired entry.
-
-If a buffer occupies only part of the Glide screen and you want to expand it
-to fill the entire screen, then click in the buffer and then select
-@code{Files} @result{} @code{One Window}.
-
-If a window is occupied by one buffer and you want to split the window
-to bring up a second buffer, perform the following steps:
-@itemize @bullet
-@item Select @code{Files} @result{} @code{Split Window};
-this will produce two windows each of which holds the original buffer
-(these are not copies, but rather different views of the same buffer contents)
-
-@item With the focus in one of the windows,
-select the desired buffer from the @code{Buffers} menu
-@end itemize
-
-@noindent
-To exit from Glide, choose @code{Files} @result{} @code{Exit}.
@end ifclear
@node The GNAT Compilation Model
* The Ada Library Information Files::
* Binding an Ada Program::
* Mixed Language Programming::
+@ifclear vms
* Building Mixed Ada & C++ Programs::
* Comparison between GNAT and C/C++ Compilation Models::
+@end ifclear
* Comparison between GNAT and Conventional Ada Library Models::
@ifset vms
* Placement of temporary files::
@noindent
Source files are in standard text file format. In addition, GNAT will
-recognize a wide variety of stream formats, in which the end of physical
+recognize a wide variety of stream formats, in which the end of
physical lines is marked by any of the following sequences:
@code{LF}, @code{CR}, @code{CR-LF}, or @code{LF-CR}. This is useful
in accommodating files that are imported from other operating systems.
@section Foreign Language Representation
@noindent
-GNAT supports the standard character sets defined in Ada 95 as well as
+GNAT supports the standard character sets defined in Ada as well as
several other non-standard character sets for use in localized versions
of the compiler (@pxref{Character Set Control}).
@menu
@noindent
The basic character set is Latin-1. This character set is defined by ISO
standard 8859, part 1. The lower half (character codes @code{16#00#}
-... @code{16#7F#)} is identical to standard ASCII coding, but the upper half
+@dots{} @code{16#7F#)} is identical to standard ASCII coding, but the upper half
is used to represent additional characters. These include extended letters
used by European languages, such as French accents, the vowels with umlauts
used in German, and the extra letter A-ring used in Swedish.
Any character in the range 80-FF allowed in identifiers, and all are
considered distinct. In other words, there are no uppercase and lowercase
equivalences in this range. This is useful in conjunction with
-certain encoding schemes used for some foreign character sets (e.g.
+certain encoding schemes used for some foreign character sets (e.g.,
the typical method of representing Chinese characters on the PC).
@item No Upper-Half
@iftex
@leftskip=.7cm
@end iftex
-16#0000#-16#007f#: 2#0xxxxxxx#
-16#0080#-16#07ff#: 2#110xxxxx# 2#10xxxxxx#
-16#0800#-16#ffff#: 2#1110xxxx# 2#10xxxxxx# 2#10xxxxxx#
+16#0000#-16#007f#: 2#0@var{xxxxxxx}#
+16#0080#-16#07ff#: 2#110@var{xxxxx}# 2#10@var{xxxxxx}#
+16#0800#-16#ffff#: 2#1110@var{xxxx}# 2#10@var{xxxxxx}# 2#10@var{xxxxxx}#
@end smallexample
@noindent
-where the xxx bits correspond to the left-padded bits of the
+where the @var{xxx} bits correspond to the left-padded bits of the
16-bit character value. Note that all lower half ASCII characters
are represented as ASCII bytes and all upper half characters and
other wide characters are represented as sequences of upper-half
@noindent
Note: Some of these coding schemes do not permit the full use of the
-Ada 95 character set. For example, neither Shift JIS, nor EUC allow the
+Ada character set. For example, neither Shift JIS, nor EUC allow the
use of the upper half of the Latin-1 set.
@node File Naming Rules
An exception arises if the file name generated by the above rules starts
with one of the characters
@ifset vms
-A,G,I, or S,
+@samp{A}, @samp{G}, @samp{I}, or @samp{S},
@end ifset
@ifclear vms
-a,g,i, or s,
+@samp{a}, @samp{g}, @samp{i}, or @samp{s},
@end ifclear
and the second character is a
minus. In this case, the character ^tilde^dollar sign^ is used in place
the standard names for child units of the packages System, Ada,
Interfaces, and GNAT, which use the prefixes
@ifset vms
-S- A- I- and G-
+@samp{S-}, @samp{A-}, @samp{I-}, and @samp{G-},
@end ifset
@ifclear vms
-s- a- i- and g-
+@samp{s-}, @samp{a-}, @samp{i-}, and @samp{g-},
@end ifclear
respectively.
file used to hold configuration
pragmas that apply to a complete compilation environment.
For more details on how the @file{gnat.adc} file is created and used
-@pxref{Handling of Configuration Pragmas}
+see @ref{Handling of Configuration Pragmas}.
@cindex @file{gnat.adc}
@ifclear vms
source file name pragma. However, if the file name specified has an
extension other than @file{.ads} or @file{.adb} it is necessary to use
a special syntax when compiling the file. The name in this case must be
-preceded by the special sequence @code{-x} followed by a space and the name
+preceded by the special sequence @option{-x} followed by a space and the name
of the language, here @code{ada}, as in:
@smallexample
@end ifclear
@noindent
-@code{gnatmake} handles non-standard file names in the usual manner (the
+@command{gnatmake} handles non-standard file names in the usual manner (the
non-standard file name for the main program is simply used as the
argument to gnatmake). Note that if the extension is also non-standard,
-then it must be included in the gnatmake command, it may not be omitted.
+then it must be included in the @command{gnatmake} command, it may not
+be omitted.
@node Alternative File Naming Schemes
@section Alternative File Naming Schemes
@smallexample @c ada
pragma Source_File_Name (
Spec_File_Name => FILE_NAME_PATTERN
- [,Casing => CASING_SPEC]
- [,Dot_Replacement => STRING_LITERAL]);
+ @r{[},Casing => CASING_SPEC@r{]}
+ @r{[},Dot_Replacement => STRING_LITERAL@r{]});
pragma Source_File_Name (
Body_File_Name => FILE_NAME_PATTERN
- [,Casing => CASING_SPEC]
- [,Dot_Replacement => STRING_LITERAL]);
+ @r{[},Casing => CASING_SPEC@r{]}
+ @r{[},Dot_Replacement => STRING_LITERAL@r{]});
pragma Source_File_Name (
Subunit_File_Name => FILE_NAME_PATTERN
- [,Casing => CASING_SPEC]
- [,Dot_Replacement => STRING_LITERAL]);
+ @r{[},Casing => CASING_SPEC@r{]}
+ @r{[},Dot_Replacement => STRING_LITERAL@r{]});
FILE_NAME_PATTERN ::= STRING_LITERAL
CASING_SPEC ::= Lowercase | Uppercase | Mixedcase
@code{Body_File_name} rule is used for subunits as well.
The separate rule for subunits can also be used to implement the rather
-unusual case of a compilation environment (e.g. a single directory) which
+unusual case of a compilation environment (e.g.@: a single directory) which
contains a subunit and a child unit with the same unit name. Although
both units cannot appear in the same partition, the Ada Reference Manual
allows (but does not require) the possibility of the two units coexisting
it is necessary to compile in optimizing mode.
@cindex @option{-gnatN} switch
-The use of @option{-gnatN} activates a more extensive inlining optimization
+The use of @option{-gnatN} activates inlining optimization
that is performed by the front end of the compiler. This inlining does
not require that the code generation be optimized. Like @option{-gnatn},
the use of this switch generates additional dependencies.
-Note that
-@option{-gnatN} automatically implies @option{-gnatn} so it is not necessary
-to specify both options.
+
+When using a gcc-based back end (in practice this means using any version
+of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of
+@option{-gnatN} is deprecated, and the use of @option{-gnatn} is preferred.
+Historically front end inlining was more extensive than the gcc back end
+inlining, but that is no longer the case.
@item
-If an object file O depends on the proper body of a subunit through inlining
-or instantiation, it depends on the parent unit of the subunit. This means that
-any modification of the parent unit or one of its subunits affects the
-compilation of O.
+If an object file @file{O} depends on the proper body of a subunit through
+inlining or instantiation, it depends on the parent unit of the subunit.
+This means that any modification of the parent unit or one of its subunits
+affects the compilation of @file{O}.
@item
The object file for a parent unit depends on all its subunit body files.
@code{C}, in file @file{c.adb}.
The set of dependent files described by these rules includes all the
-files on which the unit is semantically dependent, as described in the
-Ada 95 Language Reference Manual. However, it is a superset of what the
-ARM describes, because it includes generic, inline, and subunit dependencies.
+files on which the unit is semantically dependent, as dictated by the
+Ada language standard. However, it is a superset of what the
+standard describes, because it includes generic, inline, and subunit
+dependencies.
An object file must be recreated by recompiling the corresponding source
file if any of the source files on which it depends are modified. For
the rule for an Ada object file must mention all the source files on
which the object file depends, according to the above definition.
The determination of the necessary
-recompilations is done automatically when one uses @code{gnatmake}.
+recompilations is done automatically when one uses @command{gnatmake}.
@end itemize
@node The Ada Library Information Files
as well as the wide character encoding used during compilation).
@item
-List of arguments used in the @code{gcc} command for the compilation
+List of arguments used in the @command{gcc} command for the compilation
@item
Attributes of the unit, including configuration pragmas used, an indication
checking.
@item
-Categorization information (e.g. use of pragma @code{Pure}).
+Categorization information (e.g.@: use of pragma @code{Pure}).
@item
Information on all @code{with}'ed units, including presence of
Interfacing Ada with a foreign language such as C involves using
compiler directives to import and/or export entity definitions in each
language---using @code{extern} statements in C, for instance, and the
-@code{Import}, @code{Export}, and @code{Convention} pragmas in Ada. For
-a full treatment of these topics, read Appendix B, section 1 of the Ada
-95 Language Reference Manual.
+@code{Import}, @code{Export}, and @code{Convention} pragmas in Ada.
+A full treatment of these topics is provided in Appendix B, section 1
+of the Ada Reference Manual.
There are two ways to build a program using GNAT that contains some Ada
sources and some foreign language sources, depending on whether or not
To build this example, first compile the foreign language files to
generate object files:
@smallexample
-gcc -c file1.c
-gcc -c file2.c
+^gcc -c file1.c^gcc -c FILE1.C^
+^gcc -c file2.c^gcc -c FILE2.C^
@end smallexample
@item
example's. First, compile the foreign language files to generate object
files:
@smallexample
-gcc -c main.c
+^gcc -c main.c^gcc -c main.c^
@end smallexample
@item
This procedure yields a binary executable called @file{exec_file}.
@end enumerate
+@noindent
+Depending on the circumstances (for example when your non-Ada main object
+does not provide symbol @code{main}), you may also need to instruct the
+GNAT linker not to include the standard startup objects by passing the
+@option{^-nostartfiles^/NOSTART_FILES^} switch to @command{gnatlink}.
+
@node Calling Conventions
@subsection Calling Conventions
@cindex Foreign Languages
are unlikely to be able to be passed.
Note that in the case of GNAT running
-on a platform that supports DEC Ada 83, a higher degree of compatibility
+on a platform that supports HP Ada 83, a higher degree of compatibility
can be guaranteed, and in particular records are layed out in an identical
manner in the two compilers. Note also that if output from two different
compilers is mixed, the program is responsible for dealing with elaboration
Ada compiler for further details on elaboration.
However, it is not possible to mix the tasking run time of GNAT and
-DEC Ada 83, All the tasking operations must either be entirely within
-GNAT compiled sections of the program, or entirely within DEC Ada 83
+HP Ada 83, All the tasking operations must either be entirely within
+GNAT compiled sections of the program, or entirely within HP Ada 83
compiled sections of the program.
@cindex Interfacing to Assembly
@findex COBOL
@item COBOL
Data will be passed according to the conventions described
-in section B.4 of the Ada 95 Reference Manual.
+in section B.4 of the Ada Reference Manual.
@findex C
@cindex Interfacing to C
@cindex Convention C
@item C
Data will be passed according to the conventions described
-in section B.3 of the Ada 95 Reference Manual.
+in section B.3 of the Ada Reference Manual.
+A note on interfacing to a C ``varargs'' function:
@findex C varargs function
-@cindex Intefacing to C varargs function
-@cindex varargs function intefacs
-@item C varargs function
+@cindex Interfacing to C varargs function
+@cindex varargs function interfaces
+
+@itemize @bullet
+@item
In C, @code{varargs} allows a function to take a variable number of
arguments. There is no direct equivalent in this to Ada. One
approach that can be used is to create a C wrapper for each
create a C function @code{printfi} that takes two arguments, a
pointer to a string and an int, and calls @code{printf}.
Then in the Ada program, use pragma @code{Import} to
-interface to printfi.
+interface to @code{printfi}.
+@item
It may work on some platforms to directly interface to
a @code{varargs} function by providing a specific Ada profile
-for a a particular call. However, this does not work on
+for a particular call. However, this does not work on
all platforms, since there is no guarantee that the
calling sequence for a two argument normal C function
is the same as for calling a @code{varargs} C function with
the same two arguments.
+@end itemize
@cindex Convention Default
@findex Default
@item External
Equivalent to C.
+@ifclear vms
@findex C++
@cindex Interfacing to C++
@cindex Convention C++
-@item CPP
+@item C_Plus_Plus (or CPP)
This stands for C++. For most purposes this is identical to C.
See the separate description of the specialized GNAT pragmas relating to
C++ interfacing for further details.
+@end ifclear
@findex Fortran
@cindex Interfacing to Fortran
@cindex Convention Fortran
@item Fortran
Data will be passed according to the conventions described
-in section B.5 of the Ada 95 Reference Manual.
+in section B.5 of the Ada Reference Manual.
@item Intrinsic
-This applies to an intrinsic operation, as defined in the Ada 95
-Reference Manual. If a a pragma Import (Intrinsic) applies to a subprogram,
+This applies to an intrinsic operation, as defined in the Ada
+Reference Manual. If a pragma Import (Intrinsic) applies to a subprogram,
this means that the body of the subprogram is provided by the compiler itself,
usually by means of an efficient code sequence, and that the user does not
-supply an explicit body for it. In an application program, the pragma can
-only be applied to the following two sets of names, which the GNAT compiler
-recognizes.
+supply an explicit body for it. In an application program, the pragma may
+be applied to the following sets of names:
@itemize @bullet
@item
-Rotate_Left, Rotate_Right, Shift_Left, Shift_Right, Shift_Right_-
-Arithmetic. The corresponding subprogram declaration must have
+Rotate_Left, Rotate_Right, Shift_Left, Shift_Right,
+Shift_Right_Arithmetic. The corresponding subprogram declaration must have
two formal parameters. The
first one must be a signed integer type or a modular type with a binary
modulus, and the second parameter must be of type Natural.
The return type must be the same as the type of the first argument. The size
of this type can only be 8, 16, 32, or 64.
-@item binary arithmetic operators: ``+'', ``-'', ``*'', ``/''
+
+@item
+Binary arithmetic operators: ``+'', ``-'', ``*'', ``/''
The corresponding operator declaration must have parameters and result type
that have the same root numeric type (for example, all three are long_float
types). This simplifies the definition of operations that use type checking
explicit body. The pragma makes it simpler to introduce such declarations.
It incurs no overhead in compilation time or code size, because it is
implemented as a single machine instruction.
+
+@item
+General subprogram entities, to bind an Ada subprogram declaration to
+a compiler builtin by name with back-ends where such interfaces are
+available. A typical example is the set of ``__builtin'' functions
+exposed by the GCC back-end, as in the following example:
+
+@smallexample @c ada
+ function builtin_sqrt (F : Float) return Float;
+ pragma Import (Intrinsic, builtin_sqrt, "__builtin_sqrtf");
+@end smallexample
+
+Most of the GCC builtins are accessible this way, and as for other
+import conventions (e.g. C), it is the user's responsibility to ensure
+that the Ada subprogram profile matches the underlying builtin
+expectations.
@end itemize
+
@noindent
@ifset unw
@findex Stdcall
@cindex Convention Stdcall
@item Stdcall
-This is relevant only to NT/Win95 implementations of GNAT,
-and specifies that the Stdcall calling sequence will be used, as defined
-by the NT API.
+This is relevant only to Windows XP/2000/NT implementations of GNAT,
+and specifies that the @code{Stdcall} calling sequence will be used,
+as defined by the NT API. Nevertheless, to ease building
+cross-platform bindings this convention will be handled as a @code{C} calling
+convention on non-Windows platforms.
@findex DLL
@cindex Convention DLL
@item DLL
-This is equivalent to Stdcall.
+This is equivalent to @code{Stdcall}.
@findex Win32
@cindex Convention Win32
@item Win32
-This is equivalent to Stdcall.
+This is equivalent to @code{Stdcall}.
@end ifset
@findex Stubbed
identifier (for example in an @code{Import} pragma) with the same
meaning as Fortran.
+@ifclear vms
@node Building Mixed Ada & C++ Programs
-@section Building Mixed Ada & C++ Programs
+@section Building Mixed Ada and C++ Programs
@noindent
A programmer inexperienced with mixed-language development may find that
building an application containing both Ada and C++ code can be a
-challenge. As a matter of fact, interfacing with C++ has not been
-standardized in the Ada 95 Reference Manual due to the immaturity of --
-and lack of standards for -- C++ at the time. This section gives a few
+challenge. This section gives a few
hints that should make this task easier. The first section addresses
-the differences regarding interfacing with C. The second section
+the differences between interfacing with C and interfacing with C++.
+The second section
looks into the delicate problem of linking the complete application from
its Ada and C++ parts. The last section gives some hints on how the GNAT
-run time can be adapted in order to allow inter-language dispatching
+run-time library can be adapted in order to allow inter-language dispatching
with a new C++ compiler.
@menu
* Interfacing to C++::
* Linking a Mixed C++ & Ada Program::
* A Simple Example::
-* Adapting the Run Time to a New C++ Compiler::
+* Interfacing with C++ at the Class Level::
@end menu
@node Interfacing to C++
@subsection Interfacing to C++
@noindent
-GNAT supports interfacing with C++ compilers generating code that is
-compatible with the standard Application Binary Interface of the given
-platform.
+GNAT supports interfacing with the G++ compiler (or any C++ compiler
+generating code that is compatible with the G++ Application Binary
+Interface ---see http://www.codesourcery.com/archives/cxx-abi).
@noindent
Interfacing can be done at 3 levels: simple data, subprograms, and
-classes. In the first two cases, GNAT offers a specific @var{Convention
-CPP} that behaves exactly like @var{Convention C}. Usually, C++ mangles
-the names of subprograms, and currently, GNAT does not provide any help
-to solve the demangling problem. This problem can be addressed in two
-ways:
+classes. In the first two cases, GNAT offers a specific @code{Convention
+C_Plus_Plus} (or @code{CPP}) that behaves exactly like @code{Convention C}.
+Usually, C++ mangles the names of subprograms, and currently, GNAT does
+not provide any help to solve the demangling problem. This problem can be
+addressed in two ways:
@itemize @bullet
@item
by modifying the C++ code in order to force a C convention using
@noindent
Interfacing at the class level can be achieved by using the GNAT specific
-pragmas such as @code{CPP_Class} and @code{CPP_Virtual}. See the GNAT
-Reference Manual for additional information.
+pragmas such as @code{CPP_Constructor}. @xref{Interfacing to C++,,,
+gnat_rm, GNAT Reference Manual}, for additional information.
@node Linking a Mixed C++ & Ada Program
@subsection Linking a Mixed C++ & Ada Program
@item
Using GNAT and G++ from two different GCC installations: If both
-compilers are on the PATH, the previous method may be used. It is
-important to note that environment variables such as C_INCLUDE_PATH,
-GCC_EXEC_PREFIX, BINUTILS_ROOT, and GCC_ROOT will affect both compilers
+compilers are on the @env{PATH}, the previous method may be used. It is
+important to note that environment variables such as
+@env{C_INCLUDE_PATH}, @env{GCC_EXEC_PREFIX}, @env{BINUTILS_ROOT}, and
+@env{GCC_ROOT} will affect both compilers
at the same time and may make one of the two compilers operate
improperly if set during invocation of the wrong compiler. It is also
very important that the linker uses the proper @file{libgcc.a} GCC
library -- that is, the one from the C++ compiler installation. The
-implicit link command as suggested in the gnatmake command from the
-former example can be replaced by an explicit link command with the
-full-verbosity option in order to verify which library is used:
+implicit link command as suggested in the @command{gnatmake} command
+from the former example can be replaced by an explicit link command with
+the full-verbosity option in order to verify which library is used:
@smallexample
$ gnatbind ada_unit
$ gnatlink -v -v ada_unit file1.o file2.o --LINK=c++
@item
Using a non-GNU C++ compiler: The commands previously described can be
used to insure that the C++ linker is used. Nonetheless, you need to add
-the path to libgcc explicitly, since some libraries needed by GNAT are
-located in this directory:
+a few more parameters to the link command line, depending on the exception
+mechanism used.
+
+If the @code{setjmp/longjmp} exception mechanism is used, only the paths
+to the libgcc libraries are required:
@smallexample
$ cat ./my_script
#!/bin/sh
-CC $* `gcc -print-libgcc-file-name`
+CC $* `gcc -print-file-name=libgcc.a` `gcc -print-file-name=libgcc_eh.a`
$ gnatlink ada_unit file1.o file2.o --LINK=./my_script
@end smallexample
Where CC is the name of the non-GNU C++ compiler.
+If the @code{zero cost} exception mechanism is used, and the platform
+supports automatic registration of exception tables (e.g.@: Solaris or IRIX),
+paths to more objects are required:
+
+@smallexample
+$ cat ./my_script
+#!/bin/sh
+CC `gcc -print-file-name=crtbegin.o` $* \
+`gcc -print-file-name=libgcc.a` `gcc -print-file-name=libgcc_eh.a` \
+`gcc -print-file-name=crtend.o`
+$ gnatlink ada_unit file1.o file2.o --LINK=./my_script
+@end smallexample
+
+If the @code{zero cost} exception mechanism is used, and the platform
+doesn't support automatic registration of exception tables (e.g.@: HP-UX,
+Tru64 or AIX), the simple approach described above will not work and
+a pre-linking phase using GNAT will be necessary.
+
@end enumerate
@node A Simple Example
class A : public Origin @{
public:
void method1 (void);
- virtual void method2 (int v);
+ void method2 (int v);
A();
int a_value;
@};
a_value = 1010;
printf ("in A::A, a_value = %d \n",a_value);
@}
+@end smallexample
+@smallexample @c ada
-- Ada sources
-@b{package} @b{body} Simple_Cpp_Interface @b{is}
+package body Simple_Cpp_Interface is
- @b{procedure} Ada_Method2 (This : @b{in} @b{out} A; V : Integer) @b{is}
- @b{begin}
+ procedure Ada_Method2 (This : in out A; V : Integer) is
+ begin
Method1 (This);
This.A_Value := V;
- @b{end} Ada_Method2;
+ end Ada_Method2;
-@b{end} Simple_Cpp_Interface;
+end Simple_Cpp_Interface;
-@b{package} Simple_Cpp_Interface @b{is}
- @b{type} A @b{is} @b{limited}
- @b{record}
+with System;
+package Simple_Cpp_Interface is
+ type A is limited
+ record
+ Vptr : System.Address;
O_Value : Integer;
A_Value : Integer;
- @b{end} @b{record};
- @b{pragma} Convention (C, A);
+ end record;
+ pragma Convention (C, A);
- @b{procedure} Method1 (This : @b{in} @b{out} A);
- @b{pragma} Import (C, Method1);
+ procedure Method1 (This : in out A);
+ pragma Import (C, Method1);
- @b{procedure} Ada_Method2 (This : @b{in} @b{out} A; V : Integer);
- @b{pragma} Export (C, Ada_Method2);
+ procedure Ada_Method2 (This : in out A; V : Integer);
+ pragma Export (C, Ada_Method2);
-@b{end} Simple_Cpp_Interface;
+end Simple_Cpp_Interface;
@end smallexample
-@node Adapting the Run Time to a New C++ Compiler
-@subsection Adapting the Run Time to a New C++ Compiler
+@node Interfacing with C++ at the Class Level
+@subsection Interfacing with C++ at the Class Level
@noindent
-GNAT offers the capability to derive Ada 95 tagged types directly from
-preexisting C++ classes and . See ``Interfacing with C++'' in the
-@cite{GNAT Reference Manual}. The mechanism used by GNAT for achieving
-such a goal
-has been made user configurable through a GNAT library unit
-@code{Interfaces.CPP}. The default version of this file is adapted to
-the GNU C++ compiler. Internal knowledge of the virtual
-table layout used by the new C++ compiler is needed to configure
-properly this unit. The Interface of this unit is known by the compiler
-and cannot be changed except for the value of the constants defining the
-characteristics of the virtual table: CPP_DT_Prologue_Size, CPP_DT_Entry_Size,
-CPP_TSD_Prologue_Size, CPP_TSD_Entry_Size. Read comments in the source
-of this unit for more details.
+In this section we demonstrate the GNAT features for interfacing with
+C++ by means of an example making use of Ada 2005 abstract interface
+types. This example consists of a classification of animals; classes
+have been used to model our main classification of animals, and
+interfaces provide support for the management of secondary
+classifications. We first demonstrate a case in which the types and
+constructors are defined on the C++ side and imported from the Ada
+side, and latter the reverse case.
+
+The root of our derivation will be the @code{Animal} class, with a
+single private attribute (the @code{Age} of the animal) and two public
+primitives to set and get the value of this attribute.
+
+@smallexample
+@b{class} Animal @{
+ @b{public}:
+ @b{virtual} void Set_Age (int New_Age);
+ @b{virtual} int Age ();
+ @b{private}:
+ int Age_Count;
+@};
+@end smallexample
+
+Abstract interface types are defined in C++ by means of classes with pure
+virtual functions and no data members. In our example we will use two
+interfaces that provide support for the common management of @code{Carnivore}
+and @code{Domestic} animals:
+
+@smallexample
+@b{class} Carnivore @{
+@b{public}:
+ @b{virtual} int Number_Of_Teeth () = 0;
+@};
+
+@b{class} Domestic @{
+@b{public}:
+ @b{virtual void} Set_Owner (char* Name) = 0;
+@};
+@end smallexample
+
+Using these declarations, we can now say that a @code{Dog} is an animal that is
+both Carnivore and Domestic, that is:
+
+@smallexample
+@b{class} Dog : Animal, Carnivore, Domestic @{
+ @b{public}:
+ @b{virtual} int Number_Of_Teeth ();
+ @b{virtual} void Set_Owner (char* Name);
+
+ Dog(); // Constructor
+ @b{private}:
+ int Tooth_Count;
+ char *Owner;
+@};
+@end smallexample
+
+In the following examples we will assume that the previous declarations are
+located in a file named @code{animals.h}. The following package demonstrates
+how to import these C++ declarations from the Ada side:
+
+@smallexample @c ada
+with Interfaces.C.Strings; use Interfaces.C.Strings;
+package Animals is
+ type Carnivore is interface;
+ pragma Convention (C_Plus_Plus, Carnivore);
+ function Number_Of_Teeth (X : Carnivore)
+ return Natural is abstract;
+
+ type Domestic is interface;
+ pragma Convention (C_Plus_Plus, Set_Owner);
+ procedure Set_Owner
+ (X : in out Domestic;
+ Name : Chars_Ptr) is abstract;
+
+ type Animal is tagged record
+ Age : Natural := 0;
+ end record;
+ pragma Import (C_Plus_Plus, Animal);
+
+ procedure Set_Age (X : in out Animal; Age : Integer);
+ pragma Import (C_Plus_Plus, Set_Age);
+
+ function Age (X : Animal) return Integer;
+ pragma Import (C_Plus_Plus, Age);
+
+ type Dog is new Animal and Carnivore and Domestic with record
+ Tooth_Count : Natural;
+ Owner : String (1 .. 30);
+ end record;
+ pragma Import (C_Plus_Plus, Dog);
+
+ function Number_Of_Teeth (A : Dog) return Integer;
+ pragma Import (C_Plus_Plus, Number_Of_Teeth);
+
+ procedure Set_Owner (A : in out Dog; Name : Chars_Ptr);
+ pragma Import (C_Plus_Plus, Set_Owner);
+
+ function New_Dog return Dog'Class;
+ pragma CPP_Constructor (New_Dog);
+ pragma Import (CPP, New_Dog, "_ZN3DogC2Ev");
+end Animals;
+@end smallexample
+
+Thanks to the compatibility between GNAT run-time structures and the C++ ABI,
+interfacing with these C++ classes is easy. The only requirement is that all
+the primitives and components must be declared exactly in the same order in
+the two languages.
+
+Regarding the abstract interfaces, we must indicate to the GNAT compiler by
+means of a @code{pragma Convention (C_Plus_Plus)}, the convention used to pass
+the arguments to the called primitives will be the same as for C++. For the
+imported classes we use @code{pragma Import} with convention @code{C_Plus_Plus}
+to indicate that they have been defined on the C++ side; this is required
+because the dispatch table associated with these tagged types will be built
+in the C++ side and therefore will not contain the predefined Ada primitives
+which Ada would otherwise expect.
+
+As the reader can see there is no need to indicate the C++ mangled names
+associated with each subprogram because it is assumed that all the calls to
+these primitives will be dispatching calls. The only exception is the
+constructor, which must be registered with the compiler by means of
+@code{pragma CPP_Constructor} and needs to provide its associated C++
+mangled name because the Ada compiler generates direct calls to it.
+
+With the above packages we can now declare objects of type Dog on the Ada side
+and dispatch calls to the corresponding subprograms on the C++ side. We can
+also extend the tagged type Dog with further fields and primitives, and
+override some of its C++ primitives on the Ada side. For example, here we have
+a type derivation defined on the Ada side that inherits all the dispatching
+primitives of the ancestor from the C++ side.
+
+@smallexample
+@b{with} Animals; @b{use} Animals;
+@b{package} Vaccinated_Animals @b{is}
+ @b{type} Vaccinated_Dog @b{is new} Dog @b{with null record};
+ @b{function} Vaccination_Expired (A : Vaccinated_Dog) @b{return} Boolean;
+@b{end} Vaccinated_Animals;
+@end smallexample
+
+It is important to note that, because of the ABI compatibility, the programmer
+does not need to add any further information to indicate either the object
+layout or the dispatch table entry associated with each dispatching operation.
+
+Now let us define all the types and constructors on the Ada side and export
+them to C++, using the same hierarchy of our previous example:
+
+@smallexample @c ada
+with Interfaces.C.Strings;
+use Interfaces.C.Strings;
+package Animals is
+ type Carnivore is interface;
+ pragma Convention (C_Plus_Plus, Carnivore);
+ function Number_Of_Teeth (X : Carnivore)
+ return Natural is abstract;
+
+ type Domestic is interface;
+ pragma Convention (C_Plus_Plus, Set_Owner);
+ procedure Set_Owner
+ (X : in out Domestic;
+ Name : Chars_Ptr) is abstract;
+
+ type Animal is tagged record
+ Age : Natural := 0;
+ end record;
+ pragma Convention (C_Plus_Plus, Animal);
+
+ procedure Set_Age (X : in out Animal; Age : Integer);
+ pragma Export (C_Plus_Plus, Set_Age);
+
+ function Age (X : Animal) return Integer;
+ pragma Export (C_Plus_Plus, Age);
+
+ type Dog is new Animal and Carnivore and Domestic with record
+ Tooth_Count : Natural;
+ Owner : String (1 .. 30);
+ end record;
+ pragma Convention (C_Plus_Plus, Dog);
+
+ function Number_Of_Teeth (A : Dog) return Integer;
+ pragma Export (C_Plus_Plus, Number_Of_Teeth);
+
+ procedure Set_Owner (A : in out Dog; Name : Chars_Ptr);
+ pragma Export (C_Plus_Plus, Set_Owner);
+
+ function New_Dog return Dog'Class;
+ pragma Export (C_Plus_Plus, New_Dog);
+end Animals;
+@end smallexample
+
+Compared with our previous example the only difference is the use of
+@code{pragma Export} to indicate to the GNAT compiler that the primitives will
+be available to C++. Thanks to the ABI compatibility, on the C++ side there is
+nothing else to be done; as explained above, the only requirement is that all
+the primitives and components are declared in exactly the same order.
+
+For completeness, let us see a brief C++ main program that uses the
+declarations available in @code{animals.h} (presented in our first example) to
+import and use the declarations from the Ada side, properly initializing and
+finalizing the Ada run-time system along the way:
+
+@smallexample
+@b{#include} "animals.h"
+@b{#include} <iostream>
+@b{using namespace} std;
+
+void Check_Carnivore (Carnivore *obj) @{@dots{}@}
+void Check_Domestic (Domestic *obj) @{@dots{}@}
+void Check_Animal (Animal *obj) @{@dots{}@}
+void Check_Dog (Dog *obj) @{@dots{}@}
+
+@b{extern} "C" @{
+ void adainit (void);
+ void adafinal (void);
+ Dog* new_dog ();
+@}
+
+void test ()
+@{
+ Dog *obj = new_dog(); // Ada constructor
+ Check_Carnivore (obj); // Check secondary DT
+ Check_Domestic (obj); // Check secondary DT
+ Check_Animal (obj); // Check primary DT
+ Check_Dog (obj); // Check primary DT
+@}
+
+int main ()
+@{
+ adainit (); test(); adafinal ();
+ return 0;
+@}
+@end smallexample
@node Comparison between GNAT and C/C++ Compilation Models
@section Comparison between GNAT and C/C++ Compilation Models
Where @code{gnatbind} might complain there was no valid order of
elaboration, a C++ compiler would simply construct a program that
malfunctioned at run time.
+@end ifclear
@node Comparison between GNAT and Conventional Ada Library Models
@section Comparison between GNAT and Conventional Ada Library Models
@noindent
-This section is intended to be useful to Ada programmers who have
-previously used an Ada compiler implementing the traditional Ada library
-model, as described in the Ada 95 Language Reference Manual. If you
-have not used such a system, please go on to the next section.
+This section is intended for Ada programmers who have
+used an Ada compiler implementing the traditional Ada library
+model, as described in the Ada Reference Manual.
@cindex GNAT library
-In GNAT, there is no @dfn{library} in the normal sense. Instead, the set of
+In GNAT, there is no ``library'' in the normal sense. Instead, the set of
source files themselves acts as the library. Compiling Ada programs does
not generate any centralized information, but rather an object file and
a ALI file, which are of interest only to the binder and linker.
GNAT uses the current directory for temporary files.
@end ifset
-
@c *************************
@node Compiling Using gcc
-@chapter Compiling Using @code{gcc}
+@chapter Compiling Using @command{gcc}
@noindent
-This chapter discusses how to compile Ada programs using the @code{gcc}
+This chapter discusses how to compile Ada programs using the @command{gcc}
command. It also describes the set of switches
that can be used to control the behavior of the compiler.
@menu
@noindent
The first step in creating an executable program is to compile the units
-of the program using the @code{gcc} command. You must compile the
+of the program using the @command{gcc} command. You must compile the
following files:
@itemize @bullet
@cindex cannot generate code
If you attempt to compile any of these files, you will get one of the
-following error messages (where fff is the name of the file you compiled):
+following error messages (where @var{fff} is the name of the file you compiled):
@smallexample
cannot generate code for file @var{fff} (package spec)
The basic command for compiling a file containing an Ada unit is
@smallexample
-$ gcc -c [@var{switches}] @file{file name}
+$ gcc -c @ovar{switches} @file{file name}
@end smallexample
@noindent
@file{.ads} for a spec or @file{.adb} for a body).
@ifclear vms
You specify the
-@option{-c} switch to tell @code{gcc} to compile, but not link, the file.
+@option{-c} switch to tell @command{gcc} to compile, but not link, the file.
@end ifclear
The result of a successful compilation is an object file, which has the
same name as the source file but an extension of @file{.o} and an Ada
containing the directory information.
@findex gnat1
-@code{gcc} is actually a driver program that looks at the extensions of
+@command{gcc} is actually a driver program that looks at the extensions of
the file arguments and loads the appropriate compiler. For example, the
GNU C compiler is @file{cc1}, and the Ada compiler is @file{gnat1}.
These programs are in directories known to the driver program (in some
configurations via environment variables you set), but need not be in
-your path. The @code{gcc} driver also calls the assembler and any other
+your path. The @command{gcc} driver also calls the assembler and any other
utilities needed to complete the generation of the required object
files.
-It is possible to supply several file names on the same @code{gcc}
-command. This causes @code{gcc} to call the appropriate compiler for
+It is possible to supply several file names on the same @command{gcc}
+command. This causes @command{gcc} to call the appropriate compiler for
each file. For example, the following command lists three separate
files to be compiled:
@end ifclear
@node Switches for gcc
-@section Switches for @code{gcc}
+@section Switches for @command{gcc}
@noindent
-The @code{gcc} command accepts switches that control the
+The @command{gcc} command accepts switches that control the
compilation process. These switches are fully described in this section.
First we briefly list all the switches, in alphabetical order, then we
describe the switches in more detail in functionally grouped sections.
+More switches exist for GCC than those documented here, especially
+for specific targets. However, their use is not recommended as
+they may change code generation in ways that are incompatible with
+the Ada run-time library, or can cause inconsistencies between
+compilation units.
+
@menu
* Output and Error Message Control::
* Warning Message Control::
* Validity Checking::
* Style Checking::
* Run-Time Checks::
-* Stack Overflow Checking::
* Using gcc for Syntax Checking::
* Using gcc for Semantic Checking::
-* Compiling Ada 83 Programs::
+* Compiling Different Versions of Ada::
* Character Set Control::
* File Naming Control::
* Subprogram Inlining Control::
@table @option
@c !sort!
@ifclear vms
-@cindex @option{-b} (@code{gcc})
+@cindex @option{-b} (@command{gcc})
@item -b @var{target}
Compile your program to run on @var{target}, which is the name of a
system configuration. You must have a GNAT cross-compiler built if
@var{target} is not the same as your host system.
@item -B@var{dir}
-@cindex @option{-B} (@code{gcc})
+@cindex @option{-B} (@command{gcc})
Load compiler executables (for example, @code{gnat1}, the Ada compiler)
from @var{dir} instead of the default location. Only use this switch
-when multiple versions of the GNAT compiler are available. See the
-@code{gcc} manual page for further details. You would normally use the
-@option{-b} or @option{-V} switch instead.
+when multiple versions of the GNAT compiler are available.
+@xref{Directory Options,, Options for Directory Search, gcc, Using the
+GNU Compiler Collection (GCC)}, for further details. You would normally
+use the @option{-b} or @option{-V} switch instead.
@item -c
-@cindex @option{-c} (@code{gcc})
+@cindex @option{-c} (@command{gcc})
Compile. Always use this switch when compiling Ada programs.
-Note: for some other languages when using @code{gcc}, notably in
+Note: for some other languages when using @command{gcc}, notably in
the case of C and C++, it is possible to use
-use @code{gcc} without a @option{-c} switch to
+use @command{gcc} without a @option{-c} switch to
compile and link in one step. In the case of GNAT, you
cannot use this approach, because the binder must be run
-and @code{gcc} cannot be used to run the GNAT binder.
+and @command{gcc} cannot be used to run the GNAT binder.
@end ifclear
@item -fno-inline
-@cindex @option{-fno-inline} (@code{gcc})
+@cindex @option{-fno-inline} (@command{gcc})
Suppresses all back-end inlining, even if other optimization or inlining
switches are set.
This includes suppression of inlining that results
from the use of the pragma @code{Inline_Always}.
-See also @option{-gnatn} and @option{-gnatN}.
+Any occurrences of pragma @code{Inline} or @code{Inline_Always}
+are ignored, and @option{-gnatn} and @option{-gnatN} have no
+effect if this switch is present.
-@item -fno-strict-aliasing
-@cindex @option{-fno-strict-aliasing} (@code{gcc})
+@item -fno-inline-functions
+@cindex @option{-fno-inline-functions} (@command{gcc})
+Suppresses automatic inlining of simple subprograms, which is enabled
+if @option{-O3} is used.
+
+@item -fno-inline-small-functions
+@cindex @option{-fno-inline-small-functions} (@command{gcc})
+Suppresses automatic inlining of small subprograms, which is enabled
+if @option{-O2} is used.
+
+@item -fno-inline-functions-called-once
+@cindex @option{-fno-inline-functions-called-once} (@command{gcc})
+Suppresses inlining of subprograms local to the unit and called once
+from within it, which is enabled if @option{-O1} is used.
+
+@item -fno-strict-aliasing
+@cindex @option{-fno-strict-aliasing} (@command{gcc})
Causes the compiler to avoid assumptions regarding non-aliasing
-of objects of different types. See section
-@pxref{Optimization and Strict Aliasing} for details.
+of objects of different types. See
+@ref{Optimization and Strict Aliasing} for details.
@item -fstack-check
-@cindex @option{-fstack-check} (@code{gcc})
+@cindex @option{-fstack-check} (@command{gcc})
Activates stack checking.
-See @ref{Stack Overflow Checking} for details of the use of this option.
+See @ref{Stack Overflow Checking} for details.
+
+@item -fstack-usage
+@cindex @option{-fstack-usage} (@command{gcc})
+Makes the compiler output stack usage information for the program, on a
+per-function basis. See @ref{Static Stack Usage Analysis} for details.
+
+@item -fcallgraph-info@r{[}=su@r{]}
+@cindex @option{-fcallgraph-info} (@command{gcc})
+Makes the compiler output callgraph information for the program, on a
+per-file basis. The information is generated in the VCG format. It can
+be decorated with stack-usage per-node information.
@item ^-g^/DEBUG^
-@cindex @option{^-g^/DEBUG^} (@code{gcc})
+@cindex @option{^-g^/DEBUG^} (@command{gcc})
Generate debugging information. This information is stored in the object
file and copied from there to the final executable file by the linker,
where it can be read by the debugger. You must use the
@option{^-g^/DEBUG^} switch if you plan on using the debugger.
@item -gnat83
-@cindex @option{-gnat83} (@code{gcc})
+@cindex @option{-gnat83} (@command{gcc})
Enforce Ada 83 restrictions.
+@item -gnat95
+@cindex @option{-gnat95} (@command{gcc})
+Enforce Ada 95 restrictions.
+
+@item -gnat05
+@cindex @option{-gnat05} (@command{gcc})
+Allow full Ada 2005 features.
+
@item -gnata
-@cindex @option{-gnata} (@code{gcc})
+@cindex @option{-gnata} (@command{gcc})
Assertions enabled. @code{Pragma Assert} and @code{pragma Debug} to be
-activated.
+activated. Note that these pragmas can also be controlled using the
+configuration pragmas @code{Assertion_Policy} and @code{Debug_Policy}.
+It also activates pragmas @code{Check}, @code{Precondition}, and
+@code{Postcondition}. Note that these pragmas can also be controlled
+using the configuration pragma @code{Check_Policy}.
@item -gnatA
-@cindex @option{-gnatA} (@code{gcc})
-Avoid processing @file{gnat.adc}. If a gnat.adc file is present,
+@cindex @option{-gnatA} (@command{gcc})
+Avoid processing @file{gnat.adc}. If a @file{gnat.adc} file is present,
it will be ignored.
@item -gnatb
-@cindex @option{-gnatb} (@code{gcc})
+@cindex @option{-gnatb} (@command{gcc})
Generate brief messages to @file{stderr} even if verbose mode set.
+@item -gnatB
+@cindex @option{-gnatB} (@command{gcc})
+Assume no invalid (bad) values except for 'Valid attribute use.
+
@item -gnatc
-@cindex @option{-gnatc} (@code{gcc})
+@cindex @option{-gnatc} (@command{gcc})
Check syntax and semantics only (no code generation attempted).
@item -gnatd
-@cindex @option{-gnatd} (@code{gcc})
+@cindex @option{-gnatd} (@command{gcc})
Specify debug options for the compiler. The string of characters after
the @option{-gnatd} specify the specific debug options. The possible
characters are 0-9, a-z, A-Z, optionally preceded by a dot. See
programmers, and these are documented at appropriate points in this
users guide.
+@ifclear vms
@item -gnatD
-@cindex @option{-gnatD} (@code{gcc})
+@cindex @option{-gnatD[nn]} (@command{gcc})
+@end ifclear
+@ifset vms
+@item /XDEBUG /LXDEBUG=nnn
+@end ifset
Create expanded source files for source level debugging. This switch
also suppress generation of cross-reference information
(see @option{-gnatx}).
@item -gnatec=@var{path}
-@cindex @option{-gnatec} (@code{gcc})
+@cindex @option{-gnatec} (@command{gcc})
Specify a configuration pragma file
@ifclear vms
(the equal sign is optional)
@end ifclear
-(see @ref{The Configuration Pragmas Files}).
+(@pxref{The Configuration Pragmas Files}).
-@item ^-gnateD^/DATA_PREPROCESSING=^symbol[=value]
-@cindex @option{-gnateD} (@code{gcc})
-Defines a symbol, associated with value, for preprocessing.
-(see @ref{Integrated Preprocessing})
+@item ^-gnateD^/DATA_PREPROCESSING=^symbol@r{[}=@var{value}@r{]}
+@cindex @option{-gnateD} (@command{gcc})
+Defines a symbol, associated with @var{value}, for preprocessing.
+(@pxref{Integrated Preprocessing}).
@item -gnatef
-@cindex @option{-gnatef} (@code{gcc})
+@cindex @option{-gnatef} (@command{gcc})
Display full source path name in brief error messages.
+@item -gnateG
+@cindex @option{-gnateG} (@command{gcc})
+Save result of preprocessing in a text file.
+
@item -gnatem=@var{path}
-@cindex @option{-gnatem} (@code{gcc})
+@cindex @option{-gnatem} (@command{gcc})
Specify a mapping file
@ifclear vms
(the equal sign is optional)
@end ifclear
-(see @ref{Units to Sources Mapping Files}).
+(@pxref{Units to Sources Mapping Files}).
@item -gnatep=@var{file}
-@cindex @option{-gnatep} (@code{gcc})
+@cindex @option{-gnatep} (@command{gcc})
Specify a preprocessing data file
@ifclear vms
(the equal sign is optional)
@end ifclear
-(see @ref{Integrated Preprocessing}).
+(@pxref{Integrated Preprocessing}).
@item -gnatE
-@cindex @option{-gnatE} (@code{gcc})
+@cindex @option{-gnatE} (@command{gcc})
Full dynamic elaboration checks.
@item -gnatf
-@cindex @option{-gnatf} (@code{gcc})
+@cindex @option{-gnatf} (@command{gcc})
Full errors. Multiple errors per line, all undefined references, do not
attempt to suppress cascaded errors.
@item -gnatF
-@cindex @option{-gnatF} (@code{gcc})
+@cindex @option{-gnatF} (@command{gcc})
Externals names are folded to all uppercase.
-@item -gnatg
-@cindex @option{-gnatg} (@code{gcc})
+@item ^-gnatg^/GNAT_INTERNAL^
+@cindex @option{^-gnatg^/GNAT_INTERNAL^} (@command{gcc})
Internal GNAT implementation mode. This should not be used for
applications programs, it is intended only for use by the compiler
and its run-time library. For documentation, see the GNAT sources.
-Note that @option{-gnatg} implies @option{-gnatwu} so that warnings
-are generated on unreferenced entities, and all warnings are treated
-as errors.
+Note that @option{^-gnatg^/GNAT_INTERNAL^} implies
+@option{^-gnatwae^/WARNINGS=ALL,ERRORS^} and
+@option{^-gnatyg^/STYLE_CHECKS=GNAT^}
+so that all standard warnings and all standard style options are turned on.
+All warnings and style error messages are treated as errors.
-@item -gnatG
-@cindex @option{-gnatG} (@code{gcc})
+@ifclear vms
+@item -gnatG=nn
+@cindex @option{-gnatG[nn]} (@command{gcc})
+@end ifclear
+@ifset vms
+@item /EXPAND_SOURCE, /LEXPAND_SOURCE=nnn
+@end ifset
List generated expanded code in source form.
@item ^-gnath^/HELP^
-@cindex @option{^-gnath^/HELP^} (@code{gcc})
+@cindex @option{^-gnath^/HELP^} (@command{gcc})
Output usage information. The output is written to @file{stdout}.
@item ^-gnati^/IDENTIFIER_CHARACTER_SET=^@var{c}
-@cindex @option{^-gnati^/IDENTIFIER_CHARACTER_SET^} (@code{gcc})
+@cindex @option{^-gnati^/IDENTIFIER_CHARACTER_SET^} (@command{gcc})
Identifier character set
@ifclear vms
(@var{c}=1/2/3/4/8/9/p/f/n/w).
@end ifclear
-@ifset vms
For details of the possible selections for @var{c},
-see @xref{Character Set Control}.
-@end ifset
+see @ref{Character Set Control}.
+
+@item ^-gnatI^/IGNORE_REP_CLAUSES^
+@cindex @option{^-gnatI^IGNORE_REP_CLAUSES^} (@command{gcc})
+Ignore representation clauses. When this switch is used, all
+representation clauses are treated as comments. This is useful
+when initially porting code where you want to ignore rep clause
+problems, and also for compiling foreign code (particularly
+for use with ASIS).
+
+@item -gnatjnn
+@cindex @option{-gnatjnn} (@command{gcc})
+Reformat error messages to fit on nn character lines
@item -gnatk=@var{n}
-@cindex @option{-gnatk} (@code{gcc})
+@cindex @option{-gnatk} (@command{gcc})
Limit file names to @var{n} (1-999) characters ^(@code{k} = krunch)^^.
@item -gnatl
-@cindex @option{-gnatl} (@code{gcc})
+@cindex @option{-gnatl} (@command{gcc})
Output full source listing with embedded error messages.
@item -gnatL
-@cindex @option{-gnatL} (@code{gcc})
-Use the longjmp/setjmp method for exception handling
+@cindex @option{-gnatL} (@command{gcc})
+Used in conjunction with -gnatG or -gnatD to intersperse original
+source lines (as comment lines with line numbers) in the expanded
+source output.
@item -gnatm=@var{n}
-@cindex @option{-gnatm} (@code{gcc})
+@cindex @option{-gnatm} (@command{gcc})
Limit number of detected error or warning messages to @var{n}
-where @var{n} is in the range 1..999_999. The default setting if
-no switch is given is 9999. Compilation is terminated if this
-limit is exceeded.
+where @var{n} is in the range 1..999999. The default setting if
+no switch is given is 9999. If the number of warnings reaches this
+limit, then a message is output and further warnings are suppressed,
+but the compilation is continued. If the number of error messages
+reaches this limit, then a message is output and the compilation
+is abandoned. The equal sign here is optional. A value of zero
+means that no limit applies.
@item -gnatn
-@cindex @option{-gnatn} (@code{gcc})
+@cindex @option{-gnatn} (@command{gcc})
Activate inlining for subprograms for which
pragma @code{inline} is specified. This inlining is performed
by the GCC back-end.
@item -gnatN
-@cindex @option{-gnatN} (@code{gcc})
+@cindex @option{-gnatN} (@command{gcc})
Activate front end inlining for subprograms for which
pragma @code{Inline} is specified. This inlining is performed
by the front end and will be visible in the
@option{-gnatG} output.
-In some cases, this has proved more effective than the back end
-inlining resulting from the use of
-@option{-gnatn}.
-Note that
-@option{-gnatN} automatically implies
-@option{-gnatn} so it is not necessary
-to specify both options. There are a few cases that the back-end inlining
-catches that cannot be dealt with in the front-end.
+
+When using a gcc-based back end (in practice this means using any version
+of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of
+@option{-gnatN} is deprecated, and the use of @option{-gnatn} is preferred.
+Historically front end inlining was more extensive than the gcc back end
+inlining, but that is no longer the case.
@item -gnato
-@cindex @option{-gnato} (@code{gcc})
+@cindex @option{-gnato} (@command{gcc})
Enable numeric overflow checking (which is not normally enabled by
-default). Not that division by zero is a separate check that is not
+default). Note that division by zero is a separate check that is not
controlled by this switch (division by zero checking is on by default).
@item -gnatp
-@cindex @option{-gnatp} (@code{gcc})
-Suppress all checks.
+@cindex @option{-gnatp} (@command{gcc})
+Suppress all checks. See @ref{Run-Time Checks} for details.
@item -gnatP
-@cindex @option{-gnatP} (@code{gcc})
+@cindex @option{-gnatP} (@command{gcc})
Enable polling. This is required on some systems (notably Windows NT) to
obtain asynchronous abort and asynchronous transfer of control capability.
-See the description of pragma Polling in the GNAT Reference Manual for
-full details.
+@xref{Pragma Polling,,, gnat_rm, GNAT Reference Manual}, for full
+details.
@item -gnatq
-@cindex @option{-gnatq} (@code{gcc})
-Don't quit; try semantics, even if parse errors.
+@cindex @option{-gnatq} (@command{gcc})
+Don't quit. Try semantics, even if parse errors.
@item -gnatQ
-@cindex @option{-gnatQ} (@code{gcc})
-Don't quit; generate @file{ALI} and tree files even if illegalities.
+@cindex @option{-gnatQ} (@command{gcc})
+Don't quit. Generate @file{ALI} and tree files even if illegalities.
+
+@item -gnatr
+@cindex @option{-gnatr} (@command{gcc})
+Treat pragma Restrictions as Restriction_Warnings.
-@item ^-gnatR[0/1/2/3[s]]^/REPRESENTATION_INFO^
-@cindex @option{-gnatR} (@code{gcc})
+@item ^-gnatR@r{[}0@r{/}1@r{/}2@r{/}3@r{[}s@r{]]}^/REPRESENTATION_INFO^
+@cindex @option{-gnatR} (@command{gcc})
Output representation information for declared types and objects.
@item -gnats
-@cindex @option{-gnats} (@code{gcc})
+@cindex @option{-gnats} (@command{gcc})
Syntax check only.
@item -gnatS
-@cindex @option{-gnatS} (@code{gcc})
+@cindex @option{-gnatS} (@command{gcc})
Print package Standard.
@item -gnatt
-@cindex @option{-gnatt} (@code{gcc})
+@cindex @option{-gnatt} (@command{gcc})
Generate tree output file.
@item ^-gnatT^/TABLE_MULTIPLIER=^@var{nnn}
-@cindex @option{^-gnatT^/TABLE_MULTIPLIER^} (@code{gcc})
+@cindex @option{^-gnatT^/TABLE_MULTIPLIER^} (@command{gcc})
All compiler tables start at @var{nnn} times usual starting size.
@item -gnatu
-@cindex @option{-gnatu} (@code{gcc})
+@cindex @option{-gnatu} (@command{gcc})
List units for this compilation.
@item -gnatU
-@cindex @option{-gnatU} (@code{gcc})
+@cindex @option{-gnatU} (@command{gcc})
Tag all error messages with the unique string ``error:''
@item -gnatv
-@cindex @option{-gnatv} (@code{gcc})
+@cindex @option{-gnatv} (@command{gcc})
Verbose mode. Full error output with source lines to @file{stdout}.
@item -gnatV
-@cindex @option{-gnatV} (@code{gcc})
+@cindex @option{-gnatV} (@command{gcc})
Control level of validity checking. See separate section describing
this feature.
-@item ^-gnatw@var{xxx}^/WARNINGS=(@var{option}[,...])^
-@cindex @option{^-gnatw^/WARNINGS^} (@code{gcc})
+@item ^-gnatw@var{xxx}^/WARNINGS=(@var{option}@r{[},@dots{}@r{]})^
+@cindex @option{^-gnatw^/WARNINGS^} (@command{gcc})
Warning mode where
^@var{xxx} is a string of option letters that^the list of options^ denotes
the exact warnings that
-are enabled or disabled. (see @ref{Warning Message Control})
+are enabled or disabled (@pxref{Warning Message Control}).
@item ^-gnatW^/WIDE_CHARACTER_ENCODING=^@var{e}
-@cindex @option{^-gnatW^/WIDE_CHARACTER_ENCODING^} (@code{gcc})
+@cindex @option{^-gnatW^/WIDE_CHARACTER_ENCODING^} (@command{gcc})
Wide character encoding method
@ifclear vms
(@var{e}=n/h/u/s/e/8).
@end ifset
@item -gnatx
-@cindex @option{-gnatx} (@code{gcc})
+@cindex @option{-gnatx} (@command{gcc})
Suppress generation of cross-reference information.
-@item ^-gnaty^/STYLE_CHECKS=(option,option..)^
-@cindex @option{^-gnaty^/STYLE_CHECKS^} (@code{gcc})
-Enable built-in style checks. (see @ref{Style Checking})
+@item ^-gnaty^/STYLE_CHECKS=(option,option@dots{})^
+@cindex @option{^-gnaty^/STYLE_CHECKS^} (@command{gcc})
+Enable built-in style checks (@pxref{Style Checking}).
@item ^-gnatz^/DISTRIBUTION_STUBS=^@var{m}
-@cindex @option{^-gnatz^/DISTRIBUTION_STUBS^} (@code{gcc})
+@cindex @option{^-gnatz^/DISTRIBUTION_STUBS^} (@command{gcc})
Distribution stub generation and compilation
@ifclear vms
(@var{m}=r/c for receiver/caller stubs).
to be generated and compiled).
@end ifset
-@item -gnatZ
-Use the zero cost method for exception handling
-
@item ^-I^/SEARCH=^@var{dir}
-@cindex @option{^-I^/SEARCH^} (@code{gcc})
+@cindex @option{^-I^/SEARCH^} (@command{gcc})
@cindex RTL
Direct GNAT to search the @var{dir} directory for source files needed by
the current compilation
(@pxref{Search Paths and the Run-Time Library (RTL)}).
@item ^-I-^/NOCURRENT_DIRECTORY^
-@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@code{gcc})
+@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@command{gcc})
@cindex RTL
Except for the source file named in the command line, do not look for source
files in the directory containing the source file named in the command line
in order to compile large and/or nested @code{case} statements.
@item -o @var{file}
-@cindex @option{-o} (@code{gcc})
-This switch is used in @code{gcc} to redirect the generated object file
+@cindex @option{-o} (@command{gcc})
+This switch is used in @command{gcc} to redirect the generated object file
and its associated ALI file. Beware of this switch with GNAT, because it may
cause the object file and ALI file to have different names which in turn
may confuse the binder and the linker.
Library (RTL) ALI files.
@ifclear vms
-@item -O[@var{n}]
-@cindex @option{-O} (@code{gcc})
+@item -O@ovar{n}
+@cindex @option{-O} (@command{gcc})
@var{n} controls the optimization level.
@table @asis
@item n = 1
Normal optimization, the default if you specify @option{-O} without
-an operand.
+an operand. A good compromise between code quality and compilation
+time.
@item n = 2
-Extensive optimization
+Extensive optimization, may improve execution time, possibly at the cost of
+substantially increased compilation time.
@item n = 3
-Extensive optimization with automatic inlining of subprograms not
-specified by pragma @code{Inline}. This applies only to
-inlining within a unit. For details on control of inlining
-see @xref{Subprogram Inlining Control}.
+Same as @option{-O2}, and also includes inline expansion for small subprograms
+in the same unit.
+
+@item n = s
+Optimize space usage
@end table
+
+@noindent
+See also @ref{Optimization Levels}.
@end ifclear
@ifset vms
@item /NOOPTIMIZE
@cindex @option{/NOOPTIMIZE} (@code{GNAT COMPILE})
Equivalent to @option{/OPTIMIZE=NONE}.
-This is the default behavior in the absence of an @option{/OPTMIZE}
+This is the default behavior in the absence of an @option{/OPTIMIZE}
qualifier.
-@item /OPTIMIZE[=(keyword[,...])]
+@item /OPTIMIZE@r{[}=(keyword@r{[},@dots{}@r{]})@r{]}
@cindex @option{/OPTIMIZE} (@code{GNAT COMPILE})
Selects the level of optimization for your program. The supported
keywords are as follows:
@item ALL
Perform most optimizations, including those that
are expensive.
-This is the default if the @option{/OPTMIZE} qualifier is supplied
+This is the default if the @option{/OPTIMIZE} qualifier is supplied
without keyword options.
@item NONE
@item DEVELOPMENT
Same as @code{SOME}.
-@item INLINING
-Full optimization, and also attempt automatic inlining of small
-subprograms within a unit even when pragma @code{Inline}
-is not specified (@pxref{Inlining of Subprograms}).
+@item INLINING
+Full optimization as in @option{/OPTIMIZE=ALL}, and also attempts
+automatic inlining of small subprograms within a unit
@item UNROLL_LOOPS
Try to unroll loops. This keyword may be specified together with
any keyword above other than @code{NONE}. Loop unrolling
usually, but not always, improves the performance of programs.
+
+@item SPACE
+Optimize space usage
@end table
+
+@noindent
+See also @ref{Optimization Levels}.
@end ifset
@ifclear vms
@item -pass-exit-codes
-@cindex @option{-pass-exit-codes} (@code{gcc})
+@cindex @option{-pass-exit-codes} (@command{gcc})
Catch exit codes from the compiler and use the most meaningful as
exit status.
@end ifclear
@item --RTS=@var{rts-path}
-@cindex @option{--RTS} (@code{gcc})
+@cindex @option{--RTS} (@command{gcc})
Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (see @ref{Switches for gnatmake}).
+equivalent @command{gnatmake} flag (@pxref{Switches for gnatmake}).
@item ^-S^/ASM^
-@cindex @option{^-S^/ASM^} (@code{gcc})
+@cindex @option{^-S^/ASM^} (@command{gcc})
^Used in place of @option{-c} to^Used to^
cause the assembler source file to be
generated, using @file{^.s^.S^} as the extension,
instead of the object file.
This may be useful if you need to examine the generated assembly code.
+@item ^-fverbose-asm^/VERBOSE_ASM^
+@cindex @option{^-fverbose-asm^/VERBOSE_ASM^} (@command{gcc})
+^Used in conjunction with @option{-S}^Used in place of @option{/ASM}^
+to cause the generated assembly code file to be annotated with variable
+names, making it significantly easier to follow.
+
@item ^-v^/VERBOSE^
-@cindex @option{^-v^/VERBOSE^} (@code{gcc})
-Show commands generated by the @code{gcc} driver. Normally used only for
+@cindex @option{^-v^/VERBOSE^} (@command{gcc})
+Show commands generated by the @command{gcc} driver. Normally used only for
debugging purposes or if you need to be sure what version of the
compiler you are executing.
@ifclear vms
@item -V @var{ver}
-@cindex @option{-V} (@code{gcc})
-Execute @var{ver} version of the compiler. This is the @code{gcc}
+@cindex @option{-V} (@command{gcc})
+Execute @var{ver} version of the compiler. This is the @command{gcc}
version, not the GNAT version.
@end ifclear
+@item ^-w^/NO_BACK_END_WARNINGS^
+@cindex @option{-w} (@command{gcc})
+Turn off warnings generated by the back end of the compiler. Use of
+this switch also causes the default for front end warnings to be set
+to suppress (as though @option{-gnatws} had appeared at the start of
+the options).
+
@end table
@ifclear vms
+@c Combining qualifiers does not work on VMS
You may combine a sequence of GNAT switches into a single switch. For
example, the combined switch
@end smallexample
@end ifclear
-
-@c NEED TO CHECK THIS FOR VMS
-
@noindent
The following restrictions apply to the combination of switches
in this manner:
@end ifclear
@end itemize
-
@node Output and Error Message Control
@subsection Output and Error Message Control
@findex stderr
@noindent
The first integer after the file name is the line number in the file,
and the second integer is the column number within the line.
-@code{glide} can parse the error messages
+@ifclear vms
+@code{GPS} can parse the error messages
and point to the referenced character.
+@end ifclear
The following switches provide control over the error message
format:
@table @option
@c !sort!
@item -gnatv
-@cindex @option{-gnatv} (@code{gcc})
+@cindex @option{-gnatv} (@command{gcc})
@findex stdout
@ifclear vms
The v stands for verbose.
used the only source lines output are those with errors.
@item -gnatl
-@cindex @option{-gnatl} (@code{gcc})
+@cindex @option{-gnatl} (@command{gcc})
@ifclear vms
The @code{l} stands for list.
@end ifclear
This switch causes a full listing of
-the file to be generated. The output might look as follows:
+the file to be generated. In the case where a body is
+compiled, the corresponding spec is also listed, along
+with any subunits. Typical output from compiling a package
+body @file{p.adb} might look like:
-@smallexample
+@smallexample @c ada
@cartouche
- 1. procedure E is
- 2. V : Integer;
- 3. funcion X (Q : Integer)
- |
- >>> Incorrect spelling of keyword "function"
- 4. return Integer;
- |
- >>> ";" should be "is"
- 5. begin
- 6. return Q + Q;
- 7. end;
- 8. begin
- 9. V := X + X;
-10.end E;
+ Compiling: p.adb
+
+ 1. package body p is
+ 2. procedure a;
+ 3. procedure a is separate;
+ 4. begin
+ 5. null
+ |
+ >>> missing ";"
+
+ 6. end;
+
+Compiling: p.ads
+
+ 1. package p is
+ 2. pragma Elaborate_Body
+ |
+ >>> missing ";"
+
+ 3. end p;
+
+Compiling: p-a.adb
+
+ 1. separate p
+ |
+ >>> missing "("
+
+ 2. procedure a is
+ 3. begin
+ 4. null
+ |
+ >>> missing ";"
+
+ 5. end;
@end cartouche
@end smallexample
@file{stderr} (standard error) giving the number of error messages and
warning messages generated.
+@item -^gnatl^OUTPUT_FILE^=file
+@cindex @option{^-gnatl^OUTPUT_FILE^=fname} (@command{gcc})
+This has the same effect as @option{-gnatl} except that the output is
+written to a file instead of to standard output. If the given name
+@file{fname} does not start with a period, then it is the full name
+of the file to be written. If @file{fname} is an extension, it is
+appended to the name of the file being compiled. For example, if
+file @file{xyz.adb} is compiled with @option{^-gnatl^OUTPUT_FILE^=.lst},
+then the output is written to file ^xyz.adb.lst^xyz.adb_lst^.
+
@item -gnatU
-@cindex @option{-gnatU} (@code{gcc})
+@cindex @option{-gnatU} (@command{gcc})
This switch forces all error messages to be preceded by the unique
string ``error:''. This means that error messages take a few more
characters in space, but allows easy searching for and identification
of error messages.
@item -gnatb
-@cindex @option{-gnatb} (@code{gcc})
+@cindex @option{-gnatb} (@command{gcc})
@ifclear vms
The @code{b} stands for brief.
@end ifclear
format message or full listing (which as usual is written to
@file{stdout} (the standard output file).
-@item -gnatm^^=^@var{n}
-@cindex @option{-gnatm} (@code{gcc})
+@item -gnatm=@var{n}
+@cindex @option{-gnatm} (@command{gcc})
@ifclear vms
The @code{m} stands for maximum.
@end ifclear
@var{n} is a decimal integer in the
-range of 1 to 999 and limits the number of error messages to be
-generated. For example, using @option{-gnatm2} might yield
+range of 1 to 999999 and limits the number of error or warning
+messages to be generated. For example, using
+@option{-gnatm2} might yield
@smallexample
e.adb:3:04: Incorrect spelling of keyword "function"
e.adb:5:35: missing ".."
-fatal error: maximum errors reached
+fatal error: maximum number of errors detected
compilation abandoned
@end smallexample
+@noindent
+The default setting if
+no switch is given is 9999. If the number of warnings reaches this
+limit, then a message is output and further warnings are suppressed,
+but the compilation is continued. If the number of error messages
+reaches this limit, then a message is output and the compilation
+is abandoned. A value of zero means that no limit applies.
+
+@noindent
+Note that the equal sign is optional, so the switches
+@option{-gnatm2} and @option{-gnatm=2} are equivalent.
+
@item -gnatf
-@cindex @option{-gnatf} (@code{gcc})
+@cindex @option{-gnatf} (@command{gcc})
@cindex Error messages, suppressing
@ifclear vms
The @code{f} stands for full.
Additional details on incorrect parameters
@end itemize
+@item -gnatjnn
+@cindex @option{-gnatjnn} (@command{gcc})
+In normal operation mode (or if @option{-gnatj0} is used, then error messages
+with continuation lines are treated as though the continuation lines were
+separate messages (and so a warning with two continuation lines counts as
+three warnings, and is listed as three separate messages).
+
+If the @option{-gnatjnn} switch is used with a positive value for nn, then
+messages are output in a different manner. A message and all its continuation
+lines are treated as a unit, and count as only one warning or message in the
+statistics totals. Furthermore, the message is reformatted so that no line
+is longer than nn characters.
@item -gnatq
-@cindex @option{-gnatq} (@code{gcc})
+@cindex @option{-gnatq} (@command{gcc})
@ifclear vms
The @code{q} stands for quit (really ``don't quit'').
@end ifclear
internal fatal error when given a syntactically invalid tree.
@item -gnatQ
-@cindex @option{-gnatQ} (@code{gcc})
+@cindex @option{-gnatQ} (@command{gcc})
In normal operation mode, the @file{ALI} file is not generated if any
illegalities are detected in the program. The use of @option{-gnatQ} forces
generation of the @file{ALI} file. This file is marked as being in
error, so it cannot be used for binding purposes, but it does contain
reasonably complete cross-reference information, and thus may be useful
-for use by tools (e.g. semantic browsing tools or integrated development
+for use by tools (e.g., semantic browsing tools or integrated development
environments) that are driven from the @file{ALI} file. This switch
implies @option{-gnatq}, since the semantic phase must be run to get a
meaningful ALI file.
analysis.
When @option{-gnatQ} is used and the generated @file{ALI} file is marked as
-being in error, @code{gnatmake} will attempt to recompile the source when it
+being in error, @command{gnatmake} will attempt to recompile the source when it
finds such an @file{ALI} file, including with switch @option{-gnatc}.
Note that @option{-gnatQ} has no effect if @option{-gnats} is specified,
@end table
-
@node Warning Message Control
@subsection Warning Message Control
@cindex Warning messages
@noindent
In addition to error messages, which correspond to illegalities as defined
-in the Ada 95 Reference Manual, the compiler detects two kinds of warning
+in the Ada Reference Manual, the compiler detects two kinds of warning
situations.
First, the compiler considers some constructs suspicious and generates a
Possible order of elaboration problems
@item
+Assertions (pragma Assert) that are sure to fail
+
+@item
Unreachable code
@item
+Address clauses with possibly unaligned values, or where an attempt is
+made to overlay a smaller variable with a larger one.
+
+@item
Fixed-point type declarations with a null range
@item
@item
Attempt to return local value by reference
-
@item
Premature instantiation of a generic body
@item
Accidental hiding of name by child unit
-
@item
Access before elaboration detected at compile time
@end itemize
@noindent
-The following switches are available to control the handling of
-warning messages:
+The following section lists compiler switches that are available
+to control the handling of warning messages. It is also possible
+to exercise much finer control over what warnings are issued and
+suppressed using the GNAT pragma Warnings, @xref{Pragma Warnings,,,
+gnat_rm, GNAT Reference manual}.
@table @option
@c !sort!
@item -gnatwa
@emph{Activate all optional errors.}
-@cindex @option{-gnatwa} (@code{gcc})
+@cindex @option{-gnatwa} (@command{gcc})
This switch activates most optional warning messages, see remaining list
in this section for details on optional warning messages that can be
individually controlled. The warnings that are not turned on by this
switch are
@option{-gnatwd} (implicit dereferencing),
@option{-gnatwh} (hiding),
-and @option{-gnatwl} (elaboration warnings).
+@option{-gnatwl} (elaboration warnings),
+@option{-gnatw.o} (warn on values set by out parameters ignored)
+and @option{-gnatwt} (tracking of deleted conditional code).
All other optional warnings are turned on.
@item -gnatwA
@emph{Suppress all optional errors.}
-@cindex @option{-gnatwA} (@code{gcc})
+@cindex @option{-gnatwA} (@command{gcc})
This switch suppresses all optional warning messages, see remaining list
in this section for details on optional warning messages that can be
individually controlled.
+@item -gnatw.a
+@emph{Activate warnings on failing assertions.}
+@cindex @option{-gnatw.a} (@command{gcc})
+@cindex Assert failures
+This switch activates warnings for assertions where the compiler can tell at
+compile time that the assertion will fail. Note that this warning is given
+even if assertions are disabled. The default is that such warnings are
+generated.
+
+@item -gnatw.A
+@emph{Suppress warnings on failing assertions.}
+@cindex @option{-gnatw.A} (@command{gcc})
+@cindex Assert failures
+This switch suppresses warnings for assertions where the compiler can tell at
+compile time that the assertion will fail.
+
+@item -gnatwb
+@emph{Activate warnings on bad fixed values.}
+@cindex @option{-gnatwb} (@command{gcc})
+@cindex Bad fixed values
+@cindex Fixed-point Small value
+@cindex Small value
+This switch activates warnings for static fixed-point expressions whose
+value is not an exact multiple of Small. Such values are implementation
+dependent, since an implementation is free to choose either of the multiples
+that surround the value. GNAT always chooses the closer one, but this is not
+required behavior, and it is better to specify a value that is an exact
+multiple, ensuring predictable execution. The default is that such warnings
+are not generated.
+
+@item -gnatwB
+@emph{Suppress warnings on bad fixed values.}
+@cindex @option{-gnatwB} (@command{gcc})
+This switch suppresses warnings for static fixed-point expressions whose
+value is not an exact multiple of Small.
+
+@item -gnatw.b
+@emph{Activate warnings on biased representation.}
+@cindex @option{-gnatw.b} (@command{gcc})
+@cindex Biased representation
+This switch activates warnings when a size clause, value size clause, component
+clause, or component size clause forces the use of biased representation for an
+integer type (e.g. representing a range of 10..11 in a single bit by using 0/1
+to represent 10/11). The default is that such warnings are generated.
+
+@item -gnatw.B
+@emph{Suppress warnings on biased representation.}
+@cindex @option{-gnatwB} (@command{gcc})
+This switch suppresses warnings for representation clauses that force the use
+of biased representation.
+
@item -gnatwc
@emph{Activate warnings on conditionals.}
-@cindex @option{-gnatwc} (@code{gcc})
+@cindex @option{-gnatwc} (@command{gcc})
@cindex Conditionals, constant
This switch activates warnings for conditional expressions used in
tests that are known to be True or False at compile time. The default
not get issued for the use of boolean variables or constants whose
values are known at compile time, since this is a standard technique
for conditional compilation in Ada, and this would generate too many
-``false positive'' warnings.
+false positive warnings.
+
+This warning option also activates a special test for comparisons using
+the operators ``>='' and`` <=''.
+If the compiler can tell that only the equality condition is possible,
+then it will warn that the ``>'' or ``<'' part of the test
+is useless and that the operator could be replaced by ``=''.
+An example would be comparing a @code{Natural} variable <= 0.
+
+This warning option also generates warnings if
+one or both tests is optimized away in a membership test for integer
+values if the result can be determined at compile time. Range tests on
+enumeration types are not included, since it is common for such tests
+to include an end point.
+
This warning can also be turned on using @option{-gnatwa}.
@item -gnatwC
@emph{Suppress warnings on conditionals.}
-@cindex @option{-gnatwC} (@code{gcc})
+@cindex @option{-gnatwC} (@command{gcc})
This switch suppresses warnings for conditional expressions used in
tests that are known to be True or False at compile time.
+@item -gnatw.c
+@emph{Activate warnings on missing component clauses.}
+@cindex @option{-gnatw.c} (@command{gcc})
+@cindex Component clause, missing
+This switch activates warnings for record components where a record
+representation clause is present and has component clauses for the
+majority, but not all, of the components. A warning is given for each
+component for which no component clause is present.
+
+This warning can also be turned on using @option{-gnatwa}.
+
+@item -gnatw.C
+@emph{Suppress warnings on missing component clauses.}
+@cindex @option{-gnatwC} (@command{gcc})
+This switch suppresses warnings for record components that are
+missing a component clause in the situation described above.
+
@item -gnatwd
@emph{Activate warnings on implicit dereferencing.}
-@cindex @option{-gnatwd} (@code{gcc})
+@cindex @option{-gnatwd} (@command{gcc})
If this switch is set, then the use of a prefix of an access type
in an indexed component, slice, or selected component without an
explicit @code{.all} will generate a warning. With this warning
@item -gnatwD
@emph{Suppress warnings on implicit dereferencing.}
-@cindex @option{-gnatwD} (@code{gcc})
+@cindex @option{-gnatwD} (@command{gcc})
@cindex Implicit dereferencing
@cindex Dereferencing, implicit
This switch suppresses warnings for implicit dereferences in
@item -gnatwe
@emph{Treat warnings as errors.}
-@cindex @option{-gnatwe} (@code{gcc})
+@cindex @option{-gnatwe} (@command{gcc})
@cindex Warnings, treat as error
This switch causes warning messages to be treated as errors.
The warning string still appears, but the warning messages are counted
as errors, and prevent the generation of an object file.
+@item -gnatw.e
+@emph{Activate every optional warning}
+@cindex @option{-gnatw.e} (@command{gcc})
+@cindex Warnings, activate every optional warning
+This switch activates all optional warnings, including those which
+are not activated by @code{-gnatwa}.
+
@item -gnatwf
@emph{Activate warnings on unreferenced formals.}
-@cindex @option{-gnatwf} (@code{gcc})
+@cindex @option{-gnatwf} (@command{gcc})
@cindex Formals, unreferenced
This switch causes a warning to be generated if a formal parameter
is not referenced in the body of the subprogram. This warning can
-also be turned on using @option{-gnatwa} or @option{-gnatwu}.
+also be turned on using @option{-gnatwa} or @option{-gnatwu}. The
+default is that these warnings are not generated.
@item -gnatwF
@emph{Suppress warnings on unreferenced formals.}
-@cindex @option{-gnatwF} (@code{gcc})
+@cindex @option{-gnatwF} (@command{gcc})
This switch suppresses warnings for unreferenced formal
parameters. Note that the
combination @option{-gnatwu} followed by @option{-gnatwF} has the
@item -gnatwg
@emph{Activate warnings on unrecognized pragmas.}
-@cindex @option{-gnatwg} (@code{gcc})
+@cindex @option{-gnatwg} (@command{gcc})
@cindex Pragmas, unrecognized
This switch causes a warning to be generated if an unrecognized
pragma is encountered. Apart from issuing this warning, the
@item -gnatwG
@emph{Suppress warnings on unrecognized pragmas.}
-@cindex @option{-gnatwG} (@code{gcc})
+@cindex @option{-gnatwG} (@command{gcc})
This switch suppresses warnings for unrecognized pragmas.
@item -gnatwh
@emph{Activate warnings on hiding.}
-@cindex @option{-gnatwh} (@code{gcc})
+@cindex @option{-gnatwh} (@command{gcc})
@cindex Hiding of Declarations
This switch activates warnings on hiding declarations.
A declaration is considered hiding
@item -gnatwH
@emph{Suppress warnings on hiding.}
-@cindex @option{-gnatwH} (@code{gcc})
+@cindex @option{-gnatwH} (@command{gcc})
This switch suppresses warnings on hiding declarations.
@item -gnatwi
@emph{Activate warnings on implementation units.}
-@cindex @option{-gnatwi} (@code{gcc})
+@cindex @option{-gnatwi} (@command{gcc})
This switch activates warnings for a @code{with} of an internal GNAT
implementation unit, defined as any unit from the @code{Ada},
@code{Interfaces}, @code{GNAT},
@item -gnatwI
@emph{Disable warnings on implementation units.}
-@cindex @option{-gnatwI} (@code{gcc})
+@cindex @option{-gnatwI} (@command{gcc})
This switch disables warnings for a @code{with} of an internal GNAT
implementation unit.
@item -gnatwj
@emph{Activate warnings on obsolescent features (Annex J).}
-@cindex @option{-gnatwj} (@code{gcc})
+@cindex @option{-gnatwj} (@command{gcc})
@cindex Features, obsolescent
@cindex Obsolescent features
If this warning option is activated, then warnings are generated for
of the renamed packages (like @code{Text_IO}) and use of package
@code{ASCII} are not flagged, since these are very common and
would generate many annoying positive warnings. The default is that
-such warnings are not generated.
+such warnings are not generated. This warning is also turned on by
+the use of @option{-gnatwa}.
+
+In addition to the above cases, warnings are also generated for
+GNAT features that have been provided in past versions but which
+have been superseded (typically by features in the new Ada standard).
+For example, @code{pragma Ravenscar} will be flagged since its
+function is replaced by @code{pragma Profile(Ravenscar)}.
+
+Note that this warning option functions differently from the
+restriction @code{No_Obsolescent_Features} in two respects.
+First, the restriction applies only to annex J features.
+Second, the restriction does flag uses of package @code{ASCII}.
@item -gnatwJ
@emph{Suppress warnings on obsolescent features (Annex J).}
-@cindex @option{-gnatwJ} (@code{gcc})
+@cindex @option{-gnatwJ} (@command{gcc})
This switch disables warnings on use of obsolescent features.
@item -gnatwk
@emph{Activate warnings on variables that could be constants.}
-@cindex @option{-gnatwk} (@code{gcc})
+@cindex @option{-gnatwk} (@command{gcc})
This switch activates warnings for variables that are initialized but
-never modified, and then could be declared constants.
+never modified, and then could be declared constants. The default is that
+such warnings are not given.
+This warning can also be turned on using @option{-gnatwa}.
@item -gnatwK
@emph{Suppress warnings on variables that could be constants.}
-@cindex @option{-gnatwK} (@code{gcc})
+@cindex @option{-gnatwK} (@command{gcc})
This switch disables warnings on variables that could be declared constants.
@item -gnatwl
-@emph{Activate warnings for missing elaboration pragmas.}
-@cindex @option{-gnatwl} (@code{gcc})
+@emph{Activate warnings for elaboration pragmas.}
+@cindex @option{-gnatwl} (@command{gcc})
@cindex Elaboration, warnings
This switch activates warnings on missing
-@code{pragma Elaborate_All} statements.
+@code{Elaborate_All} and @code{Elaborate} pragmas.
See the section in this guide on elaboration checking for details on
-when such pragma should be used. Warnings are also generated if you
+when such pragmas should be used. In dynamic elaboration mode, this switch
+generations warnings about the need to add elaboration pragmas. Note however,
+that if you blindly follow these warnings, and add @code{Elaborate_All}
+warnings wherever they are recommended, you basically end up with the
+equivalent of the static elaboration model, which may not be what you want for
+legacy code for which the static model does not work.
+
+For the static model, the messages generated are labeled "info:" (for
+information messages). They are not warnings to add elaboration pragmas,
+merely informational messages showing what implicit elaboration pragmas
+have been added, for use in analyzing elaboration circularity problems.
+
+Warnings are also generated if you
are using the static mode of elaboration, and a @code{pragma Elaborate}
is encountered. The default is that such warnings
are not generated.
This warning is not automatically turned on by the use of @option{-gnatwa}.
@item -gnatwL
-@emph{Suppress warnings for missing elaboration pragmas.}
-@cindex @option{-gnatwL} (@code{gcc})
-This switch suppresses warnings on missing pragma Elaborate_All statements.
+@emph{Suppress warnings for elaboration pragmas.}
+@cindex @option{-gnatwL} (@command{gcc})
+This switch suppresses warnings on missing Elaborate and Elaborate_All pragmas.
See the section in this guide on elaboration checking for details on
-when such pragma should be used.
+when such pragmas should be used.
@item -gnatwm
@emph{Activate warnings on modified but unreferenced variables.}
-@cindex @option{-gnatwm} (@code{gcc})
+@cindex @option{-gnatwm} (@command{gcc})
This switch activates warnings for variables that are assigned (using
an initialization value or with one or more assignment statements) but
whose value is never read. The warning is suppressed for volatile
variables and also for variables that are renamings of other variables
or for which an address clause is given.
This warning can also be turned on using @option{-gnatwa}.
+The default is that these warnings are not given.
@item -gnatwM
@emph{Disable warnings on modified but unreferenced variables.}
-@cindex @option{-gnatwM} (@code{gcc})
+@cindex @option{-gnatwM} (@command{gcc})
This switch disables warnings for variables that are assigned or
initialized, but never read.
@item -gnatwn
@emph{Set normal warnings mode.}
-@cindex @option{-gnatwn} (@code{gcc})
+@cindex @option{-gnatwn} (@command{gcc})
This switch sets normal warning mode, in which enabled warnings are
issued and treated as warnings rather than errors. This is the default
mode. the switch @option{-gnatwn} can be used to cancel the effect of
@item -gnatwo
@emph{Activate warnings on address clause overlays.}
-@cindex @option{-gnatwo} (@code{gcc})
+@cindex @option{-gnatwo} (@command{gcc})
@cindex Address Clauses, warnings
This switch activates warnings for possibly unintended initialization
effects of defining address clauses that cause one variable to overlap
@item -gnatwO
@emph{Suppress warnings on address clause overlays.}
-@cindex @option{-gnatwO} (@code{gcc})
+@cindex @option{-gnatwO} (@command{gcc})
This switch suppresses warnings on possibly unintended initialization
effects of defining address clauses that cause one variable to overlap
another.
+@item -gnatw.o
+@emph{Activate warnings on modified but unreferenced out parameters.}
+@cindex @option{-gnatw.o} (@command{gcc})
+This switch activates warnings for variables that are modified by using
+them as actuals for a call to a procedure with an out mode formal, where
+the resulting assigned value is never read. It is applicable in the case
+where there is more than one out mode formal. If there is only one out
+mode formal, the warning is issued by default (controlled by -gnatwu).
+The warning is suppressed for volatile
+variables and also for variables that are renamings of other variables
+or for which an address clause is given.
+The default is that these warnings are not given. Note that this warning
+is not included in -gnatwa, it must be activated explicitly.
+
+@item -gnatw.O
+@emph{Disable warnings on modified but unreferenced out parameters.}
+@cindex @option{-gnatw.O} (@command{gcc})
+This switch suppresses warnings for variables that are modified by using
+them as actuals for a call to a procedure with an out mode formal, where
+the resulting assigned value is never read.
+
@item -gnatwp
@emph{Activate warnings on ineffective pragma Inlines.}
-@cindex @option{-gnatwp} (@code{gcc})
+@cindex @option{-gnatwp} (@command{gcc})
@cindex Inlining, warnings
This switch activates warnings for failure of front end inlining
(activated by @option{-gnatN}) to inline a particular call. There are
many reasons for not being able to inline a call, including most
-commonly that the call is too complex to inline.
+commonly that the call is too complex to inline. The default is
+that such warnings are not given.
This warning can also be turned on using @option{-gnatwa}.
+Warnings on ineffective inlining by the gcc back-end can be activated
+separately, using the gcc switch -Winline.
@item -gnatwP
@emph{Suppress warnings on ineffective pragma Inlines.}
-@cindex @option{-gnatwP} (@code{gcc})
+@cindex @option{-gnatwP} (@command{gcc})
This switch suppresses warnings on ineffective pragma Inlines. If the
inlining mechanism cannot inline a call, it will simply ignore the
request silently.
+@item -gnatw.p
+@emph{Activate warnings on parameter ordering.}
+@cindex @option{-gnatw.p} (@command{gcc})
+@cindex Parameter order, warnings
+This switch activates warnings for cases of suspicious parameter
+ordering when the list of arguments are all simple identifiers that
+match the names of the formals, but are in a different order. The
+warning is suppressed if any use of named parameter notation is used,
+so this is the appropriate way to suppress a false positive (and
+serves to emphasize that the "misordering" is deliberate). The
+default is
+that such warnings are not given.
+This warning can also be turned on using @option{-gnatwa}.
+
+@item -gnatw.P
+@emph{Suppress warnings on parameter ordering.}
+@cindex @option{-gnatw.P} (@command{gcc})
+This switch suppresses warnings on cases of suspicious parameter
+ordering.
+
+@item -gnatwq
+@emph{Activate warnings on questionable missing parentheses.}
+@cindex @option{-gnatwq} (@command{gcc})
+@cindex Parentheses, warnings
+This switch activates warnings for cases where parentheses are not used and
+the result is potential ambiguity from a readers point of view. For example
+(not a > b) when a and b are modular means ((not a) > b) and very likely the
+programmer intended (not (a > b)). Similarly (-x mod 5) means (-(x mod 5)) and
+quite likely ((-x) mod 5) was intended. In such situations it seems best to
+follow the rule of always parenthesizing to make the association clear, and
+this warning switch warns if such parentheses are not present. The default
+is that these warnings are given.
+This warning can also be turned on using @option{-gnatwa}.
+
+@item -gnatwQ
+@emph{Suppress warnings on questionable missing parentheses.}
+@cindex @option{-gnatwQ} (@command{gcc})
+This switch suppresses warnings for cases where the association is not
+clear and the use of parentheses is preferred.
+
@item -gnatwr
@emph{Activate warnings on redundant constructs.}
-@cindex @option{-gnatwr} (@code{gcc})
+@cindex @option{-gnatwr} (@command{gcc})
This switch activates warnings for redundant constructs. The following
is the current list of constructs regarded as redundant:
-This warning can also be turned on using @option{-gnatwa}.
@itemize @bullet
@item
Use of the operator abs on an operand that is known at compile time
to be non-negative
@item
-Use of an unnecessary extra level of parentheses (C-style) around conditions
-in @code{if} statements, @code{while} statements and @code{exit} statements.
-@item
Comparison of boolean expressions to an explicit True value.
@end itemize
+This warning can also be turned on using @option{-gnatwa}.
+The default is that warnings for redundant constructs are not given.
+
@item -gnatwR
@emph{Suppress warnings on redundant constructs.}
-@cindex @option{-gnatwR} (@code{gcc})
+@cindex @option{-gnatwR} (@command{gcc})
This switch suppresses warnings for redundant constructs.
@item -gnatws
@emph{Suppress all warnings.}
-@cindex @option{-gnatws} (@code{gcc})
+@cindex @option{-gnatws} (@command{gcc})
This switch completely suppresses the
output of all warning messages from the GNAT front end.
-Note that it does not suppress warnings from the @code{gcc} back end.
+Note that it does not suppress warnings from the @command{gcc} back end.
To suppress these back end warnings as well, use the switch @option{-w}
in addition to @option{-gnatws}.
+@item -gnatwt
+@emph{Activate warnings for tracking of deleted conditional code.}
+@cindex @option{-gnatwt} (@command{gcc})
+@cindex Deactivated code, warnings
+@cindex Deleted code, warnings
+This switch activates warnings for tracking of code in conditionals (IF and
+CASE statements) that is detected to be dead code which cannot be executed, and
+which is removed by the front end. This warning is off by default, and is not
+turned on by @option{-gnatwa}, it has to be turned on explicitly. This may be
+useful for detecting deactivated code in certified applications.
+
+@item -gnatwT
+@emph{Suppress warnings for tracking of deleted conditional code.}
+@cindex @option{-gnatwT} (@command{gcc})
+This switch suppresses warnings for tracking of deleted conditional code.
+
@item -gnatwu
@emph{Activate warnings on unused entities.}
-@cindex @option{-gnatwu} (@code{gcc})
+@cindex @option{-gnatwu} (@command{gcc})
This switch activates warnings to be generated for entities that
are declared but not referenced, and for units that are @code{with}'ed
and not
@code{with} can be moved to the body. The default is that
such warnings are not generated.
This switch also activates warnings on unreferenced formals
-(it is includes the effect of @option{-gnatwf}).
+(it includes the effect of @option{-gnatwf}).
This warning can also be turned on using @option{-gnatwa}.
@item -gnatwU
@emph{Suppress warnings on unused entities.}
-@cindex @option{-gnatwU} (@code{gcc})
+@cindex @option{-gnatwU} (@command{gcc})
This switch suppresses warnings for unused entities and packages.
It also turns off warnings on unreferenced formals (and thus includes
the effect of @option{-gnatwF}).
@item -gnatwv
@emph{Activate warnings on unassigned variables.}
-@cindex @option{-gnatwv} (@code{gcc})
+@cindex @option{-gnatwv} (@command{gcc})
@cindex Unassigned variable warnings
This switch activates warnings for access to variables which
may not be properly initialized. The default is that
such warnings are generated.
+This warning can also be turned on using @option{-gnatwa}.
@item -gnatwV
@emph{Suppress warnings on unassigned variables.}
-@cindex @option{-gnatwV} (@code{gcc})
+@cindex @option{-gnatwV} (@command{gcc})
This switch suppresses warnings for access to variables which
may not be properly initialized.
+For variables of a composite type, the warning can also be suppressed in
+Ada 2005 by using a default initialization with a box. For example, if
+Table is an array of records whose components are only partially uninitialized,
+then the following code:
+
+@smallexample @c ada
+ Tab : Table := (others => <>);
+@end smallexample
+
+will suppress warnings on subsequent statements that access components
+of variable Tab.
+
+@item -gnatww
+@emph{Activate warnings on wrong low bound assumption.}
+@cindex @option{-gnatww} (@command{gcc})
+@cindex String indexing warnings
+This switch activates warnings for indexing an unconstrained string parameter
+with a literal or S'Length. This is a case where the code is assuming that the
+low bound is one, which is in general not true (for example when a slice is
+passed). The default is that such warnings are generated.
+This warning can also be turned on using @option{-gnatwa}.
+
+@item -gnatwW
+@emph{Suppress warnings on wrong low bound assumption.}
+@cindex @option{-gnatwW} (@command{gcc})
+This switch suppresses warnings for indexing an unconstrained string parameter
+with a literal or S'Length. Note that this warning can also be suppressed
+in a particular case by adding an
+assertion that the lower bound is 1,
+as shown in the following example.
+
+@smallexample @c ada
+ procedure K (S : String) is
+ pragma Assert (S'First = 1);
+ @dots{}
+@end smallexample
+
+@item -gnatw.w
+@emph{Activate warnings on unnecessary Warnings Off pragmas}
+@cindex @option{-gnatw.w} (@command{gcc})
+@cindex Warnings Off control
+This switch activates warnings for use of @code{pragma Warnings (Off, entity}
+where either the pragma is entirely useless (because it suppresses no
+warnings), or it could be replaced by @code{pragma Unreferenced} or
+@code{pragma Unmodified}.The default is that these warnings are not given.
+Note that this warning is not included in -gnatwa, it must be
+activated explicitly.
+
+@item -gnatw.W
+@emph{Suppress warnings on unnecessary Warnings Off pragmas}
+@cindex @option{-gnatw.W} (@command{gcc})
+This switch suppresses warnings for use of @code{pragma Warnings (Off, entity}.
@item -gnatwx
@emph{Activate warnings on Export/Import pragmas.}
-@cindex @option{-gnatwx} (@code{gcc})
+@cindex @option{-gnatwx} (@command{gcc})
@cindex Export/Import pragma warnings
This switch activates warnings on Export/Import pragmas when
the compiler detects a possible conflict between the Ada and
because the C compiler cannot supply the proper default, so
a warning is issued. The default is that such warnings are
generated.
+This warning can also be turned on using @option{-gnatwa}.
@item -gnatwX
@emph{Suppress warnings on Export/Import pragmas.}
-@cindex @option{-gnatwX} (@code{gcc})
+@cindex @option{-gnatwX} (@command{gcc})
This switch suppresses warnings on Export/Import pragmas.
The sense of this is that you are telling the compiler that
you know what you are doing in writing the pragma, and it
should not complain at you.
+@item -gnatw.x
+@emph{Activate warnings for No_Exception_Propagation mode.}
+@cindex @option{-gnatwm} (@command{gcc})
+This switch activates warnings for exception usage when pragma Restrictions
+(No_Exception_Propagation) is in effect. Warnings are given for implicit or
+explicit exception raises which are not covered by a local handler, and for
+exception handlers which do not cover a local raise. The default is that these
+warnings are not given.
+
+@item -gnatw.X
+@emph{Disable warnings for No_Exception_Propagation mode.}
+This switch disables warnings for exception usage when pragma Restrictions
+(No_Exception_Propagation) is in effect.
+
+@item -gnatwy
+@emph{Activate warnings for Ada 2005 compatibility issues.}
+@cindex @option{-gnatwy} (@command{gcc})
+@cindex Ada 2005 compatibility issues warnings
+For the most part Ada 2005 is upwards compatible with Ada 95,
+but there are some exceptions (for example the fact that
+@code{interface} is now a reserved word in Ada 2005). This
+switch activates several warnings to help in identifying
+and correcting such incompatibilities. The default is that
+these warnings are generated. Note that at one point Ada 2005
+was called Ada 0Y, hence the choice of character.
+This warning can also be turned on using @option{-gnatwa}.
+
+@item -gnatwY
+@emph{Disable warnings for Ada 2005 compatibility issues.}
+@cindex @option{-gnatwY} (@command{gcc})
+@cindex Ada 2005 compatibility issues warnings
+This switch suppresses several warnings intended to help in identifying
+incompatibilities between Ada 95 and Ada 2005.
+
@item -gnatwz
@emph{Activate warnings on unchecked conversions.}
-@cindex @option{-gnatwz} (@code{gcc})
+@cindex @option{-gnatwz} (@command{gcc})
@cindex Unchecked_Conversion warnings
This switch activates warnings for unchecked conversions
where the types are known at compile time to have different
sizes. The default
-is that such warnings are generated.
+is that such warnings are generated. Warnings are also
+generated for subprogram pointers with different conventions,
+and, on VMS only, for data pointers with different conventions.
+This warning can also be turned on using @option{-gnatwa}.
@item -gnatwZ
@emph{Suppress warnings on unchecked conversions.}
-@cindex @option{-gnatwZ} (@code{gcc})
+@cindex @option{-gnatwZ} (@command{gcc})
This switch suppresses warnings for unchecked conversions
where the types are known at compile time to have different
-sizes.
+sizes or conventions.
+
+@item ^-Wunused^WARNINGS=UNUSED^
+@cindex @option{-Wunused}
+The warnings controlled by the @option{-gnatw} switch are generated by
+the front end of the compiler. The @option{GCC} back end can provide
+additional warnings and they are controlled by the @option{-W} switch.
+For example, @option{^-Wunused^WARNINGS=UNUSED^} activates back end
+warnings for entities that are declared but not referenced.
@item ^-Wuninitialized^WARNINGS=UNINITIALIZED^
@cindex @option{-Wuninitialized}
-The warnings controlled by the @option{-gnatw} switch are generated by the
-front end of the compiler. In some cases, the @option{^gcc^GCC^} back end
-can provide additional warnings. One such useful warning is provided by
-@option{^-Wuninitialized^WARNINGS=UNINITIALIZED^}. This must be used in
-conjunction with tunrning on optimization mode. This causes the flow
-analysis circuits of the back end optimizer to output additional
-warnings about uninitialized variables.
+Similarly, @option{^-Wuninitialized^WARNINGS=UNINITIALIZED^} activates
+the back end warning for uninitialized variables. This switch must be
+used in conjunction with an optimization level greater than zero.
+
+@item ^-Wall^/ALL_BACK_END_WARNINGS^
+@cindex @option{-Wall}
+This switch enables all the above warnings from the @option{GCC} back end.
+The code generator detects a number of warning situations that are missed
+by the @option{GNAT} front end, and this switch can be used to activate them.
+The use of this switch also sets the default front end warning mode to
+@option{-gnatwa}, that is, most front end warnings activated as well.
@item ^-w^/NO_BACK_END_WARNINGS^
@cindex @option{-w}
-This switch suppresses warnings from the @option{^gcc^GCC^} back end. It may
-be used in conjunction with @option{-gnatws} to ensure that all warnings
-are suppressed during the entire compilation process.
+Conversely, this switch suppresses warnings from the @option{GCC} back end.
+The use of this switch also sets the default front end warning mode to
+@option{-gnatws}, that is, front end warnings suppressed as well.
@end table
@end table
-
@node Debugging and Assertion Control
@subsection Debugging and Assertion Control
@table @option
@item -gnata
-@cindex @option{-gnata} (@code{gcc})
+@cindex @option{-gnata} (@command{gcc})
@findex Assert
@findex Debug
@cindex Assertions
@smallexample
@cartouche
- @b{pragma} Assert (@var{Boolean-expression} [,
- @var{static-string-expression}])
+ @b{pragma} Assert (@var{Boolean-expression} @r{[},
+ @var{static-string-expression}@r{]})
@b{pragma} Debug (@var{procedure call})
@end cartouche
@end smallexample
debugging procedures to be called between declarations.
@ifset vms
-@item /DEBUG[=debug-level]
+@item /DEBUG@r{[}=debug-level@r{]}
@itemx /NODEBUG
Specifies how much debugging information is to be included in
the resulting object file where 'debug-level' is one of the following:
@findex Validity Checking
@noindent
-The Ada 95 Reference Manual has specific requirements for checking
+The Ada Reference Manual has specific requirements for checking
for invalid values. In particular, RM 13.9.1 requires that the
evaluation of invalid values (for example from unchecked conversions),
not result in erroneous execution. In GNAT, the result of such an
and subscripts on the left hand side (where memory corruption could
occur as a result of an invalid value).
+The @option{-gnatB} switch tells the compiler to assume that all
+values are valid (that is, within their declared subtype range)
+except in the context of a use of the Valid attribute. This means
+the compiler can generate more efficient code, since the range
+of values is better known at compile time.
+
The @option{-gnatV^@var{x}^^} switch allows more control over the validity
checking mode.
@ifclear vms
to the default checks described above.
@end ifset
-
@table @option
@c !sort!
@item -gnatVa
@emph{All validity checks.}
-@cindex @option{-gnatVa} (@code{gcc})
+@cindex @option{-gnatVa} (@command{gcc})
All validity checks are turned on.
@ifclear vms
That is, @option{-gnatVa} is
@item -gnatVc
@emph{Validity checks for copies.}
-@cindex @option{-gnatVc} (@code{gcc})
+@cindex @option{-gnatVc} (@command{gcc})
The right hand side of assignments, and the initializing values of
object declarations are validity checked.
@item -gnatVd
@emph{Default (RM) validity checks.}
-@cindex @option{-gnatVd} (@code{gcc})
+@cindex @option{-gnatVd} (@command{gcc})
Some validity checks are done by default following normal Ada semantics
(RM 13.9.1 (9-11)).
A check is done in case statements that the expression is within the range
are present, then the program is erroneous, and wild jumps or memory
overwriting may occur.
+@item -gnatVe
+@emph{Validity checks for elementary components.}
+@cindex @option{-gnatVe} (@command{gcc})
+In the absence of this switch, assignments to record or array components are
+not validity checked, even if validity checks for assignments generally
+(@option{-gnatVc}) are turned on. In Ada, assignment of composite values do not
+require valid data, but assignment of individual components does. So for
+example, there is a difference between copying the elements of an array with a
+slice assignment, compared to assigning element by element in a loop. This
+switch allows you to turn off validity checking for components, even when they
+are assigned component by component.
+
@item -gnatVf
@emph{Validity checks for floating-point values.}
-@cindex @option{-gnatVf} (@code{gcc})
+@cindex @option{-gnatVf} (@command{gcc})
In the absence of this switch, validity checking occurs only for discrete
values. If @option{-gnatVf} is specified, then validity checking also applies
-for floating-point values, and NaN's and infinities are considered invalid,
+for floating-point values, and NaNs and infinities are considered invalid,
as well as out of range values for constrained types. Note that this means
-that standard @code{IEEE} infinity mode is not allowed. The exact contexts
+that standard IEEE infinity mode is not allowed. The exact contexts
in which floating-point values are checked depends on the setting of other
options. For example,
@option{^-gnatVif^VALIDITY_CHECKING=(IN_PARAMS,FLOATS)^} or
@item -gnatVi
@emph{Validity checks for @code{in} mode parameters}
-@cindex @option{-gnatVi} (@code{gcc})
+@cindex @option{-gnatVi} (@command{gcc})
Arguments for parameters of mode @code{in} are validity checked in function
and procedure calls at the point of call.
@item -gnatVm
@emph{Validity checks for @code{in out} mode parameters.}
-@cindex @option{-gnatVm} (@code{gcc})
+@cindex @option{-gnatVm} (@command{gcc})
Arguments for parameters of mode @code{in out} are validity checked in
procedure calls at the point of call. The @code{'m'} here stands for
modify, since this concerns parameters that can be modified by the call.
@item -gnatVn
@emph{No validity checks.}
-@cindex @option{-gnatVn} (@code{gcc})
+@cindex @option{-gnatVn} (@command{gcc})
This switch turns off all validity checking, including the default checking
for case statements and left hand side subscripts. Note that the use of
the switch @option{-gnatp} suppresses all run-time checks, including
@item -gnatVo
@emph{Validity checks for operator and attribute operands.}
-@cindex @option{-gnatVo} (@code{gcc})
+@cindex @option{-gnatVo} (@command{gcc})
Arguments for predefined operators and attributes are validity checked.
This includes all operators in package @code{Standard},
the shift operators defined as intrinsic in package @code{Interfaces}
and operands for attributes such as @code{Pos}. Checks are also made
-on individual component values for composite comparisons.
+on individual component values for composite comparisons, and on the
+expressions in type conversions and qualified expressions. Checks are
+also made on explicit ranges using @samp{..} (e.g.@: slices, loops etc).
@item -gnatVp
@emph{Validity checks for parameters.}
-@cindex @option{-gnatVp} (@code{gcc})
+@cindex @option{-gnatVp} (@command{gcc})
This controls the treatment of parameters within a subprogram (as opposed
to @option{-gnatVi} and @option{-gnatVm} which control validity testing
of parameters on a call. If either of these call options is used, then
@item -gnatVr
@emph{Validity checks for function returns.}
-@cindex @option{-gnatVr} (@code{gcc})
+@cindex @option{-gnatVr} (@command{gcc})
The expression in @code{return} statements in functions is validity
checked.
@item -gnatVs
@emph{Validity checks for subscripts.}
-@cindex @option{-gnatVs} (@code{gcc})
+@cindex @option{-gnatVs} (@command{gcc})
All subscripts expressions are checked for validity, whether they appear
on the right side or left side (in default mode only left side subscripts
are validity checked).
@item -gnatVt
@emph{Validity checks for tests.}
-@cindex @option{-gnatVt} (@code{gcc})
+@cindex @option{-gnatVt} (@command{gcc})
Expressions used as conditions in @code{if}, @code{while} or @code{exit}
statements are checked, as well as guard expressions in entry calls.
checking of @code{@b{in out}} procedure arguments.
The specification of additional validity checking generates extra code (and
-in the case of @option{-gnatVa} the code expansion can be substantial.
+in the case of @option{-gnatVa} the code expansion can be substantial).
However, these additional checks can be very useful in detecting
uninitialized variables, incorrect use of unchecked conversion, and other
errors leading to invalid values. The use of pragma @code{Initialize_Scalars}
the validity checking mode at the program source level, and also allows for
temporary disabling of validity checks.
-
@node Style Checking
@subsection Style Checking
@findex Style checking
@noindent
-The @option{-gnaty^x^(option,option,...)^} switch
-@cindex @option{-gnaty} (@code{gcc})
+The @option{-gnaty^x^(option,option,@dots{})^} switch
+@cindex @option{-gnaty} (@command{gcc})
causes the compiler to
enforce specified style rules. A limited set of style rules has been used
in writing the GNAT sources themselves. This switch allows user programs
specified style check, an appropriate warning message is given, preceded by
the character sequence ``(style)''.
@ifset vms
-@code{(option,option,...)} is a sequence of keywords
+@code{(option,option,@dots{})} is a sequence of keywords
@end ifset
@ifclear vms
The string @var{x} is a sequence of letters or digits
@table @option
@c !sort!
-@item 1-9
+@item 0-9
@emph{Specify indentation level.}
If a digit from 1-9 appears
^in the string after @option{-gnaty}^as an option for /STYLE_CHECKS^
then proper indentation is checked, with the digit indicating the
-indentation level required.
+indentation level required. A value of zero turns off this style check.
The general style of required indentation is as specified by
the examples in the Ada Reference Manual. Full line comments must be
aligned with the @code{--} starting on a column that is a multiple of
-the alignment level.
+the alignment level, or they may be aligned the same way as the following
+non-blank line (this is useful when full line comments appear in the middle
+of a statement.
@item ^a^ATTRIBUTE^
@emph{Check attribute casing.}
-If the ^letter a^word ATTRIBUTE^ appears in the string after @option{-gnaty}
-then attribute names, including the case of keywords such as @code{digits}
+Attribute names, including the case of keywords such as @code{digits}
used as attributes names, must be written in mixed case, that is, the
initial letter and any letter following an underscore must be uppercase.
All other letters must be lowercase.
+@item ^A^ARRAY_INDEXES^
+@emph{Use of array index numbers in array attributes.}
+When using the array attributes First, Last, Range,
+or Length, the index number must be omitted for one-dimensional arrays
+and is required for multi-dimensional arrays.
+
@item ^b^BLANKS^
@emph{Blanks not allowed at statement end.}
-If the ^letter b^word BLANKS^ appears in the string after @option{-gnaty} then
-trailing blanks are not allowed at the end of statements. The purpose of this
+Trailing blanks are not allowed at the end of statements. The purpose of this
rule, together with h (no horizontal tabs), is to enforce a canonical format
for the use of blanks to separate source tokens.
@item ^c^COMMENTS^
@emph{Check comments.}
-If the ^letter c^word COMMENTS^ appears in the string after @option{-gnaty}
-then comments must meet the following set of rules:
+Comments must meet the following set of rules:
@itemize @bullet
annotation
language (where ``@code{--#}'' is used). For the purposes of this rule, a
special character is defined as being in one of the ASCII ranges
-@code{16#21#..16#2F#} or @code{16#3A#..16#3F#}.
+@code{16#21#@dots{}16#2F#} or @code{16#3A#@dots{}16#3F#}.
Note that this usage is not permitted
-in GNAT implementation units (i.e. when @option{-gnatg} is used).
+in GNAT implementation units (i.e., when @option{-gnatg} is used).
@item
A line consisting entirely of minus signs, possibly preceded by blanks, is
signs are used to form the top and bottom of the box.
@item
-If a comment starts and ends with ``@code{--}'' is permitted as long as at
+A comment that starts and ends with ``@code{--}'' is permitted as long as at
least one blank follows the initial ``@code{--}''. Together with the preceding
rule, this allows the construction of box comments, as shown in the following
example:
@end smallexample
@end itemize
+@item ^d^DOS_LINE_ENDINGS^
+@emph{Check no DOS line terminators present.}
+All lines must be terminated by a single ASCII.LF
+character (in particular the DOS line terminator sequence CR/LF is not
+allowed).
+
@item ^e^END^
@emph{Check end/exit labels.}
-If the ^letter e^word END^ appears in the string after @option{-gnaty} then
-optional labels on @code{end} statements ending subprograms and on
+Optional labels on @code{end} statements ending subprograms and on
@code{exit} statements exiting named loops, are required to be present.
@item ^f^VTABS^
@emph{No form feeds or vertical tabs.}
-If the ^letter f^word VTABS^ appears in the string after @option{-gnaty} then
-neither form feeds nor vertical tab characters are not permitted
+Neither form feeds nor vertical tab characters are permitted
in the source text.
+@item ^g^GNAT^
+@emph{GNAT style mode}
+The set of style check switches is set to match that used by the GNAT sources.
+This may be useful when developing code that is eventually intended to be
+incorporated into GNAT. For further details, see GNAT sources.
+
@item ^h^HTABS^
@emph{No horizontal tabs.}
-If the ^letter h^word HTABS^ appears in the string after @option{-gnaty} then
-horizontal tab characters are not permitted in the source text.
+Horizontal tab characters are not permitted in the source text.
Together with the b (no blanks at end of line) check, this
enforces a canonical form for the use of blanks to separate
source tokens.
@item ^i^IF_THEN^
@emph{Check if-then layout.}
-If the ^letter i^word IF_THEN^ appears in the string after @option{-gnaty},
-then the keyword @code{then} must appear either on the same
+The keyword @code{then} must appear either on the same
line as corresponding @code{if}, or on a line on its own, lined
up under the @code{if} with at least one non-blank line in between
containing all or part of the condition to be tested.
+@item ^I^IN_MODE^
+@emph{check mode IN keywords}
+Mode @code{in} (the default mode) is not
+allowed to be given explicitly. @code{in out} is fine,
+but not @code{in} on its own.
+
@item ^k^KEYWORD^
@emph{Check keyword casing.}
-If the ^letter k^word KEYWORD^ appears in the string after @option{-gnaty} then
-all keywords must be in lower case (with the exception of keywords
+All keywords must be in lower case (with the exception of keywords
such as @code{digits} used as attribute names to which this check
does not apply).
@item ^l^LAYOUT^
@emph{Check layout.}
-If the ^letter l^word LAYOUT^ appears in the string after @option{-gnaty} then
-layout of statement and declaration constructs must follow the
+Layout of statement and declaration constructs must follow the
recommendations in the Ada Reference Manual, as indicated by the
form of the syntax rules. For example an @code{else} keyword must
be lined up with the corresponding @code{if} keyword.
in the case of record declarations, it is permissible to put the
@code{record} keyword on the same line as the @code{type} keyword, and
then the @code{end} in @code{end record} must line up under @code{type}.
-For example, either of the following two layouts is acceptable:
+This is also permitted when the type declaration is split on two lines.
+For example, any of the following three layouts is acceptable:
@smallexample @c ada
@cartouche
a : integer;
b : integer;
end record;
+
+type q is
+ record
+ a : integer;
+ b : integer;
+end record;
+
@end cartouche
@end smallexample
@item ^Lnnn^MAX_NESTING=nnn^
@emph{Set maximum nesting level}
-If the sequence ^Lnnn^MAX_NESTING=nnn^, where nnn is a decimal number in
-the range 0-999, appears in the string after @option{-gnaty} then the
-maximum level of nesting of constructs (including subprograms, loops,
-blocks, packages, and conditionals) may not exceed the given value. A
-value of zero disconnects this style check.
+The maximum level of nesting of constructs (including subprograms, loops,
+blocks, packages, and conditionals) may not exceed the given value
+@option{nnn}. A value of zero disconnects this style check.
@item ^m^LINE_LENGTH^
@emph{Check maximum line length.}
-If the ^letter m^word LINE_LENGTH^ appears in the string after @option{-gnaty}
-then the length of source lines must not exceed 79 characters, including
+The length of source lines must not exceed 79 characters, including
any trailing blanks. The value of 79 allows convenient display on an
80 character wide device or window, allowing for possible special
-treatment of 80 character lines. Note that this count is of raw
+treatment of 80 character lines. Note that this count is of
characters in the source text. This means that a tab character counts
-as one character in this count and a wide character sequence counts as
-several characters (however many are needed in the encoding).
+as one character in this count but a wide character sequence counts as
+a single character (however many bytes are needed in the encoding).
@item ^Mnnn^MAX_LENGTH=nnn^
@emph{Set maximum line length.}
-If the sequence ^M^MAX_LENGTH=^nnn, where nnn is a decimal number, appears in
-the string after @option{-gnaty} then the length of lines must not exceed the
-given value.
+The length of lines must not exceed the
+given value @option{nnn}. The maximum value that can be specified is 32767.
@item ^n^STANDARD_CASING^
@emph{Check casing of entities in Standard.}
-If the ^letter n^word STANDARD_CASING^ appears in the string
-after @option{-gnaty} then any identifier from Standard must be cased
+Any identifier from Standard must be cased
to match the presentation in the Ada Reference Manual (for example,
@code{Integer} and @code{ASCII.NUL}).
+@item ^N^NONE^
+@emph{Turn off all style checks}
+All style check options are turned off.
+
@item ^o^ORDERED_SUBPROGRAMS^
@emph{Check order of subprogram bodies.}
-If the ^letter o^word ORDERED_SUBPROGRAMS^ appears in the string
-after @option{-gnaty} then all subprogram bodies in a given scope
-(e.g. a package body) must be in alphabetical order. The ordering
+All subprogram bodies in a given scope
+(e.g.@: a package body) must be in alphabetical order. The ordering
rule uses normal Ada rules for comparing strings, ignoring casing
of letters, except that if there is a trailing numeric suffix, then
-the value of this suffix is used in the ordering (e.g. Junk2 comes
+the value of this suffix is used in the ordering (e.g.@: Junk2 comes
before Junk10).
+@item ^O^OVERRIDING_INDICATORS^
+@emph{Check that overriding subprograms are explicitly marked as such.}
+The declaration of a primitive operation of a type extension that overrides
+an inherited operation must carry an overriding indicator.
+
@item ^p^PRAGMA^
@emph{Check pragma casing.}
-If the ^letter p^word PRAGMA^ appears in the string after @option{-gnaty} then
-pragma names must be written in mixed case, that is, the
+Pragma names must be written in mixed case, that is, the
initial letter and any letter following an underscore must be uppercase.
All other letters must be lowercase.
@item ^r^REFERENCES^
@emph{Check references.}
-If the ^letter r^word REFERENCES^ appears in the string after @option{-gnaty}
-then all identifier references must be cased in the same way as the
+All identifier references must be cased in the same way as the
corresponding declaration. No specific casing style is imposed on
identifiers. The only requirement is for consistency of references
with declarations.
+@item ^S^STATEMENTS_AFTER_THEN_ELSE^
+@emph{Check no statements after THEN/ELSE.}
+No statements are allowed
+on the same line as a THEN or ELSE keyword following the
+keyword in an IF statement. OR ELSE and AND THEN are not affected,
+and a special exception allows a pragma to appear after ELSE.
+
@item ^s^SPECS^
@emph{Check separate specs.}
-If the ^letter s^word SPECS^ appears in the string after @option{-gnaty} then
-separate declarations (``specs'') are required for subprograms (a
+Separate declarations (``specs'') are required for subprograms (a
body is not allowed to serve as its own declaration). The only
exception is that parameterless library level procedures are
not required to have a separate declaration. This exception covers
@item ^t^TOKEN^
@emph{Check token spacing.}
-If the ^letter t^word TOKEN^ appears in the string after @option{-gnaty} then
-the following token spacing rules are enforced:
+The following token spacing rules are enforced:
@itemize @bullet
A vertical bar must be surrounded by spaces.
@end itemize
+@item ^u^UNNECESSARY_BLANK_LINES^
+@emph{Check unnecessary blank lines.}
+Unnecessary blank lines are not allowed. A blank line is considered
+unnecessary if it appears at the end of the file, or if more than
+one blank line occurs in sequence.
+
+@item ^x^XTRA_PARENS^
+@emph{Check extra parentheses.}
+Unnecessary extra level of parentheses (C-style) are not allowed
+around conditions in @code{if} statements, @code{while} statements and
+@code{exit} statements.
+
+@item ^y^ALL_BUILTIN^
+@emph{Set all standard style check options}
+This is equivalent to @code{gnaty3aAbcefhiklmnprst}, that is all checking
+options enabled with the exception of @option{-gnatyo}, @option{-gnatyI},
+@option{-gnatyS}, @option{-gnatyLnnn},
+@option{-gnatyd}, @option{-gnatyu}, and @option{-gnatyx}.
+
+@ifclear vms
+@item -
+@emph{Remove style check options}
+This causes any subsequent options in the string to act as canceling the
+corresponding style check option. To cancel maximum nesting level control,
+use @option{L} parameter witout any integer value after that, because any
+digit following @option{-} in the parameter string of the @option{-gnaty}
+option will be threated as canceling indentation check. The same is true
+for @option{M} parameter. @option{y} and @option{N} parameters are not
+allowed after @option{-}.
+
+@item +
+This causes any subsequent options in the string to enable the corresponding
+style check option. That is, it cancels the effect of a previous ^-^REMOVE^,
+if any.
+@end ifclear
+
+@ifset vms
+@item NOxxx
+@emph{Removing style check options}
+If the name of a style check is preceded by @option{NO} then the corresponding
+style check is turned off. For example @option{NOCOMMENTS} turns off style
+checking for comments.
+@end ifset
+@end table
+
@noindent
In the above rules, appearing in column one is always permitted, that is,
counts as meeting either a requirement for a required preceding space,
as meeting either a requirement for a following space, or as meeting
a requirement for no following space.
-@end table
-
@noindent
If any of these style rules is violated, a message is generated giving
details on the violation. The initial characters of such messages are
The switch
@ifclear vms
@option{-gnaty} on its own (that is not
-followed by any letters or digits),
-is equivalent to @code{gnaty3abcefhiklmprst}, that is all checking
-options enabled with the exception of -gnatyo,
+followed by any letters or digits), then the effect is equivalent
+to the use of @option{-gnatyy}, as described above, that is all
+built-in standard style check options are enabled.
+
@end ifclear
@ifset vms
/STYLE_CHECKS=ALL_BUILTIN enables all checking options with
-the exception of ORDERED_SUBPROGRAMS,
+the exception of ORDERED_SUBPROGRAMS, UNNECESSARY_BLANK_LINES,
+XTRA_PARENS, and DOS_LINE_ENDINGS. In addition
@end ifset
-with an indentation level of 3. This is the standard
-checking option that is used for the GNAT sources.
+
+
The switch
@ifclear vms
@cindex Access before elaboration
@cindex Checks, division by zero
@cindex Checks, access before elaboration
+@cindex Checks, stack overflow checking
@noindent
-If you compile with the default options, GNAT will insert many run-time
-checks into the compiled code, including code that performs range
-checking against constraints, but not arithmetic overflow checking for
-integer operations (including division by zero) or checks for access
-before elaboration on subprogram calls. All other run-time checks, as
-required by the Ada 95 Reference Manual, are generated by default.
-The following @code{gcc} switches refine this default behavior:
+By default, the following checks are suppressed: integer overflow
+checks, stack overflow checks, and checks for access before
+elaboration on subprogram calls. All other checks, including range
+checks and array bounds checks, are turned on by default. The
+following @command{gcc} switches refine this default behavior.
@table @option
@c !sort!
@item -gnatp
-@cindex @option{-gnatp} (@code{gcc})
+@cindex @option{-gnatp} (@command{gcc})
@cindex Suppressing checks
@cindex Checks, suppressing
@findex Suppress
-Suppress all run-time checks as though @code{pragma Suppress (all_checks})
+Suppress all run-time checks as though @code{pragma Suppress (All_checks)}
had been present in the source. Validity checks are also suppressed (in
other words @option{-gnatp} also implies @option{-gnatVn}.
Use this switch to improve the performance
of the code at the expense of safety in the presence of invalid data or
program bugs.
+Note that when checks are suppressed, the compiler is allowed, but not
+required, to omit the checking code. If the run-time cost of the
+checking code is zero or near-zero, the compiler will generate it even
+if checks are suppressed. In particular, if the compiler can prove
+that a certain check will necessarily fail, it will generate code to
+do an unconditional ``raise'', even if checks are suppressed. The
+compiler warns in this case.
+
+Of course, run-time checks are omitted whenever the compiler can prove
+that they will not fail, whether or not checks are suppressed.
+
+Note that if you suppress a check that would have failed, program
+execution is erroneous, which means the behavior is totally
+unpredictable. The program might crash, or print wrong answers, or
+do anything else. It might even do exactly what you wanted it to do
+(and then it might start failing mysteriously next week or next
+year). The compiler will generate code based on the assumption that
+the condition being checked is true, which can result in disaster if
+that assumption is wrong.
+
@item -gnato
-@cindex @option{-gnato} (@code{gcc})
+@cindex @option{-gnato} (@command{gcc})
@cindex Overflow checks
@cindex Check, overflow
Enables overflow checking for integer operations.
range of the result type. The following example shows the distinction:
@smallexample @c ada
-X1 : Integer := Integer'Last;
-X2 : Integer range 1 .. 5 := 5;
-X3 : Integer := Integer'Last;
-X4 : Integer range 1 .. 5 := 5;
-F : Float := 2.0E+20;
-...
+X1 : Integer := "Integer'Last";
+X2 : Integer range 1 .. 5 := "5";
+X3 : Integer := "Integer'Last";
+X4 : Integer range 1 .. 5 := "5";
+F : Float := "2.0E+20";
+@dots{}
X1 := X1 + 1;
X2 := X2 + 1;
X3 := Integer (F);
@end smallexample
@noindent
+Note that if explicit values are assigned at compile time, the
+compiler may be able to detect overflow at compile time, in which case
+no actual run-time checking code is required, and Constraint_Error
+will be raised unconditionally, with or without
+@option{-gnato}. That's why the assigned values in the above fragment
+are in quotes, the meaning is "assign a value not known to the
+compiler that happens to be equal to ...". The remaining discussion
+assumes that the compiler cannot detect the values at compile time.
+
Here the first addition results in a value that is outside the base range
of Integer, and hence requires an overflow check for detection of the
constraint error. Thus the first assignment to @code{X1} raises a
@code{Constraint_Error} exception only if @option{-gnato} is set.
-The second increment operation results in a violation
-of the explicit range constraint, and such range checks are always
-performed (unless specifically suppressed with a pragma @code{suppress}
-or the use of @option{-gnatp}).
+The second increment operation results in a violation of the explicit
+range constraint; such range checks are performed by default, and are
+unaffected by @option{-gnato}.
The two conversions of @code{F} both result in values that are outside
the base range of type @code{Integer} and thus will raise
(such as dividing 0.0 by 0.0).
The reason that we distinguish overflow checking from other kinds of
-range constraint checking is that a failure of an overflow check can
-generate an incorrect value, but cannot cause erroneous behavior. This
-is unlike the situation with a constraint check on an array subscript,
-where failure to perform the check can result in random memory description,
-or the range check on a case statement, where failure to perform the check
-can cause a wild jump.
+range constraint checking is that a failure of an overflow check, unlike
+for example the failure of a range check, can result in an incorrect
+value, but cannot cause random memory destruction (like an out of range
+subscript), or a wild jump (from an out of range case value). Overflow
+checking is also quite expensive in time and space, since in general it
+requires the use of double length arithmetic.
Note again that @option{-gnato} is off by default, so overflow checking is
not performed in default mode. This means that out of the box, with the
default settings, GNAT does not do all the checks expected from the
language description in the Ada Reference Manual. If you want all constraint
checks to be performed, as described in this Manual, then you must
-explicitly use the -gnato switch either on the @code{gnatmake} or
-@code{gcc} command.
+explicitly use the -gnato switch either on the @command{gnatmake} or
+@command{gcc} command.
@item -gnatE
-@cindex @option{-gnatE} (@code{gcc})
+@cindex @option{-gnatE} (@command{gcc})
@cindex Elaboration checks
@cindex Check, elaboration
Enables dynamic checks for access-before-elaboration
on subprogram calls and generic instantiations.
+Note that @option{-gnatE} is not necessary for safety, because in the
+default mode, GNAT ensures statically that the checks would not fail.
For full details of the effect and use of this switch,
@xref{Compiling Using gcc}.
+
+@item -fstack-check
+@cindex @option{-fstack-check} (@command{gcc})
+@cindex Stack Overflow Checking
+@cindex Checks, stack overflow checking
+Activates stack overflow checking. For full details of the effect and use of
+this switch see @ref{Stack Overflow Checking}.
@end table
@findex Unsuppress
checks) or @code{Unsuppress} (to add back suppressed checks) pragmas in
the program source.
-@node Stack Overflow Checking
-@subsection Stack Overflow Checking
-@cindex Stack Overflow Checking
-@cindex -fstack-check
-
-@noindent
-For most operating systems, @code{gcc} does not perform stack overflow
-checking by default. This means that if the main environment task or
-some other task exceeds the available stack space, then unpredictable
-behavior will occur.
-
-To activate stack checking, compile all units with the gcc option
-@option{-fstack-check}. For example:
-
-@smallexample
-gcc -c -fstack-check package1.adb
-@end smallexample
-
-@noindent
-Units compiled with this option will generate extra instructions to check
-that any use of the stack (for procedure calls or for declaring local
-variables in declare blocks) do not exceed the available stack space.
-If the space is exceeded, then a @code{Storage_Error} exception is raised.
-
-For declared tasks, the stack size is always controlled by the size
-given in an applicable @code{Storage_Size} pragma (or is set to
-the default size if no pragma is used.
-
-For the environment task, the stack size depends on
-system defaults and is unknown to the compiler. The stack
-may even dynamically grow on some systems, precluding the
-normal Ada semantics for stack overflow. In the worst case,
-unbounded stack usage, causes unbounded stack expansion
-resulting in the system running out of virtual memory.
-
-The stack checking may still work correctly if a fixed
-size stack is allocated, but this cannot be guaranteed.
-To ensure that a clean exception is signalled for stack
-overflow, set the environment variable
-@code{GNAT_STACK_LIMIT} to indicate the maximum
-stack area that can be used, as in:
-@cindex GNAT_STACK_LIMIT
-
-@smallexample
-SET GNAT_STACK_LIMIT 1600
-@end smallexample
-
-@noindent
-The limit is given in kilobytes, so the above declaration would
-set the stack limit of the environment task to 1.6 megabytes.
-Note that the only purpose of this usage is to limit the amount
-of stack used by the environment task. If it is necessary to
-increase the amount of stack for the environment task, then this
-is an operating systems issue, and must be addressed with the
-appropriate operating systems commands.
-
-
@node Using gcc for Syntax Checking
-@subsection Using @code{gcc} for Syntax Checking
+@subsection Using @command{gcc} for Syntax Checking
@table @option
@item -gnats
-@cindex @option{-gnats} (@code{gcc})
+@cindex @option{-gnats} (@command{gcc})
@ifclear vms
@noindent
(@pxref{Renaming Files Using gnatchop}).
@end table
-
@node Using gcc for Semantic Checking
-@subsection Using @code{gcc} for Semantic Checking
+@subsection Using @command{gcc} for Semantic Checking
@table @option
@item -gnatc
-@cindex @option{-gnatc} (@code{gcc})
+@cindex @option{-gnatc} (@command{gcc})
@ifclear vms
@noindent
@end ifclear
Causes the compiler to operate in semantic check mode,
with full checking for all illegalities specified in the
-Ada 95 Reference Manual, but without generation of any object code
+Ada Reference Manual, but without generation of any object code
(no object file is generated).
Because dependent files must be accessed, you must follow the GNAT
cross-reference tools, but this file is marked as not being suitable
for binding (since no object file is generated).
The checking corresponds exactly to the notion of
-legality in the Ada 95 Reference Manual.
+legality in the Ada Reference Manual.
Any unit can be compiled in semantics-checking-only mode, including
units that would not normally be compiled (subunits,
and specifications where a separate body is present).
@end table
-@node Compiling Ada 83 Programs
-@subsection Compiling Ada 83 Programs
+@node Compiling Different Versions of Ada
+@subsection Compiling Different Versions of Ada
+
+@noindent
+The switches described in this section allow you to explicitly specify
+the version of the Ada language that your programs are written in.
+By default @value{EDITION} assumes @value{DEFAULTLANGUAGEVERSION},
+but you can also specify @value{NONDEFAULTLANGUAGEVERSION} or
+indicate Ada 83 compatibility mode.
+
@table @option
-@cindex Ada 83 compatibility
-@item -gnat83
-@cindex @option{-gnat83} (@code{gcc})
+@cindex Compatibility with Ada 83
+
+@item -gnat83 (Ada 83 Compatibility Mode)
+@cindex @option{-gnat83} (@command{gcc})
@cindex ACVC, Ada 83 tests
+@cindex Ada 83 mode
@noindent
-Although GNAT is primarily an Ada 95 compiler, it accepts this switch to
-specify that an Ada 83 program is to be compiled in Ada 83 mode. If you specify
-this switch, GNAT rejects most Ada 95 extensions and applies Ada 83 semantics
-where this can be done easily.
+Although GNAT is primarily an Ada 95 / Ada 2005 compiler, this switch
+specifies that the program is to be compiled in Ada 83 mode. With
+@option{-gnat83}, GNAT rejects most post-Ada 83 extensions and applies Ada 83
+semantics where this can be done easily.
It is not possible to guarantee this switch does a perfect
-job; for example, some subtle tests, such as are
+job; some subtle tests, such as are
found in earlier ACVC tests (and that have been removed from the ACATS suite
for Ada 95), might not compile correctly.
Nevertheless, this switch may be useful in some circumstances, for example
-where, due to contractual reasons, legacy code needs to be maintained
+where, due to contractual reasons, existing code needs to be maintained
using only Ada 83 features.
With few exceptions (most notably the need to use @code{<>} on
@cindex Generic formal parameters
-unconstrained generic formal parameters, the use of the new Ada 95
+unconstrained generic formal parameters, the use of the new Ada 95 / Ada 2005
reserved words, and the use of packages
-with optional bodies), it is not necessary to use the
+with optional bodies), it is not necessary to specify the
@option{-gnat83} switch when compiling Ada 83 programs, because, with rare
-exceptions, Ada 95 is upwardly compatible with Ada 83. This
-means that a correct Ada 83 program is usually also a correct Ada 95
-program.
+exceptions, Ada 95 and Ada 2005 are upwardly compatible with Ada 83. Thus
+a correct Ada 83 program is usually also a correct program
+in these later versions of the language standard.
For further information, please refer to @ref{Compatibility and Porting Guide}.
+@item -gnat95 (Ada 95 mode)
+@cindex @option{-gnat95} (@command{gcc})
+@cindex Ada 95 mode
+
+@noindent
+This switch directs the compiler to implement the Ada 95 version of the
+language.
+Since Ada 95 is almost completely upwards
+compatible with Ada 83, Ada 83 programs may generally be compiled using
+this switch (see the description of the @option{-gnat83} switch for further
+information about Ada 83 mode).
+If an Ada 2005 program is compiled in Ada 95 mode,
+uses of the new Ada 2005 features will cause error
+messages or warnings.
+
+This switch also can be used to cancel the effect of a previous
+@option{-gnat83} or @option{-gnat05} switch earlier in the command line.
+
+@item -gnat05 (Ada 2005 mode)
+@cindex @option{-gnat05} (@command{gcc})
+@cindex Ada 2005 mode
+
+@noindent
+This switch directs the compiler to implement the Ada 2005 version of the
+language.
+Since Ada 2005 is almost completely upwards
+compatible with Ada 95 (and thus also with Ada 83), Ada 83 and Ada 95 programs
+may generally be compiled using this switch (see the description of the
+@option{-gnat83} and @option{-gnat95} switches for further
+information).
+
+For information about the approved ``Ada Issues'' that have been incorporated
+into Ada 2005, see @url{http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs}.
+Included with GNAT releases is a file @file{features-ada0y} that describes
+the set of implemented Ada 2005 features.
@end table
+
@node Character Set Control
@subsection Character Set Control
@table @option
@item ^-gnati^/IDENTIFIER_CHARACTER_SET=^@var{c}
-@cindex @option{^-gnati^/IDENTIFIER_CHARACTER_SET^} (@code{gcc})
+@cindex @option{^-gnati^/IDENTIFIER_CHARACTER_SET^} (@command{gcc})
@noindent
Normally GNAT recognizes the Latin-1 character set in source program
-identifiers, as described in the Ada 95 Reference Manual.
+identifiers, as described in the Ada Reference Manual.
This switch causes
GNAT to recognize alternate character sets in identifiers. @var{c} is a
single character ^^or word^ indicating the character set, as follows:
implementation of these character sets.
@item ^-gnatW^/WIDE_CHARACTER_ENCODING=^@var{e}
-@cindex @option{^-gnatW^/WIDE_CHARACTER_ENCODING^} (@code{gcc})
+@cindex @option{^-gnatW^/WIDE_CHARACTER_ENCODING^} (@command{gcc})
Specify the method of encoding for wide characters.
@var{e} is one of the following:
@item ^b^BRACKETS^
Brackets encoding only (default value)
@end table
-For full details on the these encoding
-methods see @xref{Wide Character Encodings}.
+For full details on these encoding
+methods see @ref{Wide Character Encodings}.
Note that brackets coding is always accepted, even if one of the other
options is specified, so for example @option{-gnatW8} specifies that both
-brackets and @code{UTF-8} encodings will be recognized. The units that are
+brackets and UTF-8 encodings will be recognized. The units that are
with'ed directly or indirectly will be scanned using the specified
representation scheme, and so if one of the non-brackets scheme is
used, it must be used consistently throughout the program. However,
since brackets encoding is always recognized, it may be conveniently
used in standard libraries, allowing these libraries to be used with
any of the available coding schemes.
-scheme. If no @option{-gnatW?} parameter is present, then the default
-representation is Brackets encoding only.
+scheme.
+
+If no @option{-gnatW?} parameter is present, then the default
+representation is normally Brackets encoding only. However, if the
+first three characters of the file are 16#EF# 16#BB# 16#BF# (the standard
+byte order mark or BOM for UTF-8), then these three characters are
+skipped and the default representation for the file is set to UTF-8.
Note that the wide character representation that is specified (explicitly
or by default) for the main program also acts as the default encoding used
@table @option
@item ^-gnatk^/FILE_NAME_MAX_LENGTH=^@var{n}
-@cindex @option{-gnatk} (@code{gcc})
+@cindex @option{-gnatk} (@command{gcc})
Activates file name ``krunching''. @var{n}, a decimal integer in the range
1-999, indicates the maximum allowable length of a file name (not
including the @file{.ads} or @file{.adb} extension). The default is not
For the source file naming rules, @xref{File Naming Rules}.
@end table
-
@node Subprogram Inlining Control
@subsection Subprogram Inlining Control
@table @option
@c !sort!
@item -gnatn
-@cindex @option{-gnatn} (@code{gcc})
+@cindex @option{-gnatn} (@command{gcc})
@ifclear vms
The @code{n} here is intended to suggest the first syllable of the
word ``inline''.
creating an extra source dependency for the resulting object file, and
where possible, the call will be inlined.
For further details on when inlining is possible
-see @xref{Inlining of Subprograms}.
+see @ref{Inlining of Subprograms}.
@item -gnatN
-@cindex @option{-gnatN} (@code{gcc})
-The front end inlining activated by this switch is generally more extensive,
-and quite often more effective than the standard @option{-gnatn} inlining mode.
-It will also generate additional dependencies.
-Note that
-@option{-gnatN} automatically implies @option{-gnatn} so it is not necessary
-to specify both options.
+@cindex @option{-gnatN} (@command{gcc})
+This switch activates front-end inlining which also
+generates additional dependencies.
+
+When using a gcc-based back end (in practice this means using any version
+of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of
+@option{-gnatN} is deprecated, and the use of @option{-gnatn} is preferred.
+Historically front end inlining was more extensive than the gcc back end
+inlining, but that is no longer the case.
@end table
@node Auxiliary Output Control
@table @option
@item -gnatt
-@cindex @option{-gnatt} (@code{gcc})
+@cindex @option{-gnatt} (@command{gcc})
@cindex Writing internal trees
@cindex Internal trees, writing to file
Causes GNAT to write the internal tree for a unit to a file (with the
not have to specify this switch in normal operation.
@item -gnatu
-@cindex @option{-gnatu} (@code{gcc})
+@cindex @option{-gnatu} (@command{gcc})
Print a list of units required by this compilation on @file{stdout}.
The listing includes all units on which the unit being compiled depends
either directly or indirectly.
@ifclear vms
@item -pass-exit-codes
-@cindex @option{-pass-exit-codes} (@code{gcc})
-If this switch is not used, the exit code returned by @code{gcc} when
+@cindex @option{-pass-exit-codes} (@command{gcc})
+If this switch is not used, the exit code returned by @command{gcc} when
compiling multiple files indicates whether all source files have
been successfully used to generate object files or not.
-When @option{-pass-exit-codes} is used, @code{gcc} exits with an extended
+When @option{-pass-exit-codes} is used, @command{gcc} exits with an extended
exit status and allows an integrated development environment to better
react to a compilation failure. Those exit status are:
@cindex Debugging options
@ifclear vms
@item -gnatd@var{x}
-@cindex @option{-gnatd} (@code{gcc})
+@cindex @option{-gnatd} (@command{gcc})
Activate internal debugging switches. @var{x} is a letter or digit, or
string of letters or digits, which specifies the type of debugging
outputs desired. Normally these are used only for internal development
file @file{debug.adb}.
@end ifclear
-@item -gnatG
-@cindex @option{-gnatG} (@code{gcc})
+@item -gnatG[=nn]
+@cindex @option{-gnatG} (@command{gcc})
This switch causes the compiler to generate auxiliary output containing
a pseudo-source listing of the generated expanded code. Like most Ada
compilers, GNAT works by first transforming the high level Ada code into
is to list this expanded code in a form very close to normal Ada source.
This is very useful in understanding the implications of various Ada
usage on the efficiency of the generated code. There are many cases in
-Ada (e.g. the use of controlled types), where simple Ada statements can
+Ada (e.g.@: the use of controlled types), where simple Ada statements can
generate a lot of run-time code. By using @option{-gnatG} you can identify
these cases, and consider whether it may be desirable to modify the coding
approach to improve efficiency.
+The optional parameter @code{nn} if present after -gnatG specifies an
+alternative maximum line length that overrides the normal default of 72.
+This value is in the range 40-999999, values less than 40 being silently
+reset to 40. The equal sign is optional.
+
The format of the output is very similar to standard Ada source, and is
easily understood by an Ada programmer. The following special syntactic
additions correspond to low level features used in the generated code that
do not have any exact analogies in pure Ada source form. The following
-is a partial list of these special constructions. See the specification
+is a partial list of these special constructions. See the spec
of package @code{Sprint} in file @file{sprint.ads} for a full list.
+If the switch @option{-gnatL} is used in conjunction with
+@cindex @option{-gnatL} (@command{gcc})
+@option{-gnatG}, then the original source lines are interspersed
+in the expanded source (as comment lines with the original line number).
+
@table @code
-@item new @var{xxx} [storage_pool = @var{yyy}]
+@item new @var{xxx} @r{[}storage_pool = @var{yyy}@r{]}
Shows the storage pool being used for an allocator.
@item at end @var{procedure-name};
A division or multiplication of fixed-point values which are treated as
integers without any kind of scaling.
-@item free @var{expr} [storage_pool = @var{xxx}]
+@item free @var{expr} @r{[}storage_pool = @var{xxx}@r{]}
Shows the storage pool associated with a @code{free} statement.
-@item freeze @var{typename} [@var{actions}]
-Shows the point at which @var{typename} is frozen, with possible
+@item [subtype or type declaration]
+Used to list an equivalent declaration for an internally generated
+type that is referenced elsewhere in the listing.
+
+@item freeze @var{type-name} @ovar{actions}
+Shows the point at which @var{type-name} is frozen, with possible
associated actions to be performed at the freeze point.
@item reference @var{itype}
@item @var{function-name}! (@var{arg}, @var{arg}, @var{arg})
Intrinsic function call.
-@item @var{labelname} : label
+@item @var{label-name} : label
Declaration of label @var{labelname}.
-@item @var{expr} && @var{expr} && @var{expr} ... && @var{expr}
+@item #$ @var{subprogram-name}
+An implicit call to a run-time support routine
+(to meet the requirement of H.3.1(9) in a
+convenient manner).
+
+@item @var{expr} && @var{expr} && @var{expr} @dots{} && @var{expr}
A multiple concatenation (same effect as @var{expr} & @var{expr} &
@var{expr}, but handled more efficiently).
evaluation of the expression 1.0/27.0).
@end table
-@item -gnatD
-@cindex @option{-gnatD} (@code{gcc})
+@item -gnatD[=nn]
+@cindex @option{-gnatD} (@command{gcc})
When used in conjunction with @option{-gnatG}, this switch causes
the expanded source, as described above for
@option{-gnatG} to be written to files with names
@file{^xxx.dg^XXX_DG^}, where @file{xxx} is the normal file name,
-instead of to the standard ooutput file. For
+instead of to the standard output file. For
example, if the source file name is @file{hello.adb}, then a file
@file{^hello.adb.dg^HELLO.ADB_DG^} will be written. The debugging
-information generated by the @code{gcc} @option{^-g^/DEBUG^} switch
+information generated by the @command{gcc} @option{^-g^/DEBUG^} switch
will refer to the generated @file{^xxx.dg^XXX_DG^} file. This allows
you to do source level debugging using the generated code which is
sometimes useful for complex code, for example to find out exactly
automatically, so it is not necessary to give both options.
In other words @option{-gnatD} is equivalent to @option{-gnatDG}).
+If the switch @option{-gnatL} is used in conjunction with
+@cindex @option{-gnatL} (@command{gcc})
+@option{-gnatDG}, then the original source lines are interspersed
+in the expanded source (as comment lines with the original line number).
+
+The optional parameter @code{nn} if present after -gnatD specifies an
+alternative maximum line length that overrides the normal default of 72.
+This value is in the range 40-999999, values less than 40 being silently
+reset to 40. The equal sign is optional.
+
+@item -gnatr
+@cindex @option{-gnatr} (@command{gcc})
+@cindex pragma Restrictions
+This switch causes pragma Restrictions to be treated as Restriction_Warnings
+so that violation of restrictions causes warnings rather than illegalities.
+This is useful during the development process when new restrictions are added
+or investigated. The switch also causes pragma Profile to be treated as
+Profile_Warnings, and pragma Restricted_Run_Time and pragma Ravenscar set
+restriction warnings rather than restrictions.
+
@ifclear vms
-@item -gnatR[0|1|2|3[s]]
-@cindex @option{-gnatR} (@code{gcc})
+@item -gnatR@r{[}0@r{|}1@r{|}2@r{|}3@r{[}s@r{]]}
+@cindex @option{-gnatR} (@command{gcc})
This switch controls output from the compiler of a listing showing
representation information for declared types and objects. For
@option{-gnatR0}, no information is output (equivalent to omitting
so @option{-gnatR} with no parameter has the same effect), size and alignment
information is listed for declared array and record types. For
@option{-gnatR2}, size and alignment information is listed for all
-expression information for values that are computed at run time for
+declared types and objects. Finally @option{-gnatR3} includes symbolic
+expressions for values that are computed at run time for
variant records. These symbolic expressions have a mostly obvious
format with #n being used to represent the value of the n'th
discriminant. See source files @file{repinfo.ads/adb} in the
@code{GNAT} sources for full details on the format of @option{-gnatR3}
-output. If the switch is followed by an s (e.g. @option{-gnatR2s}), then
+output. If the switch is followed by an s (e.g.@: @option{-gnatR2s}), then
the output is to a file with the name @file{^file.rep^file_REP^} where
file is the name of the corresponding source file.
@end ifclear
@ifset vms
@item /REPRESENTATION_INFO
-@cindex @option{/REPRESENTATION_INFO} (@code{gcc})
+@cindex @option{/REPRESENTATION_INFO} (@command{gcc})
This qualifier controls output from the compiler of a listing showing
representation information for declared types and objects. For
@option{/REPRESENTATION_INFO=NONE}, no information is output
@code{GNAT} sources for full details on the format of
@option{/REPRESENTATION_INFO=SYMBOLIC} output.
If _FILE is added at the end of an option
-(e.g. @option{/REPRESENTATION_INFO=ARRAYS_FILE}),
+(e.g.@: @option{/REPRESENTATION_INFO=ARRAYS_FILE}),
then the output is to a file with the name @file{file_REP} where
file is the name of the corresponding source file.
@end ifset
+Note that it is possible for record components to have zero size. In
+this case, the component clause uses an obvious extension of permitted
+Ada syntax, for example @code{at 0 range 0 .. -1}.
+
+Representation information requires that code be generated (since it is the
+code generator that lays out complex data structures). If an attempt is made
+to output representation information when no code is generated, for example
+when a subunit is compiled on its own, then no information can be generated
+and the compiler outputs a message to this effect.
@item -gnatS
-@cindex @option{-gnatS} (@code{gcc})
+@cindex @option{-gnatS} (@command{gcc})
The use of the switch @option{-gnatS} for an
Ada compilation will cause the compiler to output a
representation of package Standard in a form very
types in package Standard.
@item -gnatx
-@cindex @option{-gnatx} (@code{gcc})
+@cindex @option{-gnatx} (@command{gcc})
Normally the compiler generates full cross-referencing information in
the @file{ALI} file. This information is used by a number of tools,
including @code{gnatfind} and @code{gnatxref}. The @option{-gnatx} switch
@noindent
GNAT uses two methods for handling exceptions at run-time. The
-@code{longjmp/setjmp} method saves the context when entering
+@code{setjmp/longjmp} method saves the context when entering
a frame with an exception handler. Then when an exception is
raised, the context can be restored immediately, without the
need for tracing stack frames. This method provides very fast
subprogram invocation stack to locate the required exception
handler. This method has considerably poorer performance for
the propagation of exceptions, but there is no overhead for
-exception handlers if no exception is raised.
+exception handlers if no exception is raised. Note that in this
+mode and in the context of mixed Ada and C/C++ programming,
+to propagate an exception through a C/C++ code, the C/C++ code
+must be compiled with the @option{-funwind-tables} GCC's
+option.
-The following switches can be used to control which of the
+The following switches may be used to control which of the
two exception handling methods is used.
@table @option
@c !sort!
-@item -gnatL
-@cindex @option{-gnatL} (@code{gcc})
-This switch causes the longjmp/setjmp approach to be used
-for exception handling. If this is the default mechanism for the
-target (see below), then this has no effect. If the default
+@item --RTS=sjlj
+@cindex @option{--RTS=sjlj} (@command{gnatmake})
+This switch causes the setjmp/longjmp run-time (when available) to be used
+for exception handling. If the default
mechanism for the target is zero cost exceptions, then
-this switch can be used to modify this default, but it must be
-used for all units in the partition, including all run-time
-library units. One way to achieve this is to use the
-@option{-a} and @option{-f} switches for @code{gnatmake}.
+this switch can be used to modify this default, and must be
+used for all units in the partition.
This option is rarely used. One case in which it may be
advantageous is if you have an application where exception
raising is common and the overall performance of the
application is improved by favoring exception propagation.
-@item -gnatZ
-@cindex @option{-gnatZ} (@code{gcc})
+@item --RTS=zcx
+@cindex @option{--RTS=zcx} (@command{gnatmake})
@cindex Zero Cost Exceptions
-This switch causes the zero cost approach to be sed
+This switch causes the zero cost approach to be used
for exception handling. If this is the default mechanism for the
-target (see below), then this has no effect. If the default
-mechanism for the target is longjmp/setjmp exceptions, then
-this switch can be used to modify this default, but it must be
-used for all units in the partition, including all run-time
-library units. One way to achieve this is to use the
-@option{-a} and @option{-f} switches for @code{gnatmake}.
+target (see below), then this switch is unneeded. If the default
+mechanism for the target is setjmp/longjmp exceptions, then
+this switch can be used to modify this default, and must be
+used for all units in the partition.
This option can only be used if the zero cost approach
-is available for the target in use (see below).
+is available for the target in use, otherwise it will generate an error.
@end table
@noindent
-The @code{longjmp/setjmp} approach is available on all targets, but
-the @code{zero cost} approach is only available on selected targets.
-To determine whether zero cost exceptions can be used for a
-particular target, look at the private part of the file system.ads.
-Either @code{GCC_ZCX_Support} or @code{Front_End_ZCX_Support} must
-be True to use the zero cost approach. If both of these switches
-are set to False, this means that zero cost exception handling
-is not yet available for that target. The switch
-@code{ZCX_By_Default} indicates the default approach. If this
-switch is set to True, then the @code{zero cost} approach is
-used by default.
+The same option @option{--RTS} must be used both for @command{gcc}
+and @command{gnatbind}. Passing this option to @command{gnatmake}
+(@pxref{Switches for gnatmake}) will ensure the required consistency
+through the compilation and binding steps.
@node Units to Sources Mapping Files
@subsection Units to Sources Mapping Files
@table @option
@item -gnatem^^=^@var{path}
-@cindex @option{-gnatem} (@code{gcc})
+@cindex @option{-gnatem} (@command{gcc})
A mapping file is a way to communicate to the compiler two mappings:
from unit names to file names (without any directory information) and from
file names to path names (with full directory information). These mappings
you need not be concerned with the format or use of mapping files,
and the @option{-gnatem} switch is not a switch that you would use
explicitly. it is intended only for use by automatic tools such as
-@code{gnatmake} running under the project file facility. The
+@command{gnatmake} running under the project file facility. The
description here of the format of mapping files is provided
for completeness and for possible use by other tools.
A mapping file is a sequence of sets of three lines. In each set,
the first line is the unit name, in lower case, with ``@code{%s}''
appended for
-specifications and ``@code{%b}'' appended for bodies; the second line is the
+specs and ``@code{%b}'' appended for bodies; the second line is the
file name; and the third line is the path name.
Example:
When the switch @option{-gnatem} is specified, the compiler will create
in memory the two mappings from the specified file. If there is any problem
-(non existent file, truncated file or duplicate entries), no mapping
-will be created.
+(nonexistent file, truncated file or duplicate entries), no mapping will
+be created.
Several @option{-gnatem} switches may be specified; however, only the last
one on the command line will be taken into account.
-When using a project file, @code{gnatmake} create a temporary mapping file
+When using a project file, @command{gnatmake} create a temporary mapping file
and communicates it to the compiler using this switch.
@end table
-
@node Integrated Preprocessing
@subsection Integrated Preprocessing
@noindent
-GNAT sources may be preprocessed immediately before compilation; the actual
+GNAT sources may be preprocessed immediately before compilation.
+In this case, the actual
text of the source is not the text of the source file, but is derived from it
through a process called preprocessing. Integrated preprocessing is specified
through switches @option{-gnatep} and/or @option{-gnateD}. @option{-gnatep}
@option{-gnateD} specifies or modifies the values of preprocessing symbol.
@noindent
-It is recommended that @code{gnatmake} switch ^-s^/SWITCH_CHECK^ should be
+Note that when integrated preprocessing is used, the output from the
+preprocessor is not written to any external file. Instead it is passed
+internally to the compiler. If you need to preserve the result of
+preprocessing in a file, then you should use @command{gnatprep}
+to perform the desired preprocessing in stand-alone mode.
+
+@noindent
+It is recommended that @command{gnatmake} switch ^-s^/SWITCH_CHECK^ should be
used when Integrated Preprocessing is used. The reason is that preprocessing
with another Preprocessing Data file without changing the sources will
not trigger recompilation without this switch.
@noindent
-Note that @code{gnatmake} switch ^-m^/MINIMAL_RECOMPILATION^ will almost
+Note that @command{gnatmake} switch ^-m^/MINIMAL_RECOMPILATION^ will almost
always trigger recompilation for sources that are preprocessed,
-because @code{gnatmake} cannot compute the checksum of the source after
+because @command{gnatmake} cannot compute the checksum of the source after
preprocessing.
@noindent
@table @code
@item -gnatep=@var{file}
-@cindex @option{-gnatep} (@code{gcc})
+@cindex @option{-gnatep} (@command{gcc})
This switch indicates to the compiler the file name (without directory
information) of the preprocessor data file to use. The preprocessor data file
should be found in the source directories.
@noindent
A preprocessing data file is a text file with significant lines indicating
how should be preprocessed either a specific source or all sources not
-mentioned in other lines. A significant line is a non empty, non comment line.
+mentioned in other lines. A significant line is a nonempty, non-comment line.
Comments are similar to Ada comments.
@noindent
@noindent
After the file name or the character '*', another optional literal string
-indicating the file name of the definition file to be used for preprocessing.
-(see @ref{Form of Definitions File}. The definition files are found by the
+indicating the file name of the definition file to be used for preprocessing
+(@pxref{Form of Definitions File}). The definition files are found by the
compiler in one of the source directories. In some cases, when compiling
a source in a directory other than the current directory, if the definition
file is in the current directory, it may be necessary to add the current
-- list all symbols with their values.
@end smallexample
-@item ^-gnateD^/DATA_PREPROCESSING=^symbol[=value]
-@cindex @option{-gnateD} (@code{gcc})
+@item ^-gnateD^/DATA_PREPROCESSING=^symbol@r{[}=value@r{]}
+@cindex @option{-gnateD} (@command{gcc})
Define or redefine a preprocessing symbol, associated with value. If no value
is given on the command line, then the value of the symbol is @code{True}.
A symbol is an identifier, following normal Ada (case-insensitive)
@noindent
This switch is similar to switch @option{^-D^/ASSOCIATE^} of @code{gnatprep}.
+@item -gnateG
+When integrated preprocessing is performed and the preprocessor modifies
+the source text, write the result of this preprocessing into a file
+<source>^.prep^_prep^.
+
@end table
@node Code Generation Control
The GCC technology provides a wide range of target dependent
@option{-m} switches for controlling
details of code generation with respect to different versions of
-architectures. This includes variations in instruction sets (e.g.
+architectures. This includes variations in instruction sets (e.g.@:
different members of the power pc family), and different requirements
-for optimal arrangement of instructions (e.g. different members of
+for optimal arrangement of instructions (e.g.@: different members of
the x86 family). The list of available @option{-m} switches may be
found in the GCC documentation.
-Use of the these @option{-m} switches may in some cases result in improved
+Use of these @option{-m} switches may in some cases result in improved
code performance.
The GNAT Pro technology is tested and qualified without any
@noindent
On VMS, GNAT compiled programs return POSIX-style codes by default,
-e.g. @option{/RETURN_CODES=POSIX}.
+e.g.@: @option{/RETURN_CODES=POSIX}.
-To enable VMS style return codes, GNAT LINK with the option
+To enable VMS style return codes, use GNAT BIND and LINK with the option
@option{/RETURN_CODES=VMS}. For example:
@smallexample
+GNAT BIND MYMAIN.ALI /RETURN_CODES=VMS
GNAT LINK MYMAIN.ALI /RETURN_CODES=VMS
@end smallexample
@end ifset
-
@node Search Paths and the Run-Time Library (RTL)
@section Search Paths and the Run-Time Library (RTL)
@item
Each directory named by an @option{^-I^/SOURCE_SEARCH^} switch given on the
-@code{gcc} command line, in the order given.
+@command{gcc} command line, in the order given.
+
+@item
+@findex ADA_PRJ_INCLUDE_FILE
+Each of the directories listed in the text file whose name is given
+by the @env{ADA_PRJ_INCLUDE_FILE} ^environment variable^logical name^.
+
+@noindent
+@env{ADA_PRJ_INCLUDE_FILE} is normally set by gnatmake or by the ^gnat^GNAT^
+driver when project files are used. It should not normally be set
+by other means.
@item
@findex ADA_INCLUDE_PATH
Each of the directories listed in the value of the
-@code{ADA_INCLUDE_PATH} ^environment variable^logical name^.
+@env{ADA_INCLUDE_PATH} ^environment variable^logical name^.
@ifclear vms
Construct this value
-exactly as the @code{PATH} environment variable: a list of directory
+exactly as the @env{PATH} environment variable: a list of directory
names separated by colons (semicolons when working with the NT version).
@end ifclear
@ifset vms
list of directory names.
This variable can also be defined by means of an environment string
-(an argument to the DEC C exec* set of functions).
+(an argument to the HP C exec* set of functions).
Logical Name:
@smallexample
@end smallexample
By default, the path includes GNU:[LIB.OPENVMS7_x.2_8_x.DECLIB]
-first, followed by the standard Ada 95
+first, followed by the standard Ada
libraries in GNU:[LIB.OPENVMS7_x.2_8_x.ADAINCLUDE].
-If this is not redefined, the user will obtain the DEC Ada 83 IO packages
+If this is not redefined, the user will obtain the HP Ada 83 IO packages
(Text_IO, Sequential_IO, etc)
-instead of the Ada95 packages. Thus, in order to get the Ada 95
+instead of the standard Ada packages. Thus, in order to get the standard Ada
packages by default, ADA_INCLUDE_PATH must be redefined.
@end ifset
@item
-@findex ADA_PRJ_INCLUDE_FILE
-Each of the directories listed in the text file whose name is given
-by the @code{ADA_PRJ_INCLUDE_FILE} ^environment variable^logical name^.
-
-@noindent
-@code{ADA_PRJ_INCLUDE_FILE} is normally set by gnatmake or by the ^gnat^GNAT^
-driver when project files are used. It should not normally be set
-by other means.
-
-@item
The content of the @file{ada_source_path} file which is part of the GNAT
installation tree and is used to store standard libraries such as the
GNAT Run Time Library (RTL) source files.
@ifclear vms
-@ref{Installing the library}
+@ref{Installing a library}
@end ifclear
@end enumerate
working directory.
@ifclear vms
Caution: The object file can be redirected with the @option{-o} switch;
-however, @code{gcc} and @code{gnat1} have not been coordinated on this
+however, @command{gcc} and @code{gnat1} have not been coordinated on this
so the @file{ALI} file will not go to the right place. Therefore, you should
avoid using the @option{-o} switch.
@end ifclear
In addition to the language-defined hierarchies (@code{System}, @code{Ada} and
@code{Interfaces}), the GNAT distribution provides a fourth hierarchy,
consisting of child units of @code{GNAT}. This is a collection of generally
-useful types, subprograms, etc. See the @cite{GNAT Reference Manual} for
-further details.
+useful types, subprograms, etc. @xref{Top, GNAT Reference Manual, About
+This Guid, gnat_rm, GNAT Reference Manual}, for further details.
Besides simplifying access to the RTL, a major use of search paths is
in compiling sources from multiple directories. This can make
development environments much more flexible.
-
@node Order of Compilation Issues
@section Order of Compilation Issues
@noindent
This chapter describes the GNAT binder, @code{gnatbind}, which is used
-to bind compiled GNAT objects. The @code{gnatbind} program performs
-four separate functions:
+to bind compiled GNAT objects.
+
+Note: to invoke @code{gnatbind} with a project file, use the @code{gnat}
+driver (see @ref{The GNAT Driver and Project Files}).
+
+The @code{gnatbind} program performs four separate functions:
@enumerate
@item
Checks that a program is consistent, in accordance with the rules in
-Chapter 10 of the Ada 95 Reference Manual. In particular, error
+Chapter 10 of the Ada Reference Manual. In particular, error
messages are generated if a program uses inconsistent versions of a
given unit.
@item
Checks that an acceptable order of elaboration exists for the program
and issues an error message if it cannot find an order of elaboration
-that satisfies the rules in Chapter 10 of the Ada 95 Language Manual.
+that satisfies the rules in Chapter 10 of the Ada Language Manual.
@item
Generates a main program incorporating the given elaboration order.
This program is a small Ada package (body and spec) that
must be subsequently compiled
using the GNAT compiler. The necessary compilation step is usually
-performed automatically by @code{gnatlink}. The two most important
+performed automatically by @command{gnatlink}. The two most important
functions of this program
are to call the elaboration routines of units in an appropriate order
and to call the main program.
@item
Determines the set of object files required by the given main program.
This information is output in the forms of comments in the generated program,
-to be read by the @code{gnatlink} utility used to link the Ada application.
+to be read by the @command{gnatlink} utility used to link the Ada application.
@end enumerate
-
@node Running gnatbind
@section Running @code{gnatbind}
The form of the @code{gnatbind} command is
@smallexample
-$ gnatbind [@i{switches}] @i{mainprog}[.ali] [@i{switches}]
+$ gnatbind @ovar{switches} @var{mainprog}@r{[}.ali@r{]} @ovar{switches}
@end smallexample
@noindent
-where @file{@i{mainprog}.adb} is the Ada file containing the main program
+where @file{@var{mainprog}.adb} is the Ada file containing the main program
unit body. If no switches are specified, @code{gnatbind} constructs an Ada
package in two files whose names are
-@file{b~@i{mainprog}.ads}, and @file{b~@i{mainprog}.adb}.
+@file{b~@var{mainprog}.ads}, and @file{b~@var{mainprog}.adb}.
For example, if given the
parameter @file{hello.ali}, for a main program contained in file
@file{hello.adb}, the binder output files would be @file{b~hello.ads}
file is @file{pack.ali} and whose corresponding source spec file is
@file{pack.ads}, it attempts to locate the source file @file{pack.ads}
(using the same search path conventions as previously described for the
-@code{gcc} command). If it can locate this source file, it checks that
+@command{gcc} command). If it can locate this source file, it checks that
the time stamps
or source checksums of the source and its references to in @file{ALI} files
match. In other words, any @file{ALI} files that mentions this spec must have
are generating a mixed language program with the main program in C. The
GNAT compiler itself is an example.
The use of the @option{^-C^/BIND_FILE=C^} switch
-for both @code{gnatbind} and @code{gnatlink} will cause the program to
+for both @code{gnatbind} and @command{gnatlink} will cause the program to
be generated in C (and compiled using the gnu C compiler).
-
@node Switches for gnatbind
@section Switches for @command{gnatbind}
@table @option
@c !sort!
+
+@item --version
+@cindex @option{--version} @command{gnatbind}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatbind}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
+@item -a
+@cindex @option{-a} @command{gnatbind}
+Indicates that, if supported by the platform, the adainit procedure should
+be treated as an initialisation routine by the linker (a constructor). This
+is intended to be used by the Project Manager to automatically initialize
+shared Stand-Alone Libraries.
+
@item ^-aO^/OBJECT_SEARCH^
@cindex @option{^-aO^/OBJECT_SEARCH^} (@command{gnatbind})
Specify directory to be searched for ALI files.
@cindex @option{^-C^/BIND_FILE=C^} (@command{gnatbind})
Generate binder program in C
+@item ^-d^/DEFAULT_STACK_SIZE=^@var{nn}@r{[}k@r{|}m@r{]}
+@cindex @option{^-d^/DEFAULT_STACK_SIZE=^@var{nn}@r{[}k@r{|}m@r{]}} (@command{gnatbind})
+This switch can be used to change the default task stack size value
+to a specified size @var{nn}, which is expressed in bytes by default, or
+in kilobytes when suffixed with @var{k} or in megabytes when suffixed
+with @var{m}.
+In the absence of a @samp{@r{[}k@r{|}m@r{]}} suffix, this switch is equivalent,
+in effect, to completing all task specs with
+@smallexample @c ada
+ pragma Storage_Size (nn);
+@end smallexample
+When they do not already have such a pragma.
+
+@item ^-D^/DEFAULT_SECONDARY_STACK_SIZE=^@var{nn}@r{[}k@r{|}m@r{]}
+@cindex @option{^-D^/DEFAULT_SECONDARY_STACK_SIZE=nnnnn^} (@command{gnatbind})
+This switch can be used to change the default secondary stack size value
+to a specified size @var{nn}, which is expressed in bytes by default, or
+in kilobytes when suffixed with @var{k} or in megabytes when suffixed
+with @var{m}.
+
+The secondary stack is used to deal with functions that return a variable
+sized result, for example a function returning an unconstrained
+String. There are two ways in which this secondary stack is allocated.
+
+For most targets, the secondary stack is growing on demand and is allocated
+as a chain of blocks in the heap. The -D option is not very
+relevant. It only give some control over the size of the allocated
+blocks (whose size is the minimum of the default secondary stack size value,
+and the actual size needed for the current allocation request).
+
+For certain targets, notably VxWorks 653,
+the secondary stack is allocated by carving off a fixed ratio chunk of the
+primary task stack. The -D option is used to define the
+size of the environment task's secondary stack.
+
@item ^-e^/ELABORATION_DEPENDENCIES^
@cindex @option{^-e^/ELABORATION_DEPENDENCIES^} (@command{gnatbind})
Output complete list of elaboration-order dependencies.
@code{GNAT.Traceback.Symbolic} for more information.
@ifclear vms
Note that on x86 ports, you must not use @option{-fomit-frame-pointer}
-@code{gcc} option.
+@command{gcc} option.
@end ifclear
@item ^-F^/FORCE_ELABS_FLAGS^
@cindex @option{^-l^/ORDER_OF_ELABORATION^} (@command{gnatbind})
Output chosen elaboration order.
-@item ^-Lxxx^/BUILD_LIBRARY=xxx^
+@item ^-L@var{xxx}^/BUILD_LIBRARY=@var{xxx}^
@cindex @option{^-L^/BUILD_LIBRARY^} (@command{gnatbind})
-Binds the units for library building. In this case the adainit and
-adafinal procedures (See @pxref{Binding with Non-Ada Main Programs})
-are renamed to ^xxxinit^XXXINIT^ and
-^xxxfinal^XXXFINAL^.
+Bind the units for library building. In this case the adainit and
+adafinal procedures (@pxref{Binding with Non-Ada Main Programs})
+are renamed to ^@var{xxx}init^@var{XXX}INIT^ and
+^@var{xxx}final^@var{XXX}FINAL^.
Implies ^-n^/NOCOMPILE^.
@ifclear vms
-(@pxref{GNAT and Libraries}, for more details.)
+(@xref{GNAT and Libraries}, for more details.)
@end ifclear
@ifset vms
On OpenVMS, these init and final procedures are exported in uppercase
@item ^-Mxyz^/RENAME_MAIN=xyz^
@cindex @option{^-M^/RENAME_MAIN^} (@command{gnatbind})
-Rename generated main program from main to xyz
+Rename generated main program from main to xyz. This option is
+supported on cross environments only.
@item ^-m^/ERROR_LIMIT=^@var{n}
@cindex @option{^-m^/ERROR_LIMIT^} (@command{gnatbind})
-Limit number of detected errors to @var{n}, where @var{n} is
-in the range 1..999_999. The default value if no switch is
-given is 9999. Binding is terminated if the limit is exceeded.
+Limit number of detected errors or warnings to @var{n}, where @var{n} is
+in the range 1..999999. The default value if no switch is
+given is 9999. If the number of warnings reaches this limit, then a
+message is output and further warnings are suppressed, the bind
+continues in this case. If the number of errors reaches this
+limit, then a message is output and the bind is abandoned.
+A value of zero means that no limit is enforced. The equal
+sign is optional.
+
@ifset unw
Furthermore, under Windows, the sources pointed to by the libraries path
set in the registry are not searched for.
@item --RTS=@var{rts-path}
@cindex @option{--RTS} (@code{gnatbind})
Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (see @ref{Switches for gnatmake}).
+equivalent @command{gnatmake} flag (@pxref{Switches for gnatmake}).
@item ^-o ^/OUTPUT=^@var{file}
@cindex @option{^-o ^/OUTPUT^} (@command{gnatbind})
@cindex @option{^-p^/PESSIMISTIC_ELABORATION^} (@command{gnatbind})
Pessimistic (worst-case) elaboration order
+@item ^-R^-R^
+@cindex @option{^-R^-R^} (@command{gnatbind})
+Output closure source list.
+
@item ^-s^/READ_SOURCES=ALL^
@cindex @option{^-s^/READ_SOURCES=ALL^} (@command{gnatbind})
Require all source files to be present.
@itemize @bullet
@item ``@option{^in^INVALID^}'' requesting an invalid value where possible
@item ``@option{^lo^LOW^}'' for the lowest possible value
-possible, and the low
@item ``@option{^hi^HIGH^}'' for the highest possible value
-@item ``@option{xx}'' for a value consisting of repeated bytes with the
-value 16#xx# (i.e. xx is a string of two hexadecimal digits).
+@item ``@option{@var{xx}}'' for a value consisting of repeated bytes with the
+value @code{16#@var{xx}#} (i.e., @var{xx} is a string of two hexadecimal digits).
@end itemize
In addition, you can specify @option{-Sev} to indicate that the value is
to be set at run time. In this case, the program will look for an environment
@cindex GNAT_INIT_SCALARS
-variable of the form @code{GNAT_INIT_SCALARS=xx}, where xx is one
-of @option{in/lo/hi/xx} with the same meanings as above.
+variable of the form @env{GNAT_INIT_SCALARS=@var{xx}}, where @var{xx} is one
+of @option{in/lo/hi/@var{xx}} with the same meanings as above.
If no environment variable is found, or if it does not have a valid value,
then the default is @option{in} (invalid values).
the specification of a specific time slice value, then the indicated value
is used. If the system does not support specific time slice values, but
does support some general notion of round-robin scheduling, then any
-non-zero value will activate round-robin scheduling.
+nonzero value will activate round-robin scheduling.
A value of zero is treated specially. It turns off time
slicing, and in addition, indicates to the tasking run time that the
requirements of the Ada RM, and in particular sets the default
scheduling policy to @code{FIFO_Within_Priorities}.
+@item ^-u@var{n}^/DYNAMIC_STACK_USAGE=@var{n}^
+@cindex @option{^-u^/DYNAMIC_STACK_USAGE^} (@code{gnatbind})
+Enable dynamic stack usage, with @var{n} results stored and displayed
+at program termination. A result is generated when a task
+terminates. Results that can't be stored are displayed on the fly, at
+task termination. This option is currently not supported on Itanium
+platforms. (See @ref{Dynamic Stack Usage Analysis} for details.)
+
@item ^-v^/REPORT_ERRORS=VERBOSE^
@cindex @option{^-v^/REPORT_ERRORS=VERBOSE^} (@code{gnatbind})
Verbose mode. Write error messages, header, summary output to
Warning messages are treated as fatal errors
@end ifset
+@item ^-Wx^/WIDE_CHARACTER_ENCODING=^@var{e}
+@cindex @option{^-Wx^/WIDE_CHARACTER_ENCODING^} (@code{gnatbind})
+Override default wide character encoding for standard Text_IO files.
+
@item ^-x^/READ_SOURCES=NONE^
@cindex @option{^-x^/READ_SOURCES^} (@code{gnatbind})
Exclude source files (check object consistency only).
they are available.
@end ifset
+@item ^-y^/ENABLE_LEAP_SECONDS^
+@cindex @option{^-y^/ENABLE_LEAP_SECONDS^} (@code{gnatbind})
+Enable leap seconds support in @code{Ada.Calendar} and its children.
+
@item ^-z^/ZERO_MAIN^
@cindex @option{^-z^/ZERO_MAIN^} (@code{gnatbind})
No main subprogram.
no arguments.
@end ifclear
-
@node Consistency-Checking Modes
@subsection Consistency-Checking Modes
is simply ignored. If you specify this switch, a missing source
file is an error.
+@item ^-Wx^/WIDE_CHARACTER_ENCODING=^@var{e}
+@cindex @option{^-Wx^/WIDE_CHARACTER_ENCODING^} (@code{gnatbind})
+Override default wide character encoding for standard Text_IO files.
+Normally the default wide character encoding method used for standard
+[Wide_[Wide_]]Text_IO files is taken from the encoding specified for
+the main source input (see description of switch
+@option{^-gnatWx^/WIDE_CHARACTER_ENCODING^} for the compiler). The
+use of this switch for the binder (which has the same set of
+possible arguments) overrides this default as specified.
+
@item ^-x^/READ_SOURCES=NONE^
@cindex @option{^-x^/READ_SOURCES=NONE^} (@code{gnatbind})
Exclude source files. In this mode, the binder only checks that ALI
If a source file has been edited since it was last compiled, and you
specify this switch, the binder will not detect that the object
file is out of date with respect to the source file. Note that this is the
-mode that is automatically used by @code{gnatmake} because in this
+mode that is automatically used by @command{gnatmake} because in this
case the checking against sources has already been performed by
-@code{gnatmake} in the course of compilation (i.e. before binding).
+@command{gnatmake} in the course of compilation (i.e.@: before binding).
@ifset vms
@item /READ_SOURCES=AVAILABLE
@noindent
The following switches provide additional control over the elaboration
-order. For full details see @xref{Elaboration Order Handling in GNAT}.
+order. For full details see @ref{Elaboration Order Handling in GNAT}.
@table @option
@item ^-p^/PESSIMISTIC_ELABORATION^
switch if dynamic
elaboration checking is used (@option{-gnatE} switch used for compilation).
This is because in the default static elaboration mode, all necessary
-@code{Elaborate_All} pragmas are implicitly inserted.
+@code{Elaborate} and @code{Elaborate_All} pragmas are implicitly inserted.
These implicit pragmas are still respected by the binder in
@option{^-p^/PESSIMISTIC_ELABORATION^} mode, so a
safe elaboration order is assured.
The output is an Ada unit in source form that can
be compiled with GNAT unless the -C switch is used in which case the
output is a C source file, which must be compiled using the C compiler.
-This compilation occurs automatically as part of the @code{gnatlink}
+This compilation occurs automatically as part of the @command{gnatlink}
processing.
Currently the GNAT run time requires a FPU using 80 bits mode
Normally the binder checks that the unit name given on the command line
corresponds to a suitable main subprogram. When this switch is used,
a list of ALI files can be given, and the execution of the program
-consists of elaboration of these units in an appropriate order.
+consists of elaboration of these units in an appropriate order. Note
+that the default wide character encoding method for standard Text_IO
+files is always set to Brackets if this switch is set (you can use
+the binder switch
+@option{^-Wx^WIDE_CHARACTER_ENCODING^} to override this default).
@end table
-
@node Command-Line Access
@section Command-Line Access
@code{gnat_argv} from the @code{argc} and @code{argv} values passed to
it.
-
@node Search Paths for gnatbind
@section Search Paths for @code{gnatbind}
The binder takes the name of an ALI file as its argument and needs to
locate source files as well as other ALI files to verify object consistency.
-For source files, it follows exactly the same search rules as @code{gcc}
+For source files, it follows exactly the same search rules as @command{gcc}
(@pxref{Search Paths and the Run-Time Library (RTL)}). For ALI files the
directories searched are:
command line, in the order given.
@item
+@findex ADA_PRJ_OBJECTS_FILE
+Each of the directories listed in the text file whose name is given
+by the @env{ADA_PRJ_OBJECTS_FILE} ^environment variable^logical name^.
+
+@noindent
+@env{ADA_PRJ_OBJECTS_FILE} is normally set by gnatmake or by the ^gnat^GNAT^
+driver when project files are used. It should not normally be set
+by other means.
+
+@item
@findex ADA_OBJECTS_PATH
Each of the directories listed in the value of the
-@code{ADA_OBJECTS_PATH} ^environment variable^logical name^.
+@env{ADA_OBJECTS_PATH} ^environment variable^logical name^.
@ifset unw
Construct this value
-exactly as the @code{PATH} environment variable: a list of directory
+exactly as the @env{PATH} environment variable: a list of directory
names separated by colons (semicolons when working with the NT version
of GNAT).
@end ifset
list of directory names.
This variable can also be defined by means of an environment string
-(an argument to the DEC C exec* set of functions).
+(an argument to the HP C exec* set of functions).
Logical Name:
@smallexample
@end smallexample
By default, the path includes GNU:[LIB.OPENVMS7_x.2_8_x.DECLIB]
-first, followed by the standard Ada 95
+first, followed by the standard Ada
libraries in GNU:[LIB.OPENVMS7_x.2_8_x.ADALIB].
-If this is not redefined, the user will obtain the DEC Ada 83 IO packages
+If this is not redefined, the user will obtain the HP Ada 83 IO packages
(Text_IO, Sequential_IO, etc)
-instead of the Ada95 packages. Thus, in order to get the Ada 95
+instead of the standard Ada packages. Thus, in order to get the standard Ada
packages by default, ADA_OBJECTS_PATH must be redefined.
@end ifset
@item
-@findex ADA_PRJ_OBJECTS_FILE
-Each of the directories listed in the text file whose name is given
-by the @code{ADA_PRJ_OBJECTS_FILE} ^environment variable^logical name^.
-
-@noindent
-@code{ADA_PRJ_OBJECTS_FILE} is normally set by gnatmake or by the ^gnat^GNAT^
-driver when project files are used. It should not normally be set
-by other means.
-
-@item
The content of the @file{ada_object_path} file which is part of the GNAT
installation tree and is used to store standard libraries such as the
GNAT Run Time Library (RTL) unless the switch @option{-nostdlib} is
specified.
@ifclear vms
-@ref{Installing the library}
+@ref{Installing a library}
@end ifclear
@end enumerate
after accessing the Ada units.
@end table
-
@c ------------------------------------
@node Linking Using gnatlink
-@chapter Linking Using @code{gnatlink}
+@chapter Linking Using @command{gnatlink}
@c ------------------------------------
@findex gnatlink
@noindent
-This chapter discusses @code{gnatlink}, a tool that links
+This chapter discusses @command{gnatlink}, a tool that links
an Ada program and builds an executable file. This utility
-invokes the system linker ^(via the @code{gcc} command)^^
+invokes the system linker ^(via the @command{gcc} command)^^
with a correct list of object files and library references.
-@code{gnatlink} automatically determines the list of files and
+@command{gnatlink} automatically determines the list of files and
references for the Ada part of a program. It uses the binder file
generated by the @command{gnatbind} to determine this list.
+Note: to invoke @code{gnatlink} with a project file, use the @code{gnat}
+driver (see @ref{The GNAT Driver and Project Files}).
+
@menu
* Running gnatlink::
* Switches for gnatlink::
-* Setting Stack Size from gnatlink::
-* Setting Heap Size from gnatlink::
@end menu
@node Running gnatlink
-@section Running @code{gnatlink}
+@section Running @command{gnatlink}
@noindent
-The form of the @code{gnatlink} command is
+The form of the @command{gnatlink} command is
@smallexample
-$ gnatlink [@var{switches}] @var{mainprog}[.ali]
- [@var{non-Ada objects}] [@var{linker options}]
+$ gnatlink @ovar{switches} @var{mainprog}@r{[}.ali@r{]}
+ @ovar{non-Ada objects} @ovar{linker options}
@end smallexample
@noindent
-The arguments of @code{gnatlink} (switches, main @file{ALI} file,
+The arguments of @command{gnatlink} (switches, main @file{ALI} file,
non-Ada objects
or linker options) may be in any order, provided that no non-Ada object may
be mistaken for a main @file{ALI} file.
@noindent
@file{@var{mainprog}.ali} references the ALI file of the main program.
The @file{.ali} extension of this file can be omitted. From this
-reference, @code{gnatlink} locates the corresponding binder file
+reference, @command{gnatlink} locates the corresponding binder file
@file{b~@var{mainprog}.adb} and, using the information in this file along
with the list of non-Ada objects and linker options, constructs a
linker command file to create the executable.
-The arguments other than the @code{gnatlink} switches and the main @file{ALI}
-file are passed to the linker uninterpreted.
+The arguments other than the @command{gnatlink} switches and the main
+@file{ALI} file are passed to the linker uninterpreted.
They typically include the names of
object files for units written in other languages than Ada and any library
references required to resolve references in any of these foreign language
@var{linker options} is an optional list of linker specific
switches.
-The default linker called by gnatlink is @var{gcc} which in
+The default linker called by gnatlink is @command{gcc} which in
turn calls the appropriate system linker.
Standard options for the linker such as @option{-lmy_lib} or
@option{-Ldir} can be added as is.
For options that are not recognized by
-@var{gcc} as linker options, use the @var{gcc} switches @option{-Xlinker} or
-@option{-Wl,}.
+@command{gcc} as linker options, use the @command{gcc} switches
+@option{-Xlinker} or @option{-Wl,}.
Refer to the GCC documentation for
details. Here is an example showing how to generate a linker map:
-@ifclear vms
@smallexample
-$ gnatlink my_prog -Wl,-Map,MAPFILE
+$ ^gnatlink my_prog -Wl,-Map,MAPFILE^GNAT LINK my_prog.ali /MAP^
@end smallexample
-@end ifclear
-
-@ifset vms
-<<Need example for VMS>>
-@end ifset
Using @var{linker options} it is possible to set the program stack and
-heap size. See @ref{Setting Stack Size from gnatlink}, and
+heap size.
+@ifset unw
+See @ref{Setting Stack Size from gnatlink} and
@ref{Setting Heap Size from gnatlink}.
+@end ifset
-@code{gnatlink} determines the list of objects required by the Ada
+@command{gnatlink} determines the list of objects required by the Ada
program and prepends them to the list of objects passed to the linker.
-@code{gnatlink} also gathers any arguments set by the use of
+@command{gnatlink} also gathers any arguments set by the use of
@code{pragma Linker_Options} and adds them to the list of arguments
presented to the linker.
@ifset vms
-@code{gnatlink} accepts the following types of extra files on the command
-line: objects (.OBJ), libraries (.OLB), sharable images (.EXE), and
-options files (.OPT). These are recognized and handled according to their
-extension.
+@command{gnatlink} accepts the following types of extra files on the command
+line: objects (@file{.OBJ}), libraries (@file{.OLB}), sharable images
+(@file{.EXE}), and options files (@file{.OPT}). These are recognized and
+handled according to their extension.
@end ifset
@node Switches for gnatlink
-@section Switches for @code{gnatlink}
+@section Switches for @command{gnatlink}
@noindent
-The following switches are available with the @code{gnatlink} utility:
+The following switches are available with the @command{gnatlink} utility:
@table @option
@c !sort!
+@item --version
+@cindex @option{--version} @command{gnatlink}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatlink}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
@item ^-A^/BIND_FILE=ADA^
-@cindex @option{^-A^/BIND_FILE=ADA^} (@code{gnatlink})
+@cindex @option{^-A^/BIND_FILE=ADA^} (@command{gnatlink})
The binder has generated code in Ada. This is the default.
@item ^-C^/BIND_FILE=C^
-@cindex @option{^-C^/BIND_FILE=C^} (@code{gnatlink})
+@cindex @option{^-C^/BIND_FILE=C^} (@command{gnatlink})
If instead of generating a file in Ada, the binder has generated one in
C, then the linker needs to know about it. Use this switch to signal
-to @code{gnatlink} that the binder has generated C code rather than
+to @command{gnatlink} that the binder has generated C code rather than
Ada code.
@item ^-f^/FORCE_OBJECT_FILE_LIST^
@cindex Command line length
-@cindex @option{^-f^/FORCE_OBJECT_FILE_LIST^} (@code{gnatlink})
-On some targets, the command line length is limited, and @code{gnatlink}
+@cindex @option{^-f^/FORCE_OBJECT_FILE_LIST^} (@command{gnatlink})
+On some targets, the command line length is limited, and @command{gnatlink}
will generate a separate file for the linker if the list of object files
is too long.
The @option{^-f^/FORCE_OBJECT_FILE_LIST^} switch forces this file
@item ^-g^/DEBUG^
@cindex Debugging information, including
-@cindex @option{^-g^/DEBUG^} (@code{gnatlink})
+@cindex @option{^-g^/DEBUG^} (@command{gnatlink})
The option to include debugging information causes the Ada bind file (in
other words, @file{b~@var{mainprog}.adb}) to be compiled with
@option{^-g^/DEBUG^}.
are @file{b_@var{mainprog}.c} and @file{b_@var{mainprog}.o}.
@item ^-n^/NOCOMPILE^
-@cindex @option{^-n^/NOCOMPILE^} (@code{gnatlink})
+@cindex @option{^-n^/NOCOMPILE^} (@command{gnatlink})
Do not compile the file generated by the binder. This may be used when
a link is rerun with different options, but there is no need to recompile
the binder file.
@item ^-v^/VERBOSE^
-@cindex @option{^-v^/VERBOSE^} (@code{gnatlink})
+@cindex @option{^-v^/VERBOSE^} (@command{gnatlink})
Causes additional information to be output, including a full list of the
included object files. This switch option is most useful when you want
to see what set of object files are being used in the link step.
@item ^-v -v^/VERBOSE/VERBOSE^
-@cindex @option{^-v -v^/VERBOSE/VERBOSE^} (@code{gnatlink})
+@cindex @option{^-v -v^/VERBOSE/VERBOSE^} (@command{gnatlink})
Very verbose mode. Requests that the compiler operate in verbose mode when
it compiles the binder file, and that the system linker run in verbose mode.
@item ^-o ^/EXECUTABLE=^@var{exec-name}
-@cindex @option{^-o^/EXECUTABLE^} (@code{gnatlink})
+@cindex @option{^-o^/EXECUTABLE^} (@command{gnatlink})
@var{exec-name} specifies an alternate name for the generated
executable program. If this switch is omitted, the executable has the same
name as the main unit. For example, @code{gnatlink try.ali} creates
@ifclear vms
@item -b @var{target}
-@cindex @option{-b} (@code{gnatlink})
+@cindex @option{-b} (@command{gnatlink})
Compile your program to run on @var{target}, which is the name of a
system configuration. You must have a GNAT cross-compiler built if
@var{target} is not the same as your host system.
@item -B@var{dir}
-@cindex @option{-B} (@code{gnatlink})
+@cindex @option{-B} (@command{gnatlink})
Load compiler executables (for example, @code{gnat1}, the Ada compiler)
from @var{dir} instead of the default location. Only use this switch
-when multiple versions of the GNAT compiler are available. See the
-@code{gcc} manual page for further details. You would normally use the
-@option{-b} or @option{-V} switch instead.
+when multiple versions of the GNAT compiler are available.
+@xref{Directory Options,,, gcc, The GNU Compiler Collection},
+for further details. You would normally use the @option{-b} or
+@option{-V} switch instead.
@item --GCC=@var{compiler_name}
-@cindex @option{--GCC=compiler_name} (@code{gnatlink})
+@cindex @option{--GCC=compiler_name} (@command{gnatlink})
Program used for compiling the binder file. The default is
-`@code{gcc}'. You need to use quotes around @var{compiler_name} if
-@code{compiler_name} contains spaces or other separator characters. As
-an example @option{--GCC="foo -x -y"} will instruct @code{gnatlink} to use
-@code{foo -x -y} as your compiler. Note that switch @option{-c} is always
+@command{gcc}. You need to use quotes around @var{compiler_name} if
+@code{compiler_name} contains spaces or other separator characters.
+As an example @option{--GCC="foo -x -y"} will instruct @command{gnatlink} to
+use @code{foo -x -y} as your compiler. Note that switch @option{-c} is always
inserted after your command name. Thus in the above example the compiler
-command that will be used by @code{gnatlink} will be @code{foo -c -x -y}.
-If several @option{--GCC=compiler_name} are used, only the last
-@var{compiler_name} is taken into account. However, all the additional
-switches are also taken into account. Thus,
+command that will be used by @command{gnatlink} will be @code{foo -c -x -y}.
+A limitation of this syntax is that the name and path name of the executable
+itself must not include any embedded spaces. If the compiler executable is
+different from the default one (gcc or <prefix>-gcc), then the back-end
+switches in the ALI file are not used to compile the binder generated source.
+For example, this is the case with @option{--GCC="foo -x -y"}. But the back end
+switches will be used for @option{--GCC="gcc -gnatv"}. If several
+@option{--GCC=compiler_name} are used, only the last @var{compiler_name}
+is taken into account. However, all the additional switches are also taken
+into account. Thus,
@option{--GCC="foo -x -y" --GCC="bar -z -t"} is equivalent to
@option{--GCC="bar -x -y -z -t"}.
@item --LINK=@var{name}
-@cindex @option{--LINK=} (@code{gnatlink})
+@cindex @option{--LINK=} (@command{gnatlink})
@var{name} is the name of the linker to be invoked. This is especially
useful in mixed language programs since languages such as C++ require
their own linker to be used. When this switch is omitted, the default
-name for the linker is (@file{gcc}). When this switch is used, the
-specified linker is called instead of (@file{gcc}) with exactly the same
-parameters that would have been passed to (@file{gcc}) so if the desired
+name for the linker is @command{gcc}. When this switch is used, the
+specified linker is called instead of @command{gcc} with exactly the same
+parameters that would have been passed to @command{gcc} so if the desired
linker requires different parameters it is necessary to use a wrapper
script that massages the parameters before invoking the real linker. It
may be useful to control the exact invocation by using the verbose
@ifset vms
@item /DEBUG=TRACEBACK
-@cindex @code{/DEBUG=TRACEBACK} (@code{gnatlink})
+@cindex @code{/DEBUG=TRACEBACK} (@command{gnatlink})
This qualifier causes sufficient information to be included in the
executable file to allow a traceback, but does not include the full
symbol information needed by the debugger.
@item /NOSTART_FILES
Don't link in the object file containing the ``main'' transfer address.
-Used when linking with a foreign language main program compiled with a
-Digital compiler.
+Used when linking with a foreign language main program compiled with an
+HP compiler.
@item /STATIC
Prefer linking with object libraries over sharable images, even without
@end table
-@node Setting Stack Size from gnatlink
-@section Setting Stack Size from @code{gnatlink}
-
-@noindent
-Under Windows systems, it is possible to specify the program stack size from
-@code{gnatlink} using either:
-
-@itemize @bullet
-
-@item using @option{-Xlinker} linker option
-
-@smallexample
-$ gnatlink hello -Xlinker --stack=0x10000,0x1000
-@end smallexample
-
-This sets the stack reserve size to 0x10000 bytes and the stack commit
-size to 0x1000 bytes.
-
-@item using @option{-Wl} linker option
-
-@smallexample
-$ gnatlink hello -Wl,--stack=0x1000000
-@end smallexample
-
-This sets the stack reserve size to 0x1000000 bytes. Note that with
-@option{-Wl} option it is not possible to set the stack commit size
-because the coma is a separator for this option.
-
-@end itemize
-
-@node Setting Heap Size from gnatlink
-@section Setting Heap Size from @code{gnatlink}
-
-@noindent
-Under Windows systems, it is possible to specify the program heap size from
-@code{gnatlink} using either:
-
-@itemize @bullet
-
-@item using @option{-Xlinker} linker option
-
-@smallexample
-$ gnatlink hello -Xlinker --heap=0x10000,0x1000
-@end smallexample
-
-This sets the heap reserve size to 0x10000 bytes and the heap commit
-size to 0x1000 bytes.
-
-@item using @option{-Wl} linker option
-
-@smallexample
-$ gnatlink hello -Wl,--heap=0x1000000
-@end smallexample
-
-This sets the heap reserve size to 0x1000000 bytes. Note that with
-@option{-Wl} option it is not possible to set the heap commit size
-because the coma is a separator for this option.
-
-@end itemize
-
@node The GNAT Make Program gnatmake
-@chapter The GNAT Make Program @code{gnatmake}
+@chapter The GNAT Make Program @command{gnatmake}
@findex gnatmake
@menu
in the presence of overloading, @code{use} clauses, generics and inlined
subprograms.
-@code{gnatmake} automatically takes care of the third and fourth steps
+@command{gnatmake} automatically takes care of the third and fourth steps
of this process. It determines which sources need to be compiled,
compiles them, and binds and links the resulting object files.
the GNAT compilation model makes this possible. This means that if
changes to the source program cause corresponding changes in
dependencies, they will always be tracked exactly correctly by
-@code{gnatmake}.
+@command{gnatmake}.
@node Running gnatmake
-@section Running @code{gnatmake}
+@section Running @command{gnatmake}
@noindent
-The usual form of the @code{gnatmake} command is
+The usual form of the @command{gnatmake} command is
@smallexample
-$ gnatmake [@var{switches}] @var{file_name}
- [@var{file_names}] [@var{mode_switches}]
+$ gnatmake @ovar{switches} @var{file_name}
+ @ovar{file_names} @ovar{mode_switches}
@end smallexample
@noindent
If @var{mode_switches} are present, they must always be placed after
the last @var{file_name} and all @code{switches}.
-If you are using standard file extensions (.adb and .ads), then the
+If you are using standard file extensions (@file{.adb} and @file{.ads}), then the
extension may be omitted from the @var{file_name} arguments. However, if
you are using non-standard extensions, then it is required that the
extension be given. A relative or absolute directory path can be
specified in a @var{file_name}, in which case, the input source file will
be searched for in the specified directory only. Otherwise, the input
source file will first be searched in the directory where
-@code{gnatmake} was invoked and if it is not found, it will be search on
+@command{gnatmake} was invoked and if it is not found, it will be search on
the source path of the compiler as described in
@ref{Search Paths and the Run-Time Library (RTL)}.
-All @code{gnatmake} output (except when you specify
+All @command{gnatmake} output (except when you specify
@option{^-M^/DEPENDENCIES_LIST^}) is to
@file{stderr}. The output produced by the
@option{^-M^/DEPENDENCIES_LIST^} switch is send to
@file{stdout}.
@node Switches for gnatmake
-@section Switches for @code{gnatmake}
+@section Switches for @command{gnatmake}
@noindent
-You may specify any of the following switches to @code{gnatmake}:
+You may specify any of the following switches to @command{gnatmake}:
@table @option
@c !sort!
+
+@item --version
+@cindex @option{--version} @command{gnatmake}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatmake}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
@ifclear vms
@item --GCC=@var{compiler_name}
-@cindex @option{--GCC=compiler_name} (@code{gnatmake})
-Program used for compiling. The default is `@code{gcc}'. You need to use
+@cindex @option{--GCC=compiler_name} (@command{gnatmake})
+Program used for compiling. The default is `@command{gcc}'. You need to use
quotes around @var{compiler_name} if @code{compiler_name} contains
spaces or other separator characters. As an example @option{--GCC="foo -x
--y"} will instruct @code{gnatmake} to use @code{foo -x -y} as your
-compiler. Note that switch @option{-c} is always inserted after your
-command name. Thus in the above example the compiler command that will
-be used by @code{gnatmake} will be @code{foo -c -x -y}.
-If several @option{--GCC=compiler_name} are used, only the last
-@var{compiler_name} is taken into account. However, all the additional
-switches are also taken into account. Thus,
+-y"} will instruct @command{gnatmake} to use @code{foo -x -y} as your
+compiler. A limitation of this syntax is that the name and path name of
+the executable itself must not include any embedded spaces. Note that
+switch @option{-c} is always inserted after your command name. Thus in the
+above example the compiler command that will be used by @command{gnatmake}
+will be @code{foo -c -x -y}. If several @option{--GCC=compiler_name} are
+used, only the last @var{compiler_name} is taken into account. However,
+all the additional switches are also taken into account. Thus,
@option{--GCC="foo -x -y" --GCC="bar -z -t"} is equivalent to
@option{--GCC="bar -x -y -z -t"}.
@item --GNATBIND=@var{binder_name}
-@cindex @option{--GNATBIND=binder_name} (@code{gnatmake})
+@cindex @option{--GNATBIND=binder_name} (@command{gnatmake})
Program used for binding. The default is `@code{gnatbind}'. You need to
use quotes around @var{binder_name} if @var{binder_name} contains spaces
or other separator characters. As an example @option{--GNATBIND="bar -x
--y"} will instruct @code{gnatmake} to use @code{bar -x -y} as your
-binder. Binder switches that are normally appended by @code{gnatmake} to
-`@code{gnatbind}' are now appended to the end of @code{bar -x -y}.
+-y"} will instruct @command{gnatmake} to use @code{bar -x -y} as your
+binder. Binder switches that are normally appended by @command{gnatmake}
+to `@code{gnatbind}' are now appended to the end of @code{bar -x -y}.
+A limitation of this syntax is that the name and path name of the executable
+itself must not include any embedded spaces.
@item --GNATLINK=@var{linker_name}
-@cindex @option{--GNATLINK=linker_name} (@code{gnatmake})
-Program used for linking. The default is `@code{gnatlink}'. You need to
+@cindex @option{--GNATLINK=linker_name} (@command{gnatmake})
+Program used for linking. The default is `@command{gnatlink}'. You need to
use quotes around @var{linker_name} if @var{linker_name} contains spaces
or other separator characters. As an example @option{--GNATLINK="lan -x
--y"} will instruct @code{gnatmake} to use @code{lan -x -y} as your
-linker. Linker switches that are normally appended by @code{gnatmake} to
-`@code{gnatlink}' are now appended to the end of @code{lan -x -y}.
+-y"} will instruct @command{gnatmake} to use @code{lan -x -y} as your
+linker. Linker switches that are normally appended by @command{gnatmake} to
+`@command{gnatlink}' are now appended to the end of @code{lan -x -y}.
+A limitation of this syntax is that the name and path name of the executable
+itself must not include any embedded spaces.
@end ifclear
@item ^-a^/ALL_FILES^
-@cindex @option{^-a^/ALL_FILES^} (@code{gnatmake})
+@cindex @option{^-a^/ALL_FILES^} (@command{gnatmake})
Consider all files in the make process, even the GNAT internal system
files (for example, the predefined Ada library files), as well as any
locked files. Locked files are files whose ALI file is write-protected.
By default,
-@code{gnatmake} does not check these files,
+@command{gnatmake} does not check these files,
because the assumption is that the GNAT internal files are properly up
to date, and also that any write protected ALI files have been properly
installed. Note that if there is an installation problem, such that one
@end ifset
@item ^-b^/ACTIONS=BIND^
-@cindex @option{^-b^/ACTIONS=BIND^} (@code{gnatmake})
+@cindex @option{^-b^/ACTIONS=BIND^} (@command{gnatmake})
Bind only. Can be combined with @option{^-c^/ACTIONS=COMPILE^} to do
compilation and binding, but no link.
Can be combined with @option{^-l^/ACTIONS=LINK^}
Project File is specified, with the ALI file extension.
@item ^-c^/ACTIONS=COMPILE^
-@cindex @option{^-c^/ACTIONS=COMPILE^} (@code{gnatmake})
+@cindex @option{^-c^/ACTIONS=COMPILE^} (@command{gnatmake})
Compile only. Do not perform binding, except when @option{^-b^/ACTIONS=BIND^}
is also specified. Do not perform linking, except if both
@option{^-b^/ACTIONS=BIND^} and
- @option{^-l^/ACTIONS=LINK^} are also specified.
+@option{^-l^/ACTIONS=LINK^} are also specified.
If the root unit specified by @var{file_name} is not a main unit, this is the
-default. Otherwise @code{gnatmake} will attempt binding and linking
+default. Otherwise @command{gnatmake} will attempt binding and linking
unless all objects are up to date and the executable is more recent than
the objects.
@item ^-C^/MAPPING^
-@cindex @option{^-C^/MAPPING^} (@code{gnatmake})
+@cindex @option{^-C^/MAPPING^} (@command{gnatmake})
Use a temporary mapping file. A mapping file is a way to communicate to the
compiler two mappings: from unit names to file names (without any directory
information) and from file names to path names (with full directory
information). These mappings are used by the compiler to short-circuit the path
-search. When @code{gnatmake} is invoked with this switch, it will create
+search. When @command{gnatmake} is invoked with this switch, it will create
a temporary mapping file, initially populated by the project manager,
if @option{^-P^/PROJECT_FILE^} is used, otherwise initially empty.
Each invocation of the compiler will add the newly accessed sources to the
of the compiler.
@item ^-C=^/USE_MAPPING_FILE=^@var{file}
-@cindex @option{^-C=^/USE_MAPPING^} (@code{gnatmake})
+@cindex @option{^-C=^/USE_MAPPING^} (@command{gnatmake})
Use a specific mapping file. The file, specified as a path name (absolute or
relative) by this switch, should already exist, otherwise the switch is
ineffective. The specified mapping file will be communicated to the compiler.
(^-P^/PROJECT_FILE=^@var{file}) or with multiple compiling processes
(^-j^/PROCESSES=^nnn, when nnn is greater than 1).
+@item ^-d^/DISPLAY_PROGRESS^
+@cindex @option{^-d^/DISPLAY_PROGRESS^} (@command{gnatmake})
+Display progress for each source, up to date or not, as a single line
+
+@smallexample
+completed x out of y (zz%)
+@end smallexample
+
+If the file needs to be compiled this is displayed after the invocation of
+the compiler. These lines are displayed even in quiet output mode.
+
@item ^-D ^/DIRECTORY_OBJECTS=^@var{dir}
-@cindex @option{^-D^/DIRECTORY_OBJECTS^} (@code{gnatmake})
+@cindex @option{^-D^/DIRECTORY_OBJECTS^} (@command{gnatmake})
Put all object files and ALI file in directory @var{dir}.
If the @option{^-D^/DIRECTORY_OBJECTS^} switch is not used, all object files
and ALI files go in the current working directory.
@ifclear vms
@item -eL
-@cindex @option{-eL} (@code{gnatmake})
+@cindex @option{-eL} (@command{gnatmake})
Follow all symbolic links when processing project files.
@end ifclear
+@item ^-eS^/STANDARD_OUTPUT_FOR_COMMANDS^
+@cindex @option{^-eS^/STANDARD_OUTPUT_FOR_COMMANDS^} (@command{gnatmake})
+Output the commands for the compiler, the binder and the linker
+on ^standard output^SYS$OUTPUT^,
+instead of ^standard error^SYS$ERROR^.
+
@item ^-f^/FORCE_COMPILE^
-@cindex @option{^-f^/FORCE_COMPILE^} (@code{gnatmake})
+@cindex @option{^-f^/FORCE_COMPILE^} (@command{gnatmake})
Force recompilations. Recompile all sources, even though some object
files may be up to date, but don't recompile predefined or GNAT internal
files or locked files (files with a write-protected ALI file),
unless the @option{^-a^/ALL_FILES^} switch is also specified.
@item ^-F^/FULL_PATH_IN_BRIEF_MESSAGES^
-@cindex @option{^-F^/FULL_PATH_IN_BRIEF_MESSAGES^} (@code{gnatmake})
+@cindex @option{^-F^/FULL_PATH_IN_BRIEF_MESSAGES^} (@command{gnatmake})
When using project files, if some errors or warnings are detected during
parsing and verbose mode is not in effect (no use of switch
^-v^/VERBOSE^), then error lines start with the full path name of the project
file, rather than its simple file name.
+@item ^-g^/DEBUG^
+@cindex @option{^-g^/DEBUG^} (@command{gnatmake})
+Enable debugging. This switch is simply passed to the compiler and to the
+linker.
+
@item ^-i^/IN_PLACE^
-@cindex @option{^-i^/IN_PLACE^} (@code{gnatmake})
-In normal mode, @code{gnatmake} compiles all object files and ALI files
+@cindex @option{^-i^/IN_PLACE^} (@command{gnatmake})
+In normal mode, @command{gnatmake} compiles all object files and ALI files
into the current directory. If the @option{^-i^/IN_PLACE^} switch is used,
then instead object files and ALI files that already exist are overwritten
in place. This means that once a large project is organized into separate
-directories in the desired manner, then @code{gnatmake} will automatically
+directories in the desired manner, then @command{gnatmake} will automatically
maintain and update this organization. If no ALI files are found on the
Ada object path (@ref{Search Paths and the Run-Time Library (RTL)}),
the new object and ALI files are created in the
directory containing the source being compiled. If another organization
is desired, where objects and sources are kept in different directories,
a useful technique is to create dummy ALI files in the desired directories.
-When detecting such a dummy file, @code{gnatmake} will be forced to recompile
-the corresponding source file, and it will be put the resulting object
-and ALI files in the directory where it found the dummy file.
+When detecting such a dummy file, @command{gnatmake} will be forced to
+recompile the corresponding source file, and it will be put the resulting
+object and ALI files in the directory where it found the dummy file.
@item ^-j^/PROCESSES=^@var{n}
-@cindex @option{^-j^/PROCESSES^} (@code{gnatmake})
+@cindex @option{^-j^/PROCESSES^} (@command{gnatmake})
@cindex Parallel make
Use @var{n} processes to carry out the (re)compilations. On a
multiprocessor machine compilations will occur in parallel. In the
event of compilation errors, messages from various compilations might
-get interspersed (but @code{gnatmake} will give you the full ordered
+get interspersed (but @command{gnatmake} will give you the full ordered
list of failing compiles at the end). If this is problematic, rerun
the make process with n set to 1 to get a clean list of messages.
@item ^-k^/CONTINUE_ON_ERROR^
-@cindex @option{^-k^/CONTINUE_ON_ERROR^} (@code{gnatmake})
+@cindex @option{^-k^/CONTINUE_ON_ERROR^} (@command{gnatmake})
Keep going. Continue as much as possible after a compilation error. To
ease the programmer's task in case of compilation errors, the list of
-sources for which the compile fails is given when @code{gnatmake}
+sources for which the compile fails is given when @command{gnatmake}
terminates.
-If @code{gnatmake} is invoked with several @file{file_names} and with this
+If @command{gnatmake} is invoked with several @file{file_names} and with this
switch, if there are compilation errors when building an executable,
-@code{gnatmake} will not attempt to build the following executables.
+@command{gnatmake} will not attempt to build the following executables.
@item ^-l^/ACTIONS=LINK^
-@cindex @option{^-l^/ACTIONS=LINK^} (@code{gnatmake})
+@cindex @option{^-l^/ACTIONS=LINK^} (@command{gnatmake})
Link only. Can be combined with @option{^-b^/ACTIONS=BIND^} to binding
and linking. Linking will not be performed if combined with
@option{^-c^/ACTIONS=COMPILE^}
but not with @option{^-b^/ACTIONS=BIND^}.
When not combined with @option{^-b^/ACTIONS=BIND^}
all the units in the closure of the main program must have been previously
-compiled and must be up to date, and the main program need to have been bound.
+compiled and must be up to date, and the main program needs to have been bound.
The root unit specified by @var{file_name}
may be given without extension, with the source extension or, if no GNAT
Project File is specified, with the ALI file extension.
@item ^-m^/MINIMAL_RECOMPILATION^
-@cindex @option{^-m^/MINIMAL_RECOMPILATION^} (@code{gnatmake})
-Specifies that the minimum necessary amount of recompilations
-be performed. In this mode @code{gnatmake} ignores time
+@cindex @option{^-m^/MINIMAL_RECOMPILATION^} (@command{gnatmake})
+Specify that the minimum necessary amount of recompilations
+be performed. In this mode @command{gnatmake} ignores time
stamp differences when the only
modifications to a source file consist in adding/removing comments,
empty lines, spaces or tabs. This means that if you have changed the
comments in a source file or have simply reformatted it, using this
-switch will tell gnatmake not to recompile files that depend on it
+switch will tell @command{gnatmake} not to recompile files that depend on it
(provided other sources on which these files depend have undergone no
semantic modifications). Note that the debugging information may be
out of date with respect to the sources if the @option{-m} switch causes
@item ^-M^/DEPENDENCIES_LIST^
@cindex Dependencies, producing list
-@cindex @option{^-M^/DEPENDENCIES_LIST^} (@code{gnatmake})
+@cindex @option{^-M^/DEPENDENCIES_LIST^} (@command{gnatmake})
Check if all objects are up to date. If they are, output the object
dependences to @file{stdout} in a form that can be directly exploited in
a @file{Makefile}. By default, each source file is prefixed with its
are never reported.
@item ^-n^/DO_OBJECT_CHECK^
-@cindex @option{^-n^/DO_OBJECT_CHECK^} (@code{gnatmake})
+@cindex @option{^-n^/DO_OBJECT_CHECK^} (@command{gnatmake})
Don't compile, bind, or link. Checks if all objects are up to date.
If they are not, the full name of the first file that needs to be
recompiled is printed.
file, will eventually result in recompiling all required units.
@item ^-o ^/EXECUTABLE=^@var{exec_name}
-@cindex @option{^-o^/EXECUTABLE^} (@code{gnatmake})
+@cindex @option{^-o^/EXECUTABLE^} (@command{gnatmake})
Output executable name. The name of the final executable program will be
@var{exec_name}. If the @option{^-o^/EXECUTABLE^} switch is omitted the default
name for the executable will be the name of the input file in appropriate form
for an executable file on the host system.
-This switch cannot be used when invoking @code{gnatmake} with several
+This switch cannot be used when invoking @command{gnatmake} with several
@file{file_names}.
+@item ^-p or --create-missing-dirs^/CREATE_MISSING_DIRS^
+@cindex @option{^-p^/CREATE_MISSING_DIRS^} (@command{gnatmake})
+When using project files (^-P^/PROJECT_FILE=^@var{project}), create
+automatically missing object directories, library directories and exec
+directories.
+
@item ^-P^/PROJECT_FILE=^@var{project}
-@cindex @option{^-P^/PROJECT_FILE^} (@code{gnatmake})
+@cindex @option{^-P^/PROJECT_FILE^} (@command{gnatmake})
Use project file @var{project}. Only one such switch can be used.
-See @ref{gnatmake and Project Files}.
+@xref{gnatmake and Project Files}.
@item ^-q^/QUIET^
-@cindex @option{^-q^/QUIET^} (@code{gnatmake})
+@cindex @option{^-q^/QUIET^} (@command{gnatmake})
Quiet. When this flag is not set, the commands carried out by
-@code{gnatmake} are displayed.
+@command{gnatmake} are displayed.
@item ^-s^/SWITCH_CHECK/^
-@cindex @option{^-s^/SWITCH_CHECK^} (@code{gnatmake})
+@cindex @option{^-s^/SWITCH_CHECK^} (@command{gnatmake})
Recompile if compiler switches have changed since last compilation.
All compiler switches but -I and -o are taken into account in the
following way:
This switch is recommended when Integrated Preprocessing is used.
@item ^-u^/UNIQUE^
-@cindex @option{^-u^/UNIQUE^} (@code{gnatmake})
+@cindex @option{^-u^/UNIQUE^} (@command{gnatmake})
Unique. Recompile at most the main files. It implies -c. Combined with
-f, it is equivalent to calling the compiler directly. Note that using
^-u^/UNIQUE^ with a project file and no main has a special meaning
-(see @ref{Project Files and Main Subprograms}).
+(@pxref{Project Files and Main Subprograms}).
@item ^-U^/ALL_PROJECTS^
-@cindex @option{^-U^/ALL_PROJECTS^} (@code{gnatmake})
+@cindex @option{^-U^/ALL_PROJECTS^} (@command{gnatmake})
When used without a project file or with one or several mains on the command
line, is equivalent to ^-u^/UNIQUE^. When used with a project file and no main
on the command line, all sources of all project files are checked and compiled
if not up to date, and libraries are rebuilt, if necessary.
@item ^-v^/REASONS^
-@cindex @option{^-v^/REASONS^} (@code{gnatmake})
-Verbose. Displays the reason for all recompilations @code{gnatmake}
-decides are necessary.
+@cindex @option{^-v^/REASONS^} (@command{gnatmake})
+Verbose. Display the reason for all recompilations @command{gnatmake}
+decides are necessary, with the highest verbosity level.
+
+@item ^-vl^/LOW_VERBOSITY^
+@cindex @option{^-vl^/LOW_VERBOSITY^} (@command{gnatmake})
+Verbosity level Low. Display fewer lines than in verbosity Medium.
+
+@item ^-vm^/MEDIUM_VERBOSITY^
+@cindex @option{^-vm^/MEDIUM_VERBOSITY^} (@command{gnatmake})
+Verbosity level Medium. Potentially display fewer lines than in verbosity High.
+
+@item ^-vh^/HIGH_VERBOSITY^
+@cindex @option{^-vm^/HIGH_VERBOSITY^} (@command{gnatmake})
+Verbosity level High. Equivalent to ^-v^/REASONS^.
@item ^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}
-Indicates the verbosity of the parsing of GNAT project files.
-See @ref{Switches Related to Project Files}.
+Indicate the verbosity of the parsing of GNAT project files.
+@xref{Switches Related to Project Files}.
@item ^-x^/NON_PROJECT_UNIT_COMPILATION^
-@cindex @option{^-x^/NON_PROJECT_UNIT_COMPILATION^} (@code{gnatmake})
-Indicates that sources that are not part of any Project File may be compiled.
+@cindex @option{^-x^/NON_PROJECT_UNIT_COMPILATION^} (@command{gnatmake})
+Indicate that sources that are not part of any Project File may be compiled.
Normally, when using Project Files, only sources that are part of a Project
File may be compile. When this switch is used, a source outside of all Project
Files may be compiled. The ALI file and the object file will be put in the
object directory of the main Project. The compilation switches used will only
-be those specified on the command line.
+be those specified on the command line. Even when
+@option{^-x^/NON_PROJECT_UNIT_COMPILATION^} is used, mains specified on the
+command line need to be sources of a project file.
@item ^-X^/EXTERNAL_REFERENCE=^@var{name=value}
-Indicates that external variable @var{name} has the value @var{value}.
+Indicate that external variable @var{name} has the value @var{value}.
The Project Manager will use this value for occurrences of
@code{external(name)} when parsing the project file.
-See @ref{Switches Related to Project Files}.
+@xref{Switches Related to Project Files}.
@item ^-z^/NOMAIN^
-@cindex @option{^-z^/NOMAIN^} (@code{gnatmake})
+@cindex @option{^-z^/NOMAIN^} (@command{gnatmake})
No main subprogram. Bind and link the program even if the unit name
given on the command line is a package name. The resulting executable
will execute the elaboration routines of the package and its closure,
then the finalization routines.
-@item ^-g^/DEBUG^
-@cindex @option{^-g^/DEBUG^} (@code{gnatmake})
-Enable debugging. This switch is simply passed to the compiler and to the
-linker.
-
@end table
@table @asis
-@item @code{gcc} @asis{switches}
+@item @command{gcc} @asis{switches}
@ifclear vms
-Any uppercase or multi-character switch that is not a @code{gnatmake} switch
-is passed to @code{gcc} (e.g. @option{-O}, @option{-gnato,} etc.)
+Any uppercase or multi-character switch that is not a @command{gnatmake} switch
+is passed to @command{gcc} (e.g.@: @option{-O}, @option{-gnato,} etc.)
@end ifclear
@ifset vms
Any qualifier that cannot be recognized as a qualifier for @code{GNAT MAKE}
@table @option
@c !sort!
@item ^-aI^/SOURCE_SEARCH=^@var{dir}
-@cindex @option{^-aI^/SOURCE_SEARCH^} (@code{gnatmake})
+@cindex @option{^-aI^/SOURCE_SEARCH^} (@command{gnatmake})
When looking for source files also look in directory @var{dir}.
The order in which source files search is undertaken is
described in @ref{Search Paths and the Run-Time Library (RTL)}.
@item ^-aL^/SKIP_MISSING=^@var{dir}
-@cindex @option{^-aL^/SKIP_MISSING^} (@code{gnatmake})
+@cindex @option{^-aL^/SKIP_MISSING^} (@command{gnatmake})
Consider @var{dir} as being an externally provided Ada library.
-Instructs @code{gnatmake} to skip compilation units whose @file{.ALI}
+Instructs @command{gnatmake} to skip compilation units whose @file{.ALI}
files have been located in directory @var{dir}. This allows you to have
missing bodies for the units in @var{dir} and to ignore out of date bodies
for the same units. You still need to specify
@option{^-aI^/SOURCE_SEARCH=^@var{dir}}
or @option{^-I^/SEARCH=^@var{dir}}.
Note: this switch is provided for compatibility with previous versions
-of @code{gnatmake}. The easier method of causing standard libraries
+of @command{gnatmake}. The easier method of causing standard libraries
to be excluded from consideration is to write-protect the corresponding
ALI files.
@item ^-aO^/OBJECT_SEARCH=^@var{dir}
-@cindex @option{^-aO^/OBJECT_SEARCH^} (@code{gnatmake})
+@cindex @option{^-aO^/OBJECT_SEARCH^} (@command{gnatmake})
When searching for library and object files, look in directory
@var{dir}. The order in which library files are searched is described in
@ref{Search Paths for gnatbind}.
@item ^-A^/CONDITIONAL_SOURCE_SEARCH=^@var{dir}
-@cindex Search paths, for @code{gnatmake}
-@cindex @option{^-A^/CONDITIONAL_SOURCE_SEARCH^} (@code{gnatmake})
+@cindex Search paths, for @command{gnatmake}
+@cindex @option{^-A^/CONDITIONAL_SOURCE_SEARCH^} (@command{gnatmake})
Equivalent to @option{^-aL^/SKIP_MISSING=^@var{dir}
^-aI^/SOURCE_SEARCH=^@var{dir}}.
@item ^-I^/SEARCH=^@var{dir}
-@cindex @option{^-I^/SEARCH^} (@code{gnatmake})
+@cindex @option{^-I^/SEARCH^} (@command{gnatmake})
Equivalent to @option{^-aO^/OBJECT_SEARCH=^@var{dir}
^-aI^/SOURCE_SEARCH=^@var{dir}}.
@item ^-I-^/NOCURRENT_DIRECTORY^
-@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@code{gnatmake})
+@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@command{gnatmake})
@cindex Source files, suppressing search
Do not look for source files in the directory containing the source
file named in the command line.
Do not look for ALI or object files in the directory
-where @code{gnatmake} was invoked.
+where @command{gnatmake} was invoked.
@item ^-L^/LIBRARY_SEARCH=^@var{dir}
-@cindex @option{^-L^/LIBRARY_SEARCH^} (@code{gnatmake})
+@cindex @option{^-L^/LIBRARY_SEARCH^} (@command{gnatmake})
@cindex Linker libraries
Add directory @var{dir} to the list of directories in which the linker
will search for libraries. This is equivalent to
@end ifclear
@item -nostdinc
-@cindex @option{-nostdinc} (@code{gnatmake})
+@cindex @option{-nostdinc} (@command{gnatmake})
Do not look for source files in the system default directory.
@item -nostdlib
-@cindex @option{-nostdlib} (@code{gnatmake})
+@cindex @option{-nostdlib} (@command{gnatmake})
Do not look for library files in the system default directory.
@item --RTS=@var{rts-path}
-@cindex @option{--RTS} (@code{gnatmake})
+@cindex @option{--RTS} (@command{gnatmake})
Specifies the default location of the runtime library. GNAT looks for the
runtime
in the following directories, and stops as soon as a valid runtime is found
@end table
@node Mode Switches for gnatmake
-@section Mode Switches for @code{gnatmake}
+@section Mode Switches for @command{gnatmake}
@noindent
The mode switches (referred to as @code{mode_switches}) allow the
@table @option
@c !sort!
@item -cargs @var{switches}
-@cindex @option{-cargs} (@code{gnatmake})
+@cindex @option{-cargs} (@command{gnatmake})
Compiler switches. Here @var{switches} is a list of switches
-that are valid switches for @code{gcc}. They will be passed on to
-all compile steps performed by @code{gnatmake}.
+that are valid switches for @command{gcc}. They will be passed on to
+all compile steps performed by @command{gnatmake}.
@item -bargs @var{switches}
-@cindex @option{-bargs} (@code{gnatmake})
+@cindex @option{-bargs} (@command{gnatmake})
Binder switches. Here @var{switches} is a list of switches
that are valid switches for @code{gnatbind}. They will be passed on to
-all bind steps performed by @code{gnatmake}.
+all bind steps performed by @command{gnatmake}.
@item -largs @var{switches}
-@cindex @option{-largs} (@code{gnatmake})
+@cindex @option{-largs} (@command{gnatmake})
Linker switches. Here @var{switches} is a list of switches
-that are valid switches for @code{gnatlink}. They will be passed on to
-all link steps performed by @code{gnatmake}.
+that are valid switches for @command{gnatlink}. They will be passed on to
+all link steps performed by @command{gnatmake}.
@item -margs @var{switches}
-@cindex @option{-margs} (@code{gnatmake})
-Make switches. The switches are directly interpreted by @code{gnatmake},
+@cindex @option{-margs} (@command{gnatmake})
+Make switches. The switches are directly interpreted by @command{gnatmake},
regardless of any previous occurrence of @option{-cargs}, @option{-bargs}
or @option{-largs}.
@end table
@noindent
This section contains some additional useful notes on the operation
-of the @code{gnatmake} command.
+of the @command{gnatmake} command.
@itemize @bullet
@item
-@cindex Recompilation, by @code{gnatmake}
-If @code{gnatmake} finds no ALI files, it recompiles the main program
+@cindex Recompilation, by @command{gnatmake}
+If @command{gnatmake} finds no ALI files, it recompiles the main program
and all other units required by the main program.
-This means that @code{gnatmake}
+This means that @command{gnatmake}
can be used for the initial compile, as well as during subsequent steps of
the development cycle.
@item
If you enter @code{gnatmake @var{file}.adb}, where @file{@var{file}.adb}
-is a subunit or body of a generic unit, @code{gnatmake} recompiles
+is a subunit or body of a generic unit, @command{gnatmake} recompiles
@file{@var{file}.adb} (because it finds no ALI) and stops, issuing a
warning.
@item
-In @code{gnatmake} the switch @option{^-I^/SEARCH^}
+In @command{gnatmake} the switch @option{^-I^/SEARCH^}
is used to specify both source and
library file paths. Use @option{^-aI^/SOURCE_SEARCH^}
instead if you just want to specify
only.
@item
-@code{gnatmake} examines both an ALI file and its corresponding object file
-for consistency. If an ALI is more recent than its corresponding object,
-or if the object file is missing, the corresponding source will be recompiled.
-Note that @code{gnatmake} expects an ALI and the corresponding object file
-to be in the same directory.
-
-@item
-@code{gnatmake} will ignore any files whose ALI file is write-protected.
+@command{gnatmake} will ignore any files whose ALI file is write-protected.
This may conveniently be used to exclude standard libraries from
consideration and in particular it means that the use of the
@option{^-f^/FORCE_COMPILE^} switch will not recompile these files
unless @option{^-a^/ALL_FILES^} is also specified.
@item
-@code{gnatmake} has been designed to make the use of Ada libraries
+@command{gnatmake} has been designed to make the use of Ada libraries
particularly convenient. Assume you have an Ada library organized
as follows: @i{^obj-dir^[OBJ_DIR]^} contains the objects and ALI files for
of your Ada compilation units,
@end smallexample
@item
-Using @code{gnatmake} along with the
+Using @command{gnatmake} along with the
@option{^-m (minimal recompilation)^/MINIMAL_RECOMPILATION^}
-switch provides a mechanism for avoiding unnecessary rcompilations. Using
+switch provides a mechanism for avoiding unnecessary recompilations. Using
this switch,
you can update the comments/format of your
source files without having to recompile everything. Note, however, that
@end itemize
@node How gnatmake Works
-@section How @code{gnatmake} Works
+@section How @command{gnatmake} Works
@noindent
-Generally @code{gnatmake} automatically performs all necessary
+Generally @command{gnatmake} automatically performs all necessary
recompilations and you don't need to worry about how it works. However,
-it may be useful to have some basic understanding of the @code{gnatmake}
+it may be useful to have some basic understanding of the @command{gnatmake}
approach and in particular to understand how it uses the results of
previous compilations without incorrectly depending on them.
First a definition: an object file is considered @dfn{up to date} if the
-corresponding ALI file exists and its time stamp predates that of the
-object file and if all the source files listed in the
+corresponding ALI file exists and if all the source files listed in the
dependency section of this ALI file have time stamps matching those in
the ALI file. This means that neither the source file itself nor any
files that it depends on have been modified, and hence there is no need
to recompile this file.
-@code{gnatmake} works by first checking if the specified main unit is up
+@command{gnatmake} works by first checking if the specified main unit is up
to date. If so, no compilations are required for the main unit. If not,
-@code{gnatmake} compiles the main program to build a new ALI file that
+@command{gnatmake} compiles the main program to build a new ALI file that
reflects the latest sources. Then the ALI file of the main unit is
examined to find all the source files on which the main program depends,
-and @code{gnatmake} recursively applies the above procedure on all these files.
+and @command{gnatmake} recursively applies the above procedure on all these
+files.
-This process ensures that @code{gnatmake} only trusts the dependencies
+This process ensures that @command{gnatmake} only trusts the dependencies
in an existing ALI file if they are known to be correct. Otherwise it
always recompiles to determine a new, guaranteed accurate set of
dependencies. As a result the program is compiled ``upside down'' from what may
systems. In particular, clients are compiled before the units on which
they depend. The ability of GNAT to compile in any order is critical in
allowing an order of compilation to be chosen that guarantees that
-@code{gnatmake} will recompute a correct set of new dependencies if
+@command{gnatmake} will recompute a correct set of new dependencies if
necessary.
-When invoking @code{gnatmake} with several @var{file_names}, if a unit is
+When invoking @command{gnatmake} with several @var{file_names}, if a unit is
imported by several of the executables, it will be recompiled at most once.
Note: when using non-standard naming conventions
-(See @ref{Using Other File Names}), changing through a configuration pragmas
-file the version of a source and invoking @code{gnatmake} to recompile may
+(@pxref{Using Other File Names}), changing through a configuration pragmas
+file the version of a source and invoking @command{gnatmake} to recompile may
have no effect, if the previous version of the source is still accessible
-by @code{gnatmake}. It may be necessary to use the switch ^-f^/FORCE_COMPILE^.
+by @command{gnatmake}. It may be necessary to use the switch
+^-f^/FORCE_COMPILE^.
@node Examples of gnatmake Usage
-@section Examples of @code{gnatmake} Usage
+@section Examples of @command{gnatmake} Usage
@table @code
@item gnatmake hello.adb
@ifset vms
@item gnatmake Main_Unit /QUIET
- /COMPILER_QUALIFIERS /OPTIMIZE=ALL
- /BINDER_QUALIFIERS /ORDER_OF_ELABORATION
+/COMPILER_QUALIFIERS /OPTIMIZE=ALL
+/BINDER_QUALIFIERS /ORDER_OF_ELABORATION
@end ifset
Compile all files necessary to bind and link the main program unit
@code{Main_Unit} (from file @file{main_unit.adb}). All compilations will
be done with optimization level 2 and the order of elaboration will be
-listed by the binder. @code{gnatmake} will operate in quiet mode, not
+listed by the binder. @command{gnatmake} will operate in quiet mode, not
displaying commands it is executing.
@end table
-
@c *************************
@node Improving Performance
@chapter Improving Performance
This chapter presents several topics related to program performance.
It first describes some of the tradeoffs that need to be considered
and some of the techniques for making your program run faster.
-It then documents the @command{gnatelim} tool, which can reduce
-the size of program executables.
+It then documents the @command{gnatelim} tool and unused subprogram/data
+elimination feature, which can reduce the size of program executables.
+
+Note: to invoke @command{gnatelim} with a project file, use the @code{gnat}
+driver (see @ref{The GNAT Driver and Project Files}).
@ifnottex
@menu
* Performance Considerations::
-* Reducing the Size of Ada Executables with gnatelim::
+* Text_IO Suggestions::
+* Reducing Size of Ada Executables with gnatelim::
+* Reducing Size of Executables with unused subprogram/data elimination::
@end menu
@end ifnottex
-
@c *****************************
@node Performance Considerations
@section Performance Considerations
* Optimization Levels::
* Debugging Optimized Code::
* Inlining of Subprograms::
+* Other Optimization Switches::
* Optimization and Strict Aliasing::
+
@ifset vms
* Coverage Analysis::
@end ifset
@subsection Controlling Run-Time Checks
@noindent
-By default, GNAT generates all run-time checks, except arithmetic overflow
-checking for integer operations and checks for access before elaboration on
+By default, GNAT generates all run-time checks, except integer overflow
+checks, stack overflow checks, and checks for access before elaboration on
subprogram calls. The latter are not required in default mode, because all
necessary checking is done at compile time.
-@cindex @option{-gnatp} (@code{gcc})
-@cindex @option{-gnato} (@code{gcc})
+@cindex @option{-gnatp} (@command{gcc})
+@cindex @option{-gnato} (@command{gcc})
Two gnat switches, @option{-gnatp} and @option{-gnato} allow this default to
be modified. @xref{Run-Time Checks}.
have to be marked as non-abortable.
If you use neither the @code{abort} statement, nor asynchronous transfer
-of control (@code{select .. then abort}), then this distributed overhead
+of control (@code{select @dots{} then abort}), then this distributed overhead
is removed, which may have a general positive effect in improving
overall performance. Especially code involving frequent use of tasking
constructs and controlled types will show much improved performance.
The relevant restrictions pragmas are
-@smallexample
+@smallexample @c ada
pragma Restrictions (No_Abort_Statements);
pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);
@end smallexample
@node Optimization Levels
@subsection Optimization Levels
-@cindex @option{^-O^/OPTIMIZE^} (@code{gcc})
+@cindex @option{^-O^/OPTIMIZE^} (@command{gcc})
+
+@noindent
+Without any optimization ^option,^qualifier,^
+the compiler's goal is to reduce the cost of
+compilation and to make debugging produce the expected results.
+Statements are independent: if you stop the program with a breakpoint between
+statements, you can then assign a new value to any variable or change
+the program counter to any other statement in the subprogram and get exactly
+the results you would expect from the source code.
+
+Turning on optimization makes the compiler attempt to improve the
+performance and/or code size at the expense of compilation time and
+possibly the ability to debug the program.
+
+If you use multiple
+^-O options, with or without level numbers,^/OPTIMIZE qualifiers,^
+the last such option is the one that is effective.
@noindent
The default is optimization off. This results in the fastest compile
generated programs are considerably larger and slower than when
optimization is enabled. You can use the
@ifclear vms
-@option{-O@var{n}} switch, where @var{n} is an integer from 0 to 3,
+@option{-O} switch (the permitted forms are @option{-O0}, @option{-O1}
+@option{-O2}, @option{-O3}, and @option{-Os})
@end ifclear
@ifset vms
@code{OPTIMIZE} qualifier
@end ifset
-to @code{gcc} to control the optimization level:
+to @command{gcc} to control the optimization level:
@table @option
@item ^-O0^/OPTIMIZE=NONE^
generates unoptimized code but has
the fastest compilation time.
+Note that many other compilers do fairly extensive optimization
+even if ``no optimization'' is specified. With gcc, it is
+very unusual to use ^-O0^/OPTIMIZE=NONE^ for production if
+execution time is of any concern, since ^-O0^/OPTIMIZE=NONE^
+really does mean no optimization at all. This difference between
+gcc and other compilers should be kept in mind when doing
+performance comparisons.
+
@item ^-O1^/OPTIMIZE=SOME^
-Medium level optimization;
+Moderate optimization;
optimizes reasonably well but does not
degrade compilation time significantly.
Full optimization as in @option{-O2},
and also attempts automatic inlining of small
subprograms within a unit (@pxref{Inlining of Subprograms}).
+
+@item ^-Os^/OPTIMIZE=SPACE^
+Optimize space usage of resulting program.
@end table
@noindent
Since the precise set of optimizations done at each level will vary from
release to release (and sometime from target to target), it is best to think
of the optimization settings in general terms.
-The @cite{Using GNU GCC} manual contains details about
+@xref{Optimize Options,, Options That Control Optimization, gcc, Using
+the GNU Compiler Collection (GCC)}, for details about
^the @option{-O} settings and a number of @option{-f} options that^how to^
individually enable or disable specific optimizations.
Note regarding the use of @option{-O3}: The use of this optimization level
is generally discouraged with GNAT, since it often results in larger
executables which run more slowly. See further discussion of this point
-in @pxref{Inlining of Subprograms}.
-
+in @ref{Inlining of Subprograms}.
@node Debugging Optimized Code
@subsection Debugging Optimized Code
@noindent
Although it is possible to do a reasonable amount of debugging at
@ifclear vms
-non-zero optimization levels,
+nonzero optimization levels,
the higher the level the more likely that
@end ifclear
@ifset vms
^level^setting^ @option{-O1} or higher.
The use of the @option{^-g^/DEBUG^} switch,
-@cindex @option{^-g^/DEBUG^} (@code{gcc})
+@cindex @option{^-g^/DEBUG^} (@command{gcc})
which is needed for source-level debugging,
affects the size of the program executable on disk,
and indeed the debugging information can be quite large.
which removes both debugging information and global symbols.
@end ifclear
-
@node Inlining of Subprograms
@subsection Inlining of Subprograms
@item
The called subprogram is suitable for inlining: It must be small enough
-and not contain nested subprograms or anything else that @code{gcc}
-cannot support in inlined subprograms.
-
-@item
-The call occurs after the definition of the body of the subprogram.
+and not contain something that @command{gcc} cannot support in inlined
+subprograms.
@item
@cindex pragma Inline
@findex Inline
-Either @code{pragma Inline} applies to the subprogram or it is
-small and automatic inlining (optimization level @option{-O3}) is
-specified.
+Either @code{pragma Inline} applies to the subprogram, or it is local
+to the unit and called once from within it, or it is small and automatic
+inlining (optimization level @option{-O3}) is specified.
@end itemize
@noindent
Calls to subprograms in @code{with}'ed units are normally not inlined.
-To achieve this level of inlining, the following conditions must all be
-true:
+To achieve actual inlining (that is, replacement of the call by the code
+in the body of the subprogram), the following conditions must all be true.
@itemize @bullet
@item
@item
The called subprogram is suitable for inlining: It must be small enough
-and not contain nested subprograms or anything else @code{gcc} cannot
-support in inlined subprograms.
+and not contain something that @command{gcc} cannot support in inlined
+subprograms.
@item
The call appears in a body (not in a package spec).
There is a @code{pragma Inline} for the subprogram.
@item
-@cindex @option{-gnatn} (@code{gcc})
+@cindex @option{-gnatn} (@command{gcc})
The @option{^-gnatn^/INLINE^} switch
-is used in the @code{gcc} command line
+is used in the @command{gcc} command line
@end itemize
+Even if all these conditions are met, it may not be possible for
+the compiler to inline the call, due to the length of the body,
+or features in the body that make it impossible for the compiler
+to do the inlining.
+
Note that specifying the @option{-gnatn} switch causes additional
compilation dependencies. Consider the following:
pragma Inline (Q);
end R;
package body R is
- ...
+ @dots{}
end R;
with R;
procedure Main is
begin
- ...
+ @dots{}
R.Q;
end Main;
@end cartouche
enough, but now @code{Main} depends on the body of @code{R} in
@file{r.adb} as well as on the spec. This means that if this body is edited,
the main program must be recompiled. Note that this extra dependency
-occurs whether or not the call is in fact inlined by @code{gcc}.
+occurs whether or not the call is in fact inlined by @command{gcc}.
The use of front end inlining with @option{-gnatN} generates similar
additional dependencies.
-@cindex @option{^-fno-inline^/INLINE=SUPPRESS^} (@code{gcc})
+@cindex @option{^-fno-inline^/INLINE=SUPPRESS^} (@command{gcc})
Note: The @option{^-fno-inline^/INLINE=SUPPRESS^} switch
can be used to prevent
all inlining. This switch overrides all other conditions and ensures
@option{-gnatn} will still be active, even if
this switch is used to suppress the resulting inlining actions.
+@cindex @option{-fno-inline-functions} (@command{gcc})
+Note: The @option{-fno-inline-functions} switch can be used to prevent
+automatic inlining of small subprograms if @option{-O3} is used.
+
+@cindex @option{-fno-inline-functions-called-once} (@command{gcc})
+Note: The @option{-fno-inline-functions-called-once} switch
+can be used to prevent inlining of subprograms local to the unit
+and called once from within it if @option{-O1} is used.
+
Note regarding the use of @option{-O3}: There is no difference in inlining
behavior between @option{-O2} and @option{-O3} for subprograms with an explicit
pragma @code{Inline} assuming the use of @option{-gnatn}
@option{-O2}, and indeed you should use @option{-O3} only if tests show that
it actually improves performance.
+@node Other Optimization Switches
+@subsection Other Optimization Switches
+@cindex Optimization Switches
+
+Since @code{GNAT} uses the @command{gcc} back end, all the specialized
+@command{gcc} optimization switches are potentially usable. These switches
+have not been extensively tested with GNAT but can generally be expected
+to work. Examples of switches in this category are
+@option{-funroll-loops} and
+the various target-specific @option{-m} options (in particular, it has been
+observed that @option{-march=pentium4} can significantly improve performance
+on appropriate machines). For full details of these switches, see
+@ref{Submodel Options,, Hardware Models and Configurations, gcc, Using
+the GNU Compiler Collection (GCC)}.
+
@node Optimization and Strict Aliasing
@subsection Optimization and Strict Aliasing
@cindex Aliasing
type Int2A is access Int2;
Int1V : Int1A;
Int2V : Int2A;
- ...
+ @dots{}
begin
- ...
+ @dots{}
for J in Data'Range loop
if Data (J) = Int1V.all then
Int2V.all := Int2V.all + 1;
end if;
end loop;
- ...
+ @dots{}
end R;
@end cartouche
@end smallexample
for all iterations of the loop and avoid the extra memory reference
required to dereference it each time through the loop.
-This kind of optimziation, called strict aliasing analysis, is
+This kind of optimization, called strict aliasing analysis, is
triggered by specifying an optimization level of @option{-O2} or
higher and allows @code{GNAT} to generate more efficient code
when access values are involved.
@end smallexample
@noindent
-This program prints out 0 in @code{-O0} or @code{-O1}
-mode, but it prints out 1 in @code{-O2} mode. That's
+This program prints out 0 in @option{-O0} or @option{-O1}
+mode, but it prints out 1 in @option{-O2} mode. That's
because in strict aliasing mode, the compiler can and
does assume that the assignment to @code{v2.all} could not
affect the value of @code{v1.all}, since different types
As implied by the warning message, there are approaches you can use to
avoid the unwanted strict aliasing optimization in a case like this.
-One possibility is to simply avoid the use of @code{-O2}, but
+One possibility is to simply avoid the use of @option{-O2}, but
that is a bit drastic, since it throws away a number of useful
optimizations that do not involve strict aliasing assumptions.
A less drastic approach is to compile the program using the
-option @code{-fno-strict-aliasing}. Actually it is only the
+option @option{-fno-strict-aliasing}. Actually it is only the
unit containing the dereferencing of the suspicious pointer
that needs to be compiled. So in this case, if we compile
unit @code{m} with this switch, then we get the expected
value of zero printed. Analyzing which units might need
the switch can be painful, so a more reasonable approach
-is to compile the entire program with options @code{-O2}
-and @code{-fno-strict-aliasing}. If the performance is
+is to compile the entire program with options @option{-O2}
+and @option{-fno-strict-aliasing}. If the performance is
satisfactory with this combination of options, then the
advantage is that the entire issue of possible "wrong"
optimization due to strict aliasing is avoided.
@subsection Coverage Analysis
@noindent
-GNAT supports the Digital Performance Coverage Analyzer (PCA), which allows
+GNAT supports the HP Performance Coverage Analyzer (PCA), which allows
the user to determine the distribution of execution time across a program,
@pxref{Profiling} for details of usage.
@end ifset
-@node Reducing the Size of Ada Executables with gnatelim
-@section Reducing the Size of Ada Executables with @code{gnatelim}
+
+@node Text_IO Suggestions
+@section @code{Text_IO} Suggestions
+@cindex @code{Text_IO} and performance
+
+@noindent
+The @code{Ada.Text_IO} package has fairly high overheads due in part to
+the requirement of maintaining page and line counts. If performance
+is critical, a recommendation is to use @code{Stream_IO} instead of
+@code{Text_IO} for volume output, since this package has less overhead.
+
+If @code{Text_IO} must be used, note that by default output to the standard
+output and standard error files is unbuffered (this provides better
+behavior when output statements are used for debugging, or if the
+progress of a program is observed by tracking the output, e.g. by
+using the Unix @command{tail -f} command to watch redirected output.
+
+If you are generating large volumes of output with @code{Text_IO} and
+performance is an important factor, use a designated file instead
+of the standard output file, or change the standard output file to
+be buffered using @code{Interfaces.C_Streams.setvbuf}.
+
+
+
+@node Reducing Size of Ada Executables with gnatelim
+@section Reducing Size of Ada Executables with @code{gnatelim}
@findex gnatelim
@noindent
@code{Eliminate} pragmas in the GNAT configuration file @file{gnat.adc} and
recompiling your program, you may decrease the size of its executable,
because the compiler will not generate the code for 'eliminated' subprograms.
-See GNAT Reference Manual for more information about this pragma.
+@xref{Pragma Eliminate,,, gnat_rm, GNAT Reference Manual}, for more
+information about this pragma.
@code{gnatelim} needs as its input data the name of the main subprogram
and a bind file for a main subprogram.
@code{gnatelim} has the following command-line interface:
@smallexample
-$ gnatelim [options] name
+$ gnatelim @ovar{options} name
@end smallexample
@noindent
@cindex @option{^-a^/ALL^} (@command{gnatelim})
Also look for subprograms from the GNAT run time that can be eliminated. Note
that when @file{gnat.adc} is produced using this switch, the entire program
-must be recompiled with switch @option{^-a^/ALL_FILES^} to @code{gnatmake}.
+must be recompiled with switch @option{^-a^/ALL_FILES^} to @command{gnatmake}.
@item ^-I^/INCLUDE_DIRS=^@var{dir}
@cindex @option{^-I^/INCLUDE_DIRS^} (@command{gnatelim})
@item ^--GCC^/COMPILER^=@var{compiler_name}
@cindex @option{^-GCC^/COMPILER^} (@command{gnatelim})
-Instructs @code{gnatelim} to use specific @code{gcc} compiler instead of one
+Instructs @code{gnatelim} to use specific @command{gcc} compiler instead of one
available on the path.
@item ^--GNATMAKE^/GNATMAKE^=@var{gnatmake_name}
@cindex @option{^--GNATMAKE^/GNATMAKE^} (@command{gnatelim})
-Instructs @code{gnatelim} to use specific @code{gnatmake} instead of one
+Instructs @code{gnatelim} to use specific @command{gnatmake} instead of one
available on the path.
-
-@item -d@var{x}
-@cindex @option{-d@var{x}} (@command{gnatelim})
-Activate internal debugging switches. @var{x} is a letter or digit, or
-string of letters or digits, which specifies the type of debugging
-mode desired. Normally these are used only for internal development
-or system debugging purposes. You can find full documentation for these
-switches in the spec of the @code{Gnatelim} unit in the compiler
-source file @file{gnatelim.ads}.
@end table
@noindent
from scratch after that, because you need a consistent @file{gnat.adc} file
during the entire compilation.
-
@node Making Your Executables Smaller
@subsection Making Your Executables Smaller
$ PIPE GNAT ELIM MAIN_PROG > GNAT.ADC
@end ifset
@ifclear vms
-$ gnatelim main_prog >[>] gnat.adc
+$ gnatelim main_prog >@r{[}>@r{]} gnat.adc
@end ifclear
@end smallexample
@end enumerate
+@node Reducing Size of Executables with unused subprogram/data elimination
+@section Reducing Size of Executables with Unused Subprogram/Data Elimination
+@findex unused subprogram/data elimination
+
+@noindent
+This section describes how you can eliminate unused subprograms and data from
+your executable just by setting options at compilation time.
+
+@menu
+* About unused subprogram/data elimination::
+* Compilation options::
+* Example of unused subprogram/data elimination::
+@end menu
+
+@node About unused subprogram/data elimination
+@subsection About unused subprogram/data elimination
+
+@noindent
+By default, an executable contains all code and data of its composing objects
+(directly linked or coming from statically linked libraries), even data or code
+never used by this executable.
+
+This feature will allow you to eliminate such unused code from your
+executable, making it smaller (in disk and in memory).
+
+This functionality is available on all Linux platforms except for the IA-64
+architecture and on all cross platforms using the ELF binary file format.
+In both cases GNU binutils version 2.16 or later are required to enable it.
+
+@node Compilation options
+@subsection Compilation options
+
+@noindent
+The operation of eliminating the unused code and data from the final executable
+is directly performed by the linker.
+
+In order to do this, it has to work with objects compiled with the
+following options:
+@option{-ffunction-sections} @option{-fdata-sections}.
+@cindex @option{-ffunction-sections} (@command{gcc})
+@cindex @option{-fdata-sections} (@command{gcc})
+These options are usable with C and Ada files.
+They will place respectively each
+function or data in a separate section in the resulting object file.
+
+Once the objects and static libraries are created with these options, the
+linker can perform the dead code elimination. You can do this by setting
+the @option{-Wl,--gc-sections} option to gcc command or in the
+@option{-largs} section of @command{gnatmake}. This will perform a
+garbage collection of code and data never referenced.
+
+If the linker performs a partial link (@option{-r} ld linker option), then you
+will need to provide one or several entry point using the
+@option{-e} / @option{--entry} ld option.
+
+Note that objects compiled without the @option{-ffunction-sections} and
+@option{-fdata-sections} options can still be linked with the executable.
+However, no dead code elimination will be performed on those objects (they will
+be linked as is).
+
+The GNAT static library is now compiled with -ffunction-sections and
+-fdata-sections on some platforms. This allows you to eliminate the unused code
+and data of the GNAT library from your executable.
+
+@node Example of unused subprogram/data elimination
+@subsection Example of unused subprogram/data elimination
+
+@noindent
+Here is a simple example:
+
+@smallexample @c ada
+with Aux;
+
+procedure Test is
+begin
+ Aux.Used (10);
+end Test;
+
+package Aux is
+ Used_Data : Integer;
+ Unused_Data : Integer;
+
+ procedure Used (Data : Integer);
+ procedure Unused (Data : Integer);
+end Aux;
+
+package body Aux is
+ procedure Used (Data : Integer) is
+ begin
+ Used_Data := Data;
+ end Used;
+
+ procedure Unused (Data : Integer) is
+ begin
+ Unused_Data := Data;
+ end Unused;
+end Aux;
+@end smallexample
+
+@noindent
+@code{Unused} and @code{Unused_Data} are never referenced in this code
+excerpt, and hence they may be safely removed from the final executable.
+
+@smallexample
+$ gnatmake test
+
+$ nm test | grep used
+020015f0 T aux__unused
+02005d88 B aux__unused_data
+020015cc T aux__used
+02005d84 B aux__used_data
+$ gnatmake test -cargs -fdata-sections -ffunction-sections \
+ -largs -Wl,--gc-sections
+
+$ nm test | grep used
+02005350 T aux__used
+0201ffe0 B aux__used_data
+@end smallexample
+@noindent
+It can be observed that the procedure @code{Unused} and the object
+@code{Unused_Data} are removed by the linker when using the
+appropriate options.
@c ********************************
@node Renaming Files Using gnatchop
time you compile, regarding the source files that it writes as temporary
files that you throw away.
+Note that if your file containing multiple units starts with a byte order
+mark (BOM) specifying UTF-8 encoding, then the files generated by gnatchop
+will each start with a copy of this BOM, meaning that they can be compiled
+automatically in UTF-8 mode without needing to specify an explicit encoding.
@node Operating gnatchop in Compilation Mode
@section Operating gnatchop in Compilation Mode
environment. Using GNAT, the current directory, possibly containing a
@file{gnat.adc} file is the representation
of a compilation environment. For more information on the
-@file{gnat.adc} file, see the section on handling of configuration
-pragmas @pxref{Handling of Configuration Pragmas}.
+@file{gnat.adc} file, see @ref{Handling of Configuration Pragmas}.
Second, in compilation mode, if @code{gnatchop}
is given a file that starts with
The @code{gnatchop} command has the form:
@smallexample
-$ gnatchop switches @var{file name} [@var{file name} @var{file name} ...]
- [@var{directory}]
+$ gnatchop switches @var{file name} @r{[}@var{file name} @dots{}@r{]}
+ @ovar{directory}
@end smallexample
@noindent
@table @option
@c !sort!
+@item --version
+@cindex @option{--version} @command{gnatchop}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatchop}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
@item ^-c^/COMPILATION^
@cindex @option{^-c^/COMPILATION^} (@code{gnatchop})
Causes @code{gnatchop} to operate in compilation mode, in which
previous section for a full description of this mode.
@ifclear vms
-@item -gnatxxx
-This passes the given @option{-gnatxxx} switch to @code{gnat} which is
-used to parse the given file. Not all @code{xxx} options make sense,
+@item -gnat@var{xxx}
+This passes the given @option{-gnat@var{xxx}} switch to @code{gnat} which is
+used to parse the given file. Not all @var{xxx} options make sense,
but for example, the use of @option{-gnati2} allows @code{gnatchop} to
process a source file that uses Latin-2 coding for identifiers.
@end ifclear
The result is that all error messages refer back to the original
unchopped file.
In addition, the debugging information placed into the object file (when
-the @option{^-g^/DEBUG^} switch of @code{gcc} or @code{gnatmake} is specified)
+the @option{^-g^/DEBUG^} switch of @command{gcc} or @command{gnatmake} is
+specified)
also refers back to this original file so that tools like profilers and
debuggers will give information in terms of the original unchopped file.
units to be skipped.
@ifclear vms
-@item --GCC=xxxx
+@item --GCC=@var{xxxx}
@cindex @option{--GCC=} (@code{gnatchop})
Specify the path of the GNAT parser to be used. When this switch is used,
no attempt is made to add the prefix to the GNAT parser executable.
around, for example in email messages. The required sources are simply
concatenated (for example, using a ^Unix @code{cat}^VMS @code{APPEND/NEW}^
command), and then
-@code{gnatchop} is used at the other end to reconstitute the original
+@command{gnatchop} is used at the other end to reconstitute the original
file names.
@item gnatchop file1 file2 file3 direc
@cindex Pragmas, configuration
@noindent
-In Ada 95, configuration pragmas include those pragmas described as
-such in the Ada 95 Reference Manual, as well as
-implementation-dependent pragmas that are configuration pragmas. See the
-individual descriptions of pragmas in the GNAT Reference Manual for
-details on these additional GNAT-specific configuration pragmas. Most
-notably, the pragma @code{Source_File_Name}, which allows
+Configuration pragmas include those pragmas described as
+such in the Ada Reference Manual, as well as
+implementation-dependent pragmas that are configuration pragmas.
+@xref{Implementation Defined Pragmas,,, gnat_rm, GNAT Reference Manual},
+for details on these additional GNAT-specific configuration pragmas.
+Most notably, the pragma @code{Source_File_Name}, which allows
specifying non-default names for source files, is a configuration
pragma. The following is a complete list of configuration pragmas
-recognized by @code{GNAT}:
+recognized by GNAT:
@smallexample
Ada_83
Ada_95
+ Ada_05
+ Ada_2005
+ Assertion_Policy
C_Pass_By_Copy
+ Check_Name
+ Check_Policy
+ Compile_Time_Error
+ Compile_Time_Warning
+ Compiler_Unit
Component_Alignment
+ Debug_Policy
+ Detect_Blocking
Discard_Names
Elaboration_Checks
Eliminate
Extend_System
- Extensions_Allowed
External_Name_Casing
+ Fast_Math
+ Favor_Top_Level
Float_Representation
+ Implicit_Packing
Initialize_Scalars
+ Interrupt_State
License
Locking_Policy
Long_Float
+ No_Run_Time
+ No_Strict_Aliasing
Normalize_Scalars
+ Optimize_Alignment
+ Persistent_BSS
Polling
+ Priority_Specific_Dispatching
Profile
Profile_Warnings
Propagate_Exceptions
Restrictions_Warnings
Reviewable
Source_File_Name
+ Source_File_Name_Project
Style_Checks
Suppress
+ Suppress_Exception_Locations
Task_Dispatching_Policy
Universal_Data
Unsuppress
Use_VADS_Size
- Warnings
Validity_Checks
+ Warnings
+ Wide_Character_Encoding
+
@end smallexample
@menu
GNAT also provides the @code{gnatchop} utility to provide an automatic
way to handle configuration pragmas following the semantics for
compilations (that is, files with multiple units), described in the RM.
-See section @pxref{Operating gnatchop in Compilation Mode} for details.
+See @ref{Operating gnatchop in Compilation Mode} for details.
However, for most purposes, it will be more convenient to edit the
@file{gnat.adc} file that contains configuration pragmas directly,
as described in the following section.
direct editing of the @file{gnat.adc} file, which is a standard format
source file.
-In addition to @file{gnat.adc}, one additional file containing configuration
+In addition to @file{gnat.adc}, additional files containing configuration
pragmas may be applied to the current compilation using the switch
@option{-gnatec}@var{path}. @var{path} must designate an existing file that
contains only configuration pragmas. These configuration pragmas are
in addition to those found in @file{gnat.adc} (provided @file{gnat.adc}
is present and switch @option{-gnatA} is not used).
-It is allowed to specify several switches @option{-gnatec}, however only
-the last one on the command line will be taken into account.
+It is allowed to specify several switches @option{-gnatec}, all of which
+will be taken into account.
If you are using project file, a separate mechanism is provided using
project attributes, see @ref{Specifying Configuration Pragmas} for more
@noindent
In the presence of this pragma, GNAT adds to the definition of the
predefined package SYSTEM all the additional types and subprograms that are
-defined in DEC Ada. See @pxref{Compatibility with DEC Ada} for details.
+defined in HP Ada. See @ref{Compatibility with HP Ada} for details.
@end ifset
@node Handling Arbitrary File Naming Conventions Using gnatname
@noindent
When the source file names do not follow the standard GNAT default file naming
conventions, the GNAT compiler must be given additional information through
-a configuration pragmas file (see @ref{Configuration Pragmas})
+a configuration pragmas file (@pxref{Configuration Pragmas})
or a project file.
-When the non standard file naming conventions are well-defined,
+When the non-standard file naming conventions are well-defined,
a small number of pragmas @code{Source_File_Name} specifying a naming pattern
-(see @ref{Alternative File Naming Schemes}) may be sufficient. However,
+(@pxref{Alternative File Naming Schemes}) may be sufficient. However,
if the file naming conventions are irregular or arbitrary, a number
of pragma @code{Source_File_Name} for individual compilation units
must be defined.
The usual form of the @code{gnatname} command is
@smallexample
-$ gnatname [@var{switches}] @var{naming_pattern} [@var{naming_patterns}]
+$ gnatname @ovar{switches} @var{naming_pattern} @ovar{naming_patterns}
+ @r{[}--and @ovar{switches} @var{naming_pattern} @ovar{naming_patterns}@r{]}
@end smallexample
@noindent
used in file names by the Unix shells or the DOS prompt.
@noindent
+@code{gnatname} may be called with several sections of directories/patterns.
+Sections are separated by switch @code{--and}. In each section, there must be
+at least one pattern. If no directory is specified in a section, the current
+directory (or the project directory is @code{-P} is used) is implied.
+The options other that the directory switches and the patterns apply globally
+even if they are in different sections.
+
+@noindent
Examples of Naming Patterns are
@smallexample
(the ``Glob'' regular expressions).
@noindent
-When invoked with no switches, @code{gnatname} will create a configuration
-pragmas file @file{gnat.adc} in the current working directory, with pragmas
-@code{Source_File_Name} for each file that contains a valid Ada unit.
+When invoked with no switch @code{-P}, @code{gnatname} will create a
+configuration pragmas file @file{gnat.adc} in the current working directory,
+with pragmas @code{Source_File_Name} for each file that contains a valid Ada
+unit.
@node Switches for gnatname
@section Switches for @code{gnatname}
@table @option
@c !sort!
+@item --version
+@cindex @option{--version} @command{gnatname}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatname}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
+@item --and
+Start another section of directories/patterns.
+
@item ^-c^/CONFIG_FILE=^@file{file}
@cindex @option{^-c^/CONFIG_FILE^} (@code{gnatname})
Create a configuration pragmas file @file{file} (instead of the default
There may be zero, one or more spaces between @option{^-D^/DIRS_FILE=^}
and @file{file}.
@file{file} must be an existing, readable text file.
-Each non empty line in @file{file} must be a directory.
+Each nonempty line in @file{file} must be a directory.
Specifying switch @option{^-D^/DIRS_FILE^} is equivalent to specifying as many
-switches @option{^-d^/SOURCE_DIRS^} as there are non empty lines in
+switches @option{^-d^/SOURCE_DIRS^} as there are nonempty lines in
@file{file}.
@item ^-f^/FOREIGN_PATTERN=^@file{pattern}
@noindent
will look for Ada units in all files with the @file{.ada} extension,
and will add to the list of file for project @file{prj.gpr} the C files
-with extension ".^c^C^".
+with extension @file{.^c^C^}.
@item ^-h^/HELP^
@cindex @option{^-h^/HELP^} (@code{gnatname})
@option{^-D^/DIRS_FILE^}. Several Naming Patterns and one excluded pattern
are used in this example.
-
@c *****************************************
@c * G N A T P r o j e c t M a n a g e r *
@c *****************************************
* Objects and Sources in Project Files::
* Importing Projects::
* Project Extension::
+* Project Hierarchy Extension::
* External References in Project Files::
* Packages in Project Files::
* Variables from Imported Projects::
* Naming Schemes::
* Library Projects::
-* Using Third-Party Libraries through Projects::
* Stand-alone Library Projects::
* Switches Related to Project Files::
* Tools Supporting Project Files::
@end ifclear
If you want to define (on the command line) an external variable that is
queried by the project file, you must use the
-@option{^-X^/EXTERNAT_REFERENCE=^@emph{vbl}=@emph{value}} switch.
+@option{^-X^/EXTERNAL_REFERENCE=^@emph{vbl}=@emph{value}} switch.
The Project Manager parses and interprets the project file, and drives the
invoked tool based on the project settings.
The next section introduces the main features of GNAT's project facility
through a sequence of examples; subsequent sections will present the syntax
and semantics in more detail. A more formal description of the project
-facility appears in the GNAT Reference Manual.
+facility appears in @ref{Project File Reference,,, gnat_rm, GNAT
+Reference Manual}.
@c *****************************
@c * Examples of Project Files *
main subprograms. This property is captured in the @code{Main} attribute,
whose value is a list of strings. If a project defines the @code{Main}
attribute, it is not necessary to identify the main subprogram(s) when
-invoking @command{gnatmake} (see @ref{gnatmake and Project Files}).
+invoking @command{gnatmake} (@pxref{gnatmake and Project Files}).
@node Executable File Names
@unnumberedsubsubsec Executable File Names
@noindent
By default, the executable file name corresponding to a main source is
-deducted from the main source file name. Through the attributes
+deduced from the main source file name. Through the attributes
@code{Executable} and @code{Executable_Suffix} of package @code{Builder},
it is possible to change this default.
In project @code{Debug} above, the executable file name
for main source @file{^proc.adb^PROC.ADB^} is
@file{^proc1^PROC1.EXE^}.
Attribute @code{Executable_Suffix}, when specified, may change the suffix
-of the the executable files, when no attribute @code{Executable} applies:
+of the executable files, when no attribute @code{Executable} applies:
its value replace the platform-specific executable suffix.
Attributes @code{Executable} and @code{Executable_Suffix} are the only ways to
-specify a non default executable file name when several mains are built at once
+specify a non-default executable file name when several mains are built at once
in a single @command{gnatmake} command.
@node Source File Naming Conventions
@node Importing Other Projects
@subsection Importing Other Projects
+@cindex @code{ADA_PROJECT_PATH}
@noindent
A compilation unit in a source file in one project may depend on compilation
@noindent
We want to develop an application in directory @file{^/app^[APP]^} that
@code{with} the packages @code{GUI} and @code{Comm}, using the properties of
-the corresponding project files (e.g. the ^switch^switch^ settings
+the corresponding project files (e.g.@: the ^switch^switch^ settings
and object directory).
Skeletal code for a main procedure might be something like the following:
@group
with GUI, Comm;
procedure App_Main is
- ...
+ @dots{}
begin
- ...
+ @dots{}
end App_Main;
@end group
@end smallexample
@noindent
In large software systems it is common to have multiple
implementations of a common interface; in Ada terms, multiple versions of a
-package body for the same specification. For example, one implementation
+package body for the same spec. For example, one implementation
might be safe for use in tasking programs, while another might only be used
in sequential applications. This can be modeled in GNAT using the concept
of @emph{project extension}. If one project (the ``child'') @emph{extends}
the inherited body is not part of the sources of the project, otherwise there
will be a compilation error when compiling the spec.
-For that purpose, the attribute @code{Locally_Removed_Files} is used.
-Its value is a string list: a list of file names.
+For that purpose, the attribute @code{Excluded_Source_Files} is used.
+Its value is a string list: a list of file names. It is also possible to use
+attribute @code{Excluded_Source_List_File}. Its value is a single string:
+the file name of a text file containing a list of file names, one per line.
@smallexample @c @projectfile
project B extends "a" is
for Source_Files use ("pkg.ads");
-- New spec of Pkg does not need a completion
- for Locally_Removed_Files use ("pkg.adb");
+ for Excluded_Source_Files use ("pkg.adb");
end B;
@end smallexample
-Attribute @code{Locally_Removed_Files} may also be used to check if a source
-is still needed: if it is possible to build using @code{gnatmake} when such
-a source is put in attribute @code{Locally_Removed_Files} of a project P, then
+Attribute @code{Excluded_Source_Files} may also be used to check if a source
+is still needed: if it is possible to build using @command{gnatmake} when such
+a source is put in attribute @code{Excluded_Source_Files} of a project P, then
it is possible to remove the source completely from a system that includes
project P.
@menu
* Basic Syntax::
+* Qualified Projects::
* Packages::
* Expressions::
* String Types::
Any name in a project file, such as the project name or a variable name,
has the same syntax as an Ada identifier.
-The reserved words of project files are the Ada reserved words plus
+The reserved words of project files are the Ada 95 reserved words plus
@code{extends}, @code{external}, and @code{project}. Note that the only Ada
reserved words currently used in project file syntax are:
@itemize @bullet
@item
+@code{all}
+@item
+@code{at}
+@item
@code{case}
@item
@code{end}
@item
@code{is}
@item
+@code{limited}
+@item
+@code{null}
+@item
@code{others}
@item
@code{package}
@end itemize
@noindent
-Comments in project files have the same syntax as in Ada, two consecutives
+Comments in project files have the same syntax as in Ada, two consecutive
hyphens through the end of the line.
+@node Qualified Projects
+@subsection Qualified Projects
+
+@noindent
+Before the reserved @code{project}, there may be one or two "qualifiers", that
+is identifiers or other reserved words, to qualify the project.
+
+The current list of qualifiers is:
+
+@itemize @bullet
+@item
+@code{abstract}: qualify a project with no sources. An abstract project must
+have a declaration specifying that there are no sources in the project, and,
+if it extends another project, the project it extends must also be a qualified
+abstract project.
+
+@item
+@code{standard}: a standard project is a non library project with sources.
+
+@item
+@code{aggregate}: for future extension
+
+@item
+@code{aggregate library}: for future extension
+
+@item
+@code{library}: a library project must declare both attributes
+@code{Library_Name} and @code{Library_Dir}.
+
+@item
+@code{configuration}: a configuration project cannot be in a project tree.
+@end itemize
+
@node Packages
@subsection Packages
@item
@code{Eliminate}
@item
+@code{Pretty_Printer}
+@item
+@code{Metrics}
+@item
@code{gnatls}
@item
@code{gnatstub}
@item
@code{IDE}
+@item
+@code{Language_Processing}
@end itemize
@noindent
A @emph{simple string expression} is one of the following:
@itemize @bullet
-@item A literal string; e.g.@code{"comm/my_proj.gpr"}
-@item A string-valued variable reference (see @ref{Variables})
-@item A string-valued attribute reference (see @ref{Attributes})
-@item An external reference (see @ref{External References in Project Files})
+@item A literal string; e.g.@: @code{"comm/my_proj.gpr"}
+@item A string-valued variable reference (@pxref{Variables})
+@item A string-valued attribute reference (@pxref{Attributes})
+@item An external reference (@pxref{External References in Project Files})
@end itemize
@noindent
variables are called @emph{untyped variables}. Typed variables are
particularly useful in @code{case} constructions, to support conditional
attribute declarations.
-(see @ref{case Constructions}).
+(@pxref{case Constructions}).
The string literals in the list are case sensitive and must all be different.
They may include any graphic characters allowed in Ada, including spaces.
others have values that are string lists.
There are two categories of attributes: @emph{simple attributes}
-and @emph{associative arrays} (see @ref{Associative Array Attributes}).
+and @emph{associative arrays} (@pxref{Associative Array Attributes}).
Legal project attribute names, and attribute names for each legal package are
listed below. Attributes names are case-insensitive.
@tab string
@item @code{Exec_Dir}
@tab string
-@item @code{Locally_Removed_Files}
+@item @code{Excluded_Source_Dirs}
@tab string list
-@item @code{Main}
+@item @code{Excluded_Source_Files}
@tab string list
+@item @code{Excluded_Source_List_File}
+@tab string
@item @code{Languages}
@tab string list
-@item @code{Main_Language}
-@tab string
+@item @code{Main}
+@tab string list
@item @code{Library_Dir}
@tab string
@item @code{Library_Name}
@tab string
@item @code{Library_Options}
@tab string list
+@item @code{Library_Src_Dir}
+@tab string
+@item @code{Library_ALI_Dir}
+@tab string
@item @code{Library_GCC}
@tab string
+@item @code{Library_Symbol_File}
+@tab string
+@item @code{Library_Symbol_Policy}
+@tab string
+@item @code{Library_Reference_Symbol_File}
+@tab string
+@item @code{Externally_Built}
+@tab string
@end multitable
@noindent
The following attributes are defined for package @code{Naming}
-(see @ref{Naming Schemes}):
+(@pxref{Naming Schemes}):
@multitable @columnfractions .4 .2 .2 .2
@item Attribute Name @tab Category @tab Index @tab Value
The following attributes are defined for packages @code{Builder},
@code{Compiler}, @code{Binder},
@code{Linker}, @code{Cross_Reference}, and @code{Finder}
-(see @ref{^Switches^Switches^ and Project Files}).
+(@pxref{^Switches^Switches^ and Project Files}).
@multitable @columnfractions .4 .2 .2 .2
@item Attribute Name @tab Category @tab Index @tab Value
@item The name of an imported project
@item The name of a parent project that is extended by the current project
@item An expanded name whose prefix is imported/parent project name,
- and whose selector is a package name
+and whose selector is a package name
@end itemize
@noindent
@end smallexample
@noindent
-In this example, @code{Default} must be either an project imported by the
+In this example, @code{Default} must be either a project imported by the
current project, or the project that the current project extends. If the
attribute is in a package (in this case, in package @code{Builder}), the same
package needs to be specified.
The syntax of a @code{case} construction is based on the Ada case statement
(although there is no @code{null} construction for empty alternatives).
-The case expression must a typed string variable.
+The case expression must be a typed string variable.
Each alternative comprises the reserved word @code{when}, either a list of
literal strings separated by the @code{"|"} character or the reserved word
@code{others}, and the @code{"=>"} token.
An @code{others} alternative, if present, must occur last.
After each @code{=>}, there are zero or more constructions. The only
-constructions allowed in a case construction are other case constructions and
-attribute declarations. String type declarations, variable declarations and
-package declarations are not allowed.
+constructions allowed in a case construction are other case constructions,
+attribute declarations and variable declarations. String type declarations and
+package declarations are not allowed. Variable declarations are restricted to
+variables that have already been declared before the case construction.
The value of the case variable is often given by an external reference
-(see @ref{External References in Project Files}).
+(@pxref{External References in Project Files}).
@c ****************************************
@c * Objects and Sources in Project Files *
Each project has exactly one object directory and one or more source
directories. The source directories must contain at least one source file,
unless the project file explicitly specifies that no source files are present
-(see @ref{Source File Names}).
+(@pxref{Source File Names}).
@node Object Directory
@subsection Object Directory
@end smallexample
@noindent
-The attribute @var{Object_Dir} has a string value, the path name of the object
+The attribute @code{Object_Dir} has a string value, the path name of the object
directory. The path name may be absolute or relative to the directory of the
project file. This directory must already exist, and be readable and writable.
@end smallexample
@noindent
-The attribute @var{Exec_Dir} has a string value, the path name of the exec
+The attribute @code{Exec_Dir} has a string value, the path name of the exec
directory. The path name may be absolute or relative to the directory of the
project file. This directory must already exist, and be writable.
By default, if neither the attribute @code{Source_Files} nor the attribute
@code{Source_List_File} is given an explicit value, then each file in the
source directories that conforms to the project's naming scheme
-(see @ref{Naming Schemes}) is an immediate source of the project.
+(@pxref{Naming Schemes}) is an immediate source of the project.
A warning is issued if both attributes @code{Source_Files} and
@code{Source_List_File} are given explicit values. In this case, the attribute
Otherwise, a project must contain at least one immediate source.
Projects with no source files are useful as template packages
-(see @ref{Packages in Project Files}) for other projects; in particular to
-define a package @code{Naming} (see @ref{Naming Schemes}).
+(@pxref{Packages in Project Files}) for other projects; in particular to
+define a package @code{Naming} (@pxref{Naming Schemes}).
@c ****************************
@c * Importing Projects *
@node Importing Projects
@section Importing Projects
+@cindex @code{ADA_PROJECT_PATH}
@noindent
An immediate source of a project P may depend on source files that
with "project1", "utilities.gpr";
with "/namings/apex.gpr";
project Main is
- ...
+ @dots{}
@end group
@end smallexample
project files rather than packages.
Each literal string is the file name or path name (absolute or relative) of a
-project file. If a string is simply a file name, with no path, then its
-location is determined by the @emph{project path}:
+project file. If a string corresponds to a file name, with no path or a
+relative path, then its location is determined by the @emph{project path}. The
+latter can be queried using @code{gnatls -v}. It contains:
@itemize @bullet
@item
-If the ^environment variable^logical name^ @env{ADA_PROJECT_PATH} exists,
-then the project path includes all the directories in this
-^environment variable^logical name^, plus the directory of the project file.
+In first position, the directory containing the current project file.
+@item
+In last position, the default project directory. This default project directory
+is part of the GNAT installation and is the standard place to install project
+files giving access to standard support libraries.
+@ifclear vms
+@ref{Installing a library}
+@end ifclear
@item
-If the ^environment variable^logical name^ @env{ADA_PROJECT_PATH} does not
-exist, then the project path contains only one directory, namely the one where
-the project file is located.
+In between, all the directories referenced in the
+^environment variable^logical name^ @env{ADA_PROJECT_PATH} if it exists.
@end itemize
@noindent
@end smallexample
@noindent
-then the path is relative to the directory where the importing project file is
-located. Any symbolic link will be fully resolved in the directory
-of the importing project file before the imported project file is examined.
+then the full path for the project is constructed by concatenating this
+relative path to those in the project path, in order, until a matching file is
+found. Any symbolic link will be fully resolved in the directory of the
+importing project file before the imported project file is examined.
If the @code{with}'ed project file name does not have an extension,
the default is @file{^.gpr^.GPR^}. If a file with this extension is not found,
is not allowed to import @code{A}. However, there are cases when cyclic
dependencies would be beneficial. For these cases, another form of import
between projects exists, the @code{limited with}: a project @code{A} that
-imports a project @code{B} with a straigh @code{with} may also be imported,
+imports a project @code{B} with a straight @code{with} may also be imported,
directly or indirectly, by @code{B} on the condition that imports from @code{B}
to @code{A} include at least one @code{limited with}.
sources. This can be achieved through the @emph{project extension} facility.
@smallexample @c projectfile
- project Modified_Utilities extends "/baseline/utilities.gpr" is ...
+ project Modified_Utilities extends "/baseline/utilities.gpr" is @dots{}
@end smallexample
@noindent
An inherited source file retains any switches specified in the parent project.
-For example if the project @code{Utilities} contains the specification and the
+For example if the project @code{Utilities} contains the spec and the
body of an Ada package @code{Util_IO}, then the project
@code{Modified_Utilities} can contain a new body for package @code{Util_IO}.
The original body of @code{Util_IO} will not be considered in program builds.
-However, the package specification will still be found in the project
+However, the package spec will still be found in the project
@code{Utilities}.
-A child project can have only one parent but it may import any number of other
-projects.
+A child project can have only one parent, except when it is qualified as
+abstract. But it may import any number of other projects.
A project is not allowed to import directly or indirectly at the same time a
child project and any of its ancestors.
-@c ****************************************
-@c * External References in Project Files *
-@c ****************************************
+@c *******************************
+@c * Project Hierarchy Extension *
+@c *******************************
+
+@node Project Hierarchy Extension
+@section Project Hierarchy Extension
+
+@noindent
+When extending a large system spanning multiple projects, it is often
+inconvenient to extend every project in the hierarchy that is impacted by a
+small change introduced. In such cases, it is possible to create a virtual
+extension of entire hierarchy using @code{extends all} relationship.
+
+When the project is extended using @code{extends all} inheritance, all projects
+that are imported by it, both directly and indirectly, are considered virtually
+extended. That is, the Project Manager creates "virtual projects"
+that extend every project in the hierarchy; all these virtual projects have
+no sources of their own and have as object directory the object directory of
+the root of "extending all" project.
+
+It is possible to explicitly extend one or more projects in the hierarchy
+in order to modify the sources. These extending projects must be imported by
+the "extending all" project, which will replace the corresponding virtual
+projects with the explicit ones.
+
+When building such a project hierarchy extension, the Project Manager will
+ensure that both modified sources and sources in virtual extending projects
+that depend on them, are recompiled.
+
+By means of example, consider the following hierarchy of projects.
+
+@enumerate
+@item
+project A, containing package P1
+@item
+project B importing A and containing package P2 which depends on P1
+@item
+project C importing B and containing package P3 which depends on P2
+@end enumerate
+
+@noindent
+We want to modify packages P1 and P3.
+
+This project hierarchy will need to be extended as follows:
+
+@enumerate
+@item
+Create project A1 that extends A, placing modified P1 there:
+
+@smallexample @c 0projectfile
+project A1 extends "(@dots{})/A" is
+end A1;
+@end smallexample
+
+@item
+Create project C1 that "extends all" C and imports A1, placing modified
+P3 there:
+
+@smallexample @c 0projectfile
+with "(@dots{})/A1";
+project C1 extends all "(@dots{})/C" is
+end C1;
+@end smallexample
+@end enumerate
+
+When you build project C1, your entire modified project space will be
+recompiled, including the virtual project B1 that has been impacted by the
+"extending all" inheritance of project C.
+
+Note that if a Library Project in the hierarchy is virtually extended,
+the virtual project that extends the Library Project is not a Library Project.
+
+@c ****************************************
+@c * External References in Project Files *
+@c ****************************************
@node External References in Project Files
@section External References in Project Files
Mode : Mode_Type := external ("MODE");
case Mode is
when "Debug" =>
- ...
+ @dots{}
@end group
@end smallexample
A @emph{package} defines the settings for project-aware tools within a
project.
For each such tool one can declare a package; the names for these
-packages are preset (see @ref{Packages}).
+packages are preset (@pxref{Packages}).
A package may contain variable declarations, attribute declarations, and case
constructions.
with "/global/apex.gpr";
project Example is
package Naming renames Apex.Naming;
- ...
+ @dots{}
end Example;
@end group
@end smallexample
In addition to the tool-oriented packages, you can also declare a package
named @code{Naming} to establish specialized source file naming conventions
-(see @ref{Naming Schemes}).
+(@pxref{Naming Schemes}).
@c ************************************
@c * Variables from Imported Projects *
@group
package Builder is
for ^Default_Switches^Default_Switches^ ("Ada")
- use Imported.Builder.Ada_^Switches^Switches^ &
+ use Imported.Builder'Ada_^Switches^Switches^ &
"^-gnatg^-gnatg^" &
"^-v^-v^";
end Builder;
@group
package Compiler is
for ^Default_Switches^Default_Switches^ ("Ada")
- use Base.Compiler.Ada_^Switches^Switches^;
+ use Base.Compiler'Ada_^Switches^Switches^;
end Compiler;
end Main;
@end group
naming scheme in the @code{Naming} package in your project file.
@noindent
-Note that the use of pragmas described in @ref{Alternative
-File Naming Schemes} by mean of a configuration pragmas file is not
-supported when using project files. You must use the features described
-in this paragraph. You can however use specify other configuration
-pragmas (see @ref{Specifying Configuration Pragmas}).
+Note that the use of pragmas described in
+@ref{Alternative File Naming Schemes} by mean of a configuration
+pragmas file is not supported when using project files. You must use
+the features described in this paragraph. You can however use specify
+other configuration pragmas (@pxref{Specifying Configuration Pragmas}).
@ifclear vms
For example, the following
@end ifclear
@ifset vms
-For example, the following package models the DEC Ada file naming rules:
+For example, the following package models the HP Ada file naming rules:
@smallexample @c projectfile
@group
@table @code
-@item @var{Casing}
+@item @code{Casing}
This must be a string with one of the three values @code{"lowercase"},
@code{"uppercase"} or @code{"mixedcase"}; these strings are case insensitive.
@noindent
-If @var{Casing} is not specified, then the default is @code{"lowercase"}.
+If @code{Casing} is not specified, then the default is @code{"lowercase"}.
-@item @var{Dot_Replacement}
+@item @code{Dot_Replacement}
This must be a string whose value satisfies the following conditions:
@itemize @bullet
@noindent
If @code{Dot_Replacement} is not specified, then the default is @code{"-"}.
-@item @var{Spec_Suffix}
+@item @code{Spec_Suffix}
This is an associative array (indexed by the programming language name, case
insensitive) whose value is a string that must satisfy the following
conditions:
If @code{Spec_Suffix ("Ada")} is not specified, then the default is
@code{"^.ads^.ADS^"}.
-@item @var{Body_Suffix}
+@item @code{Body_Suffix}
This is an associative array (indexed by the programming language name, case
insensitive) whose value is a string that must satisfy the following
conditions:
@itemize @bullet
@item It must not be empty
@item It must include at least one dot
-@item It cannot end with the same string as @code{Spec_Suffix ("Ada")}
+@item It cannot be the same as @code{Spec_Suffix ("Ada")}
@end itemize
@noindent
+If @code{Body_Suffix ("Ada")} and @code{Spec_Suffix ("Ada")} end with the
+same string, then a file name that ends with the longest of these two suffixes
+will be a body if the longest suffix is @code{Body_Suffix ("Ada")} or a spec
+if the longest suffix is @code{Spec_Suffix ("Ada")}.
+
If @code{Body_Suffix ("Ada")} is not specified, then the default is
@code{"^.adb^.ADB^"}.
-@item @var{Separate_Suffix}
+@item @code{Separate_Suffix}
This must be a string whose value satisfies the same conditions as
-@code{Body_Suffix}.
+@code{Body_Suffix}. The same "longest suffix" rules apply.
@noindent
If @code{Separate_Suffix ("Ada")} is not specified, then it defaults to same
value as @code{Body_Suffix ("Ada")}.
-@item @var{Spec}
+@item @code{Spec}
@noindent
You can use the associative array attribute @code{Spec} to define
the source file name for an individual Ada compilation unit's spec. The array
for Spec ("MyPack.MyChild") use "mypack.mychild.spec";
@end smallexample
-@item @var{Body}
+@item @code{Body}
You can use the associative array attribute @code{Body} to
define the source file name for an individual Ada compilation unit's body
To create a library project, you need to define in its project file
two project-level attributes: @code{Library_Name} and @code{Library_Dir}.
-Additionally, you may define the library-related attributes
+Additionally, you may define other library-related attributes such as
@code{Library_Kind}, @code{Library_Version}, @code{Library_Interface},
@code{Library_Auto_Init}, @code{Library_Options} and @code{Library_GCC}.
The @code{Library_Name} attribute has a string value. There is no restriction
-on the name of a library. It is the responsability of the developer to
-choose a name that will be accepted by the platform. It is recommanded to
+on the name of a library. It is the responsibility of the developer to
+choose a name that will be accepted by the platform. It is recommended to
choose names that could be Ada identifiers; such names are almost guaranteed
to be acceptable on all platforms.
The @code{Library_Dir} attribute has a string value that designates the path
(absolute or relative) of the directory where the library will reside.
-It must designate an existing directory, and this directory must be
-different from the project's object directory. It also needs to be writable.
-The directory should only be used for one library; the reason is that all
-files contained in this directory may be deleted by the Project Manager.
+It must designate an existing directory, and this directory must be writable,
+different from the project's object directory and from any source directory
+in the project tree.
If both @code{Library_Name} and @code{Library_Dir} are specified and
are legal, then the project file defines a library project. The optional
following (case insensitive): @code{"static"}, @code{"dynamic"} or
@code{"relocatable"} (which is a synonym for @code{"dynamic"}). If this
attribute is not specified, the library is a static library, that is
-an archive of object files that can be potentially linked into an
+an archive of object files that can be potentially linked into a
static executable. Otherwise, the library may be dynamic or
relocatable, that is a library that is loaded only at the start of execution.
two different project files, or a single one which uses external variables
to indicate what kind of library should be build.
+The @code{Library_ALI_Dir} attribute may be specified to indicate the
+directory where the ALI files of the library will be copied. When it is
+not specified, the ALI files are copied to the directory specified in
+attribute @code{Library_Dir}. The directory specified by @code{Library_ALI_Dir}
+must be writable and different from the project's object directory and from
+any source directory in the project tree.
+
The @code{Library_Version} attribute has a string value whose interpretation
is platform dependent. It has no effect on VMS and Windows. On Unix, it is
used only for dynamic/relocatable libraries as the internal name of the
and rebuild the library if any of the sources have been recompiled.
Standard project files can import library project files. In such cases,
-the libraries will only be rebuild if some of its sources are recompiled
+the libraries will only be rebuilt if some of its sources are recompiled
because they are in the closure of some other source in an importing project.
Sources of the library project files that are not in such a closure will
not be checked, unless the full library is checked, because one of its sources
@file{l2.ads}, @file{l2.adb}.
If @file{l1.adb} has been modified, then the library associated with @code{L}
-will be rebuild when compiling all the immediate sources of @code{A} only
+will be rebuilt when compiling all the immediate sources of @code{A} only
if @file{a1.ads}, @file{a2.ads} or @file{a2.adb} includes a statement
@code{"with L1;"}.
To be sure that all the sources in the library associated with @code{L} are
-up to date, and that all the sources of parject @code{A} are also up to date,
+up to date, and that all the sources of project @code{A} are also up to date,
the following two commands needs to be used:
@smallexample
library directory. To build executables, @command{gnatmake} will use the
library rather than the individual object files.
-
-@c **********************************************
-@c * Using Third-Party Libraries through Projects
-@c **********************************************
-@node Using Third-Party Libraries through Projects
-@section Using Third-Party Libraries through Projects
-
-Whether you are exporting your own library to make it available to
-clients, or you are using a library provided by a third party, it is
-convenient to have project files that automatically set the correct
-command line switches for the compiler and linker.
-
-Such project files are very similar to the library project files;
-@xref{Library Projects}. The only difference is that you set the
-@code{Source_Dirs} and @code{Object_Dir} attribute so that they point to the
-directories where, respectively, the sources and the read-only ALI files have
-been installed.
-
-If you need to interface with a set of libraries, as opposed to a
-single one, you need to create one library project for each of the
-libraries. In addition, a top-level project that imports all these
-library projects should be provided, so that the user of your library
-has a single @code{with} clause to add to his own projects.
-
-For instance, let's assume you are providing two static libraries
-@file{liba.a} and @file{libb.a}. The user needs to link with
-both of these libraries. Each of these is associated with its
-own set of header files. Let's assume furthermore that all the
-header files for the two libraries have been installed in the same
-directory @file{headers}. The @file{ALI} files are found in the same
-@file{headers} directory.
-
-In this case, you should provide the following three projects:
-
-@smallexample @c projectfile
-@group
-with "liba", "libb";
-project My_Library is
- for Source_Dirs use ("headers");
- for Object_Dir use "headers";
-end My_Library;
-@end group
-
-@group
-project Liba is
- for Source_Dirs use ();
- for Library_Dir use "lib";
- for Library_Name use "a";
- for Library_Kind use "static";
-end Liba;
-@end group
-
-@group
-project Libb is
- for Source_Dirs use ();
- for Library_Dir use "lib";
- for Library_Name use "b";
- for Library_Kind use "static";
-end Libb;
-@end group
-@end smallexample
+@ifclear vms
+It is also possible to create library project files for third-party libraries
+that are precompiled and cannot be compiled locally thanks to the
+@code{externally_built} attribute. (See @ref{Installing a library}).
+@end ifclear
@c *******************************
@c * Stand-alone Library Projects *
@end group
@end smallexample
-Attribute @code{Library_Interface} has a non empty string list value,
+Attribute @code{Library_Interface} has a nonempty string list value,
each string in the list designating a unit contained in an immediate source
of the project file.
"false" for attribute @code{Library_Auto_Init} will prevent automatic
initialization of dynamic or relocatable libraries.
-When a non automatically initialized Stand-alone Library is used
+When a non-automatically initialized Stand-alone Library is used
in an executable, its initialization procedure must be called before
any service of the library is used.
When the main subprogram is in Ada, it may mean that the initialization
@table @option
@item ^-P^/PROJECT_FILE=^@var{project}
-@cindex @option{^-P^/PROJECT_FILE^} (any tool supporting project files)
+@cindex @option{^-P^/PROJECT_FILE^} (any project-aware tool)
Indicates the name of a project file. This project file will be parsed with
the verbosity indicated by @option{^-vP^MESSAGE_PROJECT_FILES=^@emph{x}},
if any, and using the external references indicated
or @option{^-X^/EXTERNAL_REFERENCE^} is not significant.
@item ^-X^/EXTERNAL_REFERENCE=^@var{name=value}
-@cindex @option{^-X^/EXTERNAL_REFERENCE^} (any tool supporting project files)
+@cindex @option{^-X^/EXTERNAL_REFERENCE^} (any project-aware tool)
Indicates that external variable @var{name} has the value @var{value}.
The Project Manager will use this value for occurrences of
@code{external(name)} when parsing the project file.
takes precedence over the value of the same name in the environment.
@item ^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}
-@cindex @code{^-vP^/MESSAGES_PROJECT_FILE^} (any tool supporting project files)
-@c Previous line uses code vs option command, to stay less than 80 chars
+@cindex @option{^-vP^/MESSAGES_PROJECT_FILE^} (any project-aware tool)
Indicates the verbosity of the parsing of GNAT project files.
@ifclear vms
If several @option{^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}} switches are present,
only the last one is used.
+@item ^-aP^/ADD_PROJECT_SEARCH_DIR=^<dir>
+@cindex @option{^-aP^/ADD_PROJECT_SEARCH_DIR=^} (any project-aware tool)
+Add directory <dir> at the beginning of the project search path, in order,
+after the current working directory.
+
+@ifclear vms
+@item -eL
+@cindex @option{-eL} (any project-aware tool)
+Follow all symbolic links when processing project files.
+@end ifclear
+
+@item ^--subdirs^/SUBDIRS^=<subdir>
+@cindex @option{^--subdirs^/SUBDIRS^=} (gnatmake and gnatclean)
+This switch is recognized by gnatmake and gnatclean. It indicate that the real
+directories (except the source directories) are the subdirectories <subdir>
+of the directories specified in the project files. This applies in particular
+to object directories, library directories and exec directories. If the
+subdirectories do not exist, they are created automatically.
+
@end table
@c **********************************
@menu
* gnatmake and Project Files::
* The GNAT Driver and Project Files::
-@ifclear vms
-* Glide and Project Files::
-@end ifclear
@end menu
@node gnatmake and Project Files
-- Ada source file:
with Pack;
procedure Foo_Main is
- ...
+ @dots{}
end Foo_Main;
@end group
@end smallexample
@noindent
A number of GNAT tools, other than @command{^gnatmake^gnatmake^}
-are project-aware:
+can benefit from project files:
@command{^gnatbind^gnatbind^},
+@command{^gnatcheck^gnatcheck^}),
+@command{^gnatclean^gnatclean^}),
+@command{^gnatelim^gnatelim^},
@command{^gnatfind^gnatfind^},
@command{^gnatlink^gnatlink^},
@command{^gnatls^gnatls^},
-@command{^gnatelim^gnatelim^},
+@command{^gnatmetric^gnatmetric^},
@command{^gnatpp^gnatpp^},
+@command{^gnatstub^gnatstub^},
and @command{^gnatxref^gnatxref^}. However, none of these tools can be invoked
directly with a project file switch (@option{^-P^/PROJECT_FILE=^}).
They must be invoked through the @command{gnat} driver.
-The @command{gnat} driver is a front-end that accepts a number of commands and
-call the corresponding tool. It has been designed initially for VMS to convert
-VMS style qualifiers to Unix style switches, but it is now available to all
-the GNAT supported platforms.
+The @command{gnat} driver is a wrapper that accepts a number of commands and
+calls the corresponding tool. It was designed initially for VMS platforms (to
+convert VMS qualifiers to Unix-style switches), but it is now available on all
+GNAT platforms.
-On non VMS platforms, the @command{gnat} driver accepts the following commands
+On non-VMS platforms, the @command{gnat} driver accepts the following commands
(case insensitive):
@itemize @bullet
@item
PP or PRETTY to invoke @command{^gnatpp^gnatpp^}
@item
+METRIC to invoke @command{^gnatmetric^gnatmetric^}
+@item
STUB to invoke @command{^gnatstub^gnatstub^}
@item
XREF to invoke @command{^gnatxref^gnatxref^}
@command{^gnatmake -f -u -c^gnatmake -f -u -c^}).
@noindent
-On non VMS platforms, between @command{gnat} and the command, two
+On non-VMS platforms, between @command{gnat} and the command, two
special switches may be used:
@itemize @bullet
@end smallexample
@noindent
-In addition, for command BIND, COMP or COMPILE, FIND, ELIM, LS or LIST, LINK,
-PP or PRETTY and XREF, the project file related switches
+In addition, for commands BIND, COMP or COMPILE, FIND, ELIM, LS or LIST, LINK,
+METRIC, PP or PRETTY, STUB and XREF, the project file related switches
(@option{^-P^/PROJECT_FILE^},
@option{^-X^/EXTERNAL_REFERENCE^} and
@option{^-vP^/MESSAGES_PROJECT_FILE=^x}) may be used in addition to
the immediate sources of the specified project file.
@noindent
-For each of these commands, there is optionally a corresponding package
-in the main project.
+When GNAT METRIC is used with a project file, but with no source
+specified on the command line, it invokes @command{^gnatmetric^gnatmetric^}
+with all the immediate sources of the specified project file and with
+@option{^-d^/DIRECTORY^} with the parameter pointing to the object directory
+of the project.
+
+@noindent
+In addition, when GNAT PP, GNAT PRETTY or GNAT METRIC is used with
+a project file, no source is specified on the command line and
+switch ^-U^/ALL_PROJECTS^ is specified on the command line, then
+the underlying tool (^gnatpp^gnatpp^ or
+^gnatmetric^gnatmetric^) is invoked for all sources of all projects,
+not only for the immediate sources of the main project.
+@ifclear vms
+(-U stands for Universal or Union of the project files of the project tree)
+@end ifclear
+
+@noindent
+For each of the following commands, there is optionally a corresponding
+package in the main project.
@itemize @bullet
@item
package @code{Binder} for command BIND (invoking @code{^gnatbind^gnatbind^})
@item
+package @code{Check} for command CHECK (invoking
+@code{^gnatcheck^gnatcheck^})
+
+@item
package @code{Compiler} for command COMP or COMPILE (invoking the compiler)
@item
-package @code{Finder} for command FIND (invoking @code{^gnatfind^gnatfind^})
+package @code{Cross_Reference} for command XREF (invoking
+@code{^gnatxref^gnatxref^})
@item
package @code{Eliminate} for command ELIM (invoking
@code{^gnatelim^gnatelim^})
@item
+package @code{Finder} for command FIND (invoking @code{^gnatfind^gnatfind^})
+
+@item
package @code{Gnatls} for command LS or LIST (invoking @code{^gnatls^gnatls^})
@item
+package @code{Gnatstub} for command STUB
+(invoking @code{^gnatstub^gnatstub^})
+
+@item
package @code{Linker} for command LINK (invoking @code{^gnatlink^gnatlink^})
@item
-package @code{Pretty_Printer} for command PP or PRETTY
-(invoking @code{^gnatpp^gnatpp^})
+package @code{Metrics} for command METRIC
+(invoking @code{^gnatmetric^gnatmetric^})
@item
-package @code{Cross_Reference} for command XREF (invoking
-@code{^gnatxref^gnatxref^})
+package @code{Pretty_Printer} for command PP or PRETTY
+(invoking @code{^gnatpp^gnatpp^})
@end itemize
@code{^Default_Switches^Default_Switches^}.
@noindent
-@code{^Switches^Switches^} is an associated array attribute, indexed by the
+@code{^Switches^Switches^} is an associative array attribute, indexed by the
source file name, that has a string list value: the ^switches^switches^ to be
used when the tool corresponding to the package is invoked for the specific
source file.
@code{^Default_Switches^Default_Switches^ ("Ada")} for all tools,
except @code{^Switches^Switches^ ("main.adb")}
for @code{^gnatlink^gnatlink^}.
-
-@ifclear vms
-@node Glide and Project Files
-@subsection Glide and Project Files
-
-@noindent
-Glide will automatically recognize the @file{.gpr} extension for
-project files, and will
-convert them to its own internal format automatically. However, it
-doesn't provide a syntax-oriented editor for modifying these
-files.
-The project file will be loaded as text when you select the menu item
-@code{Ada} @result{} @code{Project} @result{} @code{Edit}.
-You can edit this text and save the @file{gpr} file;
-when you next select this project file in Glide it
-will be automatically reloaded.
-@end ifclear
+It is also possible to invoke some of the tools,
+@code{^gnatcheck^gnatcheck^}),
+@code{^gnatmetric^gnatmetric^}),
+and @code{^gnatpp^gnatpp^})
+on a set of project units thanks to the combination of the switches
+@option{-P}, @option{-U} and possibly the main unit when one is interested
+in its closure. For instance,
+@smallexample
+gnat metric -Pproj
+@end smallexample
+will compute the metrics for all the immediate units of project
+@code{proj}.
+@smallexample
+gnat metric -Pproj -U
+@end smallexample
+will compute the metrics for all the units of the closure of projects
+rooted at @code{proj}.
+@smallexample
+gnat metric -Pproj -U main_unit
+@end smallexample
+will compute the metrics for the closure of units rooted at
+@code{main_unit}. This last possibility relies implicitly
+on @command{gnatbind}'s option @option{-R}.
@c **********************
@node An Extended Example
other_declarative_item
package_declaration ::=
- package_specification | package_renaming
+ package_spec | package_renaming
-package_specification ::=
+package_spec ::=
@b{package} package_identifier @b{is}
@{simple_declarative_item@}
@b{end} package_identifier ;
@end smallexample
-
@node The Cross-Referencing Tools gnatxref and gnatfind
@chapter The Cross-Referencing Tools @code{gnatxref} and @code{gnatfind}
@findex gnatxref
cross-references.
To use these tools, you must not compile your application using the
-@option{-gnatx} switch on the @file{gnatmake} command line
-(see @ref{The GNAT Make Program gnatmake}). Otherwise, cross-referencing
+@option{-gnatx} switch on the @command{gnatmake} command line
+(@pxref{The GNAT Make Program gnatmake}). Otherwise, cross-referencing
information will not be generated.
+Note: to invoke @code{gnatxref} or @code{gnatfind} with a project file,
+use the @code{gnat} driver (see @ref{The GNAT Driver and Project Files}).
+
@menu
* gnatxref Switches::
* gnatfind Switches::
@noindent
The command invocation for @code{gnatxref} is:
@smallexample
-$ gnatxref [switches] sourcefile1 [sourcefile2 ...]
+$ gnatxref @ovar{switches} @var{sourcefile1} @r{[}@var{sourcefile2} @dots{}@r{]}
@end smallexample
@noindent
where
-@table @code
-@item sourcefile1, sourcefile2
+@table @var
+@item sourcefile1
+@itemx sourcefile2
identifies the source files for which a report is to be generated. The
``with''ed units will be processed too. You must provide at least one file.
@end table
@noindent
-The switches can be :
+The switches can be:
@table @option
@c !sort!
+@item --version
+@cindex @option{--version} @command{gnatxref}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatxref}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
@item ^-a^/ALL_FILES^
@cindex @option{^-a^/ALL_FILES^} (@command{gnatxref})
If this switch is present, @code{gnatfind} and @code{gnatxref} will parse
@item -aIDIR
@cindex @option{-aIDIR} (@command{gnatxref})
When looking for source files also look in directory DIR. The order in which
-source file search is undertaken is the same as for @file{gnatmake}.
+source file search is undertaken is the same as for @command{gnatmake}.
@item -aODIR
@cindex @option{-aODIR} (@command{gnatxref})
When searching for library and object files, look in directory
DIR. The order in which library files are searched is the same as for
-@file{gnatmake}.
+@command{gnatmake}.
@item -nostdinc
@cindex @option{-nostdinc} (@command{gnatxref})
@item --RTS=@var{rts-path}
@cindex @option{--RTS} (@command{gnatxref})
Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (see @ref{Switches for gnatmake}).
+equivalent @command{gnatmake} flag (@pxref{Switches for gnatmake}).
@item ^-d^/DERIVED_TYPES^
@cindex @option{^-d^/DERIVED_TYPES^} (@command{gnatxref})
@item -pFILE
@cindex @option{-pFILE} (@command{gnatxref})
-Specify a project file to use @xref{Project Files}. These project files are
-the @file{.adp} files used by Glide. If you need to use the @file{.gpr}
+Specify a project file to use @xref{Project Files}.
+If you need to use the @file{.gpr}
project files, you should use gnatxref through the GNAT driver
(@command{gnat xref -Pproject}).
@item -v
Instead of producing the default output, @code{gnatxref} will generate a
@file{tags} file that can be used by vi. For examples how to use this
-feature, see @xref{Examples of gnatxref Usage}. The tags file is output
+feature, see @ref{Examples of gnatxref Usage}. The tags file is output
to the standard output, thus you will have to redirect it to a file.
@end ifclear
The command line for @code{gnatfind} is:
@smallexample
-$ gnatfind [switches] pattern[:sourcefile[:line[:column]]]
- [file1 file2 ...]
+$ gnatfind @ovar{switches} @var{pattern}@r{[}:@var{sourcefile}@r{[}:@var{line}@r{[}:@var{column}@r{]]]}
+ @r{[}@var{file1} @var{file2} @dots{}]
@end smallexample
@noindent
where
-@table @code
+@table @var
@item pattern
An entity will be output only if it matches the regular expression found
-in @samp{pattern}, see @xref{Regular Expressions in gnatfind and gnatxref}.
+in @var{pattern}, see @ref{Regular Expressions in gnatfind and gnatxref}.
Omitting the pattern is equivalent to specifying @samp{*}, which
will match any entity. Note that if you do not provide a pattern, you
@item sourcefile
@code{gnatfind} will look for references, bodies or declarations
-of symbols referenced in @file{sourcefile}, at line @samp{line}
-and column @samp{column}. See @pxref{Examples of gnatfind Usage}
+of symbols referenced in @file{@var{sourcefile}}, at line @var{line}
+and column @var{column}. See @ref{Examples of gnatfind Usage}
for syntax examples.
@item line
line of the first character of the identifier for the
entity reference. Columns are numbered from 1.
-@item file1 file2 ...
+@item file1 file2 @dots{}
The search will be restricted to these source files. If none are given, then
the search will be done for every library file in the search path.
These file must appear only after the pattern or sourcefile.
These file names are considered to be regular expressions, so for instance
-specifying 'source*.adb' is the same as giving every file in the current
-directory whose name starts with 'source' and whose extension is 'adb'.
+specifying @file{source*.adb} is the same as giving every file in the current
+directory whose name starts with @file{source} and whose extension is
+@file{adb}.
The location of the spec of the entity will always be displayed, even if it
-isn't in one of file1, file2,... The occurrences of the entity in the
-separate units of the ones given on the command line will also be displayed.
+isn't in one of @file{@var{file1}}, @file{@var{file2}},@enddots{} The
+occurrences of the entity in the separate units of the ones given on the
+command line will also be displayed.
Note that if you specify at least one file in this part, @code{gnatfind} may
-sometimes not be able to find the body of the subprograms...
+sometimes not be able to find the body of the subprograms.
@end table
@table @option
@c !sort!
+@cindex @option{--version} @command{gnatfind}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatfind}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
@item ^-a^/ALL_FILES^
@cindex @option{^-a^/ALL_FILES^} (@command{gnatfind})
If this switch is present, @code{gnatfind} and @code{gnatxref} will parse
@item -aIDIR
@cindex @option{-aIDIR} (@command{gnatfind})
When looking for source files also look in directory DIR. The order in which
-source file search is undertaken is the same as for @file{gnatmake}.
+source file search is undertaken is the same as for @command{gnatmake}.
@item -aODIR
@cindex @option{-aODIR} (@command{gnatfind})
When searching for library and object files, look in directory
DIR. The order in which library files are searched is the same as for
-@file{gnatmake}.
+@command{gnatmake}.
@item -nostdinc
@cindex @option{-nostdinc} (@command{gnatfind})
@item --RTS=@var{rts-path}
@cindex @option{--RTS} (@command{gnatfind})
Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (see @ref{Switches for gnatmake}).
+equivalent @command{gnatmake} flag (@pxref{Switches for gnatmake}).
@item ^-d^/DERIVED_TYPE_INFORMATION^
@cindex @option{^-d^/DERIVED_TYPE_INFORMATION^} (@code{gnatfind})
Project files allow a programmer to specify how to compile its
application, where to find sources, etc. These files are used
@ifclear vms
-primarily by the Glide Ada mode, but they can also be used
+primarily by GPS, but they can also be used
@end ifclear
by the two tools
@code{gnatxref} and @code{gnatfind}.
@ifclear vms
@item make_cmd=COMMAND
[default: @code{"gnatmake $@{main@} -aI$@{src_dir@}
- -aO$@{obj_dir@} -g -gnatq -cargs $@{comp_opt@}
- -bargs $@{bind_opt@} -largs $@{link_opt@}"}]
+-aO$@{obj_dir@} -g -gnatq -cargs $@{comp_opt@}
+-bargs $@{bind_opt@} -largs $@{link_opt@}"}]
@end ifclear
specifies the command used to recompile the whole application.
@noindent
As specified in the section about @command{gnatfind}, the pattern can be a
regular expression. Actually, there are to set of regular expressions
-which are recognized by the program :
+which are recognized by the program:
@table @code
@item globbing patterns
These are the most usual regular expression. They are the same that you
generally used in a Unix shell command line, or in a DOS session.
-Here is a more formal grammar :
+Here is a more formal grammar:
@smallexample
@group
@iftex
term ::= elmt elmt -- concatenation (elmt then elmt)
term ::= * -- any string of 0 or more characters
term ::= ? -- matches any character
-term ::= [char @{char@}] -- matches any character listed
+term ::= [char @{char@}] -- matches any character listed
term ::= [char - char] -- matches any character in range
@end group
@end smallexample
@leftskip=.5cm
@end iftex
@group
-regexp ::= term @{| term@} -- alternation (term or term ...)
+regexp ::= term @{| term@} -- alternation (term or term @dots{})
-term ::= item @{item@} -- concatenation (item then item)
+term ::= item @{item@} -- concatenation (item then item)
item ::= elmt -- match elmt
item ::= elmt * -- zero or more elmt's
@end group
@end smallexample
-Following are a few examples :
+Following are a few examples:
@table @samp
@item abcde|fghi
-will match any of the two strings 'abcde' and 'fghi'.
+will match any of the two strings @samp{abcde} and @samp{fghi},
@item abc*d
-will match any string like 'abd', 'abcd', 'abccd', 'abcccd', and so on
+will match any string like @samp{abd}, @samp{abcd}, @samp{abccd},
+@samp{abcccd}, and so on,
@item [a-z]+
will match any string which has only lowercase characters in it (and at
-least one character
+least one character.
@end table
@end table
@subsection General Usage
@noindent
-For the following examples, we will consider the following units :
+For the following examples, we will consider the following units:
@smallexample @c ada
@group
@subsection Using gnatxref with vi
@code{gnatxref} can generate a tags file output, which can be used
-directly from @file{vi}. Note that the standard version of @file{vi}
+directly from @command{vi}. Note that the standard version of @command{vi}
will not work properly with overloaded symbols. Consider using another
-free implementation of @file{vi}, such as @file{vim}.
+free implementation of @command{vi}, such as @command{vim}.
@smallexample
$ gnatxref -v gnatfind.adb > tags
will generate the tags file for @code{gnatfind} itself (if the sources
are in the search path!).
-From @file{vi}, you can then use the command @samp{:tag @i{entity}}
-(replacing @i{entity} by whatever you are looking for), and vi will
+From @command{vi}, you can then use the command @samp{:tag @var{entity}}
+(replacing @var{entity} by whatever you are looking for), and vi will
display a new file with the corresponding declaration of entity.
@end ifclear
@end table
-
@c *********************************
@node The GNAT Pretty-Printer gnatpp
@chapter The GNAT Pretty-Printer @command{gnatpp}
If this condition is not met, @command{gnatpp} will terminate with an
error message; no output file will be generated.
+If the source files presented to @command{gnatpp} contain
+preprocessing directives, then the output file will
+correspond to the generated source after all
+preprocessing is carried out. There is no way
+using @command{gnatpp} to obtain pretty printed files that
+include the preprocessing directives.
+
If the compilation unit
contained in the input source depends semantically upon units located
outside the current directory, you have to provide the source search path
The @command{gnatpp} command has the form
@smallexample
-$ gnatpp [@var{switches}] @var{filename}
+$ gnatpp @ovar{switches} @var{filename}
@end smallexample
@noindent
follow the GNAT file naming rules
@end itemize
-
@menu
* Switches for gnatpp::
* Formatting Rules::
* Other gnatpp Switches::
@end menu
-
@node Alignment Control
@subsection Alignment Control
@cindex Alignment control in @command{gnatpp}
@item ^-A4^/ALIGN=ARROWS^
Align @code{=>} in associations
+
+@item ^-A5^/ALIGN=COMPONENT_CLAUSES^
+Align @code{at} keywords in the component clauses in record
+representation clauses
@end table
@noindent
The @option{^-A^/ALIGN^} switches are mutually compatible; any combination
is allowed.
-
@node Casing Control
@subsection Casing Control
@cindex Casing control in @command{gnatpp}
@option{^-D@var{file}^/DICTIONARY=@var{file}^} switches are mutually
compatible.
-
@node Construct Layout Control
@subsection Construct Layout Control
@cindex Layout control in @command{gnatpp}
@noindent
This group of @command{gnatpp} switches controls the layout of comments and
-complex syntactic constructs. See @ref{Formatting Comments}, for details
+complex syntactic constructs. See @ref{Formatting Comments} for details
on their effect.
@table @option
@item ^-c4^/COMMENTS_LAYOUT=REFORMAT^
Reformat comment blocks
+@item ^-c5^/COMMENTS_LAYOUT=KEEP_SPECIAL^
+Keep unchanged special form comments
+
+Reformat comment blocks
+
@cindex @option{^-l@var{n}^/CONSTRUCT_LAYOUT^} (@command{gnatpp})
@item ^-l1^/CONSTRUCT_LAYOUT=GNAT^
GNAT-style layout (this is the default)
@item ^-l3^/CONSTRUCT_LAYOUT=UNCOMPACT^
Uncompact layout
-@item ^-notab^/NOTABS^
+@cindex @option{^-N^/NOTABS^} (@command{gnatpp})
+@item ^-N^/NOTABS^
All the VT characters are removed from the comment text. All the HT characters
are expanded with the sequences of space characters to get to the next tab
stops.
+@cindex @option{^--no-separate-is^/NO_SEPARATE_IS^} (@command{gnatpp})
+@item ^--no-separate-is^/NO_SEPARATE_IS^
+Do not place the keyword @code{is} on a separate line in a subprogram body in
+case if the spec occupies more then one line.
+
+@cindex @option{^--separate-loop-then^/SEPARATE_LOOP_THEN^} (@command{gnatpp})
+@item ^--separate-loop-then^/SEPARATE_LOOP_THEN^
+Place the keyword @code{loop} in FOR and WHILE loop statements and the
+keyword @code{then} in IF statements on a separate line.
+
+@cindex @option{^--no-separate-loop-then^/NO_SEPARATE_LOOP_THEN^} (@command{gnatpp})
+@item ^--no-separate-loop-then^/NO_SEPARATE_LOOP_THEN^
+Do not place the keyword @code{loop} in FOR and WHILE loop statements and the
+keyword @code{then} in IF statements on a separate line. This option is
+incompatible with @option{^--separate-loop-then^/SEPARATE_LOOP_THEN^} option.
+
+@cindex @option{^--use-on-new-line^/USE_ON_NEW_LINE^} (@command{gnatpp})
+@item ^--use-on-new-line^/USE_ON_NEW_LINE^
+Start each USE clause in a context clause from a separate line.
+
+@cindex @option{^--separate-stmt-name^/STMT_NAME_ON_NEW_LINE^} (@command{gnatpp})
+@item ^--separate-stmt-name^/STMT_NAME_ON_NEW_LINE^
+Use a separate line for a loop or block statement name, but do not use an extra
+indentation level for the statement itself.
+
@end table
@ifclear vms
These switches allow control over line length and indentation.
@table @option
-@item ^-M@i{nnn}^/LINE_LENGTH_MAX=@i{nnn}^
+@item ^-M@var{nnn}^/LINE_LENGTH_MAX=@var{nnn}^
@cindex @option{^-M^/LINE_LENGTH^} (@command{gnatpp})
-Maximum line length, @i{nnn} from 32 ..256, the default value is 79
+Maximum line length, @var{nnn} from 32@dots{}256, the default value is 79
-@item ^-i@i{nnn}^/INDENTATION_LEVEL=@i{nnn}^
+@item ^-i@var{nnn}^/INDENTATION_LEVEL=@var{nnn}^
@cindex @option{^-i^/INDENTATION_LEVEL^} (@command{gnatpp})
-Indentation level, @i{nnn} from 1 .. 9, the default value is 3
+Indentation level, @var{nnn} from 1@dots{}9, the default value is 3
-@item ^-cl@i{nnn}^/CONTINUATION_INDENT=@i{nnn}^
+@item ^-cl@var{nnn}^/CONTINUATION_INDENT=@var{nnn}^
@cindex @option{^-cl^/CONTINUATION_INDENT^} (@command{gnatpp})
Indentation level for continuation lines (relative to the line being
-continued), @i{nnn} from 1 .. 9.
+continued), @var{nnn} from 1@dots{}9.
The default
value is one less then the (normal) indentation level, unless the
indentation is set to 1 (in which case the default value for continuation
line indentation is also 1)
@end table
-
@node Other Formatting Options
@subsection Other Formatting Options
@cindex @option{^-ff^/FORM_FEED_AFTER_PRAGMA_PAGE^} (@command{gnatpp})
Insert a Form Feed character after a pragma Page.
-@item ^-T@i{nnn}^/MAX_INDENT=@i{nnn}^
+@item ^-T@var{nnn}^/MAX_INDENT=@var{nnn}^
@cindex @option{^-T^/MAX_INDENT^} (@command{gnatpp})
Do not use an additional indentation level for @b{case} alternatives
-and variants if there are @i{nnn} or more (the default
+and variants if there are @var{nnn} or more (the default
value is 10).
-If @i{nnn} is 0, an additional indentation level is
+If @var{nnn} is 0, an additional indentation level is
used for @b{case} alternatives and variants regardless of their number.
@end table
@end table
-
@node Output File Control
@subsection Output File Control
Like @option{^-r^/REPLACE^} except that if the file with the specified name
already exists, it is overwritten.
-@item ^-rnb^/NO_BACKUP^
-@cindex @option{^-rnb^/NO_BACKUP^} (@code{gnatpp})
+@item ^-rnb^/REPLACE_NO_BACKUP^
+@cindex @option{^-rnb^/REPLACE_NO_BACKUP^} (@code{gnatpp})
Replace the input source file with the reformatted output without
creating any backup copy of the input source.
+
+@item ^--eol=@var{xxx}^/END_OF_LINE=@var{xxx}^
+@cindex @option{^--eol^/END_OF_LINE^} (@code{gnatpp})
+Specifies the format of the reformatted output file. The @var{xxx}
+^string specified with the switch^option^ may be either
+@itemize @bullet
+@item ``@option{^dos^DOS^}'' MS DOS style, lines end with CR LF characters
+@item ``@option{^crlf^CRLF^}''
+the same as @option{^crlf^CRLF^}
+@item ``@option{^unix^UNIX^}'' UNIX style, lines end with LF character
+@item ``@option{^lf^LF^}''
+the same as @option{^unix^UNIX^}
+@end itemize
+
+@item ^-W^/RESULT_ENCODING=^@var{e}
+@cindex @option{^-W^/RESULT_ENCODING=^} (@command{gnatpp})
+Specify the wide character encoding method used to write the code in the
+result file
+@var{e} is one of the following:
+
+@itemize @bullet
+
+@item ^h^HEX^
+Hex encoding
+
+@item ^u^UPPER^
+Upper half encoding
+
+@item ^s^SHIFT_JIS^
+Shift/JIS encoding
+
+@item ^e^EUC^
+EUC encoding
+
+@item ^8^UTF8^
+UTF-8 encoding
+
+@item ^b^BRACKETS^
+Brackets encoding (default value)
+@end itemize
+
@end table
@noindent
Options @option{^-pipe^/STANDARD_OUTPUT^},
@option{^-o^/OUTPUT^} and
@option{^-of^/FORCED_OUTPUT^} are allowed only if the call to gnatpp
-contains only one file to reformat
+contains only one file to reformat.
+Option
+@option{^--eol^/END_OF_LINE^}
+and
+@option{^-W^/RESULT_ENCODING^}
+cannot be used together
+with @option{^-pipe^/STANDARD_OUTPUT^} option.
@node Other gnatpp Switches
@subsection Other @code{gnatpp} Switches
@item ^-w^/WARNINGS^
@cindex @option{^-w^/WARNINGS^} (@code{gnatpp})
Warning mode;
-@command{gnatpp} generates a warning whenever it can not provide
+@command{gnatpp} generates a warning whenever it cannot provide
a required layout in the result source.
@end table
-
@node Formatting Rules
@section Formatting Rules
* Name Casing::
@end menu
-
@node White Space and Empty Lines
@subsection White Space and Empty Lines
Likewise, if for some reason you wish to have a sequence of empty lines,
use a sequence of empty comments instead.
-
@node Formatting Comments
@subsection Formatting Comments
word processor style (that is, moving words between lines and putting as
many words in a line as possible).
+@noindent
+The @option{^-c5^/COMMENTS_LAYOUT=KEEP_SPECIAL^} switch specifies, that comments
+that has a special format (that is, a character that is neither a letter nor digit
+not white space nor line break immediately following the leading @code{--} of
+the comment) should be without any change moved from the argument source
+into reformatted source. This switch allows to preserve comments that are used
+as a special marks in the code (e.g.@: SPARK annotation).
@node Construct Layout
@subsection Construct Layout
@noindent
+In several cases the suggested layout in the Ada Reference Manual includes
+an extra level of indentation that many programmers prefer to avoid. The
+affected cases include:
+
+@itemize @bullet
+
+@item Record type declaration (RM 3.8)
+
+@item Record representation clause (RM 13.5.1)
+
+@item Loop statement in case if a loop has a statement identifier (RM 5.6)
+
+@item Block statement in case if a block has a statement identifier (RM 5.6)
+@end itemize
+
+@noindent
+In compact mode (when GNAT style layout or compact layout is set),
+the pretty printer uses one level of indentation instead
+of two. This is achieved in the record definition and record representation
+clause cases by putting the @code{record} keyword on the same line as the
+start of the declaration or representation clause, and in the block and loop
+case by putting the block or loop header on the same line as the statement
+identifier.
+
+@noindent
The difference between GNAT style @option{^-l1^/CONSTRUCT_LAYOUT=GNAT^}
and compact @option{^-l2^/CONSTRUCT_LAYOUT=COMPACT^}
layout on the one hand, and uncompact layout
@item
@smallexample @c ada
+for q use record
+ a at 0 range 0 .. 31;
+ b at 4 range 0 .. 31;
+end record;
+@end smallexample
+@tab
+@smallexample @c ada
+for q use
+ record
+ a at 0 range 0 .. 31;
+ b at 4 range 0 .. 31;
+ end record;
+@end smallexample
+
+@item
+@smallexample @c ada
Block : declare
A : Integer := 3;
begin
end record; b : integer;
end record;
+for q use record for q use
+ a at 0 range 0 .. 31; record
+ b at 4 range 0 .. 31; a at 0 range 0 .. 31;
+end record; b at 4 range 0 .. 31;
+ end record;
Block : declare Block :
A : Integer := 3; declare
GNAT style layout inserts empty lines as separation for
compound statements, return statements and bodies.
+Note that the layout specified by
+@option{^--separate-stmt-name^/STMT_NAME_ON_NEW_LINE^}
+for named block and loop statements overrides the layout defined by these
+constructs by @option{^-l1^/CONSTRUCT_LAYOUT=GNAT^},
+@option{^-l2^/CONSTRUCT_LAYOUT=COMPACT^} or
+@option{^-l3^/CONSTRUCT_LAYOUT=UNCOMPACT^} option.
@node Name Casing
@subsection Name Casing
@smallexample
@cartouche
- @var{casing_schema} ::= @var{identifier} | [*]@var{simple_identifier}[*]
+ @var{casing_schema} ::= @var{identifier} | *@var{simple_identifier}*
@var{simple_identifier} ::= @var{letter}@{@var{letter_or_digit}@}
@end cartouche
@end smallexample
@noindent
-(The @code{[]} metanotation stands for an optional part;
-see @cite{Ada Reference Manual}, Section 2.3) for the definition of the
-@var{identifier} lexical element and the @var{letter_or_digit} category).
+(See @cite{Ada Reference Manual}, Section 2.3) for the definition of the
+@var{identifier} lexical element and the @var{letter_or_digit} category.)
The casing schema string can be followed by white space and/or an Ada-style
comment; any amount of white space is allowed before the string.
the casing defined by the dictionary; no subwords are checked for this word
@item
-for the first subword (that is, for the subword preceding the leftmost
-``_''), @command{gnatpp} checks if the dictionary contains the corresponding
-string of the form @code{@var{simple_identifier}*}, and if it does, the
-casing of this @var{simple_identifier} is used for this subword
-
-@item
-for the last subword (following the rightmost ``_'') @command{gnatpp}
-checks if the dictionary contains the corresponding string of the form
-@code{*@var{simple_identifier}}, and if it does, the casing of this
-@var{simple_identifier} is used for this subword
+for every subword @command{gnatpp} checks if the dictionary contains the
+corresponding string of the form @code{*@var{simple_identifier}*},
+and if it does, the casing of this @var{simple_identifier} is used
+for this subword
@item
-for every intermediate subword (surrounded by two'_') @command{gnatpp} checks
-if the dictionary contains the corresponding string of the form
-@code{*@var{simple_identifier}*}, and if it does, the casing of this
-simple_identifier is used for this subword
+if the whole name does not contain any ``_'' inside, and if for this name
+the dictionary contains two entries - one of the form @var{identifier},
+and another - of the form *@var{simple_identifier}*, then the first one
+is applied to define the casing of this name
@item
if more than one dictionary file is passed as @command{gnatpp} switches, each
@i{dict1:}
NAME1
*NaMe3*
- *NAME2
+ *Name1*
@end cartouche
@cartouche
@cartouche
procedure Test is
NAME1 : Integer := 1;
- Name4_NAME3_NAME2 : integer := 2;
+ Name4_NAME3_Name2 : Integer := 2;
Name2_NAME3_Name4 : Boolean;
Name1_Var : Float;
begin
- Name2_NAME3_Name4 := Name4_NAME3_NAME2 > NAME1;
+ Name2_NAME3_Name4 := Name4_NAME3_Name2 > NAME1;
end Test;
@end cartouche
@end smallexample
+@c *********************************
+@node The GNAT Metric Tool gnatmetric
+@chapter The GNAT Metric Tool @command{gnatmetric}
+@findex gnatmetric
+@cindex Metric tool
+@noindent
+^The @command{gnatmetric} tool^@command{GNAT METRIC}^ is an ASIS-based utility
+for computing various program metrics.
+It takes an Ada source file as input and generates a file containing the
+metrics data as output. Various switches control which
+metrics are computed and output.
-@c ***********************************
-@node File Name Krunching Using gnatkr
-@chapter File Name Krunching Using @code{gnatkr}
-@findex gnatkr
+@command{gnatmetric} generates and uses the ASIS
+tree for the input source and thus requires the input to be syntactically and
+semantically legal.
+If this condition is not met, @command{gnatmetric} will generate
+an error message; no metric information for this file will be
+computed and reported.
-@noindent
-This chapter discusses the method used by the compiler to shorten
-the default file names chosen for Ada units so that they do not
-exceed the maximum length permitted. It also describes the
-@code{gnatkr} utility that can be used to determine the result of
-applying this shortening.
-@menu
-* About gnatkr::
-* Using gnatkr::
-* Krunching Method::
-* Examples of gnatkr Usage::
-@end menu
+If the compilation unit contained in the input source depends semantically
+upon units in files located outside the current directory, you have to provide
+the source search path when invoking @command{gnatmetric}.
+If it depends semantically upon units that are contained
+in files with names that do not follow the GNAT file naming rules, you have to
+provide the configuration file describing the corresponding naming scheme (see
+the description of the @command{gnatmetric} switches below.)
+Alternatively, you may use a project file and invoke @command{gnatmetric}
+through the @command{gnat} driver.
-@node About gnatkr
-@section About @code{gnatkr}
+The @command{gnatmetric} command has the form
+
+@smallexample
+$ gnatmetric @ovar{switches} @{@var{filename}@} @r{[}-cargs @var{gcc_switches}@r{]}
+@end smallexample
@noindent
-The default file naming rule in GNAT
-is that the file name must be derived from
-the unit name. The exact default rule is as follows:
+where
@itemize @bullet
@item
-Take the unit name and replace all dots by hyphens.
+@var{switches} specify the metrics to compute and define the destination for
+the output
+
@item
-If such a replacement occurs in the
-second character position of a name, and the first character is
-^a, g, s, or i^A, G, S, or I^ then replace the dot by the character
-^~ (tilde)^$ (dollar sign)^
-instead of a minus.
-@end itemize
-The reason for this exception is to avoid clashes
-with the standard names for children of System, Ada, Interfaces,
-and GNAT, which use the prefixes ^s- a- i- and g-^S- A- I- and G-^
-respectively.
+Each @var{filename} is the name (including the extension) of a source
+file to process. ``Wildcards'' are allowed, and
+the file name may contain path information.
+If no @var{filename} is supplied, then the @var{switches} list must contain
+at least one
+@option{-files} switch (@pxref{Other gnatmetric Switches}).
+Including both a @option{-files} switch and one or more
+@var{filename} arguments is permitted.
-The @option{^-gnatk^/FILE_NAME_MAX_LENGTH=^@var{nn}}
-switch of the compiler activates a ``krunching''
-circuit that limits file names to nn characters (where nn is a decimal
-integer). For example, using OpenVMS,
-where the maximum file name length is
-39, the value of nn is usually set to 39, but if you want to generate
-a set of files that would be usable if ported to a system with some
-different maximum file length, then a different value can be specified.
-The default value of 39 for OpenVMS need not be specified.
+@item
+@samp{-cargs @var{gcc_switches}} is a list of switches for
+@command{gcc}. They will be passed on to all compiler invocations made by
+@command{gnatmetric} to generate the ASIS trees. Here you can provide
+@option{^-I^/INCLUDE_DIRS=^} switches to form the source search path,
+and use the @option{-gnatec} switch to set the configuration file.
+@end itemize
-The @code{gnatkr} utility can be used to determine the krunched name for
-a given file, when krunched to a specified maximum length.
+@menu
+* Switches for gnatmetric::
+@end menu
-@node Using gnatkr
-@section Using @code{gnatkr}
+@node Switches for gnatmetric
+@section Switches for @command{gnatmetric}
@noindent
-The @code{gnatkr} command has the form
+The following subsections describe the various switches accepted by
+@command{gnatmetric}, organized by category.
-@ifclear vms
-@smallexample
-$ gnatkr @var{name} [@var{length}]
-@end smallexample
-@end ifclear
+@menu
+* Output Files Control::
+* Disable Metrics For Local Units::
+* Specifying a set of metrics to compute::
+* Other gnatmetric Switches::
+* Generate project-wide metrics::
+@end menu
-@ifset vms
-@smallexample
-$ gnatkr @var{name} /COUNT=nn
-@end smallexample
-@end ifset
+@node Output Files Control
+@subsection Output File Control
+@cindex Output file control in @command{gnatmetric}
@noindent
-@var{name} is the uncrunched file name, derived from the name of the unit
-in the standard manner described in the previous section (i.e. in particular
-all dots are replaced by hyphens). The file name may or may not have an
-extension (defined as a suffix of the form period followed by arbitrary
-characters other than period). If an extension is present then it will
-be preserved in the output. For example, when krunching @file{hellofile.ads}
-to eight characters, the result will be hellofil.ads.
+@command{gnatmetric} has two output formats. It can generate a
+textual (human-readable) form, and also XML. By default only textual
+output is generated.
-Note: for compatibility with previous versions of @code{gnatkr} dots may
-appear in the name instead of hyphens, but the last dot will always be
-taken as the start of an extension. So if @code{gnatkr} is given an argument
-such as @file{Hello.World.adb} it will be treated exactly as if the first
-period had been a hyphen, and for example krunching to eight characters
-gives the result @file{hellworl.adb}.
+When generating the output in textual form, @command{gnatmetric} creates
+for each Ada source file a corresponding text file
+containing the computed metrics, except for the case when the set of metrics
+specified by gnatmetric parameters consists only of metrics that are computed
+for the whole set of analyzed sources, but not for each Ada source.
+By default, this file is placed in the same directory as where the source
+file is located, and its name is obtained
+by appending the ^@file{.metrix}^@file{$METRIX}^ suffix to the name of the
+input file.
-Note that the result is always all lower case (except on OpenVMS where it is
-all upper case). Characters of the other case are folded as required.
+All the output information generated in XML format is placed in a single
+file. By default this file is placed in the current directory and has the
+name ^@file{metrix.xml}^@file{METRIX$XML}^.
-@var{length} represents the length of the krunched name. The default
-when no argument is given is ^8^39^ characters. A length of zero stands for
-unlimited, in other words do not chop except for system files where the
-impled crunching length is always eight characters.
+Some of the computed metrics are summed over the units passed to
+@command{gnatmetric}; for example, the total number of lines of code.
+By default this information is sent to @file{stdout}, but a file
+can be specified with the @option{-og} switch.
-@noindent
-The output is the krunched name. The output has an extension only if the
-original argument was a file name with an extension.
+The following switches control the @command{gnatmetric} output:
-@node Krunching Method
-@section Krunching Method
+@table @option
+@cindex @option{^-x^/XML^} (@command{gnatmetric})
+@item ^-x^/XML^
+Generate the XML output
+
+@cindex @option{^-nt^/NO_TEXT^} (@command{gnatmetric})
+@item ^-nt^/NO_TEXT^
+Do not generate the output in text form (implies @option{^-x^/XML^})
+
+@cindex @option{^-d^/DIRECTORY^} (@command{gnatmetric})
+@item ^-d @var{output_dir}^/DIRECTORY=@var{output_dir}^
+Put textual files with detailed metrics into @var{output_dir}
+
+@cindex @option{^-o^/SUFFIX_DETAILS^} (@command{gnatmetric})
+@item ^-o @var{file_suffix}^/SUFFIX_DETAILS=@var{file_suffix}^
+Use @var{file_suffix}, instead of ^@file{.metrix}^@file{$METRIX}^
+in the name of the output file.
+
+@cindex @option{^-og^/GLOBAL_OUTPUT^} (@command{gnatmetric})
+@item ^-og @var{file_name}^/GLOBAL_OUTPUT=@var{file_name}^
+Put global metrics into @var{file_name}
+
+@cindex @option{^-ox^/XML_OUTPUT^} (@command{gnatmetric})
+@item ^-ox @var{file_name}^/XML_OUTPUT=@var{file_name}^
+Put the XML output into @var{file_name} (also implies @option{^-x^/XML^})
+
+@cindex @option{^-sfn^/SHORT_SOURCE_FILE_NAME^} (@command{gnatmetric})
+@item ^-sfn^/SHORT_SOURCE_FILE_NAME^
+Use ``short'' source file names in the output. (The @command{gnatmetric}
+output includes the name(s) of the Ada source file(s) from which the metrics
+are computed. By default each name includes the absolute path. The
+@option{^-sfn^/SHORT_SOURCE_FILE_NAME^} switch causes @command{gnatmetric}
+to exclude all directory information from the file names that are output.)
+
+@end table
+
+@node Disable Metrics For Local Units
+@subsection Disable Metrics For Local Units
+@cindex Disable Metrics For Local Units in @command{gnatmetric}
@noindent
-The initial file name is determined by the name of the unit that the file
-contains. The name is formed by taking the full expanded name of the
-unit and replacing the separating dots with hyphens and
-using ^lowercase^uppercase^
-for all letters, except that a hyphen in the second character position is
-replaced by a ^tilde^dollar sign^ if the first character is
-^a, i, g, or s^A, I, G, or S^.
-The extension is @code{.ads} for a
-specification and @code{.adb} for a body.
-Krunching does not affect the extension, but the file name is shortened to
-the specified length by following these rules:
+@command{gnatmetric} relies on the GNAT compilation model @minus{}
+one compilation
+unit per one source file. It computes line metrics for the whole source
+file, and it also computes syntax
+and complexity metrics for the file's outermost unit.
+
+By default, @command{gnatmetric} will also compute all metrics for certain
+kinds of locally declared program units:
@itemize @bullet
@item
-The name is divided into segments separated by hyphens, tildes or
-underscores and all hyphens, tildes, and underscores are
-eliminated. If this leaves the name short enough, we are done.
+subprogram (and generic subprogram) bodies;
@item
-If the name is too long, the longest segment is located (left-most
-if there are two of equal length), and shortened by dropping
-its last character. This is repeated until the name is short enough.
-
-As an example, consider the krunching of @*@file{our-strings-wide_fixed.adb}
-to fit the name into 8 characters as required by some operating systems.
+package (and generic package) specs and bodies;
-@smallexample
-our-strings-wide_fixed 22
-our strings wide fixed 19
-our string wide fixed 18
-our strin wide fixed 17
-our stri wide fixed 16
-our stri wide fixe 15
-our str wide fixe 14
-our str wid fixe 13
-our str wid fix 12
-ou str wid fix 11
-ou st wid fix 10
-ou st wi fix 9
-ou st wi fi 8
-Final file name: oustwifi.adb
-@end smallexample
+@item
+task object and type specifications and bodies;
@item
-The file names for all predefined units are always krunched to eight
-characters. The krunching of these predefined units uses the following
-special prefix replacements:
+protected object and type specifications and bodies.
+@end itemize
-@table @file
-@item ada-
-replaced by @file{^a^A^-}
+@noindent
+These kinds of entities will be referred to as
+@emph{eligible local program units}, or simply @emph{eligible local units},
+@cindex Eligible local unit (for @command{gnatmetric})
+in the discussion below.
-@item gnat-
-replaced by @file{^g^G^-}
+Note that a subprogram declaration, generic instantiation,
+or renaming declaration only receives metrics
+computation when it appear as the outermost entity
+in a source file.
-@item interfaces-
-replaced by @file{^i^I^-}
+Suppression of metrics computation for eligible local units can be
+obtained via the following switch:
+
+@table @option
+@cindex @option{^-n@var{x}^/SUPPRESS^} (@command{gnatmetric})
+@item ^-nolocal^/SUPPRESS=LOCAL_DETAILS^
+Do not compute detailed metrics for eligible local program units
-@item system-
-replaced by @file{^s^S^-}
@end table
-These system files have a hyphen in the second character position. That
-is why normal user files replace such a character with a
-^tilde^dollar sign^, to
-avoid confusion with system file names.
+@node Specifying a set of metrics to compute
+@subsection Specifying a set of metrics to compute
-As an example of this special rule, consider
-@*@file{ada-strings-wide_fixed.adb}, which gets krunched as follows:
+@noindent
+By default all the metrics are computed and reported. The switches
+described in this subsection allow you to control, on an individual
+basis, whether metrics are computed and
+reported. If at least one positive metric
+switch is specified (that is, a switch that defines that a given
+metric or set of metrics is to be computed), then only
+explicitly specified metrics are reported.
-@smallexample
-ada-strings-wide_fixed 22
-a- strings wide fixed 18
-a- string wide fixed 17
-a- strin wide fixed 16
-a- stri wide fixed 15
-a- stri wide fixe 14
-a- str wide fixe 13
-a- str wid fixe 12
-a- str wid fix 11
-a- st wid fix 10
-a- st wi fix 9
-a- st wi fi 8
-Final file name: a-stwifi.adb
-@end smallexample
-@end itemize
+@menu
+* Line Metrics Control::
+* Syntax Metrics Control::
+* Complexity Metrics Control::
+* Object-Oriented Metrics Control::
+@end menu
-Of course no file shortening algorithm can guarantee uniqueness over all
-possible unit names, and if file name krunching is used then it is your
-responsibility to ensure that no name clashes occur. The utility
-program @code{gnatkr} is supplied for conveniently determining the
-krunched name of a file.
+@node Line Metrics Control
+@subsubsection Line Metrics Control
+@cindex Line metrics control in @command{gnatmetric}
-@node Examples of gnatkr Usage
-@section Examples of @code{gnatkr} Usage
+@noindent
+For any (legal) source file, and for each of its
+eligible local program units, @command{gnatmetric} computes the following
+metrics:
-@smallexample
-@iftex
-@leftskip=0cm
-@end iftex
-@ifclear vms
-$ gnatkr very_long_unit_name.ads --> velounna.ads
-$ gnatkr grandparent-parent-child.ads --> grparchi.ads
-$ gnatkr Grandparent.Parent.Child.ads --> grparchi.ads
-$ gnatkr grandparent-parent-child --> grparchi
-@end ifclear
-$ gnatkr very_long_unit_name.ads/count=6 --> vlunna.ads
-$ gnatkr very_long_unit_name.ads/count=0 --> very_long_unit_name.ads
-@end smallexample
+@itemize @bullet
+@item
+the total number of lines;
-@node Preprocessing Using gnatprep
-@chapter Preprocessing Using @code{gnatprep}
-@findex gnatprep
+@item
+the total number of code lines (i.e., non-blank lines that are not comments)
-@noindent
-The @code{gnatprep} utility provides
-a simple preprocessing capability for Ada programs.
-It is designed for use with GNAT, but is not dependent on any special
-features of GNAT.
+@item
+the number of comment lines
-@menu
-* Using gnatprep::
-* Switches for gnatprep::
-* Form of Definitions File::
-* Form of Input Text for gnatprep::
-@end menu
+@item
+the number of code lines containing end-of-line comments;
-@node Using gnatprep
-@section Using @code{gnatprep}
+@item
+the comment percentage: the ratio between the number of lines that contain
+comments and the number of all non-blank lines, expressed as a percentage;
-@noindent
-To call @code{gnatprep} use
+@item
+the number of empty lines and lines containing only space characters and/or
+format effectors (blank lines)
-@smallexample
-$ gnatprep [-bcrsu] [-Dsymbol=value] infile outfile [deffile]
-@end smallexample
+@item
+the average number of code lines in subprogram bodies, task bodies, entry
+bodies and statement sequences in package bodies (this metric is only computed
+across the whole set of the analyzed units)
+
+@end itemize
@noindent
-where
-@table @code
-@item infile
-is the full name of the input file, which is an Ada source
-file containing preprocessor directives.
+@command{gnatmetric} sums the values of the line metrics for all the
+files being processed and then generates the cumulative results. The tool
+also computes for all the files being processed the average number of code
+lines in bodies.
-@item outfile
-is the full name of the output file, which is an Ada source
-in standard Ada form. When used with GNAT, this file name will
-normally have an ads or adb suffix.
+You can use the following switches to select the specific line metrics
+to be computed and reported.
-@item deffile
-is the full name of a text file containing definitions of
-symbols to be referenced by the preprocessor. This argument is
-optional, and can be replaced by the use of the @option{-D} switch.
+@table @option
+@cindex @option{^--lines@var{x}^/LINE_COUNT_METRICS^} (@command{gnatmetric})
-@item switches
-is an optional sequence of switches as described in the next section.
-@end table
+@ifclear vms
+@cindex @option{--no-lines@var{x}}
+@end ifclear
-@node Switches for gnatprep
-@section Switches for @code{gnatprep}
+@item ^--lines-all^/LINE_COUNT_METRICS=ALL_ON^
+Report all the line metrics
-@table @option
-@c !sort!
+@item ^--no-lines-all^/LINE_COUNT_METRICS=ALL_OFF^
+Do not report any of line metrics
-@item ^-b^/BLANK_LINES^
-@cindex @option{^-b^/BLANK_LINES^} (@command{gnatprep})
-Causes both preprocessor lines and the lines deleted by
-preprocessing to be replaced by blank lines in the output source file,
-preserving line numbers in the output file.
+@item ^--lines^/LINE_COUNT_METRICS=ALL_LINES_ON^
+Report the number of all lines
-@item ^-c^/COMMENTS^
-@cindex @option{^-c^/COMMENTS^} (@command{gnatprep})
-Causes both preprocessor lines and the lines deleted
-by preprocessing to be retained in the output source as comments marked
-with the special string @code{"--! "}. This option will result in line numbers
-being preserved in the output file.
+@item ^--no-lines^/LINE_COUNT_METRICS=ALL_LINES_OFF^
+Do not report the number of all lines
-@item ^-Dsymbol=value^/ASSOCIATE="symbol=value"^
-@cindex @option{^-D^/ASSOCIATE^} (@command{gnatprep})
-Defines a new symbol, associated with value. If no value is given on the
-command line, then symbol is considered to be @code{True}. This switch
-can be used in place of a definition file.
+@item ^--lines-code^/LINE_COUNT_METRICS=CODE_LINES_ON^
+Report the number of code lines
-@ifset vms
-@item /REMOVE
-@cindex @option{/REMOVE} (@command{gnatprep})
-This is the default setting which causes lines deleted by preprocessing
-to be entirely removed from the output file.
-@end ifset
+@item ^--no-lines-code^/LINE_COUNT_METRICS=CODE_LINES_OFF^
+Do not report the number of code lines
-@item ^-r^/REFERENCE^
-@cindex @option{^-r^/REFERENCE^} (@command{gnatprep})
-Causes a @code{Source_Reference} pragma to be generated that
-references the original input file, so that error messages will use
-the file name of this original file. The use of this switch implies
-that preprocessor lines are not to be removed from the file, so its
-use will force @option{^-b^/BLANK_LINES^} mode if
-@option{^-c^/COMMENTS^}
-has not been specified explicitly.
+@item ^--lines-comment^/LINE_COUNT_METRICS=COMMENT_LINES_ON^
+Report the number of comment lines
-Note that if the file to be preprocessed contains multiple units, then
-it will be necessary to @code{gnatchop} the output file from
-@code{gnatprep}. If a @code{Source_Reference} pragma is present
-in the preprocessed file, it will be respected by
-@code{gnatchop ^-r^/REFERENCE^}
-so that the final chopped files will correctly refer to the original
-input source file for @code{gnatprep}.
+@item ^--no-lines-comment^/LINE_COUNT_METRICS=COMMENT_LINES_OFF^
+Do not report the number of comment lines
-@item ^-s^/SYMBOLS^
-@cindex @option{^-s^/SYMBOLS^} (@command{gnatprep})
-Causes a sorted list of symbol names and values to be
-listed on the standard output file.
+@item ^--lines-eol-comment^/LINE_COUNT_METRICS=CODE_COMMENT_LINES_ON^
+Report the number of code lines containing
+end-of-line comments
-@item ^-u^/UNDEFINED^
-@cindex @option{^-u^/UNDEFINED^} (@command{gnatprep})
-Causes undefined symbols to be treated as having the value FALSE in the context
-of a preprocessor test. In the absence of this option, an undefined symbol in
-a @code{#if} or @code{#elsif} test will be treated as an error.
+@item ^--no-lines-eol-comment^/LINE_COUNT_METRICS=CODE_COMMENT_LINES_OFF^
+Do not report the number of code lines containing
+end-of-line comments
+
+@item ^--lines-ratio^/LINE_COUNT_METRICS=COMMENT_PERCENTAGE_ON^
+Report the comment percentage in the program text
+
+@item ^--no-lines-ratio^/LINE_COUNT_METRICS=COMMENT_PERCENTAGE_OFF^
+Do not report the comment percentage in the program text
+
+@item ^--lines-blank^/LINE_COUNT_METRICS=BLANK_LINES_ON^
+Report the number of blank lines
+
+@item ^--no-lines-blank^/LINE_COUNT_METRICS=BLANK_LINES_OFF^
+Do not report the number of blank lines
+
+@item ^--lines-average^/LINE_COUNT_METRICS=AVERAGE_BODY_LINES_ON^
+Report the average number of code lines in subprogram bodies, task bodies,
+entry bodies and statement sequences in package bodies. The metric is computed
+and reported for the whole set of processed Ada sources only.
+
+@item ^--no-lines-average^/LINE_COUNT_METRICS=AVERAGE_BODY_LINES_OFF^
+Do not report the average number of code lines in subprogram bodies,
+task bodies, entry bodies and statement sequences in package bodies.
@end table
-@ifclear vms
+@node Syntax Metrics Control
+@subsubsection Syntax Metrics Control
+@cindex Syntax metrics control in @command{gnatmetric}
+
@noindent
-Note: if neither @option{-b} nor @option{-c} is present,
-then preprocessor lines and
-deleted lines are completely removed from the output, unless -r is
-specified, in which case -b is assumed.
-@end ifclear
+@command{gnatmetric} computes various syntactic metrics for the
+outermost unit and for each eligible local unit:
-@node Form of Definitions File
-@section Form of Definitions File
+@table @emph
+@item LSLOC (``Logical Source Lines Of Code'')
+The total number of declarations and the total number of statements
+
+@item Maximal static nesting level of inner program units
+According to
+@cite{Ada Reference Manual}, 10.1(1), ``A program unit is either a
+package, a task unit, a protected unit, a
+protected entry, a generic unit, or an explicitly declared subprogram other
+than an enumeration literal.''
+
+@item Maximal nesting level of composite syntactic constructs
+This corresponds to the notion of the
+maximum nesting level in the GNAT built-in style checks
+(@pxref{Style Checking})
+@end table
@noindent
-The definitions file contains lines of the form
+For the outermost unit in the file, @command{gnatmetric} additionally computes
+the following metrics:
-@smallexample
-symbol := value
-@end smallexample
+@table @emph
+@item Public subprograms
+This metric is computed for package specs. It is the
+number of subprograms and generic subprograms declared in the visible
+part (including the visible part of nested packages, protected objects, and
+protected types).
+
+@item All subprograms
+This metric is computed for bodies and subunits. The
+metric is equal to a total number of subprogram bodies in the compilation
+unit.
+Neither generic instantiations nor renamings-as-a-body nor body stubs
+are counted. Any subprogram body is counted, independently of its nesting
+level and enclosing constructs. Generic bodies and bodies of protected
+subprograms are counted in the same way as ``usual'' subprogram bodies.
+
+@item Public types
+This metric is computed for package specs and
+generic package declarations. It is the total number of types
+that can be referenced from outside this compilation unit, plus the
+number of types from all the visible parts of all the visible generic
+packages. Generic formal types are not counted. Only types, not subtypes,
+are included.
@noindent
-where symbol is an identifier, following normal Ada (case-insensitive)
-rules for its syntax, and value is one of the following:
+Along with the total number of public types, the following
+types are counted and reported separately:
@itemize @bullet
@item
-Empty, corresponding to a null substitution
+Abstract types
+
@item
-A string literal using normal Ada syntax
+Root tagged types (abstract, non-abstract, private, non-private). Type
+extensions are @emph{not} counted
+
@item
-Any sequence of characters from the set
-(letters, digits, period, underline).
+Private types (including private extensions)
+
+@item
+Task types
+
+@item
+Protected types
+
@end itemize
-@noindent
-Comment lines may also appear in the definitions file, starting with
-the usual @code{--},
-and comments may be added to the definitions lines.
+@item All types
+This metric is computed for any compilation unit. It is equal to the total
+number of the declarations of different types given in the compilation unit.
+The private and the corresponding full type declaration are counted as one
+type declaration. Incomplete type declarations and generic formal types
+are not counted.
+No distinction is made among different kinds of types (abstract,
+private etc.); the total number of types is computed and reported.
-@node Form of Input Text for gnatprep
-@section Form of Input Text for @code{gnatprep}
+@end table
@noindent
-The input text may contain preprocessor conditional inclusion lines,
-as well as general symbol substitution sequences.
+By default, all the syntax metrics are computed and reported. You can use the
+following switches to select specific syntax metrics.
-The preprocessor conditional inclusion commands have the form
+@table @option
-@smallexample
-@group
-@cartouche
-#if @i{expression} [then]
- lines
-#elsif @i{expression} [then]
- lines
-#elsif @i{expression} [then]
- lines
-...
-#else
- lines
-#end if;
-@end cartouche
-@end group
-@end smallexample
+@cindex @option{^--syntax@var{x}^/SYNTAX_METRICS^} (@command{gnatmetric})
-@noindent
-In this example, @i{expression} is defined by the following grammar:
-@smallexample
-@i{expression} ::= <symbol>
-@i{expression} ::= <symbol> = "<value>"
-@i{expression} ::= <symbol> = <symbol>
-@i{expression} ::= <symbol> 'Defined
-@i{expression} ::= not @i{expression}
-@i{expression} ::= @i{expression} and @i{expression}
-@i{expression} ::= @i{expression} or @i{expression}
-@i{expression} ::= @i{expression} and then @i{expression}
-@i{expression} ::= @i{expression} or else @i{expression}
-@i{expression} ::= ( @i{expression} )
-@end smallexample
+@ifclear vms
+@cindex @option{--no-syntax@var{x}} (@command{gnatmetric})
+@end ifclear
-@noindent
-For the first test (@i{expression} ::= <symbol>) the symbol must have
-either the value true or false, that is to say the right-hand of the
-symbol definition must be one of the (case-insensitive) literals
-@code{True} or @code{False}. If the value is true, then the
-corresponding lines are included, and if the value is false, they are
-excluded.
+@item ^--syntax-all^/SYNTAX_METRICS=ALL_ON^
+Report all the syntax metrics
-The test (@i{expression} ::= <symbol> @code{'Defined}) is true only if
-the symbol has been defined in the definition file or by a @option{-D}
-switch on the command line. Otherwise, the test is false.
+@item ^--no-syntax-all^/ALL_OFF^
+Do not report any of syntax metrics
-The equality tests are case insensitive, as are all the preprocessor lines.
+@item ^--declarations^/SYNTAX_METRICS=DECLARATIONS_ON^
+Report the total number of declarations
-If the symbol referenced is not defined in the symbol definitions file,
-then the effect depends on whether or not switch @option{-u}
-is specified. If so, then the symbol is treated as if it had the value
-false and the test fails. If this switch is not specified, then
-it is an error to reference an undefined symbol. It is also an error to
-reference a symbol that is defined with a value other than @code{True}
-or @code{False}.
+@item ^--no-declarations^/SYNTAX_METRICS=DECLARATIONS_OFF^
+Do not report the total number of declarations
-The use of the @code{not} operator inverts the sense of this logical test, so
-that the lines are included only if the symbol is not defined.
-The @code{then} keyword is optional as shown
+@item ^--statements^/SYNTAX_METRICS=STATEMENTS_ON^
+Report the total number of statements
-The @code{#} must be the first non-blank character on a line, but
-otherwise the format is free form. Spaces or tabs may appear between
-the @code{#} and the keyword. The keywords and the symbols are case
-insensitive as in normal Ada code. Comments may be used on a
-preprocessor line, but other than that, no other tokens may appear on a
-preprocessor line. Any number of @code{elsif} clauses can be present,
-including none at all. The @code{else} is optional, as in Ada.
+@item ^--no-statements^/SYNTAX_METRICS=STATEMENTS_OFF^
+Do not report the total number of statements
-The @code{#} marking the start of a preprocessor line must be the first
-non-blank character on the line, i.e. it must be preceded only by
-spaces or horizontal tabs.
+@item ^--public-subprograms^/SYNTAX_METRICS=PUBLIC_SUBPROGRAMS_ON^
+Report the number of public subprograms in a compilation unit
-Symbol substitution outside of preprocessor lines is obtained by using
-the sequence
+@item ^--no-public-subprograms^/SYNTAX_METRICS=PUBLIC_SUBPROGRAMS_OFF^
+Do not report the number of public subprograms in a compilation unit
-@smallexample
-$symbol
-@end smallexample
+@item ^--all-subprograms^/SYNTAX_METRICS=ALL_SUBPROGRAMS_ON^
+Report the number of all the subprograms in a compilation unit
-@noindent
-anywhere within a source line, except in a comment or within a
-string literal. The identifier
-following the @code{$} must match one of the symbols defined in the symbol
-definition file, and the result is to substitute the value of the
-symbol in place of @code{$symbol} in the output file.
+@item ^--no-all-subprograms^/SYNTAX_METRICS=ALL_SUBPROGRAMS_OFF^
+Do not report the number of all the subprograms in a compilation unit
-Note that although the substitution of strings within a string literal
-is not possible, it is possible to have a symbol whose defined value is
-a string literal. So instead of setting XYZ to @code{hello} and writing:
+@item ^--public-types^/SYNTAX_METRICS=PUBLIC_TYPES_ON^
+Report the number of public types in a compilation unit
-@smallexample
-Header : String := "$XYZ";
-@end smallexample
+@item ^--no-public-types^/SYNTAX_METRICS=PUBLIC_TYPES_OFF^
+Do not report the number of public types in a compilation unit
-@noindent
-you should set XYZ to @code{"hello"} and write:
+@item ^--all-types^/SYNTAX_METRICS=ALL_TYPES_ON^
+Report the number of all the types in a compilation unit
-@smallexample
-Header : String := $XYZ;
-@end smallexample
+@item ^--no-all-types^/SYNTAX_METRICS=ALL_TYPES_OFF^
+Do not report the number of all the types in a compilation unit
-@noindent
-and then the substitution will occur as desired.
+@item ^--unit-nesting^/SYNTAX_METRICS=UNIT_NESTING_ON^
+Report the maximal program unit nesting level
-@ifset vms
-@node The GNAT Run-Time Library Builder gnatlbr
-@chapter The GNAT Run-Time Library Builder @code{gnatlbr}
-@findex gnatlbr
-@cindex Library builder
+@item ^--no-unit-nesting^/SYNTAX_METRICS=UNIT_NESTING_OFF^
+Do not report the maximal program unit nesting level
+
+@item ^--construct-nesting^/SYNTAX_METRICS=CONSTRUCT_NESTING_ON^
+Report the maximal construct nesting level
+
+@item ^--no-construct-nesting^/SYNTAX_METRICS=CONSTRUCT_NESTING_OFF^
+Do not report the maximal construct nesting level
+
+@end table
+
+@node Complexity Metrics Control
+@subsubsection Complexity Metrics Control
+@cindex Complexity metrics control in @command{gnatmetric}
@noindent
-@code{gnatlbr} is a tool for rebuilding the GNAT run time with user
-supplied configuration pragmas.
+For a program unit that is an executable body (a subprogram body (including
+generic bodies), task body, entry body or a package body containing
+its own statement sequence) @command{gnatmetric} computes the following
+complexity metrics:
-@menu
-* Running gnatlbr::
-* Switches for gnatlbr::
-* Examples of gnatlbr Usage::
-@end menu
+@itemize @bullet
+@item
+McCabe cyclomatic complexity;
-@node Running gnatlbr
-@section Running @code{gnatlbr}
+@item
+McCabe essential complexity;
+
+@item
+maximal loop nesting level
+
+@end itemize
@noindent
-The @code{gnatlbr} command has the form
+The McCabe complexity metrics are defined
+in @url{http://www.mccabe.com/pdf/nist235r.pdf}
-@smallexample
-$ GNAT LIBRARY /[CREATE | SET | DELETE]=directory [/CONFIG=file]
-@end smallexample
+According to McCabe, both control statements and short-circuit control forms
+should be taken into account when computing cyclomatic complexity. For each
+body, we compute three metric values:
-@node Switches for gnatlbr
-@section Switches for @code{gnatlbr}
+@itemize @bullet
+@item
+the complexity introduced by control
+statements only, without taking into account short-circuit forms,
+
+@item
+the complexity introduced by short-circuit control forms only, and
+
+@item
+the total
+cyclomatic complexity, which is the sum of these two values.
+@end itemize
@noindent
-@code{gnatlbr} recognizes the following switches:
+When computing cyclomatic and essential complexity, @command{gnatmetric} skips
+the code in the exception handlers and in all the nested program units.
+
+By default, all the complexity metrics are computed and reported.
+For more fine-grained control you can use
+the following switches:
@table @option
-@c !sort!
-@item /CREATE=directory
-@cindex @code{/CREATE} (@code{gnatlbr})
- Create the new run-time library in the specified directory.
+@cindex @option{^-complexity@var{x}^/COMPLEXITY_METRICS^} (@command{gnatmetric})
-@item /SET=directory
-@cindex @code{/SET} (@code{gnatlbr})
- Make the library in the specified directory the current run-time
- library.
+@ifclear vms
+@cindex @option{--no-complexity@var{x}}
+@end ifclear
-@item /DELETE=directory
-@cindex @code{/DELETE} (@code{gnatlbr})
- Delete the run-time library in the specified directory.
+@item ^--complexity-all^/COMPLEXITY_METRICS=ALL_ON^
+Report all the complexity metrics
-@item /CONFIG=file
-@cindex @code{/CONFIG} (@code{gnatlbr})
- With /CREATE:
- Use the configuration pragmas in the specified file when building
- the library.
+@item ^--no-complexity-all^/COMPLEXITY_METRICS=ALL_OFF^
+Do not report any of complexity metrics
- With /SET:
- Use the configuration pragmas in the specified file when compiling.
+@item ^--complexity-cyclomatic^/COMPLEXITY_METRICS=CYCLOMATIC_ON^
+Report the McCabe Cyclomatic Complexity
-@end table
+@item ^--no-complexity-cyclomatic^/COMPLEXITY_METRICS=CYCLOMATIC_OFF^
+Do not report the McCabe Cyclomatic Complexity
-@node Examples of gnatlbr Usage
-@section Example of @code{gnatlbr} Usage
+@item ^--complexity-essential^/COMPLEXITY_METRICS=ESSENTIAL_ON^
+Report the Essential Complexity
-@smallexample
-Contents of VAXFLOAT.ADC:
-pragma Float_Representation (VAX_Float);
+@item ^--no-complexity-essential^/COMPLEXITY_METRICS=ESSENTIAL_OFF^
+Do not report the Essential Complexity
-$ GNAT LIBRARY /CREATE=[.VAXFLOAT] /CONFIG=VAXFLOAT.ADC
+@item ^--loop-nesting^/COMPLEXITY_METRICS=LOOP_NESTING_ON^
+Report maximal loop nesting level
-GNAT LIBRARY rebuilds the run-time library in directory [.VAXFLOAT]
+@item ^--no-loop-nesting^/COMPLEXITY_METRICS=LOOP_NESTING_OFF^
+Do not report maximal loop nesting level
-@end smallexample
-@end ifset
+@item ^--complexity-average^/COMPLEXITY_METRICS=AVERAGE_COMPLEXITY_ON^
+Report the average McCabe Cyclomatic Complexity for all the subprogram bodies,
+task bodies, entry bodies and statement sequences in package bodies.
+The metric is computed and reported for whole set of processed Ada sources
+only.
-@node The GNAT Library Browser gnatls
-@chapter The GNAT Library Browser @code{gnatls}
-@findex gnatls
-@cindex Library browser
+@item ^--no-complexity-average^/COMPLEXITY_METRICS=AVERAGE_COMPLEXITY_OFF^
+Do not report the average McCabe Cyclomatic Complexity for all the subprogram
+bodies, task bodies, entry bodies and statement sequences in package bodies
-@noindent
-@code{gnatls} is a tool that outputs information about compiled
-units. It gives the relationship between objects, unit names and source
-files. It can also be used to check the source dependencies of a unit
-as well as various characteristics.
+@cindex @option{^-ne^/NO_EXITS_AS_GOTOS^} (@command{gnatmetric})
+@item ^-ne^/NO_EXITS_AS_GOTOS^
+Do not consider @code{exit} statements as @code{goto}s when
+computing Essential Complexity
-@menu
-* Running gnatls::
-* Switches for gnatls::
-* Examples of gnatls Usage::
-@end menu
+@end table
-@node Running gnatls
-@section Running @code{gnatls}
-@noindent
-The @code{gnatls} command has the form
+@node Object-Oriented Metrics Control
+@subsubsection Object-Oriented Metrics Control
+@cindex Object-Oriented metrics control in @command{gnatmetric}
+
+@noindent
+@cindex Coupling metrics (in in @command{gnatmetric})
+Coupling metrics are object-oriented metrics that measure the
+dependencies between a given class (or a group of classes) and the
+``external world'' (that is, the other classes in the program). In this
+subsection the term ``class'' is used in its
+traditional object-oriented programming sense
+(an instantiable module that contains data and/or method members).
+A @emph{category} (of classes)
+is a group of closely related classes that are reused and/or
+modified together.
+
+A class @code{K}'s @emph{efferent coupling} is the number of classes
+that @code{K} depends upon.
+A category's efferent coupling is the number of classes outside the
+category that the classes inside the category depend upon.
+
+A class @code{K}'s @emph{afferent coupling} is the number of classes
+that depend upon @code{K}.
+A category's afferent coupling is the number of classes outside the
+category that depend on classes belonging to the category.
+
+Ada's implementation of the object-oriented paradigm does not use the
+traditional class notion, so the definition of the coupling
+metrics for Ada maps the class and class category notions
+onto Ada constructs.
+
+For the coupling metrics, several kinds of modules -- a library package,
+a library generic package, and a library generic package instantiation --
+that define a tagged type or an interface type are
+considered to be a class. A category consists of a library package (or
+a library generic package) that defines a tagged or an interface type,
+together with all its descendant (generic) packages that define tagged
+or interface types. For any package counted as a class,
+its body (if any) is considered
+together with its spec when counting the dependencies. For dependencies
+between classes, the Ada semantic dependencies are considered.
+For coupling metrics, only dependencies on units that are considered as
+classes, are considered.
+
+When computing coupling metrics, @command{gnatmetric} counts only
+dependencies between units that are arguments of the gnatmetric call.
+Coupling metrics are program-wide (or project-wide) metrics, so to
+get a valid result, you should call @command{gnatmetric} for
+the whole set of sources that make up your program. It can be done
+by calling @command{gnatmetric} from the GNAT driver with @option{-U}
+option (see See @ref{The GNAT Driver and Project Files} for details.
+
+By default, all the coupling metrics are disabled. You can use the following
+switches to specify the coupling metrics to be computed and reported:
-@smallexample
-$ gnatls switches @var{object_or_ali_file}
-@end smallexample
+@table @option
-@noindent
-The main argument is the list of object or @file{ali} files
-(@pxref{The Ada Library Information Files})
-for which information is requested.
+@ifclear vms
+@cindex @option{--package@var{x}} (@command{gnatmetric})
+@cindex @option{--no-package@var{x}} (@command{gnatmetric})
+@cindex @option{--category@var{x}} (@command{gnatmetric})
+@cindex @option{--no-category@var{x}} (@command{gnatmetric})
+@end ifclear
-In normal mode, without additional option, @code{gnatls} produces a
-four-column listing. Each line represents information for a specific
-object. The first column gives the full path of the object, the second
-column gives the name of the principal unit in this object, the third
-column gives the status of the source and the fourth column gives the
-full path of the source representing this unit.
-Here is a simple example of use:
+@ifset vms
+@cindex @option{/COUPLING_METRICS} (@command{gnatmetric})
+@end ifset
-@smallexample
-$ gnatls *.o
-^./^[]^demo1.o demo1 DIF demo1.adb
-^./^[]^demo2.o demo2 OK demo2.adb
-^./^[]^hello.o h1 OK hello.adb
-^./^[]^instr-child.o instr.child MOK instr-child.adb
-^./^[]^instr.o instr OK instr.adb
-^./^[]^tef.o tef DIF tef.adb
-^./^[]^text_io_example.o text_io_example OK text_io_example.adb
-^./^[]^tgef.o tgef DIF tgef.adb
-@end smallexample
+@item ^--coupling-all^/COUPLING_METRICS=ALL_ON^
+Report all the coupling metrics
-@noindent
-The first line can be interpreted as follows: the main unit which is
-contained in
-object file @file{demo1.o} is demo1, whose main source is in
-@file{demo1.adb}. Furthermore, the version of the source used for the
-compilation of demo1 has been modified (DIF). Each source file has a status
-qualifier which can be:
+@item ^--no-coupling-all^/COUPLING_METRICS=ALL_OFF^
+Do not report any of metrics
-@table @code
-@item OK (unchanged)
-The version of the source file used for the compilation of the
-specified unit corresponds exactly to the actual source file.
+@item ^--package-efferent-coupling^/COUPLING_METRICS=PACKAGE_EFFERENT_ON^
+Report package efferent coupling
-@item MOK (slightly modified)
-The version of the source file used for the compilation of the
-specified unit differs from the actual source file but not enough to
-require recompilation. If you use gnatmake with the qualifier
-@option{^-m (minimal recompilation)^/MINIMAL_RECOMPILATION^}, a file marked
-MOK will not be recompiled.
+@item ^--no-package-efferent-coupling^/COUPLING_METRICS=PACKAGE_EFFERENT_OFF^
+Do not report package efferent coupling
-@item DIF (modified)
-No version of the source found on the path corresponds to the source
-used to build this object.
+@item ^--package-afferent-coupling^/COUPLING_METRICS=PACKAGE_AFFERENT_ON^
+Report package afferent coupling
-@item ??? (file not found)
-No source file was found for this unit.
+@item ^--no-package-afferent-coupling^/COUPLING_METRICS=PACKAGE_AFFERENT_OFF^
+Do not report package afferent coupling
-@item HID (hidden, unchanged version not first on PATH)
-The version of the source that corresponds exactly to the source used
-for compilation has been found on the path but it is hidden by another
-version of the same source that has been modified.
+@item ^--category-efferent-coupling^/COUPLING_METRICS=CATEGORY_EFFERENT_ON^
+Report category efferent coupling
+
+@item ^--no-category-efferent-coupling^/COUPLING_METRICS=CATEGORY_EFFERENT_OFF^
+Do not report category efferent coupling
+
+@item ^--category-afferent-coupling^/COUPLING_METRICS=CATEGORY_AFFERENT_ON^
+Report category afferent coupling
+
+@item ^--no-category-afferent-coupling^/COUPLING_METRICS=CATEGORY_AFFERENT_OFF^
+Do not report category afferent coupling
@end table
-@node Switches for gnatls
-@section Switches for @code{gnatls}
+@node Other gnatmetric Switches
+@subsection Other @code{gnatmetric} Switches
@noindent
-@code{gnatls} recognizes the following switches:
+Additional @command{gnatmetric} switches are as follows:
@table @option
-@c !sort!
-@item ^-a^/ALL_UNITS^
-@cindex @option{^-a^/ALL_UNITS^} (@code{gnatls})
-Consider all units, including those of the predefined Ada library.
-Especially useful with @option{^-d^/DEPENDENCIES^}.
+@item ^-files @var{filename}^/FILES=@var{filename}^
+@cindex @option{^-files^/FILES^} (@code{gnatmetric})
+Take the argument source files from the specified file. This file should be an
+ordinary text file containing file names separated by spaces or
+line breaks. You can use this switch more then once in the same call to
+@command{gnatmetric}. You also can combine this switch with
+an explicit list of files.
-@item ^-d^/DEPENDENCIES^
-@cindex @option{^-d^/DEPENDENCIES^} (@code{gnatls})
-List sources from which specified units depend on.
+@item ^-v^/VERBOSE^
+@cindex @option{^-v^/VERBOSE^} (@code{gnatmetric})
+Verbose mode;
+@command{gnatmetric} generates version information and then
+a trace of sources being processed.
-@item ^-h^/OUTPUT=OPTIONS^
-@cindex @option{^-h^/OUTPUT=OPTIONS^} (@code{gnatls})
-Output the list of options.
+@item ^-dv^/DEBUG_OUTPUT^
+@cindex @option{^-dv^/DEBUG_OUTPUT^} (@code{gnatmetric})
+Debug mode;
+@command{gnatmetric} generates various messages useful to understand what
+happens during the metrics computation
-@item ^-o^/OUTPUT=OBJECTS^
-@cindex @option{^-o^/OUTPUT=OBJECTS^} (@code{gnatls})
+@item ^-q^/QUIET^
+@cindex @option{^-q^/QUIET^} (@code{gnatmetric})
+Quiet mode.
+@end table
+
+@node Generate project-wide metrics
+@subsection Generate project-wide metrics
+
+In order to compute metrics on all units of a given project, you can use
+the @command{gnat} driver along with the @option{-P} option:
+@smallexample
+ gnat metric -Pproj
+@end smallexample
+
+@noindent
+If the project @code{proj} depends upon other projects, you can compute
+the metrics on the project closure using the @option{-U} option:
+@smallexample
+ gnat metric -Pproj -U
+@end smallexample
+
+@noindent
+Finally, if not all the units are relevant to a particular main
+program in the project closure, you can generate metrics for the set
+of units needed to create a given main program (unit closure) using
+the @option{-U} option followed by the name of the main unit:
+@smallexample
+ gnat metric -Pproj -U main
+@end smallexample
+
+
+@c ***********************************
+@node File Name Krunching Using gnatkr
+@chapter File Name Krunching Using @code{gnatkr}
+@findex gnatkr
+
+@noindent
+This chapter discusses the method used by the compiler to shorten
+the default file names chosen for Ada units so that they do not
+exceed the maximum length permitted. It also describes the
+@code{gnatkr} utility that can be used to determine the result of
+applying this shortening.
+@menu
+* About gnatkr::
+* Using gnatkr::
+* Krunching Method::
+* Examples of gnatkr Usage::
+@end menu
+
+@node About gnatkr
+@section About @code{gnatkr}
+
+@noindent
+The default file naming rule in GNAT
+is that the file name must be derived from
+the unit name. The exact default rule is as follows:
+@itemize @bullet
+@item
+Take the unit name and replace all dots by hyphens.
+@item
+If such a replacement occurs in the
+second character position of a name, and the first character is
+^@samp{a}, @samp{g}, @samp{s}, or @samp{i}, ^@samp{A}, @samp{G}, @samp{S}, or @samp{I},^
+then replace the dot by the character
+^@samp{~} (tilde)^@samp{$} (dollar sign)^
+instead of a minus.
+@end itemize
+The reason for this exception is to avoid clashes
+with the standard names for children of System, Ada, Interfaces,
+and GNAT, which use the prefixes
+^@samp{s-}, @samp{a-}, @samp{i-}, and @samp{g-},^@samp{S-}, @samp{A-}, @samp{I-}, and @samp{G-},^
+respectively.
+
+The @option{^-gnatk^/FILE_NAME_MAX_LENGTH=^@var{nn}}
+switch of the compiler activates a ``krunching''
+circuit that limits file names to nn characters (where nn is a decimal
+integer). For example, using OpenVMS,
+where the maximum file name length is
+39, the value of nn is usually set to 39, but if you want to generate
+a set of files that would be usable if ported to a system with some
+different maximum file length, then a different value can be specified.
+The default value of 39 for OpenVMS need not be specified.
+
+The @code{gnatkr} utility can be used to determine the krunched name for
+a given file, when krunched to a specified maximum length.
+
+@node Using gnatkr
+@section Using @code{gnatkr}
+
+@noindent
+The @code{gnatkr} command has the form
+
+@ifclear vms
+@smallexample
+$ gnatkr @var{name} @ovar{length}
+@end smallexample
+@end ifclear
+
+@ifset vms
+@smallexample
+$ gnatkr @var{name} /COUNT=nn
+@end smallexample
+@end ifset
+
+@noindent
+@var{name} is the uncrunched file name, derived from the name of the unit
+in the standard manner described in the previous section (i.e., in particular
+all dots are replaced by hyphens). The file name may or may not have an
+extension (defined as a suffix of the form period followed by arbitrary
+characters other than period). If an extension is present then it will
+be preserved in the output. For example, when krunching @file{hellofile.ads}
+to eight characters, the result will be hellofil.ads.
+
+Note: for compatibility with previous versions of @code{gnatkr} dots may
+appear in the name instead of hyphens, but the last dot will always be
+taken as the start of an extension. So if @code{gnatkr} is given an argument
+such as @file{Hello.World.adb} it will be treated exactly as if the first
+period had been a hyphen, and for example krunching to eight characters
+gives the result @file{hellworl.adb}.
+
+Note that the result is always all lower case (except on OpenVMS where it is
+all upper case). Characters of the other case are folded as required.
+
+@var{length} represents the length of the krunched name. The default
+when no argument is given is ^8^39^ characters. A length of zero stands for
+unlimited, in other words do not chop except for system files where the
+implied crunching length is always eight characters.
+
+@noindent
+The output is the krunched name. The output has an extension only if the
+original argument was a file name with an extension.
+
+@node Krunching Method
+@section Krunching Method
+
+@noindent
+The initial file name is determined by the name of the unit that the file
+contains. The name is formed by taking the full expanded name of the
+unit and replacing the separating dots with hyphens and
+using ^lowercase^uppercase^
+for all letters, except that a hyphen in the second character position is
+replaced by a ^tilde^dollar sign^ if the first character is
+^@samp{a}, @samp{i}, @samp{g}, or @samp{s}^@samp{A}, @samp{I}, @samp{G}, or @samp{S}^.
+The extension is @code{.ads} for a
+spec and @code{.adb} for a body.
+Krunching does not affect the extension, but the file name is shortened to
+the specified length by following these rules:
+
+@itemize @bullet
+@item
+The name is divided into segments separated by hyphens, tildes or
+underscores and all hyphens, tildes, and underscores are
+eliminated. If this leaves the name short enough, we are done.
+
+@item
+If the name is too long, the longest segment is located (left-most
+if there are two of equal length), and shortened by dropping
+its last character. This is repeated until the name is short enough.
+
+As an example, consider the krunching of @*@file{our-strings-wide_fixed.adb}
+to fit the name into 8 characters as required by some operating systems.
+
+@smallexample
+our-strings-wide_fixed 22
+our strings wide fixed 19
+our string wide fixed 18
+our strin wide fixed 17
+our stri wide fixed 16
+our stri wide fixe 15
+our str wide fixe 14
+our str wid fixe 13
+our str wid fix 12
+ou str wid fix 11
+ou st wid fix 10
+ou st wi fix 9
+ou st wi fi 8
+Final file name: oustwifi.adb
+@end smallexample
+
+@item
+The file names for all predefined units are always krunched to eight
+characters. The krunching of these predefined units uses the following
+special prefix replacements:
+
+@table @file
+@item ada-
+replaced by @file{^a^A^-}
+
+@item gnat-
+replaced by @file{^g^G^-}
+
+@item interfaces-
+replaced by @file{^i^I^-}
+
+@item system-
+replaced by @file{^s^S^-}
+@end table
+
+These system files have a hyphen in the second character position. That
+is why normal user files replace such a character with a
+^tilde^dollar sign^, to
+avoid confusion with system file names.
+
+As an example of this special rule, consider
+@*@file{ada-strings-wide_fixed.adb}, which gets krunched as follows:
+
+@smallexample
+ada-strings-wide_fixed 22
+a- strings wide fixed 18
+a- string wide fixed 17
+a- strin wide fixed 16
+a- stri wide fixed 15
+a- stri wide fixe 14
+a- str wide fixe 13
+a- str wid fixe 12
+a- str wid fix 11
+a- st wid fix 10
+a- st wi fix 9
+a- st wi fi 8
+Final file name: a-stwifi.adb
+@end smallexample
+@end itemize
+
+Of course no file shortening algorithm can guarantee uniqueness over all
+possible unit names, and if file name krunching is used then it is your
+responsibility to ensure that no name clashes occur. The utility
+program @code{gnatkr} is supplied for conveniently determining the
+krunched name of a file.
+
+@node Examples of gnatkr Usage
+@section Examples of @code{gnatkr} Usage
+
+@smallexample
+@iftex
+@leftskip=0cm
+@end iftex
+@ifclear vms
+$ gnatkr very_long_unit_name.ads --> velounna.ads
+$ gnatkr grandparent-parent-child.ads --> grparchi.ads
+$ gnatkr Grandparent.Parent.Child.ads --> grparchi.ads
+$ gnatkr grandparent-parent-child --> grparchi
+@end ifclear
+$ gnatkr very_long_unit_name.ads/count=6 --> vlunna.ads
+$ gnatkr very_long_unit_name.ads/count=0 --> very_long_unit_name.ads
+@end smallexample
+
+@node Preprocessing Using gnatprep
+@chapter Preprocessing Using @code{gnatprep}
+@findex gnatprep
+
+@noindent
+This chapter discusses how to use GNAT's @code{gnatprep} utility for simple
+preprocessing.
+Although designed for use with GNAT, @code{gnatprep} does not depend on any
+special GNAT features.
+For further discussion of conditional compilation in general, see
+@ref{Conditional Compilation}.
+
+@menu
+* Preprocessing Symbols::
+* Using gnatprep::
+* Switches for gnatprep::
+* Form of Definitions File::
+* Form of Input Text for gnatprep::
+@end menu
+
+@node Preprocessing Symbols
+@section Preprocessing Symbols
+
+@noindent
+Preprocessing symbols are defined in definition files and referred to in
+sources to be preprocessed. A Preprocessing symbol is an identifier, following
+normal Ada (case-insensitive) rules for its syntax, with the restriction that
+all characters need to be in the ASCII set (no accented letters).
+
+@node Using gnatprep
+@section Using @code{gnatprep}
+
+@noindent
+To call @code{gnatprep} use
+
+@smallexample
+$ gnatprep @ovar{switches} @var{infile} @var{outfile} @ovar{deffile}
+@end smallexample
+
+@noindent
+where
+@table @var
+@item switches
+is an optional sequence of switches as described in the next section.
+
+@item infile
+is the full name of the input file, which is an Ada source
+file containing preprocessor directives.
+
+@item outfile
+is the full name of the output file, which is an Ada source
+in standard Ada form. When used with GNAT, this file name will
+normally have an ads or adb suffix.
+
+@item deffile
+is the full name of a text file containing definitions of
+preprocessing symbols to be referenced by the preprocessor. This argument is
+optional, and can be replaced by the use of the @option{-D} switch.
+
+@end table
+
+@node Switches for gnatprep
+@section Switches for @code{gnatprep}
+
+@table @option
+@c !sort!
+
+@item ^-b^/BLANK_LINES^
+@cindex @option{^-b^/BLANK_LINES^} (@command{gnatprep})
+Causes both preprocessor lines and the lines deleted by
+preprocessing to be replaced by blank lines in the output source file,
+preserving line numbers in the output file.
+
+@item ^-c^/COMMENTS^
+@cindex @option{^-c^/COMMENTS^} (@command{gnatprep})
+Causes both preprocessor lines and the lines deleted
+by preprocessing to be retained in the output source as comments marked
+with the special string @code{"--! "}. This option will result in line numbers
+being preserved in the output file.
+
+@item ^-C^/REPLACE_IN_COMMENTS^
+@cindex @option{^-C^/REPLACE_IN_COMMENTS^} (@command{gnatprep})
+Causes comments to be scanned. Normally comments are ignored by gnatprep.
+If this option is specified, then comments are scanned and any $symbol
+substitutions performed as in program text. This is particularly useful
+when structured comments are used (e.g., when writing programs in the
+SPARK dialect of Ada). Note that this switch is not available when
+doing integrated preprocessing (it would be useless in this context
+since comments are ignored by the compiler in any case).
+
+@item ^-Dsymbol=value^/ASSOCIATE="symbol=value"^
+@cindex @option{^-D^/ASSOCIATE^} (@command{gnatprep})
+Defines a new preprocessing symbol, associated with value. If no value is given
+on the command line, then symbol is considered to be @code{True}. This switch
+can be used in place of a definition file.
+
+@ifset vms
+@item /REMOVE
+@cindex @option{/REMOVE} (@command{gnatprep})
+This is the default setting which causes lines deleted by preprocessing
+to be entirely removed from the output file.
+@end ifset
+
+@item ^-r^/REFERENCE^
+@cindex @option{^-r^/REFERENCE^} (@command{gnatprep})
+Causes a @code{Source_Reference} pragma to be generated that
+references the original input file, so that error messages will use
+the file name of this original file. The use of this switch implies
+that preprocessor lines are not to be removed from the file, so its
+use will force @option{^-b^/BLANK_LINES^} mode if
+@option{^-c^/COMMENTS^}
+has not been specified explicitly.
+
+Note that if the file to be preprocessed contains multiple units, then
+it will be necessary to @code{gnatchop} the output file from
+@code{gnatprep}. If a @code{Source_Reference} pragma is present
+in the preprocessed file, it will be respected by
+@code{gnatchop ^-r^/REFERENCE^}
+so that the final chopped files will correctly refer to the original
+input source file for @code{gnatprep}.
+
+@item ^-s^/SYMBOLS^
+@cindex @option{^-s^/SYMBOLS^} (@command{gnatprep})
+Causes a sorted list of symbol names and values to be
+listed on the standard output file.
+
+@item ^-u^/UNDEFINED^
+@cindex @option{^-u^/UNDEFINED^} (@command{gnatprep})
+Causes undefined symbols to be treated as having the value FALSE in the context
+of a preprocessor test. In the absence of this option, an undefined symbol in
+a @code{#if} or @code{#elsif} test will be treated as an error.
+
+@end table
+
+@ifclear vms
+@noindent
+Note: if neither @option{-b} nor @option{-c} is present,
+then preprocessor lines and
+deleted lines are completely removed from the output, unless -r is
+specified, in which case -b is assumed.
+@end ifclear
+
+@node Form of Definitions File
+@section Form of Definitions File
+
+@noindent
+The definitions file contains lines of the form
+
+@smallexample
+symbol := value
+@end smallexample
+
+@noindent
+where symbol is a preprocessing symbol, and value is one of the following:
+
+@itemize @bullet
+@item
+Empty, corresponding to a null substitution
+@item
+A string literal using normal Ada syntax
+@item
+Any sequence of characters from the set
+(letters, digits, period, underline).
+@end itemize
+
+@noindent
+Comment lines may also appear in the definitions file, starting with
+the usual @code{--},
+and comments may be added to the definitions lines.
+
+@node Form of Input Text for gnatprep
+@section Form of Input Text for @code{gnatprep}
+
+@noindent
+The input text may contain preprocessor conditional inclusion lines,
+as well as general symbol substitution sequences.
+
+The preprocessor conditional inclusion commands have the form
+
+@smallexample
+@group
+@cartouche
+#if @i{expression} @r{[}then@r{]}
+ lines
+#elsif @i{expression} @r{[}then@r{]}
+ lines
+#elsif @i{expression} @r{[}then@r{]}
+ lines
+@dots{}
+#else
+ lines
+#end if;
+@end cartouche
+@end group
+@end smallexample
+
+@noindent
+In this example, @i{expression} is defined by the following grammar:
+@smallexample
+@i{expression} ::= <symbol>
+@i{expression} ::= <symbol> = "<value>"
+@i{expression} ::= <symbol> = <symbol>
+@i{expression} ::= <symbol> 'Defined
+@i{expression} ::= not @i{expression}
+@i{expression} ::= @i{expression} and @i{expression}
+@i{expression} ::= @i{expression} or @i{expression}
+@i{expression} ::= @i{expression} and then @i{expression}
+@i{expression} ::= @i{expression} or else @i{expression}
+@i{expression} ::= ( @i{expression} )
+@end smallexample
+
+The following restriction exists: it is not allowed to have "and" or "or"
+following "not" in the same expression without parentheses. For example, this
+is not allowed:
+
+@smallexample
+ not X or Y
+@end smallexample
+
+This should be one of the following:
+
+@smallexample
+ (not X) or Y
+ not (X or Y)
+@end smallexample
+
+@noindent
+For the first test (@i{expression} ::= <symbol>) the symbol must have
+either the value true or false, that is to say the right-hand of the
+symbol definition must be one of the (case-insensitive) literals
+@code{True} or @code{False}. If the value is true, then the
+corresponding lines are included, and if the value is false, they are
+excluded.
+
+The test (@i{expression} ::= <symbol> @code{'Defined}) is true only if
+the symbol has been defined in the definition file or by a @option{-D}
+switch on the command line. Otherwise, the test is false.
+
+The equality tests are case insensitive, as are all the preprocessor lines.
+
+If the symbol referenced is not defined in the symbol definitions file,
+then the effect depends on whether or not switch @option{-u}
+is specified. If so, then the symbol is treated as if it had the value
+false and the test fails. If this switch is not specified, then
+it is an error to reference an undefined symbol. It is also an error to
+reference a symbol that is defined with a value other than @code{True}
+or @code{False}.
+
+The use of the @code{not} operator inverts the sense of this logical test.
+The @code{not} operator cannot be combined with the @code{or} or @code{and}
+operators, without parentheses. For example, "if not X or Y then" is not
+allowed, but "if (not X) or Y then" and "if not (X or Y) then" are.
+
+The @code{then} keyword is optional as shown
+
+The @code{#} must be the first non-blank character on a line, but
+otherwise the format is free form. Spaces or tabs may appear between
+the @code{#} and the keyword. The keywords and the symbols are case
+insensitive as in normal Ada code. Comments may be used on a
+preprocessor line, but other than that, no other tokens may appear on a
+preprocessor line. Any number of @code{elsif} clauses can be present,
+including none at all. The @code{else} is optional, as in Ada.
+
+The @code{#} marking the start of a preprocessor line must be the first
+non-blank character on the line, i.e., it must be preceded only by
+spaces or horizontal tabs.
+
+Symbol substitution outside of preprocessor lines is obtained by using
+the sequence
+
+@smallexample
+$symbol
+@end smallexample
+
+@noindent
+anywhere within a source line, except in a comment or within a
+string literal. The identifier
+following the @code{$} must match one of the symbols defined in the symbol
+definition file, and the result is to substitute the value of the
+symbol in place of @code{$symbol} in the output file.
+
+Note that although the substitution of strings within a string literal
+is not possible, it is possible to have a symbol whose defined value is
+a string literal. So instead of setting XYZ to @code{hello} and writing:
+
+@smallexample
+Header : String := "$XYZ";
+@end smallexample
+
+@noindent
+you should set XYZ to @code{"hello"} and write:
+
+@smallexample
+Header : String := $XYZ;
+@end smallexample
+
+@noindent
+and then the substitution will occur as desired.
+
+@ifset vms
+@node The GNAT Run-Time Library Builder gnatlbr
+@chapter The GNAT Run-Time Library Builder @code{gnatlbr}
+@findex gnatlbr
+@cindex Library builder
+
+@noindent
+@code{gnatlbr} is a tool for rebuilding the GNAT run time with user
+supplied configuration pragmas.
+
+@menu
+* Running gnatlbr::
+* Switches for gnatlbr::
+* Examples of gnatlbr Usage::
+@end menu
+
+@node Running gnatlbr
+@section Running @code{gnatlbr}
+
+@noindent
+The @code{gnatlbr} command has the form
+
+@smallexample
+$ GNAT LIBRARY /@r{[}CREATE@r{|}SET@r{|}DELETE@r{]}=directory @r{[}/CONFIG=file@r{]}
+@end smallexample
+
+@node Switches for gnatlbr
+@section Switches for @code{gnatlbr}
+
+@noindent
+@code{gnatlbr} recognizes the following switches:
+
+@table @option
+@c !sort!
+@item /CREATE=directory
+@cindex @code{/CREATE} (@code{gnatlbr})
+Create the new run-time library in the specified directory.
+
+@item /SET=directory
+@cindex @code{/SET} (@code{gnatlbr})
+Make the library in the specified directory the current run-time library.
+
+@item /DELETE=directory
+@cindex @code{/DELETE} (@code{gnatlbr})
+Delete the run-time library in the specified directory.
+
+@item /CONFIG=file
+@cindex @code{/CONFIG} (@code{gnatlbr})
+With /CREATE: Use the configuration pragmas in the specified file when
+building the library.
+
+With /SET: Use the configuration pragmas in the specified file when
+compiling.
+
+@end table
+
+@node Examples of gnatlbr Usage
+@section Example of @code{gnatlbr} Usage
+
+@smallexample
+Contents of VAXFLOAT.ADC:
+pragma Float_Representation (VAX_Float);
+
+$ GNAT LIBRARY /CREATE=[.VAXFLOAT] /CONFIG=VAXFLOAT.ADC
+
+GNAT LIBRARY rebuilds the run-time library in directory [.VAXFLOAT]
+
+@end smallexample
+@end ifset
+
+@node The GNAT Library Browser gnatls
+@chapter The GNAT Library Browser @code{gnatls}
+@findex gnatls
+@cindex Library browser
+
+@noindent
+@code{gnatls} is a tool that outputs information about compiled
+units. It gives the relationship between objects, unit names and source
+files. It can also be used to check the source dependencies of a unit
+as well as various characteristics.
+
+Note: to invoke @code{gnatls} with a project file, use the @code{gnat}
+driver (see @ref{The GNAT Driver and Project Files}).
+
+@menu
+* Running gnatls::
+* Switches for gnatls::
+* Examples of gnatls Usage::
+@end menu
+
+@node Running gnatls
+@section Running @code{gnatls}
+
+@noindent
+The @code{gnatls} command has the form
+
+@smallexample
+$ gnatls switches @var{object_or_ali_file}
+@end smallexample
+
+@noindent
+The main argument is the list of object or @file{ali} files
+(@pxref{The Ada Library Information Files})
+for which information is requested.
+
+In normal mode, without additional option, @code{gnatls} produces a
+four-column listing. Each line represents information for a specific
+object. The first column gives the full path of the object, the second
+column gives the name of the principal unit in this object, the third
+column gives the status of the source and the fourth column gives the
+full path of the source representing this unit.
+Here is a simple example of use:
+
+@smallexample
+$ gnatls *.o
+^./^[]^demo1.o demo1 DIF demo1.adb
+^./^[]^demo2.o demo2 OK demo2.adb
+^./^[]^hello.o h1 OK hello.adb
+^./^[]^instr-child.o instr.child MOK instr-child.adb
+^./^[]^instr.o instr OK instr.adb
+^./^[]^tef.o tef DIF tef.adb
+^./^[]^text_io_example.o text_io_example OK text_io_example.adb
+^./^[]^tgef.o tgef DIF tgef.adb
+@end smallexample
+
+@noindent
+The first line can be interpreted as follows: the main unit which is
+contained in
+object file @file{demo1.o} is demo1, whose main source is in
+@file{demo1.adb}. Furthermore, the version of the source used for the
+compilation of demo1 has been modified (DIF). Each source file has a status
+qualifier which can be:
+
+@table @code
+@item OK (unchanged)
+The version of the source file used for the compilation of the
+specified unit corresponds exactly to the actual source file.
+
+@item MOK (slightly modified)
+The version of the source file used for the compilation of the
+specified unit differs from the actual source file but not enough to
+require recompilation. If you use gnatmake with the qualifier
+@option{^-m (minimal recompilation)^/MINIMAL_RECOMPILATION^}, a file marked
+MOK will not be recompiled.
+
+@item DIF (modified)
+No version of the source found on the path corresponds to the source
+used to build this object.
+
+@item ??? (file not found)
+No source file was found for this unit.
+
+@item HID (hidden, unchanged version not first on PATH)
+The version of the source that corresponds exactly to the source used
+for compilation has been found on the path but it is hidden by another
+version of the same source that has been modified.
+
+@end table
+
+@node Switches for gnatls
+@section Switches for @code{gnatls}
+
+@noindent
+@code{gnatls} recognizes the following switches:
+
+@table @option
+@c !sort!
+@cindex @option{--version} @command{gnatls}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatls}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
+@item ^-a^/ALL_UNITS^
+@cindex @option{^-a^/ALL_UNITS^} (@code{gnatls})
+Consider all units, including those of the predefined Ada library.
+Especially useful with @option{^-d^/DEPENDENCIES^}.
+
+@item ^-d^/DEPENDENCIES^
+@cindex @option{^-d^/DEPENDENCIES^} (@code{gnatls})
+List sources from which specified units depend on.
+
+@item ^-h^/OUTPUT=OPTIONS^
+@cindex @option{^-h^/OUTPUT=OPTIONS^} (@code{gnatls})
+Output the list of options.
+
+@item ^-o^/OUTPUT=OBJECTS^
+@cindex @option{^-o^/OUTPUT=OBJECTS^} (@code{gnatls})
Only output information about object files.
-@item ^-s^/OUTPUT=SOURCES^
-@cindex @option{^-s^/OUTPUT=SOURCES^} (@code{gnatls})
-Only output information about source files.
+@item ^-s^/OUTPUT=SOURCES^
+@cindex @option{^-s^/OUTPUT=SOURCES^} (@code{gnatls})
+Only output information about source files.
+
+@item ^-u^/OUTPUT=UNITS^
+@cindex @option{^-u^/OUTPUT=UNITS^} (@code{gnatls})
+Only output information about compilation units.
+
+@item ^-files^/FILES^=@var{file}
+@cindex @option{^-files^/FILES^} (@code{gnatls})
+Take as arguments the files listed in text file @var{file}.
+Text file @var{file} may contain empty lines that are ignored.
+Each nonempty line should contain the name of an existing file.
+Several such switches may be specified simultaneously.
+
+@item ^-aO^/OBJECT_SEARCH=^@var{dir}
+@itemx ^-aI^/SOURCE_SEARCH=^@var{dir}
+@itemx ^-I^/SEARCH=^@var{dir}
+@itemx ^-I-^/NOCURRENT_DIRECTORY^
+@itemx -nostdinc
+@cindex @option{^-aO^/OBJECT_SEARCH^} (@code{gnatls})
+@cindex @option{^-aI^/SOURCE_SEARCH^} (@code{gnatls})
+@cindex @option{^-I^/SEARCH^} (@code{gnatls})
+@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@code{gnatls})
+Source path manipulation. Same meaning as the equivalent @command{gnatmake}
+flags (@pxref{Switches for gnatmake}).
+
+@item --RTS=@var{rts-path}
+@cindex @option{--RTS} (@code{gnatls})
+Specifies the default location of the runtime library. Same meaning as the
+equivalent @command{gnatmake} flag (@pxref{Switches for gnatmake}).
+
+@item ^-v^/OUTPUT=VERBOSE^
+@cindex @option{^-v^/OUTPUT=VERBOSE^} (@code{gnatls})
+Verbose mode. Output the complete source, object and project paths. Do not use
+the default column layout but instead use long format giving as much as
+information possible on each requested units, including special
+characteristics such as:
+
+@table @code
+@item Preelaborable
+The unit is preelaborable in the Ada sense.
+
+@item No_Elab_Code
+No elaboration code has been produced by the compiler for this unit.
+
+@item Pure
+The unit is pure in the Ada sense.
+
+@item Elaborate_Body
+The unit contains a pragma Elaborate_Body.
+
+@item Remote_Types
+The unit contains a pragma Remote_Types.
+
+@item Shared_Passive
+The unit contains a pragma Shared_Passive.
+
+@item Predefined
+This unit is part of the predefined environment and cannot be modified
+by the user.
+
+@item Remote_Call_Interface
+The unit contains a pragma Remote_Call_Interface.
+
+@end table
+
+@end table
+
+@node Examples of gnatls Usage
+@section Example of @code{gnatls} Usage
+@ifclear vms
+
+@noindent
+Example of using the verbose switch. Note how the source and
+object paths are affected by the -I switch.
+
+@smallexample
+$ gnatls -v -I.. demo1.o
+
+GNATLS 5.03w (20041123-34)
+Copyright 1997-2004 Free Software Foundation, Inc.
+
+Source Search Path:
+ <Current_Directory>
+ ../
+ /home/comar/local/adainclude/
+
+Object Search Path:
+ <Current_Directory>
+ ../
+ /home/comar/local/lib/gcc-lib/x86-linux/3.4.3/adalib/
+
+Project Search Path:
+ <Current_Directory>
+ /home/comar/local/lib/gnat/
+
+./demo1.o
+ Unit =>
+ Name => demo1
+ Kind => subprogram body
+ Flags => No_Elab_Code
+ Source => demo1.adb modified
+@end smallexample
+
+@noindent
+The following is an example of use of the dependency list.
+Note the use of the -s switch
+which gives a straight list of source files. This can be useful for
+building specialized scripts.
+
+@smallexample
+$ gnatls -d demo2.o
+./demo2.o demo2 OK demo2.adb
+ OK gen_list.ads
+ OK gen_list.adb
+ OK instr.ads
+ OK instr-child.ads
+
+$ gnatls -d -s -a demo1.o
+demo1.adb
+/home/comar/local/adainclude/ada.ads
+/home/comar/local/adainclude/a-finali.ads
+/home/comar/local/adainclude/a-filico.ads
+/home/comar/local/adainclude/a-stream.ads
+/home/comar/local/adainclude/a-tags.ads
+gen_list.ads
+gen_list.adb
+/home/comar/local/adainclude/gnat.ads
+/home/comar/local/adainclude/g-io.ads
+instr.ads
+/home/comar/local/adainclude/system.ads
+/home/comar/local/adainclude/s-exctab.ads
+/home/comar/local/adainclude/s-finimp.ads
+/home/comar/local/adainclude/s-finroo.ads
+/home/comar/local/adainclude/s-secsta.ads
+/home/comar/local/adainclude/s-stalib.ads
+/home/comar/local/adainclude/s-stoele.ads
+/home/comar/local/adainclude/s-stratt.ads
+/home/comar/local/adainclude/s-tasoli.ads
+/home/comar/local/adainclude/s-unstyp.ads
+/home/comar/local/adainclude/unchconv.ads
+@end smallexample
+@end ifclear
+
+@ifset vms
+@smallexample
+GNAT LIST /DEPENDENCIES /OUTPUT=SOURCES /ALL_UNITS DEMO1.ADB
+
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]ada.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-finali.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-filico.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-stream.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-tags.ads
+demo1.adb
+gen_list.ads
+gen_list.adb
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]gnat.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]g-io.ads
+instr.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]system.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-exctab.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-finimp.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-finroo.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-secsta.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-stalib.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-stoele.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-stratt.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-tasoli.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-unstyp.ads
+GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]unchconv.ads
+@end smallexample
+@end ifset
+
+@node Cleaning Up Using gnatclean
+@chapter Cleaning Up Using @code{gnatclean}
+@findex gnatclean
+@cindex Cleaning tool
+
+@noindent
+@code{gnatclean} is a tool that allows the deletion of files produced by the
+compiler, binder and linker, including ALI files, object files, tree files,
+expanded source files, library files, interface copy source files, binder
+generated files and executable files.
+
+@menu
+* Running gnatclean::
+* Switches for gnatclean::
+@c * Examples of gnatclean Usage::
+@end menu
+
+@node Running gnatclean
+@section Running @code{gnatclean}
+
+@noindent
+The @code{gnatclean} command has the form:
+
+@smallexample
+$ gnatclean switches @var{names}
+@end smallexample
+
+@noindent
+@var{names} is a list of source file names. Suffixes @code{.^ads^ADS^} and
+@code{^adb^ADB^} may be omitted. If a project file is specified using switch
+@code{^-P^/PROJECT_FILE=^}, then @var{names} may be completely omitted.
+
+@noindent
+In normal mode, @code{gnatclean} delete the files produced by the compiler and,
+if switch @code{^-c^/COMPILER_FILES_ONLY^} is not specified, by the binder and
+the linker. In informative-only mode, specified by switch
+@code{^-n^/NODELETE^}, the list of files that would have been deleted in
+normal mode is listed, but no file is actually deleted.
+
+@node Switches for gnatclean
+@section Switches for @code{gnatclean}
+
+@noindent
+@code{gnatclean} recognizes the following switches:
+
+@table @option
+@c !sort!
+@cindex @option{--version} @command{gnatclean}
+Display Copyright and version, then exit disregarding all other options.
+
+@item --help
+@cindex @option{--help} @command{gnatclean}
+If @option{--version} was not used, display usage, then exit disregarding
+all other options.
+
+@item ^-c^/COMPILER_FILES_ONLY^
+@cindex @option{^-c^/COMPILER_FILES_ONLY^} (@code{gnatclean})
+Only attempt to delete the files produced by the compiler, not those produced
+by the binder or the linker. The files that are not to be deleted are library
+files, interface copy files, binder generated files and executable files.
+
+@item ^-D ^/DIRECTORY_OBJECTS=^@var{dir}
+@cindex @option{^-D^/DIRECTORY_OBJECTS^} (@code{gnatclean})
+Indicate that ALI and object files should normally be found in directory
+@var{dir}.
+
+@item ^-F^/FULL_PATH_IN_BRIEF_MESSAGES^
+@cindex @option{^-F^/FULL_PATH_IN_BRIEF_MESSAGES^} (@code{gnatclean})
+When using project files, if some errors or warnings are detected during
+parsing and verbose mode is not in effect (no use of switch
+^-v^/VERBOSE^), then error lines start with the full path name of the project
+file, rather than its simple file name.
+
+@item ^-h^/HELP^
+@cindex @option{^-h^/HELP^} (@code{gnatclean})
+Output a message explaining the usage of @code{^gnatclean^gnatclean^}.
+
+@item ^-n^/NODELETE^
+@cindex @option{^-n^/NODELETE^} (@code{gnatclean})
+Informative-only mode. Do not delete any files. Output the list of the files
+that would have been deleted if this switch was not specified.
+
+@item ^-P^/PROJECT_FILE=^@var{project}
+@cindex @option{^-P^/PROJECT_FILE^} (@code{gnatclean})
+Use project file @var{project}. Only one such switch can be used.
+When cleaning a project file, the files produced by the compilation of the
+immediate sources or inherited sources of the project files are to be
+deleted. This is not depending on the presence or not of executable names
+on the command line.
+
+@item ^-q^/QUIET^
+@cindex @option{^-q^/QUIET^} (@code{gnatclean})
+Quiet output. If there are no errors, do not output anything, except in
+verbose mode (switch ^-v^/VERBOSE^) or in informative-only mode
+(switch ^-n^/NODELETE^).
+
+@item ^-r^/RECURSIVE^
+@cindex @option{^-r^/RECURSIVE^} (@code{gnatclean})
+When a project file is specified (using switch ^-P^/PROJECT_FILE=^),
+clean all imported and extended project files, recursively. If this switch
+is not specified, only the files related to the main project file are to be
+deleted. This switch has no effect if no project file is specified.
+
+@item ^-v^/VERBOSE^
+@cindex @option{^-v^/VERBOSE^} (@code{gnatclean})
+Verbose mode.
+
+@item ^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}
+@cindex @option{^-vP^/MESSAGES_PROJECT_FILE^} (@code{gnatclean})
+Indicates the verbosity of the parsing of GNAT project files.
+@xref{Switches Related to Project Files}.
+
+@item ^-X^/EXTERNAL_REFERENCE=^@var{name=value}
+@cindex @option{^-X^/EXTERNAL_REFERENCE^} (@code{gnatclean})
+Indicates that external variable @var{name} has the value @var{value}.
+The Project Manager will use this value for occurrences of
+@code{external(name)} when parsing the project file.
+@xref{Switches Related to Project Files}.
+
+@item ^-aO^/OBJECT_SEARCH=^@var{dir}
+@cindex @option{^-aO^/OBJECT_SEARCH^} (@code{gnatclean})
+When searching for ALI and object files, look in directory
+@var{dir}.
+
+@item ^-I^/SEARCH=^@var{dir}
+@cindex @option{^-I^/SEARCH^} (@code{gnatclean})
+Equivalent to @option{^-aO^/OBJECT_SEARCH=^@var{dir}}.
+
+@item ^-I-^/NOCURRENT_DIRECTORY^
+@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@code{gnatclean})
+@cindex Source files, suppressing search
+Do not look for ALI or object files in the directory
+where @code{gnatclean} was invoked.
+
+@end table
+
+@c @node Examples of gnatclean Usage
+@c @section Examples of @code{gnatclean} Usage
+
+@ifclear vms
+@node GNAT and Libraries
+@chapter GNAT and Libraries
+@cindex Library, building, installing, using
+
+@noindent
+This chapter describes how to build and use libraries with GNAT, and also shows
+how to recompile the GNAT run-time library. You should be familiar with the
+Project Manager facility (@pxref{GNAT Project Manager}) before reading this
+chapter.
+
+@menu
+* Introduction to Libraries in GNAT::
+* General Ada Libraries::
+* Stand-alone Ada Libraries::
+* Rebuilding the GNAT Run-Time Library::
+@end menu
+
+@node Introduction to Libraries in GNAT
+@section Introduction to Libraries in GNAT
+
+@noindent
+A library is, conceptually, a collection of objects which does not have its
+own main thread of execution, but rather provides certain services to the
+applications that use it. A library can be either statically linked with the
+application, in which case its code is directly included in the application,
+or, on platforms that support it, be dynamically linked, in which case
+its code is shared by all applications making use of this library.
+
+GNAT supports both types of libraries.
+In the static case, the compiled code can be provided in different ways. The
+simplest approach is to provide directly the set of objects resulting from
+compilation of the library source files. Alternatively, you can group the
+objects into an archive using whatever commands are provided by the operating
+system. For the latter case, the objects are grouped into a shared library.
+
+In the GNAT environment, a library has three types of components:
+@itemize @bullet
+@item
+Source files.
+@item
+@file{ALI} files.
+@xref{The Ada Library Information Files}.
+@item
+Object files, an archive or a shared library.
+@end itemize
+
+@noindent
+A GNAT library may expose all its source files, which is useful for
+documentation purposes. Alternatively, it may expose only the units needed by
+an external user to make use of the library. That is to say, the specs
+reflecting the library services along with all the units needed to compile
+those specs, which can include generic bodies or any body implementing an
+inlined routine. In the case of @emph{stand-alone libraries} those exposed
+units are called @emph{interface units} (@pxref{Stand-alone Ada Libraries}).
+
+All compilation units comprising an application, including those in a library,
+need to be elaborated in an order partially defined by Ada's semantics. GNAT
+computes the elaboration order from the @file{ALI} files and this is why they
+constitute a mandatory part of GNAT libraries. Except in the case of
+@emph{stand-alone libraries}, where a specific library elaboration routine is
+produced independently of the application(s) using the library.
+
+@node General Ada Libraries
+@section General Ada Libraries
+
+@menu
+* Building a library::
+* Installing a library::
+* Using a library::
+@end menu
+
+@node Building a library
+@subsection Building a library
+
+@noindent
+The easiest way to build a library is to use the Project Manager,
+which supports a special type of project called a @emph{Library Project}
+(@pxref{Library Projects}).
+
+A project is considered a library project, when two project-level attributes
+are defined in it: @code{Library_Name} and @code{Library_Dir}. In order to
+control different aspects of library configuration, additional optional
+project-level attributes can be specified:
+@table @code
+@item Library_Kind
+This attribute controls whether the library is to be static or dynamic
+
+@item Library_Version
+This attribute specifies the library version; this value is used
+during dynamic linking of shared libraries to determine if the currently
+installed versions of the binaries are compatible.
+
+@item Library_Options
+@item Library_GCC
+These attributes specify additional low-level options to be used during
+library generation, and redefine the actual application used to generate
+library.
+@end table
+
+@noindent
+The GNAT Project Manager takes full care of the library maintenance task,
+including recompilation of the source files for which objects do not exist
+or are not up to date, assembly of the library archive, and installation of
+the library (i.e., copying associated source, object and @file{ALI} files
+to the specified location).
+
+Here is a simple library project file:
+@smallexample @c ada
+project My_Lib is
+ for Source_Dirs use ("src1", "src2");
+ for Object_Dir use "obj";
+ for Library_Name use "mylib";
+ for Library_Dir use "lib";
+ for Library_Kind use "dynamic";
+end My_lib;
+@end smallexample
+
+@noindent
+and the compilation command to build and install the library:
+
+@smallexample @c ada
+ $ gnatmake -Pmy_lib
+@end smallexample
+
+@noindent
+It is not entirely trivial to perform manually all the steps required to
+produce a library. We recommend that you use the GNAT Project Manager
+for this task. In special cases where this is not desired, the necessary
+steps are discussed below.
+
+There are various possibilities for compiling the units that make up the
+library: for example with a Makefile (@pxref{Using the GNU make Utility}) or
+with a conventional script. For simple libraries, it is also possible to create
+a dummy main program which depends upon all the packages that comprise the
+interface of the library. This dummy main program can then be given to
+@command{gnatmake}, which will ensure that all necessary objects are built.
+
+After this task is accomplished, you should follow the standard procedure
+of the underlying operating system to produce the static or shared library.
+
+Here is an example of such a dummy program:
+@smallexample @c ada
+@group
+with My_Lib.Service1;
+with My_Lib.Service2;
+with My_Lib.Service3;
+procedure My_Lib_Dummy is
+begin
+ null;
+end;
+@end group
+@end smallexample
+
+@noindent
+Here are the generic commands that will build an archive or a shared library.
+
+@smallexample
+# compiling the library
+$ gnatmake -c my_lib_dummy.adb
+
+# we don't need the dummy object itself
+$ rm my_lib_dummy.o my_lib_dummy.ali
+
+# create an archive with the remaining objects
+$ ar rc libmy_lib.a *.o
+# some systems may require "ranlib" to be run as well
+
+# or create a shared library
+$ gcc -shared -o libmy_lib.so *.o
+# some systems may require the code to have been compiled with -fPIC
+
+# remove the object files that are now in the library
+$ rm *.o
+
+# Make the ALI files read-only so that gnatmake will not try to
+# regenerate the objects that are in the library
+$ chmod -w *.ali
+@end smallexample
+
+@noindent
+Please note that the library must have a name of the form @file{lib@var{xxx}.a}
+or @file{lib@var{xxx}.so} (or @file{lib@var{xxx}.dll} on Windows) in order to
+be accessed by the directive @option{-l@var{xxx}} at link time.
+
+@node Installing a library
+@subsection Installing a library
+@cindex @code{ADA_PROJECT_PATH}
+
+@noindent
+If you use project files, library installation is part of the library build
+process. Thus no further action is needed in order to make use of the
+libraries that are built as part of the general application build. A usable
+version of the library is installed in the directory specified by the
+@code{Library_Dir} attribute of the library project file.
+
+You may want to install a library in a context different from where the library
+is built. This situation arises with third party suppliers, who may want
+to distribute a library in binary form where the user is not expected to be
+able to recompile the library. The simplest option in this case is to provide
+a project file slightly different from the one used to build the library, by
+using the @code{externally_built} attribute. For instance, the project
+file used to build the library in the previous section can be changed into the
+following one when the library is installed:
+
+@smallexample @c projectfile
+project My_Lib is
+ for Source_Dirs use ("src1", "src2");
+ for Library_Name use "mylib";
+ for Library_Dir use "lib";
+ for Library_Kind use "dynamic";
+ for Externally_Built use "true";
+end My_lib;
+@end smallexample
+
+@noindent
+This project file assumes that the directories @file{src1},
+@file{src2}, and @file{lib} exist in
+the directory containing the project file. The @code{externally_built}
+attribute makes it clear to the GNAT builder that it should not attempt to
+recompile any of the units from this library. It allows the library provider to
+restrict the source set to the minimum necessary for clients to make use of the
+library as described in the first section of this chapter. It is the
+responsibility of the library provider to install the necessary sources, ALI
+files and libraries in the directories mentioned in the project file. For
+convenience, the user's library project file should be installed in a location
+that will be searched automatically by the GNAT
+builder. These are the directories referenced in the @env{ADA_PROJECT_PATH}
+environment variable (@pxref{Importing Projects}), and also the default GNAT
+library location that can be queried with @command{gnatls -v} and is usually of
+the form $gnat_install_root/lib/gnat.
+
+When project files are not an option, it is also possible, but not recommended,
+to install the library so that the sources needed to use the library are on the
+Ada source path and the ALI files & libraries be on the Ada Object path (see
+@ref{Search Paths and the Run-Time Library (RTL)}. Alternatively, the system
+administrator can place general-purpose libraries in the default compiler
+paths, by specifying the libraries' location in the configuration files
+@file{ada_source_path} and @file{ada_object_path}. These configuration files
+must be located in the GNAT installation tree at the same place as the gcc spec
+file. The location of the gcc spec file can be determined as follows:
+@smallexample
+$ gcc -v
+@end smallexample
+
+@noindent
+The configuration files mentioned above have a simple format: each line
+must contain one unique directory name.
+Those names are added to the corresponding path
+in their order of appearance in the file. The names can be either absolute
+or relative; in the latter case, they are relative to where theses files
+are located.
+
+The files @file{ada_source_path} and @file{ada_object_path} might not be
+present in a
+GNAT installation, in which case, GNAT will look for its run-time library in
+the directories @file{adainclude} (for the sources) and @file{adalib} (for the
+objects and @file{ALI} files). When the files exist, the compiler does not
+look in @file{adainclude} and @file{adalib}, and thus the
+@file{ada_source_path} file
+must contain the location for the GNAT run-time sources (which can simply
+be @file{adainclude}). In the same way, the @file{ada_object_path} file must
+contain the location for the GNAT run-time objects (which can simply
+be @file{adalib}).
+
+You can also specify a new default path to the run-time library at compilation
+time with the switch @option{--RTS=rts-path}. You can thus choose / change
+the run-time library you want your program to be compiled with. This switch is
+recognized by @command{gcc}, @command{gnatmake}, @command{gnatbind},
+@command{gnatls}, @command{gnatfind} and @command{gnatxref}.
+
+It is possible to install a library before or after the standard GNAT
+library, by reordering the lines in the configuration files. In general, a
+library must be installed before the GNAT library if it redefines
+any part of it.
+
+@node Using a library
+@subsection Using a library
+
+@noindent Once again, the project facility greatly simplifies the use of
+libraries. In this context, using a library is just a matter of adding a
+@code{with} clause in the user project. For instance, to make use of the
+library @code{My_Lib} shown in examples in earlier sections, you can
+write:
+
+@smallexample @c projectfile
+with "my_lib";
+project My_Proj is
+ @dots{}
+end My_Proj;
+@end smallexample
+
+Even if you have a third-party, non-Ada library, you can still use GNAT's
+Project Manager facility to provide a wrapper for it. For example, the
+following project, when @code{with}ed by your main project, will link with the
+third-party library @file{liba.a}:
+
+@smallexample @c projectfile
+@group
+project Liba is
+ for Externally_Built use "true";
+ for Source_Files use ();
+ for Library_Dir use "lib";
+ for Library_Name use "a";
+ for Library_Kind use "static";
+end Liba;
+@end group
+@end smallexample
+This is an alternative to the use of @code{pragma Linker_Options}. It is
+especially interesting in the context of systems with several interdependent
+static libraries where finding a proper linker order is not easy and best be
+left to the tools having visibility over project dependence information.
+
+@noindent
+In order to use an Ada library manually, you need to make sure that this
+library is on both your source and object path
+(see @ref{Search Paths and the Run-Time Library (RTL)}
+and @ref{Search Paths for gnatbind}). Furthermore, when the objects are grouped
+in an archive or a shared library, you need to specify the desired
+library at link time.
+
+For example, you can use the library @file{mylib} installed in
+@file{/dir/my_lib_src} and @file{/dir/my_lib_obj} with the following commands:
+
+@smallexample
+$ gnatmake -aI/dir/my_lib_src -aO/dir/my_lib_obj my_appl \
+ -largs -lmy_lib
+@end smallexample
+
+@noindent
+This can be expressed more simply:
+@smallexample
+$ gnatmake my_appl
+@end smallexample
+@noindent
+when the following conditions are met:
+@itemize @bullet
+@item
+@file{/dir/my_lib_src} has been added by the user to the environment
+variable @env{ADA_INCLUDE_PATH}, or by the administrator to the file
+@file{ada_source_path}
+@item
+@file{/dir/my_lib_obj} has been added by the user to the environment
+variable @env{ADA_OBJECTS_PATH}, or by the administrator to the file
+@file{ada_object_path}
+@item
+a pragma @code{Linker_Options} has been added to one of the sources.
+For example:
+
+@smallexample @c ada
+pragma Linker_Options ("-lmy_lib");
+@end smallexample
+@end itemize
+
+@node Stand-alone Ada Libraries
+@section Stand-alone Ada Libraries
+@cindex Stand-alone library, building, using
+
+@menu
+* Introduction to Stand-alone Libraries::
+* Building a Stand-alone Library::
+* Creating a Stand-alone Library to be used in a non-Ada context::
+* Restrictions in Stand-alone Libraries::
+@end menu
+
+@node Introduction to Stand-alone Libraries
+@subsection Introduction to Stand-alone Libraries
+
+@noindent
+A Stand-alone Library (abbreviated ``SAL'') is a library that contains the
+necessary code to
+elaborate the Ada units that are included in the library. In contrast with
+an ordinary library, which consists of all sources, objects and @file{ALI}
+files of the
+library, a SAL may specify a restricted subset of compilation units
+to serve as a library interface. In this case, the fully
+self-sufficient set of files will normally consist of an objects
+archive, the sources of interface units' specs, and the @file{ALI}
+files of interface units.
+If an interface spec contains a generic unit or an inlined subprogram,
+the body's
+source must also be provided; if the units that must be provided in the source
+form depend on other units, the source and @file{ALI} files of those must
+also be provided.
+
+The main purpose of a SAL is to minimize the recompilation overhead of client
+applications when a new version of the library is installed. Specifically,
+if the interface sources have not changed, client applications do not need to
+be recompiled. If, furthermore, a SAL is provided in the shared form and its
+version, controlled by @code{Library_Version} attribute, is not changed,
+then the clients do not need to be relinked.
+
+SALs also allow the library providers to minimize the amount of library source
+text exposed to the clients. Such ``information hiding'' might be useful or
+necessary for various reasons.
+
+Stand-alone libraries are also well suited to be used in an executable whose
+main routine is not written in Ada.
+
+@node Building a Stand-alone Library
+@subsection Building a Stand-alone Library
+
+@noindent
+GNAT's Project facility provides a simple way of building and installing
+stand-alone libraries; see @ref{Stand-alone Library Projects}.
+To be a Stand-alone Library Project, in addition to the two attributes
+that make a project a Library Project (@code{Library_Name} and
+@code{Library_Dir}; see @ref{Library Projects}), the attribute
+@code{Library_Interface} must be defined. For example:
+
+@smallexample @c projectfile
+@group
+ for Library_Dir use "lib_dir";
+ for Library_Name use "dummy";
+ for Library_Interface use ("int1", "int1.child");
+@end group
+@end smallexample
+
+@noindent
+Attribute @code{Library_Interface} has a non-empty string list value,
+each string in the list designating a unit contained in an immediate source
+of the project file.
+
+When a Stand-alone Library is built, first the binder is invoked to build
+a package whose name depends on the library name
+(@file{^b~dummy.ads/b^B$DUMMY.ADS/B^} in the example above).
+This binder-generated package includes initialization and
+finalization procedures whose
+names depend on the library name (@code{dummyinit} and @code{dummyfinal}
+in the example
+above). The object corresponding to this package is included in the library.
+
+You must ensure timely (e.g., prior to any use of interfaces in the SAL)
+calling of these procedures if a static SAL is built, or if a shared SAL
+is built
+with the project-level attribute @code{Library_Auto_Init} set to
+@code{"false"}.
+
+For a Stand-Alone Library, only the @file{ALI} files of the Interface Units
+(those that are listed in attribute @code{Library_Interface}) are copied to
+the Library Directory. As a consequence, only the Interface Units may be
+imported from Ada units outside of the library. If other units are imported,
+the binding phase will fail.
+
+The attribute @code{Library_Src_Dir} may be specified for a
+Stand-Alone Library. @code{Library_Src_Dir} is a simple attribute that has a
+single string value. Its value must be the path (absolute or relative to the
+project directory) of an existing directory. This directory cannot be the
+object directory or one of the source directories, but it can be the same as
+the library directory. The sources of the Interface
+Units of the library that are needed by an Ada client of the library will be
+copied to the designated directory, called the Interface Copy directory.
+These sources include the specs of the Interface Units, but they may also
+include bodies and subunits, when pragmas @code{Inline} or @code{Inline_Always}
+are used, or when there is a generic unit in the spec. Before the sources
+are copied to the Interface Copy directory, an attempt is made to delete all
+files in the Interface Copy directory.
+
+Building stand-alone libraries by hand is somewhat tedious, but for those
+occasions when it is necessary here are the steps that you need to perform:
+@itemize @bullet
+@item
+Compile all library sources.
+
+@item
+Invoke the binder with the switch @option{-n} (No Ada main program),
+with all the @file{ALI} files of the interfaces, and
+with the switch @option{-L} to give specific names to the @code{init}
+and @code{final} procedures. For example:
+@smallexample
+ gnatbind -n int1.ali int2.ali -Lsal1
+@end smallexample
+
+@item
+Compile the binder generated file:
+@smallexample
+ gcc -c b~int2.adb
+@end smallexample
+
+@item
+Link the dynamic library with all the necessary object files,
+indicating to the linker the names of the @code{init} (and possibly
+@code{final}) procedures for automatic initialization (and finalization).
+The built library should be placed in a directory different from
+the object directory.
+
+@item
+Copy the @code{ALI} files of the interface to the library directory,
+add in this copy an indication that it is an interface to a SAL
+(i.e., add a word @option{SL} on the line in the @file{ALI} file that starts
+with letter ``P'') and make the modified copy of the @file{ALI} file
+read-only.
+@end itemize
+
+@noindent
+Using SALs is not different from using other libraries
+(see @ref{Using a library}).
+
+@node Creating a Stand-alone Library to be used in a non-Ada context
+@subsection Creating a Stand-alone Library to be used in a non-Ada context
+
+@noindent
+It is easy to adapt the SAL build procedure discussed above for use of a SAL in
+a non-Ada context.
+
+The only extra step required is to ensure that library interface subprograms
+are compatible with the main program, by means of @code{pragma Export}
+or @code{pragma Convention}.
+
+Here is an example of simple library interface for use with C main program:
+
+@smallexample @c ada
+package Interface is
+
+ procedure Do_Something;
+ pragma Export (C, Do_Something, "do_something");
+
+ procedure Do_Something_Else;
+ pragma Export (C, Do_Something_Else, "do_something_else");
+
+end Interface;
+@end smallexample
+
+@noindent
+On the foreign language side, you must provide a ``foreign'' view of the
+library interface; remember that it should contain elaboration routines in
+addition to interface subprograms.
+
+The example below shows the content of @code{mylib_interface.h} (note
+that there is no rule for the naming of this file, any name can be used)
+@smallexample
+/* the library elaboration procedure */
+extern void mylibinit (void);
+
+/* the library finalization procedure */
+extern void mylibfinal (void);
+
+/* the interface exported by the library */
+extern void do_something (void);
+extern void do_something_else (void);
+@end smallexample
+
+@noindent
+Libraries built as explained above can be used from any program, provided
+that the elaboration procedures (named @code{mylibinit} in the previous
+example) are called before the library services are used. Any number of
+libraries can be used simultaneously, as long as the elaboration
+procedure of each library is called.
+
+Below is an example of a C program that uses the @code{mylib} library.
+
+@smallexample
+#include "mylib_interface.h"
+
+int
+main (void)
+@{
+ /* First, elaborate the library before using it */
+ mylibinit ();
+
+ /* Main program, using the library exported entities */
+ do_something ();
+ do_something_else ();
+
+ /* Library finalization at the end of the program */
+ mylibfinal ();
+ return 0;
+@}
+@end smallexample
+
+@noindent
+Note that invoking any library finalization procedure generated by
+@code{gnatbind} shuts down the Ada run-time environment.
+Consequently, the
+finalization of all Ada libraries must be performed at the end of the program.
+No call to these libraries or to the Ada run-time library should be made
+after the finalization phase.
+
+@node Restrictions in Stand-alone Libraries
+@subsection Restrictions in Stand-alone Libraries
+
+@noindent
+The pragmas listed below should be used with caution inside libraries,
+as they can create incompatibilities with other Ada libraries:
+@itemize @bullet
+@item pragma @code{Locking_Policy}
+@item pragma @code{Queuing_Policy}
+@item pragma @code{Task_Dispatching_Policy}
+@item pragma @code{Unreserve_All_Interrupts}
+@end itemize
+
+@noindent
+When using a library that contains such pragmas, the user must make sure
+that all libraries use the same pragmas with the same values. Otherwise,
+@code{Program_Error} will
+be raised during the elaboration of the conflicting
+libraries. The usage of these pragmas and its consequences for the user
+should therefore be well documented.
+
+Similarly, the traceback in the exception occurrence mechanism should be
+enabled or disabled in a consistent manner across all libraries.
+Otherwise, Program_Error will be raised during the elaboration of the
+conflicting libraries.
+
+If the @code{Version} or @code{Body_Version}
+attributes are used inside a library, then you need to
+perform a @code{gnatbind} step that specifies all @file{ALI} files in all
+libraries, so that version identifiers can be properly computed.
+In practice these attributes are rarely used, so this is unlikely
+to be a consideration.
+
+@node Rebuilding the GNAT Run-Time Library
+@section Rebuilding the GNAT Run-Time Library
+@cindex GNAT Run-Time Library, rebuilding
+@cindex Building the GNAT Run-Time Library
+@cindex Rebuilding the GNAT Run-Time Library
+@cindex Run-Time Library, rebuilding
+
+@noindent
+It may be useful to recompile the GNAT library in various contexts, the
+most important one being the use of partition-wide configuration pragmas
+such as @code{Normalize_Scalars}. A special Makefile called
+@code{Makefile.adalib} is provided to that effect and can be found in
+the directory containing the GNAT library. The location of this
+directory depends on the way the GNAT environment has been installed and can
+be determined by means of the command:
+
+@smallexample
+$ gnatls -v
+@end smallexample
+
+@noindent
+The last entry in the object search path usually contains the
+gnat library. This Makefile contains its own documentation and in
+particular the set of instructions needed to rebuild a new library and
+to use it.
+
+@node Using the GNU make Utility
+@chapter Using the GNU @code{make} Utility
+@findex make
+
+@noindent
+This chapter offers some examples of makefiles that solve specific
+problems. It does not explain how to write a makefile (@pxref{Top,, GNU
+make, make, GNU @code{make}}), nor does it try to replace the
+@command{gnatmake} utility (@pxref{The GNAT Make Program gnatmake}).
+
+All the examples in this section are specific to the GNU version of
+make. Although @command{make} is a standard utility, and the basic language
+is the same, these examples use some advanced features found only in
+@code{GNU make}.
+
+@menu
+* Using gnatmake in a Makefile::
+* Automatically Creating a List of Directories::
+* Generating the Command Line Switches::
+* Overcoming Command Line Length Limits::
+@end menu
+
+@node Using gnatmake in a Makefile
+@section Using gnatmake in a Makefile
+@findex makefile
+@cindex GNU make
+
+@noindent
+Complex project organizations can be handled in a very powerful way by
+using GNU make combined with gnatmake. For instance, here is a Makefile
+which allows you to build each subsystem of a big project into a separate
+shared library. Such a makefile allows you to significantly reduce the link
+time of very big applications while maintaining full coherence at
+each step of the build process.
+
+The list of dependencies are handled automatically by
+@command{gnatmake}. The Makefile is simply used to call gnatmake in each of
+the appropriate directories.
+
+Note that you should also read the example on how to automatically
+create the list of directories
+(@pxref{Automatically Creating a List of Directories})
+which might help you in case your project has a lot of subdirectories.
+
+@smallexample
+@iftex
+@leftskip=0cm
+@font@heightrm=cmr8
+@heightrm
+@end iftex
+## This Makefile is intended to be used with the following directory
+## configuration:
+## - The sources are split into a series of csc (computer software components)
+## Each of these csc is put in its own directory.
+## Their name are referenced by the directory names.
+## They will be compiled into shared library (although this would also work
+## with static libraries
+## - The main program (and possibly other packages that do not belong to any
+## csc is put in the top level directory (where the Makefile is).
+## toplevel_dir __ first_csc (sources) __ lib (will contain the library)
+## \_ second_csc (sources) __ lib (will contain the library)
+## \_ @dots{}
+## Although this Makefile is build for shared library, it is easy to modify
+## to build partial link objects instead (modify the lines with -shared and
+## gnatlink below)
+##
+## With this makefile, you can change any file in the system or add any new
+## file, and everything will be recompiled correctly (only the relevant shared
+## objects will be recompiled, and the main program will be re-linked).
+
+# The list of computer software component for your project. This might be
+# generated automatically.
+CSC_LIST=aa bb cc
+
+# Name of the main program (no extension)
+MAIN=main
+
+# If we need to build objects with -fPIC, uncomment the following line
+#NEED_FPIC=-fPIC
+
+# The following variable should give the directory containing libgnat.so
+# You can get this directory through 'gnatls -v'. This is usually the last
+# directory in the Object_Path.
+GLIB=@dots{}
+
+# The directories for the libraries
+# (This macro expands the list of CSC to the list of shared libraries, you
+# could simply use the expanded form:
+# LIB_DIR=aa/lib/libaa.so bb/lib/libbb.so cc/lib/libcc.so
+LIB_DIR=$@{foreach dir,$@{CSC_LIST@},$@{dir@}/lib/lib$@{dir@}.so@}
+
+$@{MAIN@}: objects $@{LIB_DIR@}
+ gnatbind $@{MAIN@} $@{CSC_LIST:%=-aO%/lib@} -shared
+ gnatlink $@{MAIN@} $@{CSC_LIST:%=-l%@}
+
+objects::
+ # recompile the sources
+ gnatmake -c -i $@{MAIN@}.adb $@{NEED_FPIC@} $@{CSC_LIST:%=-I%@}
+
+# Note: In a future version of GNAT, the following commands will be simplified
+# by a new tool, gnatmlib
+$@{LIB_DIR@}:
+ mkdir -p $@{dir $@@ @}
+ cd $@{dir $@@ @} && gcc -shared -o $@{notdir $@@ @} ../*.o -L$@{GLIB@} -lgnat
+ cd $@{dir $@@ @} && cp -f ../*.ali .
+
+# The dependencies for the modules
+# Note that we have to force the expansion of *.o, since in some cases
+# make won't be able to do it itself.
+aa/lib/libaa.so: $@{wildcard aa/*.o@}
+bb/lib/libbb.so: $@{wildcard bb/*.o@}
+cc/lib/libcc.so: $@{wildcard cc/*.o@}
+
+# Make sure all of the shared libraries are in the path before starting the
+# program
+run::
+ LD_LIBRARY_PATH=`pwd`/aa/lib:`pwd`/bb/lib:`pwd`/cc/lib ./$@{MAIN@}
+
+clean::
+ $@{RM@} -rf $@{CSC_LIST:%=%/lib@}
+ $@{RM@} $@{CSC_LIST:%=%/*.ali@}
+ $@{RM@} $@{CSC_LIST:%=%/*.o@}
+ $@{RM@} *.o *.ali $@{MAIN@}
+@end smallexample
+
+@node Automatically Creating a List of Directories
+@section Automatically Creating a List of Directories
+
+@noindent
+In most makefiles, you will have to specify a list of directories, and
+store it in a variable. For small projects, it is often easier to
+specify each of them by hand, since you then have full control over what
+is the proper order for these directories, which ones should be
+included.
+
+However, in larger projects, which might involve hundreds of
+subdirectories, it might be more convenient to generate this list
+automatically.
+
+The example below presents two methods. The first one, although less
+general, gives you more control over the list. It involves wildcard
+characters, that are automatically expanded by @command{make}. Its
+shortcoming is that you need to explicitly specify some of the
+organization of your project, such as for instance the directory tree
+depth, whether some directories are found in a separate tree, @enddots{}
+
+The second method is the most general one. It requires an external
+program, called @command{find}, which is standard on all Unix systems. All
+the directories found under a given root directory will be added to the
+list.
+
+@smallexample
+@iftex
+@leftskip=0cm
+@font@heightrm=cmr8
+@heightrm
+@end iftex
+# The examples below are based on the following directory hierarchy:
+# All the directories can contain any number of files
+# ROOT_DIRECTORY -> a -> aa -> aaa
+# -> ab
+# -> ac
+# -> b -> ba -> baa
+# -> bb
+# -> bc
+# This Makefile creates a variable called DIRS, that can be reused any time
+# you need this list (see the other examples in this section)
+
+# The root of your project's directory hierarchy
+ROOT_DIRECTORY=.
+
+####
+# First method: specify explicitly the list of directories
+# This allows you to specify any subset of all the directories you need.
+####
+
+DIRS := a/aa/ a/ab/ b/ba/
+
+####
+# Second method: use wildcards
+# Note that the argument(s) to wildcard below should end with a '/'.
+# Since wildcards also return file names, we have to filter them out
+# to avoid duplicate directory names.
+# We thus use make's @code{dir} and @code{sort} functions.
+# It sets DIRs to the following value (note that the directories aaa and baa
+# are not given, unless you change the arguments to wildcard).
+# DIRS= ./a/a/ ./b/ ./a/aa/ ./a/ab/ ./a/ac/ ./b/ba/ ./b/bb/ ./b/bc/
+####
+
+DIRS := $@{sort $@{dir $@{wildcard $@{ROOT_DIRECTORY@}/*/
+ $@{ROOT_DIRECTORY@}/*/*/@}@}@}
+
+####
+# Third method: use an external program
+# This command is much faster if run on local disks, avoiding NFS slowdowns.
+# This is the most complete command: it sets DIRs to the following value:
+# DIRS= ./a ./a/aa ./a/aa/aaa ./a/ab ./a/ac ./b ./b/ba ./b/ba/baa ./b/bb ./b/bc
+####
+
+DIRS := $@{shell find $@{ROOT_DIRECTORY@} -type d -print@}
+
+@end smallexample
+
+@node Generating the Command Line Switches
+@section Generating the Command Line Switches
+
+@noindent
+Once you have created the list of directories as explained in the
+previous section (@pxref{Automatically Creating a List of Directories}),
+you can easily generate the command line arguments to pass to gnatmake.
+
+For the sake of completeness, this example assumes that the source path
+is not the same as the object path, and that you have two separate lists
+of directories.
+
+@smallexample
+# see "Automatically creating a list of directories" to create
+# these variables
+SOURCE_DIRS=
+OBJECT_DIRS=
+
+GNATMAKE_SWITCHES := $@{patsubst %,-aI%,$@{SOURCE_DIRS@}@}
+GNATMAKE_SWITCHES += $@{patsubst %,-aO%,$@{OBJECT_DIRS@}@}
+
+all:
+ gnatmake $@{GNATMAKE_SWITCHES@} main_unit
+@end smallexample
+
+@node Overcoming Command Line Length Limits
+@section Overcoming Command Line Length Limits
+
+@noindent
+One problem that might be encountered on big projects is that many
+operating systems limit the length of the command line. It is thus hard to give
+gnatmake the list of source and object directories.
+
+This example shows how you can set up environment variables, which will
+make @command{gnatmake} behave exactly as if the directories had been
+specified on the command line, but have a much higher length limit (or
+even none on most systems).
+
+It assumes that you have created a list of directories in your Makefile,
+using one of the methods presented in
+@ref{Automatically Creating a List of Directories}.
+For the sake of completeness, we assume that the object
+path (where the ALI files are found) is different from the sources patch.
+
+Note a small trick in the Makefile below: for efficiency reasons, we
+create two temporary variables (SOURCE_LIST and OBJECT_LIST), that are
+expanded immediately by @code{make}. This way we overcome the standard
+make behavior which is to expand the variables only when they are
+actually used.
+
+On Windows, if you are using the standard Windows command shell, you must
+replace colons with semicolons in the assignments to these variables.
+
+@smallexample
+@iftex
+@leftskip=0cm
+@font@heightrm=cmr8
+@heightrm
+@end iftex
+# In this example, we create both ADA_INCLUDE_PATH and ADA_OBJECT_PATH.
+# This is the same thing as putting the -I arguments on the command line.
+# (the equivalent of using -aI on the command line would be to define
+# only ADA_INCLUDE_PATH, the equivalent of -aO is ADA_OBJECT_PATH).
+# You can of course have different values for these variables.
+#
+# Note also that we need to keep the previous values of these variables, since
+# they might have been set before running 'make' to specify where the GNAT
+# library is installed.
+
+# see "Automatically creating a list of directories" to create these
+# variables
+SOURCE_DIRS=
+OBJECT_DIRS=
+
+empty:=
+space:=$@{empty@} $@{empty@}
+SOURCE_LIST := $@{subst $@{space@},:,$@{SOURCE_DIRS@}@}
+OBJECT_LIST := $@{subst $@{space@},:,$@{OBJECT_DIRS@}@}
+ADA_INCLUDE_PATH += $@{SOURCE_LIST@}
+ADA_OBJECT_PATH += $@{OBJECT_LIST@}
+export ADA_INCLUDE_PATH
+export ADA_OBJECT_PATH
+
+all:
+ gnatmake main_unit
+@end smallexample
+@end ifclear
+
+@node Memory Management Issues
+@chapter Memory Management Issues
+
+@noindent
+This chapter describes some useful memory pools provided in the GNAT library
+and in particular the GNAT Debug Pool facility, which can be used to detect
+incorrect uses of access values (including ``dangling references'').
+@ifclear vms
+It also describes the @command{gnatmem} tool, which can be used to track down
+``memory leaks''.
+@end ifclear
+
+@menu
+* Some Useful Memory Pools::
+* The GNAT Debug Pool Facility::
+@ifclear vms
+* The gnatmem Tool::
+@end ifclear
+@end menu
+
+@node Some Useful Memory Pools
+@section Some Useful Memory Pools
+@findex Memory Pool
+@cindex storage, pool
+
+@noindent
+The @code{System.Pool_Global} package offers the Unbounded_No_Reclaim_Pool
+storage pool. Allocations use the standard system call @code{malloc} while
+deallocations use the standard system call @code{free}. No reclamation is
+performed when the pool goes out of scope. For performance reasons, the
+standard default Ada allocators/deallocators do not use any explicit storage
+pools but if they did, they could use this storage pool without any change in
+behavior. That is why this storage pool is used when the user
+manages to make the default implicit allocator explicit as in this example:
+@smallexample @c ada
+ type T1 is access Something;
+ -- no Storage pool is defined for T2
+ type T2 is access Something_Else;
+ for T2'Storage_Pool use T1'Storage_Pool;
+ -- the above is equivalent to
+ for T2'Storage_Pool use System.Pool_Global.Global_Pool_Object;
+@end smallexample
+
+@noindent
+The @code{System.Pool_Local} package offers the Unbounded_Reclaim_Pool storage
+pool. The allocation strategy is similar to @code{Pool_Local}'s
+except that the all
+storage allocated with this pool is reclaimed when the pool object goes out of
+scope. This pool provides a explicit mechanism similar to the implicit one
+provided by several Ada 83 compilers for allocations performed through a local
+access type and whose purpose was to reclaim memory when exiting the
+scope of a given local access. As an example, the following program does not
+leak memory even though it does not perform explicit deallocation:
+
+@smallexample @c ada
+with System.Pool_Local;
+procedure Pooloc1 is
+ procedure Internal is
+ type A is access Integer;
+ X : System.Pool_Local.Unbounded_Reclaim_Pool;
+ for A'Storage_Pool use X;
+ v : A;
+ begin
+ for I in 1 .. 50 loop
+ v := new Integer;
+ end loop;
+ end Internal;
+begin
+ for I in 1 .. 100 loop
+ Internal;
+ end loop;
+end Pooloc1;
+@end smallexample
+
+@noindent
+The @code{System.Pool_Size} package implements the Stack_Bounded_Pool used when
+@code{Storage_Size} is specified for an access type.
+The whole storage for the pool is
+allocated at once, usually on the stack at the point where the access type is
+elaborated. It is automatically reclaimed when exiting the scope where the
+access type is defined. This package is not intended to be used directly by the
+user and it is implicitly used for each such declaration:
+
+@smallexample @c ada
+ type T1 is access Something;
+ for T1'Storage_Size use 10_000;
+@end smallexample
+
+@node The GNAT Debug Pool Facility
+@section The GNAT Debug Pool Facility
+@findex Debug Pool
+@cindex storage, pool, memory corruption
+
+@noindent
+The use of unchecked deallocation and unchecked conversion can easily
+lead to incorrect memory references. The problems generated by such
+references are usually difficult to tackle because the symptoms can be
+very remote from the origin of the problem. In such cases, it is
+very helpful to detect the problem as early as possible. This is the
+purpose of the Storage Pool provided by @code{GNAT.Debug_Pools}.
+
+In order to use the GNAT specific debugging pool, the user must
+associate a debug pool object with each of the access types that may be
+related to suspected memory problems. See Ada Reference Manual 13.11.
+@smallexample @c ada
+type Ptr is access Some_Type;
+Pool : GNAT.Debug_Pools.Debug_Pool;
+for Ptr'Storage_Pool use Pool;
+@end smallexample
+
+@noindent
+@code{GNAT.Debug_Pools} is derived from a GNAT-specific kind of
+pool: the @code{Checked_Pool}. Such pools, like standard Ada storage pools,
+allow the user to redefine allocation and deallocation strategies. They
+also provide a checkpoint for each dereference, through the use of
+the primitive operation @code{Dereference} which is implicitly called at
+each dereference of an access value.
+
+Once an access type has been associated with a debug pool, operations on
+values of the type may raise four distinct exceptions,
+which correspond to four potential kinds of memory corruption:
+@itemize @bullet
+@item
+@code{GNAT.Debug_Pools.Accessing_Not_Allocated_Storage}
+@item
+@code{GNAT.Debug_Pools.Accessing_Deallocated_Storage}
+@item
+@code{GNAT.Debug_Pools.Freeing_Not_Allocated_Storage}
+@item
+@code{GNAT.Debug_Pools.Freeing_Deallocated_Storage }
+@end itemize
+
+@noindent
+For types associated with a Debug_Pool, dynamic allocation is performed using
+the standard GNAT allocation routine. References to all allocated chunks of
+memory are kept in an internal dictionary. Several deallocation strategies are
+provided, whereupon the user can choose to release the memory to the system,
+keep it allocated for further invalid access checks, or fill it with an easily
+recognizable pattern for debug sessions. The memory pattern is the old IBM
+hexadecimal convention: @code{16#DEADBEEF#}.
+
+See the documentation in the file g-debpoo.ads for more information on the
+various strategies.
+
+Upon each dereference, a check is made that the access value denotes a
+properly allocated memory location. Here is a complete example of use of
+@code{Debug_Pools}, that includes typical instances of memory corruption:
+@smallexample @c ada
+@iftex
+@leftskip=0cm
+@end iftex
+with Gnat.Io; use Gnat.Io;
+with Unchecked_Deallocation;
+with Unchecked_Conversion;
+with GNAT.Debug_Pools;
+with System.Storage_Elements;
+with Ada.Exceptions; use Ada.Exceptions;
+procedure Debug_Pool_Test is
+
+ type T is access Integer;
+ type U is access all T;
+
+ P : GNAT.Debug_Pools.Debug_Pool;
+ for T'Storage_Pool use P;
+
+ procedure Free is new Unchecked_Deallocation (Integer, T);
+ function UC is new Unchecked_Conversion (U, T);
+ A, B : aliased T;
+
+ procedure Info is new GNAT.Debug_Pools.Print_Info(Put_Line);
+
+begin
+ Info (P);
+ A := new Integer;
+ B := new Integer;
+ B := A;
+ Info (P);
+ Free (A);
+ begin
+ Put_Line (Integer'Image(B.all));
+ exception
+ when E : others => Put_Line ("raised: " & Exception_Name (E));
+ end;
+ begin
+ Free (B);
+ exception
+ when E : others => Put_Line ("raised: " & Exception_Name (E));
+ end;
+ B := UC(A'Access);
+ begin
+ Put_Line (Integer'Image(B.all));
+ exception
+ when E : others => Put_Line ("raised: " & Exception_Name (E));
+ end;
+ begin
+ Free (B);
+ exception
+ when E : others => Put_Line ("raised: " & Exception_Name (E));
+ end;
+ Info (P);
+end Debug_Pool_Test;
+@end smallexample
+
+@noindent
+The debug pool mechanism provides the following precise diagnostics on the
+execution of this erroneous program:
+@smallexample
+Debug Pool info:
+ Total allocated bytes : 0
+ Total deallocated bytes : 0
+ Current Water Mark: 0
+ High Water Mark: 0
+
+Debug Pool info:
+ Total allocated bytes : 8
+ Total deallocated bytes : 0
+ Current Water Mark: 8
+ High Water Mark: 8
+
+raised: GNAT.DEBUG_POOLS.ACCESSING_DEALLOCATED_STORAGE
+raised: GNAT.DEBUG_POOLS.FREEING_DEALLOCATED_STORAGE
+raised: GNAT.DEBUG_POOLS.ACCESSING_NOT_ALLOCATED_STORAGE
+raised: GNAT.DEBUG_POOLS.FREEING_NOT_ALLOCATED_STORAGE
+Debug Pool info:
+ Total allocated bytes : 8
+ Total deallocated bytes : 4
+ Current Water Mark: 4
+ High Water Mark: 8
+@end smallexample
+
+@ifclear vms
+@node The gnatmem Tool
+@section The @command{gnatmem} Tool
+@findex gnatmem
+
+@noindent
+The @code{gnatmem} utility monitors dynamic allocation and
+deallocation activity in a program, and displays information about
+incorrect deallocations and possible sources of memory leaks.
+It is designed to work in association with a static runtime library
+only and in this context provides three types of information:
+@itemize @bullet
+@item
+General information concerning memory management, such as the total
+number of allocations and deallocations, the amount of allocated
+memory and the high water mark, i.e.@: the largest amount of allocated
+memory in the course of program execution.
+
+@item
+Backtraces for all incorrect deallocations, that is to say deallocations
+which do not correspond to a valid allocation.
+
+@item
+Information on each allocation that is potentially the origin of a memory
+leak.
+@end itemize
+
+@menu
+* Running gnatmem::
+* Switches for gnatmem::
+* Example of gnatmem Usage::
+@end menu
+
+@node Running gnatmem
+@subsection Running @code{gnatmem}
+
+@noindent
+@code{gnatmem} makes use of the output created by the special version of
+allocation and deallocation routines that record call information. This
+allows to obtain accurate dynamic memory usage history at a minimal cost to
+the execution speed. Note however, that @code{gnatmem} is not supported on
+all platforms (currently, it is supported on AIX, HP-UX, GNU/Linux,
+Solaris and Windows NT/2000/XP (x86).
+
+@noindent
+The @code{gnatmem} command has the form
+
+@smallexample
+ $ gnatmem @ovar{switches} user_program
+@end smallexample
+
+@noindent
+The program must have been linked with the instrumented version of the
+allocation and deallocation routines. This is done by linking with the
+@file{libgmem.a} library. For correct symbolic backtrace information,
+the user program should be compiled with debugging options
+(see @ref{Switches for gcc}). For example to build @file{my_program}:
+
+@smallexample
+$ gnatmake -g my_program -largs -lgmem
+@end smallexample
+
+@noindent
+As library @file{libgmem.a} contains an alternate body for package
+@code{System.Memory}, @file{s-memory.adb} should not be compiled and linked
+when an executable is linked with library @file{libgmem.a}. It is then not
+recommended to use @command{gnatmake} with switch @option{^-a^/ALL_FILES^}.
+
+@noindent
+When @file{my_program} is executed, the file @file{gmem.out} is produced.
+This file contains information about all allocations and deallocations
+performed by the program. It is produced by the instrumented allocations and
+deallocations routines and will be used by @code{gnatmem}.
+
+In order to produce symbolic backtrace information for allocations and
+deallocations performed by the GNAT run-time library, you need to use a
+version of that library that has been compiled with the @option{-g} switch
+(see @ref{Rebuilding the GNAT Run-Time Library}).
+
+Gnatmem must be supplied with the @file{gmem.out} file and the executable to
+examine. If the location of @file{gmem.out} file was not explicitly supplied by
+@option{-i} switch, gnatmem will assume that this file can be found in the
+current directory. For example, after you have executed @file{my_program},
+@file{gmem.out} can be analyzed by @code{gnatmem} using the command:
+
+@smallexample
+$ gnatmem my_program
+@end smallexample
+
+@noindent
+This will produce the output with the following format:
+
+*************** debut cc
+@smallexample
+$ gnatmem my_program
+
+Global information
+------------------
+ Total number of allocations : 45
+ Total number of deallocations : 6
+ Final Water Mark (non freed mem) : 11.29 Kilobytes
+ High Water Mark : 11.40 Kilobytes
+
+.
+.
+.
+Allocation Root # 2
+-------------------
+ Number of non freed allocations : 11
+ Final Water Mark (non freed mem) : 1.16 Kilobytes
+ High Water Mark : 1.27 Kilobytes
+ Backtrace :
+ my_program.adb:23 my_program.alloc
+.
+.
+.
+@end smallexample
+
+The first block of output gives general information. In this case, the
+Ada construct ``@code{@b{new}}'' was executed 45 times, and only 6 calls to an
+Unchecked_Deallocation routine occurred.
+
+@noindent
+Subsequent paragraphs display information on all allocation roots.
+An allocation root is a specific point in the execution of the program
+that generates some dynamic allocation, such as a ``@code{@b{new}}''
+construct. This root is represented by an execution backtrace (or subprogram
+call stack). By default the backtrace depth for allocations roots is 1, so
+that a root corresponds exactly to a source location. The backtrace can
+be made deeper, to make the root more specific.
+
+@node Switches for gnatmem
+@subsection Switches for @code{gnatmem}
+
+@noindent
+@code{gnatmem} recognizes the following switches:
+
+@table @option
+
+@item -q
+@cindex @option{-q} (@code{gnatmem})
+Quiet. Gives the minimum output needed to identify the origin of the
+memory leaks. Omits statistical information.
+
+@item @var{N}
+@cindex @var{N} (@code{gnatmem})
+N is an integer literal (usually between 1 and 10) which controls the
+depth of the backtraces defining allocation root. The default value for
+N is 1. The deeper the backtrace, the more precise the localization of
+the root. Note that the total number of roots can depend on this
+parameter. This parameter must be specified @emph{before} the name of the
+executable to be analyzed, to avoid ambiguity.
+
+@item -b n
+@cindex @option{-b} (@code{gnatmem})
+This switch has the same effect as just depth parameter.
+
+@item -i @var{file}
+@cindex @option{-i} (@code{gnatmem})
+Do the @code{gnatmem} processing starting from @file{file}, rather than
+@file{gmem.out} in the current directory.
+
+@item -m n
+@cindex @option{-m} (@code{gnatmem})
+This switch causes @code{gnatmem} to mask the allocation roots that have less
+than n leaks. The default value is 1. Specifying the value of 0 will allow to
+examine even the roots that didn't result in leaks.
+
+@item -s order
+@cindex @option{-s} (@code{gnatmem})
+This switch causes @code{gnatmem} to sort the allocation roots according to the
+specified order of sort criteria, each identified by a single letter. The
+currently supported criteria are @code{n, h, w} standing respectively for
+number of unfreed allocations, high watermark, and final watermark
+corresponding to a specific root. The default order is @code{nwh}.
+
+@end table
+
+@node Example of gnatmem Usage
+@subsection Example of @code{gnatmem} Usage
+
+@noindent
+The following example shows the use of @code{gnatmem}
+on a simple memory-leaking program.
+Suppose that we have the following Ada program:
+
+@smallexample @c ada
+@group
+@cartouche
+with Unchecked_Deallocation;
+procedure Test_Gm is
+
+ type T is array (1..1000) of Integer;
+ type Ptr is access T;
+ procedure Free is new Unchecked_Deallocation (T, Ptr);
+ A : Ptr;
+
+ procedure My_Alloc is
+ begin
+ A := new T;
+ end My_Alloc;
+
+ procedure My_DeAlloc is
+ B : Ptr := A;
+ begin
+ Free (B);
+ end My_DeAlloc;
+
+begin
+ My_Alloc;
+ for I in 1 .. 5 loop
+ for J in I .. 5 loop
+ My_Alloc;
+ end loop;
+ My_Dealloc;
+ end loop;
+end;
+@end cartouche
+@end group
+@end smallexample
+
+@noindent
+The program needs to be compiled with debugging option and linked with
+@code{gmem} library:
+
+@smallexample
+$ gnatmake -g test_gm -largs -lgmem
+@end smallexample
+
+@noindent
+Then we execute the program as usual:
+
+@smallexample
+$ test_gm
+@end smallexample
+
+@noindent
+Then @code{gnatmem} is invoked simply with
+@smallexample
+$ gnatmem test_gm
+@end smallexample
+
+@noindent
+which produces the following output (result may vary on different platforms):
+
+@smallexample
+Global information
+------------------
+ Total number of allocations : 18
+ Total number of deallocations : 5
+ Final Water Mark (non freed mem) : 53.00 Kilobytes
+ High Water Mark : 56.90 Kilobytes
+
+Allocation Root # 1
+-------------------
+ Number of non freed allocations : 11
+ Final Water Mark (non freed mem) : 42.97 Kilobytes
+ High Water Mark : 46.88 Kilobytes
+ Backtrace :
+ test_gm.adb:11 test_gm.my_alloc
+
+Allocation Root # 2
+-------------------
+ Number of non freed allocations : 1
+ Final Water Mark (non freed mem) : 10.02 Kilobytes
+ High Water Mark : 10.02 Kilobytes
+ Backtrace :
+ s-secsta.adb:81 system.secondary_stack.ss_init
+
+Allocation Root # 3
+-------------------
+ Number of non freed allocations : 1
+ Final Water Mark (non freed mem) : 12 Bytes
+ High Water Mark : 12 Bytes
+ Backtrace :
+ s-secsta.adb:181 system.secondary_stack.ss_init
+@end smallexample
+
+@noindent
+Note that the GNAT run time contains itself a certain number of
+allocations that have no corresponding deallocation,
+as shown here for root #2 and root
+#3. This is a normal behavior when the number of non-freed allocations
+is one, it allocates dynamic data structures that the run time needs for
+the complete lifetime of the program. Note also that there is only one
+allocation root in the user program with a single line back trace:
+test_gm.adb:11 test_gm.my_alloc, whereas a careful analysis of the
+program shows that 'My_Alloc' is called at 2 different points in the
+source (line 21 and line 24). If those two allocation roots need to be
+distinguished, the backtrace depth parameter can be used:
+
+@smallexample
+$ gnatmem 3 test_gm
+@end smallexample
+
+@noindent
+which will give the following output:
+
+@smallexample
+Global information
+------------------
+ Total number of allocations : 18
+ Total number of deallocations : 5
+ Final Water Mark (non freed mem) : 53.00 Kilobytes
+ High Water Mark : 56.90 Kilobytes
+
+Allocation Root # 1
+-------------------
+ Number of non freed allocations : 10
+ Final Water Mark (non freed mem) : 39.06 Kilobytes
+ High Water Mark : 42.97 Kilobytes
+ Backtrace :
+ test_gm.adb:11 test_gm.my_alloc
+ test_gm.adb:24 test_gm
+ b_test_gm.c:52 main
+
+Allocation Root # 2
+-------------------
+ Number of non freed allocations : 1
+ Final Water Mark (non freed mem) : 10.02 Kilobytes
+ High Water Mark : 10.02 Kilobytes
+ Backtrace :
+ s-secsta.adb:81 system.secondary_stack.ss_init
+ s-secsta.adb:283 <system__secondary_stack___elabb>
+ b_test_gm.c:33 adainit
+
+Allocation Root # 3
+-------------------
+ Number of non freed allocations : 1
+ Final Water Mark (non freed mem) : 3.91 Kilobytes
+ High Water Mark : 3.91 Kilobytes
+ Backtrace :
+ test_gm.adb:11 test_gm.my_alloc
+ test_gm.adb:21 test_gm
+ b_test_gm.c:52 main
+
+Allocation Root # 4
+-------------------
+ Number of non freed allocations : 1
+ Final Water Mark (non freed mem) : 12 Bytes
+ High Water Mark : 12 Bytes
+ Backtrace :
+ s-secsta.adb:181 system.secondary_stack.ss_init
+ s-secsta.adb:283 <system__secondary_stack___elabb>
+ b_test_gm.c:33 adainit
+@end smallexample
-@item ^-u^/OUTPUT=UNITS^
-@cindex @option{^-u^/OUTPUT=UNITS^} (@code{gnatls})
-Only output information about compilation units.
+@noindent
+The allocation root #1 of the first example has been split in 2 roots #1
+and #3 thanks to the more precise associated backtrace.
-@item ^-files^/FILES^=@var{file}
-@cindex @option{^-files^/FILES^} (@code{gnatls})
-Take as arguments the files listed in text file @var{file}.
-Text file @var{file} may contain empty lines that are ignored.
-Each non empty line should contain the name of an existing file.
-Several such switches may be specified simultaneously.
+@end ifclear
-@item ^-aO^/OBJECT_SEARCH=^@var{dir}
-@itemx ^-aI^/SOURCE_SEARCH=^@var{dir}
-@itemx ^-I^/SEARCH=^@var{dir}
-@itemx ^-I-^/NOCURRENT_DIRECTORY^
-@itemx -nostdinc
-@cindex @option{^-aO^/OBJECT_SEARCH^} (@code{gnatls})
-@cindex @option{^-aI^/SOURCE_SEARCH^} (@code{gnatls})
-@cindex @option{^-I^/SEARCH^} (@code{gnatls})
-@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@code{gnatls})
-Source path manipulation. Same meaning as the equivalent @code{gnatmake} flags
-(see @ref{Switches for gnatmake}).
+@node Stack Related Facilities
+@chapter Stack Related Facilities
-@item --RTS=@var{rts-path}
-@cindex @option{--RTS} (@code{gnatls})
-Specifies the default location of the runtime library. Same meaning as the
-equivalent @code{gnatmake} flag (see @ref{Switches for gnatmake}).
+@noindent
+This chapter describes some useful tools associated with stack
+checking and analysis. In
+particular, it deals with dynamic and static stack usage measurements.
+
+@menu
+* Stack Overflow Checking::
+* Static Stack Usage Analysis::
+* Dynamic Stack Usage Analysis::
+@end menu
+
+@node Stack Overflow Checking
+@section Stack Overflow Checking
+@cindex Stack Overflow Checking
+@cindex -fstack-check
+
+@noindent
+For most operating systems, @command{gcc} does not perform stack overflow
+checking by default. This means that if the main environment task or
+some other task exceeds the available stack space, then unpredictable
+behavior will occur. Most native systems offer some level of protection by
+adding a guard page at the end of each task stack. This mechanism is usually
+not enough for dealing properly with stack overflow situations because
+a large local variable could ``jump'' above the guard page.
+Furthermore, when the
+guard page is hit, there may not be any space left on the stack for executing
+the exception propagation code. Enabling stack checking avoids
+such situations.
+
+To activate stack checking, compile all units with the gcc option
+@option{-fstack-check}. For example:
+
+@smallexample
+gcc -c -fstack-check package1.adb
+@end smallexample
+
+@noindent
+Units compiled with this option will generate extra instructions to check
+that any use of the stack (for procedure calls or for declaring local
+variables in declare blocks) does not exceed the available stack space.
+If the space is exceeded, then a @code{Storage_Error} exception is raised.
+
+For declared tasks, the stack size is controlled by the size
+given in an applicable @code{Storage_Size} pragma or by the value specified
+at bind time with @option{-d} (@pxref{Switches for gnatbind}) or is set to
+the default size as defined in the GNAT runtime otherwise.
+
+For the environment task, the stack size depends on
+system defaults and is unknown to the compiler. Stack checking
+may still work correctly if a fixed
+size stack is allocated, but this cannot be guaranteed.
+@ifclear vms
+To ensure that a clean exception is signalled for stack
+overflow, set the environment variable
+@env{GNAT_STACK_LIMIT} to indicate the maximum
+stack area that can be used, as in:
+@cindex GNAT_STACK_LIMIT
+
+@smallexample
+SET GNAT_STACK_LIMIT 1600
+@end smallexample
+
+@noindent
+The limit is given in kilobytes, so the above declaration would
+set the stack limit of the environment task to 1.6 megabytes.
+Note that the only purpose of this usage is to limit the amount
+of stack used by the environment task. If it is necessary to
+increase the amount of stack for the environment task, then this
+is an operating systems issue, and must be addressed with the
+appropriate operating systems commands.
+@end ifclear
+@ifset vms
+To have a fixed size stack in the environment task, the stack must be put
+in the P0 address space and its size specified. Use these switches to
+create a p0 image:
+
+@smallexample
+gnatmake my_progs -largs "-Wl,--opt=STACK=4000,/p0image"
+@end smallexample
+
+@noindent
+The quotes are required to keep case. The number after @samp{STACK=} is the
+size of the environmental task stack in pagelets (512 bytes). In this example
+the stack size is about 2 megabytes.
+
+@noindent
+A consequence of the @option{/p0image} qualifier is also to makes RMS buffers
+be placed in P0 space. Refer to @cite{HP OpenVMS Linker Utility Manual} for
+more details about the @option{/p0image} qualifier and the @option{stack}
+option.
+@end ifset
+
+@node Static Stack Usage Analysis
+@section Static Stack Usage Analysis
+@cindex Static Stack Usage Analysis
+@cindex -fstack-usage
+
+@noindent
+A unit compiled with @option{-fstack-usage} will generate an extra file
+that specifies
+the maximum amount of stack used, on a per-function basis.
+The file has the same
+basename as the target object file with a @file{.su} extension.
+Each line of this file is made up of three fields:
+
+@itemize
+@item
+The name of the function.
+@item
+A number of bytes.
+@item
+One or more qualifiers: @code{static}, @code{dynamic}, @code{bounded}.
+@end itemize
+
+The second field corresponds to the size of the known part of the function
+frame.
+
+The qualifier @code{static} means that the function frame size
+is purely static.
+It usually means that all local variables have a static size.
+In this case, the second field is a reliable measure of the function stack
+utilization.
+
+The qualifier @code{dynamic} means that the function frame size is not static.
+It happens mainly when some local variables have a dynamic size. When this
+qualifier appears alone, the second field is not a reliable measure
+of the function stack analysis. When it is qualified with @code{bounded}, it
+means that the second field is a reliable maximum of the function stack
+utilization.
+
+@node Dynamic Stack Usage Analysis
+@section Dynamic Stack Usage Analysis
+
+@noindent
+It is possible to measure the maximum amount of stack used by a task, by
+adding a switch to @command{gnatbind}, as:
+
+@smallexample
+$ gnatbind -u0 file
+@end smallexample
+
+@noindent
+With this option, at each task termination, its stack usage is output on
+@file{stderr}.
+It is not always convenient to output the stack usage when the program
+is still running. Hence, it is possible to delay this output until program
+termination. for a given number of tasks specified as the argument of the
+@option{-u} option. For instance:
+
+@smallexample
+$ gnatbind -u100 file
+@end smallexample
+
+@noindent
+will buffer the stack usage information of the first 100 tasks to terminate and
+output this info at program termination. Results are displayed in four
+columns:
+
+@noindent
+Index | Task Name | Stack Size | Actual Use [min - max]
+
+@noindent
+where:
+
+@table @emph
+@item Index
+is a number associated with each task.
+
+@item Task Name
+is the name of the task analyzed.
+
+@item Stack Size
+is the maximum size for the stack.
+
+@item Actual Use
+is the measure done by the stack analyzer. In order to prevent overflow,
+the stack is not entirely analyzed, and it's not possible to know exactly how
+much has actually been used. The real amount of stack used is between the min
+and max values.
+
+@end table
+
+@noindent
+The environment task stack, e.g., the stack that contains the main unit, is
+only processed when the environment variable GNAT_STACK_LIMIT is set.
+
+
+@c *********************************
+@c * GNATCHECK *
+@c *********************************
+@node Verifying Properties Using gnatcheck
+@chapter Verifying Properties Using @command{gnatcheck}
+@findex gnatcheck
+@cindex @command{gnatcheck}
+
+@noindent
+The @command{gnatcheck} tool is an ASIS-based utility that checks properties
+of Ada source files according to a given set of semantic rules.
+@cindex ASIS
+
+In order to check compliance with a given rule, @command{gnatcheck} has to
+semantically analyze the Ada sources.
+Therefore, checks can only be performed on
+legal Ada units. Moreover, when a unit depends semantically upon units located
+outside the current directory, the source search path has to be provided when
+calling @command{gnatcheck}, either through a specified project file or
+through @command{gnatcheck} switches as described below.
+
+A number of rules are predefined in @command{gnatcheck} and are described
+later in this chapter.
+You can also add new rules, by modifying the @command{gnatcheck} code and
+rebuilding the tool. In order to add a simple rule making some local checks,
+a small amount of straightforward ASIS-based programming is usually needed.
+
+Project support for @command{gnatcheck} is provided by the GNAT
+driver (see @ref{The GNAT Driver and Project Files}).
+
+Invoking @command{gnatcheck} on the command line has the form:
+
+@smallexample
+$ gnatcheck @ovar{switches} @{@var{filename}@}
+ @r{[}^-files^/FILES^=@{@var{arg_list_filename}@}@r{]}
+ @r{[}-cargs @var{gcc_switches}@r{]} @r{[}-rules @var{rule_options}@r{]}
+@end smallexample
+
+@noindent
+where
+@itemize @bullet
+@item
+@var{switches} specify the general tool options
+
+@item
+Each @var{filename} is the name (including the extension) of a source
+file to process. ``Wildcards'' are allowed, and
+the file name may contain path information.
+
+@item
+Each @var{arg_list_filename} is the name (including the extension) of a text
+file containing the names of the source files to process, separated by spaces
+or line breaks.
+
+@item
+@var{gcc_switches} is a list of switches for
+@command{gcc}. They will be passed on to all compiler invocations made by
+@command{gnatcheck} to generate the ASIS trees. Here you can provide
+@option{^-I^/INCLUDE_DIRS=^} switches to form the source search path,
+and use the @option{-gnatec} switch to set the configuration file.
+
+@item
+@var{rule_options} is a list of options for controlling a set of
+rules to be checked by @command{gnatcheck} (@pxref{gnatcheck Rule Options}).
+@end itemize
+
+@noindent
+Either a @file{@var{filename}} or an @file{@var{arg_list_filename}} must be supplied.
+
+@menu
+* Format of the Report File::
+* General gnatcheck Switches::
+* gnatcheck Rule Options::
+* Adding the Results of Compiler Checks to gnatcheck Output::
+* Project-Wide Checks::
+* Predefined Rules::
+@end menu
+
+@node Format of the Report File
+@section Format of the Report File
+@cindex Report file (for @code{gnatcheck})
+
+@noindent
+The @command{gnatcheck} tool outputs on @file{stdout} all messages concerning
+rule violations.
+It also creates, in the current
+directory, a text file named @file{^gnatcheck.out^GNATCHECK.OUT^} that
+contains the complete report of the last gnatcheck run. This report contains:
+@itemize @bullet
+@item a list of the Ada source files being checked,
+@item a list of enabled and disabled rules,
+@item a list of the diagnostic messages, ordered in three different ways
+and collected in three separate
+sections. Section 1 contains the raw list of diagnostic messages. It
+corresponds to the output going to @file{stdout}. Section 2 contains
+messages ordered by rules.
+Section 3 contains messages ordered by source files.
+@end itemize
+
+@node General gnatcheck Switches
+@section General @command{gnatcheck} Switches
+
+@noindent
+The following switches control the general @command{gnatcheck} behavior
+
+@table @option
+@c !sort!
+@cindex @option{^-a^/ALL^} (@command{gnatcheck})
+@item ^-a^/ALL^
+Process all units including those with read-only ALI files such as
+those from GNAT Run-Time library.
+
+@ifclear vms
+@ignore
+@cindex @option{-d} (@command{gnatcheck})
+@item -d
+Debug mode
+@end ignore
+
+@cindex @option{-dd} (@command{gnatcheck})
+@item -dd
+Progress indicator mode (for use in GPS)
+@end ifclear
+
+@cindex @option{^-h^/HELP^} (@command{gnatcheck})
+@item ^-h^/HELP^
+List the predefined and user-defined rules. For more details see
+@ref{Predefined Rules}.
+
+@cindex @option{^-l^/LOCS^} (@command{gnatcheck})
+@item ^-l^/LOCS^
+Use full source locations references in the report file. For a construct from
+a generic instantiation a full source location is a chain from the location
+of this construct in the generic unit to the place where this unit is
+instantiated.
+
+@cindex @option{^-m^/DIAGNOSTIC_LIMIT^} (@command{gnatcheck})
+@item ^-m@i{nnn}^/DIAGNOSTIC_LIMIT=@i{nnn}^
+Maximum number of diagnoses to be sent to Stdout, @i{nnn} from o@dots{}1000,
+the default value is 500. Zero means that there is no limitation on
+the number of diagnostic messages to be printed into Stdout.
+
+@cindex @option{^-q^/QUIET^} (@command{gnatcheck})
+@item ^-q^/QUIET^
+Quiet mode. All the diagnoses about rule violations are placed in the
+@command{gnatcheck} report file only, without duplicating in @file{stdout}.
+
+@cindex @option{^-s^/SHORT^} (@command{gnatcheck})
+@item ^-s^/SHORT^
+Short format of the report file (no version information, no list of applied
+rules, no list of checked sources is included)
+
+@cindex @option{^-s1^/COMPILER_STYLE^} (@command{gnatcheck})
+@item ^-s1^/COMPILER_STYLE^
+Include the compiler-style section in the report file
+
+@cindex @option{^-s2^/BY_RULES^} (@command{gnatcheck})
+@item ^-s2^/BY_RULES^
+Include the section containing diagnoses ordered by rules in the report file
+
+@cindex @option{^-s3^/BY_FILES_BY_RULES^} (@command{gnatcheck})
+@item ^-s3^/BY_FILES_BY_RULES^
+Include the section containing diagnoses ordered by files and then by rules
+in the report file
+
+@cindex @option{^-v^/VERBOSE^} (@command{gnatcheck})
+@item ^-v^/VERBOSE^
+Verbose mode; @command{gnatcheck} generates version information and then
+a trace of sources being processed.
+
+@end table
+
+@noindent
+Note that if any of the options @option{^-s1^/COMPILER_STYLE^},
+@option{^-s2^/BY_RULES^} or
+@option{^-s3^/BY_FILES_BY_RULES^} is specified,
+then the @command{gnatcheck} report file will only contain sections
+explicitly denoted by these options.
+
+@node gnatcheck Rule Options
+@section @command{gnatcheck} Rule Options
+
+@noindent
+The following options control the processing performed by
+@command{gnatcheck}.
+
+@table @option
+@cindex @option{+ALL} (@command{gnatcheck})
+@item +ALL
+Turn all the rule checks ON.
+
+@cindex @option{-ALL} (@command{gnatcheck})
+@item -ALL
+Turn all the rule checks OFF.
+
+@cindex @option{+R} (@command{gnatcheck})
+@item +R@var{rule_id}@r{[}:@var{param}@r{]}
+Turn on the check for a specified rule with the specified parameter, if any.
+@var{rule_id} must be the identifier of one of the currently implemented rules
+(use @option{^-h^/HELP^} for the list of implemented rules). Rule identifiers
+are not case-sensitive. The @var{param} item must
+be a string representing a valid parameter(s) for the specified rule.
+If it contains any space characters then this string must be enclosed in
+quotation marks.
+
+@cindex @option{-R} (@command{gnatcheck})
+@item -R@var{rule_id}@r{[}:@var{param}@r{]}
+Turn off the check for a specified rule with the specified parameter, if any.
+
+@cindex @option{-from} (@command{gnatcheck})
+@item -from=@var{rule_option_filename}
+Read the rule options from the text file @var{rule_option_filename}, referred as
+``rule file'' below.
+
+@end table
+
+@noindent
+The default behavior is that all the rule checks are disabled.
+
+A rule file is a text file containing a set of rule options.
+@cindex Rule file (for @code{gnatcheck})
+The file may contain empty lines and Ada-style comments (comment
+lines and end-of-line comments). The rule file has free format; that is,
+you do not have to start a new rule option on a new line.
+
+A rule file may contain other @option{-from=@var{rule_option_filename}}
+options, each such option being replaced with the content of the
+corresponding rule file during the rule files processing. In case a
+cycle is detected (that is, @file{@var{rule_file_1}} reads rule options
+from @file{@var{rule_file_2}}, and @file{@var{rule_file_2}} reads
+(directly or indirectly) rule options from @file{@var{rule_file_1}}),
+the processing of rule files is interrupted and a part of their content
+is ignored.
+
+
+@node Adding the Results of Compiler Checks to gnatcheck Output
+@section Adding the Results of Compiler Checks to @command{gnatcheck} Output
+
+@noindent
+The @command{gnatcheck} tool can include in the generated diagnostic messages
+and in
+the report file the results of the checks performed by the compiler. Though
+disabled by default, this effect may be obtained by using @option{+R} with
+the following rule identifiers and parameters:
+
+@table @option
+@item Restrictions
+To record restrictions violations (that are performed by the compiler if the
+pragma @code{Restrictions} or @code{Restriction_Warnings} are given),
+use the rule named
+@code{Restrictions} with the same parameters as pragma
+@code{Restrictions} or @code{Restriction_Warnings}.
+
+@item Style_Checks
+To record compiler style checks(@pxref{Style Checking}), use the rule named
+@code{Style_Checks}. A parameter of this rule can be either @code{All_Checks},
+which enables all the standard style checks that corresponds to @option{-gnatyy}
+GNAT style check option, or a string that has exactly the same
+structure and semantics as the @code{string_LITERAL} parameter of GNAT pragma
+@code{Style_Checks} (for further information about this pragma,
+@pxref{Pragma Style_Checks,,, gnat_rm, GNAT Reference Manual}).
+
+@item Warnings
+To record compiler warnings (@pxref{Warning Message Control}), use the rule
+named @code{Warnings} with a parameter that is a valid
+@i{static_string_expression} argument of GNAT pragma @code{Warnings}
+(for further information about this pragma, @pxref{Pragma Warnings,,,
+gnat_rm, GNAT Reference Manual}). Note, that in case of gnatcheck
+'s' parameter, that corresponds to the GNAT @option{-gnatws} option, disables
+all the specific warnings, but not suppresses the warning mode,
+and 'e' parameter, corresponding to @option{-gnatwe} that means
+"treat warnings as errors", does not have any effect.
+
+@end table
+
+To disable a specific restriction check, use @code{-RStyle_Checks} gnatcheck
+option with the corresponding restriction name as a parameter. @code{-R} is
+not available for @code{Style_Checks} and @code{Warnings} options, to disable
+warnings and style checks, use the corresponding warning and style options.
+
+@node Project-Wide Checks
+@section Project-Wide Checks
+@cindex Project-wide checks (for @command{gnatcheck})
+
+@noindent
+In order to perform checks on all units of a given project, you can use
+the GNAT driver along with the @option{-P} option:
+@smallexample
+ gnat check -Pproj -rules -from=my_rules
+@end smallexample
+
+@noindent
+If the project @code{proj} depends upon other projects, you can perform
+checks on the project closure using the @option{-U} option:
+@smallexample
+ gnat check -Pproj -U -rules -from=my_rules
+@end smallexample
+
+@noindent
+Finally, if not all the units are relevant to a particular main
+program in the project closure, you can perform checks for the set
+of units needed to create a given main program (unit closure) using
+the @option{-U} option followed by the name of the main unit:
+@smallexample
+ gnat check -Pproj -U main -rules -from=my_rules
+@end smallexample
+
+
+@node Predefined Rules
+@section Predefined Rules
+@cindex Predefined rules (for @command{gnatcheck})
+
+@ignore
+@c (Jan 2007) Since the global rules are still under development and are not
+@c documented, there is no point in explaining the difference between
+@c global and local rules
+@noindent
+A rule in @command{gnatcheck} is either local or global.
+A @emph{local rule} is a rule that applies to a well-defined section
+of a program and that can be checked by analyzing only this section.
+A @emph{global rule} requires analysis of some global properties of the
+whole program (mostly related to the program call graph).
+As of @value{NOW}, the implementation of global rules should be
+considered to be at a preliminary stage. You can use the
+@option{+GLOBAL} option to enable all the global rules, and the
+@option{-GLOBAL} rule option to disable all the global rules.
+
+All the global rules in the list below are
+so indicated by marking them ``GLOBAL''.
+This +GLOBAL and -GLOBAL options are not
+included in the list of gnatcheck options above, because at the moment they
+are considered as a temporary debug options.
+
+@command{gnatcheck} performs rule checks for generic
+instances only for global rules. This limitation may be relaxed in a later
+release.
+@end ignore
+
+@noindent
+The following subsections document the rules implemented in
+@command{gnatcheck}.
+The subsection title is the same as the rule identifier, which may be
+used as a parameter of the @option{+R} or @option{-R} options.
+
+
+@menu
+* Abstract_Type_Declarations::
+* Anonymous_Arrays::
+* Anonymous_Subtypes::
+* Blocks::
+* Boolean_Relational_Operators::
+@ignore
+* Ceiling_Violations::
+@end ignore
+* Controlled_Type_Declarations::
+* Declarations_In_Blocks::
+* Default_Parameters::
+* Discriminated_Records::
+* Enumeration_Ranges_In_CASE_Statements::
+* Exceptions_As_Control_Flow::
+* EXIT_Statements_With_No_Loop_Name::
+* Expanded_Loop_Exit_Names::
+* Explicit_Full_Discrete_Ranges::
+* Float_Equality_Checks::
+* Forbidden_Pragmas::
+* Function_Style_Procedures::
+* Generics_In_Subprograms::
+* GOTO_Statements::
+* Implicit_IN_Mode_Parameters::
+* Implicit_SMALL_For_Fixed_Point_Types::
+* Improperly_Located_Instantiations::
+* Improper_Returns::
+* Library_Level_Subprograms::
+* Local_Packages::
+@ignore
+* Improperly_Called_Protected_Entries::
+@end ignore
+* Metrics::
+* Misnamed_Identifiers::
+* Multiple_Entries_In_Protected_Definitions::
+* Name_Clashes::
+* Non_Qualified_Aggregates::
+* Non_Short_Circuit_Operators::
+* Non_SPARK_Attributes::
+* Non_Tagged_Derived_Types::
+* Non_Visible_Exceptions::
+* Numeric_Literals::
+* OTHERS_In_Aggregates::
+* OTHERS_In_CASE_Statements::
+* OTHERS_In_Exception_Handlers::
+* Outer_Loop_Exits::
+* Overloaded_Operators::
+* Overly_Nested_Control_Structures::
+* Parameters_Out_Of_Order::
+* Positional_Actuals_For_Defaulted_Generic_Parameters::
+* Positional_Actuals_For_Defaulted_Parameters::
+* Positional_Components::
+* Positional_Generic_Parameters::
+* Positional_Parameters::
+* Predefined_Numeric_Types::
+* Raising_External_Exceptions::
+* Raising_Predefined_Exceptions::
+* Separate_Numeric_Error_Handlers::
+@ignore
+* Recursion::
+* Side_Effect_Functions::
+@end ignore
+* Slices::
+* Unassigned_OUT_Parameters::
+* Uncommented_BEGIN_In_Package_Bodies::
+* Unconstrained_Array_Returns::
+* Universal_Ranges::
+* Unnamed_Blocks_And_Loops::
+@ignore
+* Unused_Subprograms::
+@end ignore
+* USE_PACKAGE_Clauses::
+* Volatile_Objects_Without_Address_Clauses::
+@end menu
+
+
+@node Abstract_Type_Declarations
+@subsection @code{Abstract_Type_Declarations}
+@cindex @code{Abstract_Type_Declarations} rule (for @command{gnatcheck})
+
+@noindent
+Flag all declarations of abstract types. For an abstract private
+type, both the private and full type declarations are flagged.
-@item ^-v^/OUTPUT=VERBOSE^
-@cindex @option{^-v^/OUTPUT=VERBOSE^} (@code{gnatls})
-Verbose mode. Output the complete source and object paths. Do not use
-the default column layout but instead use long format giving as much as
-information possible on each requested units, including special
-characteristics such as:
+This rule has no parameters.
-@table @code
-@item Preelaborable
-The unit is preelaborable in the Ada 95 sense.
-@item No_Elab_Code
-No elaboration code has been produced by the compiler for this unit.
+@node Anonymous_Arrays
+@subsection @code{Anonymous_Arrays}
+@cindex @code{Anonymous_Arrays} rule (for @command{gnatcheck})
-@item Pure
-The unit is pure in the Ada 95 sense.
+@noindent
+Flag all anonymous array type definitions (by Ada semantics these can only
+occur in object declarations).
-@item Elaborate_Body
-The unit contains a pragma Elaborate_Body.
+This rule has no parameters.
-@item Remote_Types
-The unit contains a pragma Remote_Types.
+@node Anonymous_Subtypes
+@subsection @code{Anonymous_Subtypes}
+@cindex @code{Anonymous_Subtypes} rule (for @command{gnatcheck})
-@item Shared_Passive
-The unit contains a pragma Shared_Passive.
+@noindent
+Flag all uses of anonymous subtypes. A use of an anonymous subtype is
+any instance of a subtype indication with a constraint, other than one
+that occurs immediately within a subtype declaration. Any use of a range
+other than as a constraint used immediately within a subtype declaration
+is considered as an anonymous subtype.
-@item Predefined
-This unit is part of the predefined environment and cannot be modified
-by the user.
+An effect of this rule is that @code{for} loops such as the following are
+flagged (since @code{1..N} is formally a ``range''):
-@item Remote_Call_Interface
-The unit contains a pragma Remote_Call_Interface.
+@smallexample @c ada
+for I in 1 .. N loop
+ @dots{}
+end loop;
+@end smallexample
-@end table
+@noindent
+Declaring an explicit subtype solves the problem:
-@end table
+@smallexample @c ada
+subtype S is Integer range 1..N;
+@dots{}
+for I in S loop
+ @dots{}
+end loop;
+@end smallexample
-@node Examples of gnatls Usage
-@section Example of @code{gnatls} Usage
-@ifclear vms
+@noindent
+This rule has no parameters.
+
+@node Blocks
+@subsection @code{Blocks}
+@cindex @code{Blocks} rule (for @command{gnatcheck})
@noindent
-Example of using the verbose switch. Note how the source and
-object paths are affected by the -I switch.
+Flag each block statement.
-@smallexample
-$ gnatls -v -I.. demo1.o
+This rule has no parameters.
-GNATLS 3.10w (970212) Copyright 1999 Free Software Foundation, Inc.
+@node Boolean_Relational_Operators
+@subsection @code{Boolean_Relational_Operators}
+@cindex @code{Boolean_Relational_Operators} rule (for @command{gnatcheck})
-Source Search Path:
- <Current_Directory>
- ../
- /home/comar/local/adainclude/
+@noindent
+Flag each call to a predefined relational operator (``<'', ``>'', ``<='',
+``>='', ``='' and ``/='') for the predefined Boolean type.
+(This rule is useful in enforcing the SPARK language restrictions.)
-Object Search Path:
- <Current_Directory>
- ../
- /home/comar/local/lib/gcc-lib/mips-sni-sysv4/2.7.2/adalib/
+Calls to predefined relational operators of any type derived from
+@code{Standard.Boolean} are not detected. Calls to user-defined functions
+with these designators, and uses of operators that are renamings
+of the predefined relational operators for @code{Standard.Boolean},
+are likewise not detected.
-./demo1.o
- Unit =>
- Name => demo1
- Kind => subprogram body
- Flags => No_Elab_Code
- Source => demo1.adb modified
-@end smallexample
+This rule has no parameters.
+
+@ignore
+@node Ceiling_Violations
+@subsection @code{Ceiling_Violations} (under construction, GLOBAL)
+@cindex @code{Ceiling_Violations} rule (for @command{gnatcheck})
@noindent
-The following is an example of use of the dependency list.
-Note the use of the -s switch
-which gives a straight list of source files. This can be useful for
-building specialized scripts.
+Flag invocations of a protected operation by a task whose priority exceeds
+the protected object's ceiling.
-@smallexample
-$ gnatls -d demo2.o
-./demo2.o demo2 OK demo2.adb
- OK gen_list.ads
- OK gen_list.adb
- OK instr.ads
- OK instr-child.ads
+As of @value{NOW}, this rule has the following limitations:
-$ gnatls -d -s -a demo1.o
-demo1.adb
-/home/comar/local/adainclude/ada.ads
-/home/comar/local/adainclude/a-finali.ads
-/home/comar/local/adainclude/a-filico.ads
-/home/comar/local/adainclude/a-stream.ads
-/home/comar/local/adainclude/a-tags.ads
-gen_list.ads
-gen_list.adb
-/home/comar/local/adainclude/gnat.ads
-/home/comar/local/adainclude/g-io.ads
-instr.ads
-/home/comar/local/adainclude/system.ads
-/home/comar/local/adainclude/s-exctab.ads
-/home/comar/local/adainclude/s-finimp.ads
-/home/comar/local/adainclude/s-finroo.ads
-/home/comar/local/adainclude/s-secsta.ads
-/home/comar/local/adainclude/s-stalib.ads
-/home/comar/local/adainclude/s-stoele.ads
-/home/comar/local/adainclude/s-stratt.ads
-/home/comar/local/adainclude/s-tasoli.ads
-/home/comar/local/adainclude/s-unstyp.ads
-/home/comar/local/adainclude/unchconv.ads
-@end smallexample
-@end ifclear
+@itemize @bullet
-@ifset vms
-@smallexample
-GNAT LIST /DEPENDENCIES /OUTPUT=SOURCES /ALL_UNITS DEMO1.ADB
+@item
+ We consider only pragmas Priority and Interrupt_Priority as means to define
+ a task/protected operation priority. We do not consider the effect of using
+ Ada.Dynamic_Priorities.Set_Priority procedure;
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]ada.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-finali.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-filico.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-stream.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]a-tags.ads
-demo1.adb
-gen_list.ads
-gen_list.adb
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]gnat.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]g-io.ads
-instr.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]system.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-exctab.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-finimp.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-finroo.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-secsta.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-stalib.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-stoele.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-stratt.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-tasoli.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]s-unstyp.ads
-GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB]unchconv.ads
-@end smallexample
-@end ifset
+@item
+ We consider only base task priorities, and no priority inheritance. That is,
+ we do not make a difference between calls issued during task activation and
+ execution of the sequence of statements from task body;
-@node Cleaning Up Using gnatclean
-@chapter Cleaning Up Using @code{gnatclean}
-@findex gnatclean
-@cindex Cleaning tool
+@item
+ Any situation when the priority of protected operation caller is set by a
+ dynamic expression (that is, the corresponding Priority or
+ Interrupt_Priority pragma has a non-static expression as an argument) we
+ treat as a priority inconsistency (and, therefore, detect this situation).
+@end itemize
@noindent
-@code{gnatclean} is a tool that allows the deletion of files produced by the
-compiler, binder and linker, including ALI files, object files, tree files,
-expanded source files, library files, interface copy source files, binder
-generated files and executable files.
+At the moment the notion of the main subprogram is not implemented in
+gnatcheck, so any pragma Priority in a library level subprogram body (in case
+if this subprogram can be a main subprogram of a partition) changes the
+priority of an environment task. So if we have more then one such pragma in
+the set of processed sources, the pragma that is processed last, defines the
+priority of an environment task.
-@menu
-* Running gnatclean::
-* Switches for gnatclean::
-* Examples of gnatclean Usage::
-@end menu
+This rule has no parameters.
+@end ignore
-@node Running gnatclean
-@section Running @code{gnatclean}
+@node Controlled_Type_Declarations
+@subsection @code{Controlled_Type_Declarations}
+@cindex @code{Controlled_Type_Declarations} rule (for @command{gnatcheck})
@noindent
-The @code{gnatclean} command has the form:
+Flag all declarations of controlled types. A declaration of a private type
+is flagged if its full declaration declares a controlled type. A declaration
+of a derived type is flagged if its ancestor type is controlled. Subtype
+declarations are not checked. A declaration of a type that itself is not a
+descendant of a type declared in @code{Ada.Finalization} but has a controlled
+component is not checked.
+
+This rule has no parameters.
-@smallexample
-$ gnatclean switches @var{names}
-@end smallexample
-@noindent
-@var{names} is a list of source file names. Suffixes @code{.^ads^ADS^} and
-@code{^adb^ADB^} may be omitted. If a project file is specified using switch
-@code{^-P^/PROJECT_FILE=^}, then @var{names} may be completely omitted.
+
+@node Declarations_In_Blocks
+@subsection @code{Declarations_In_Blocks}
+@cindex @code{Declarations_In_Blocks} rule (for @command{gnatcheck})
@noindent
-In normal mode, @code{gnatclean} delete the files produced by the compiler and,
-if switch @code{^-c^/COMPILER_FILES_ONLY^} is not specified, by the binder and
-the linker. In informative-only mode, specified by switch
-@code{^-n^/NODELETE^}, the list of files that would have been deleted in
-normal mode is listed, but no file is actually deleted.
+Flag all block statements containing local declarations. A @code{declare}
+block with an empty @i{declarative_part} or with a @i{declarative part}
+containing only pragmas and/or @code{use} clauses is not flagged.
-@node Switches for gnatclean
-@section Switches for @code{gnatclean}
+This rule has no parameters.
+
+
+@node Default_Parameters
+@subsection @code{Default_Parameters}
+@cindex @code{Default_Parameters} rule (for @command{gnatcheck})
@noindent
-@code{gnatclean} recognizes the following switches:
+Flag all default expressions for subprogram parameters. Parameter
+declarations of formal and generic subprograms are also checked.
-@table @option
-@c !sort!
-@item ^-c^/COMPILER_FILES_ONLY^
-@cindex @option{^-c^/COMPILER_FILES_ONLY^} (@code{gnatclean})
-Only attempt to delete the files produced by the compiler, not those produced
-by the binder or the linker. The files that are not to be deleted are library
-files, interface copy files, binder generated files and executable files.
+This rule has no parameters.
-@item ^-D ^/DIRECTORY_OBJECTS=^@var{dir}
-@cindex @option{^-D^/DIRECTORY_OBJECTS^} (@code{gnatclean})
-Indicate that ALI and object files should normally be found in directory
-@var{dir}.
-@item ^-F^/FULL_PATH_IN_BRIEF_MESSAGES^
-@cindex @option{^-F^/FULL_PATH_IN_BRIEF_MESSAGES^} (@code{gnatclean})
-When using project files, if some errors or warnings are detected during
-parsing and verbose mode is not in effect (no use of switch
-^-v^/VERBOSE^), then error lines start with the full path name of the project
-file, rather than its simple file name.
+@node Discriminated_Records
+@subsection @code{Discriminated_Records}
+@cindex @code{Discriminated_Records} rule (for @command{gnatcheck})
-@item ^-h^/HELP^
-@cindex @option{^-h^/HELP^} (@code{gnatclean})
-Output a message explaining the usage of @code{^gnatclean^gnatclean^}.
+@noindent
+Flag all declarations of record types with discriminants. Only the
+declarations of record and record extension types are checked. Incomplete,
+formal, private, derived and private extension type declarations are not
+checked. Task and protected type declarations also are not checked.
-@item ^-n^/NODELETE^
-@cindex @option{^-n^/NODELETE^} (@code{gnatclean})
-Informative-only mode. Do not delete any files. Output the list of the files
-that would have been deleted if this switch was not specified.
+This rule has no parameters.
-@item ^-P^/PROJECT_FILE=^@var{project}
-@cindex @option{^-P^/PROJECT_FILE^} (@code{gnatclean})
-Use project file @var{project}. Only one such switch can be used.
-When cleaning a project file, the files produced by the compilation of the
-immediate sources or inherited sources of the project files are to be
-deleted. This is not depending on the presence or not of executable names
-on the command line.
-@item ^-q^/QUIET^
-@cindex @option{^-q^/QUIET^} (@code{gnatclean})
-Quiet output. If there are no error, do not ouuput anything, except in
-verbose mode (switch ^-v^/VERBOSE^) or in informative-only mode
-(switch ^-n^/NODELETE^).
+@node Enumeration_Ranges_In_CASE_Statements
+@subsection @code{Enumeration_Ranges_In_CASE_Statements}
+@cindex @code{Enumeration_Ranges_In_CASE_Statements} (for @command{gnatcheck})
-@item ^-r^/RECURSIVE^
-@cindex @option{^-r^/RECURSIVE^} (@code{gnatclean})
-When a project file is specified (using switch ^-P^/PROJECT_FILE=^),
-clean all imported and extended project files, recursively. If this switch
-is not specified, only the files related to the main project file are to be
-deleted. This switch has no effect if no project file is specified.
+@noindent
+Flag each use of a range of enumeration literals as a choice in a
+@code{case} statement.
+All forms for specifying a range (explicit ranges
+such as @code{A .. B}, subtype marks and @code{'Range} attributes) are flagged.
+An enumeration range is
+flagged even if contains exactly one enumeration value or no values at all. A
+type derived from an enumeration type is considered as an enumeration type.
-@item ^-v^/VERBOSE^
-@cindex @option{^-v^/VERBOSE^} (@code{gnatclean})
-Verbose mode.
+This rule helps prevent maintenance problems arising from adding an
+enumeration value to a type and having it implicitly handled by an existing
+@code{case} statement with an enumeration range that includes the new literal.
-@item ^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}
-@cindex @option{^-vP^/MESSAGES_PROJECT_FILE^} (@code{gnatclean})
-Indicates the verbosity of the parsing of GNAT project files.
-See @ref{Switches Related to Project Files}.
+This rule has no parameters.
-@item ^-X^/EXTERNAL_REFERENCE=^@var{name=value}
-@cindex @option{^-X^/EXTERNAL_REFERENCE^} (@code{gnatclean})
-Indicates that external variable @var{name} has the value @var{value}.
-The Project Manager will use this value for occurrences of
-@code{external(name)} when parsing the project file.
-See @ref{Switches Related to Project Files}.
-@item ^-aO^/OBJECT_SEARCH=^@var{dir}
-@cindex @option{^-aO^/OBJECT_SEARCH^} (@code{gnatclean})
-When searching for ALI and object files, look in directory
-@var{dir}.
+@node Exceptions_As_Control_Flow
+@subsection @code{Exceptions_As_Control_Flow}
+@cindex @code{Exceptions_As_Control_Flow} (for @command{gnatcheck})
-@item ^-I^/SEARCH=^@var{dir}
-@cindex @option{^-I^/SEARCH^} (@code{gnatclean})
-Equivalent to @option{^-aO^/OBJECT_SEARCH=^@var{dir}}.
+@noindent
+Flag each place where an exception is explicitly raised and handled in the
+same subprogram body. A @code{raise} statement in an exception handler,
+package body, task body or entry body is not flagged.
-@item ^-I-^/NOCURRENT_DIRECTORY^
-@cindex @option{^-I-^/NOCURRENT_DIRECTORY^} (@code{gnatclean})
-@cindex Source files, suppressing search
-Do not look for ALI or object files in the directory
-where @code{gnatclean} was invoked.
+The rule has no parameters.
-@end table
+@node EXIT_Statements_With_No_Loop_Name
+@subsection @code{EXIT_Statements_With_No_Loop_Name}
+@cindex @code{EXIT_Statements_With_No_Loop_Name} (for @command{gnatcheck})
-@node Examples of gnatclean Usage
-@section Examples of @code{gnatclean} Usage
+@noindent
+Flag each @code{exit} statement that does not specify the name of the loop
+being exited.
-@ifclear vms
-@node GNAT and Libraries
-@chapter GNAT and Libraries
-@cindex Library, building, installing, using
+The rule has no parameters.
+
+
+@node Expanded_Loop_Exit_Names
+@subsection @code{Expanded_Loop_Exit_Names}
+@cindex @code{Expanded_Loop_Exit_Names} rule (for @command{gnatcheck})
@noindent
-This chapter describes how to build and use
-libraries with GNAT, and also shows how to recompile the GNAT run-time library.
-You should be familiar with the
-Project Manager facility (see @ref{GNAT Project Manager}) before reading this
-chapter.
+Flag all expanded loop names in @code{exit} statements.
-@menu
-* Introduction to Libraries in GNAT::
-* General Ada Libraries::
-* Stand-alone Ada Libraries::
-* Rebuilding the GNAT Run-Time Library::
-@end menu
+This rule has no parameters.
-@node Introduction to Libraries in GNAT
-@section Introduction to Libraries in GNAT
+@node Explicit_Full_Discrete_Ranges
+@subsection @code{Explicit_Full_Discrete_Ranges}
+@cindex @code{Explicit_Full_Discrete_Ranges} rule (for @command{gnatcheck})
@noindent
-A library is, conceptually, a collection of objects which does not have its
-own main thread of execution, but rather provides certain services to the
-applications that use it. A library can be either statically linked with the
-application, in which case its code is directly included in the application,
-or, on platforms that support it, be dynamically linked, in which case
-its code is shared by all applications making use of this library.
+Flag each discrete range that has the form @code{A'First .. A'Last}.
-GNAT supports both types of libraries.
-In the static case, the compiled code can be provided in different ways.
-The simplest approach is to provide directly the
-set of objects resulting from compilation of the library source files.
-Alternatively, you can group the objects into an archive using whatever
-commands are provided by the operating system. For the latter case,
-the objects are grouped into a shared library.
-
-In the GNAT environment, a library has two types of components:
-@itemize @bullet
-@item
-Source files.
-@item
-Compiled code and @file{ALI} files.
-See @ref{The Ada Library Information Files}.
-@end itemize
+This rule has no parameters.
+
+@node Float_Equality_Checks
+@subsection @code{Float_Equality_Checks}
+@cindex @code{Float_Equality_Checks} rule (for @command{gnatcheck})
@noindent
-A GNAT library may either completely expose its source files to the
-compilation context of the user's application.
-Alternatively, it may expose
-a limited subset of its source files, called @emph{interface units},
-in which case the library is referred to as a @emph{stand-alone library}
-(see @ref{Stand-alone Ada Libraries}). In addition, GNAT fully supports
-foreign libraries, which are only available in the object format.
+Flag all calls to the predefined equality operations for floating-point types.
+Both ``@code{=}'' and ``@code{/=}'' operations are checked.
+User-defined equality operations are not flagged, nor are ``@code{=}''
+and ``@code{/=}'' operations for fixed-point types.
-All compilation units comprising
-an application are elaborated, in an order partially defined by Ada language
-semantics.
-Where possible, GNAT provides facilities
-to ensure that compilation units of a library are automatically elaborated;
-however, there are cases where this must be responsibility of a user. This will
-be addressed in greater detail below.
+This rule has no parameters.
-@node General Ada Libraries
-@section General Ada Libraries
-
-@menu
-* Building the library::
-* Installing the library::
-* Using the library::
-@end menu
-@node Building the library
-@subsection Building the library
+@node Forbidden_Pragmas
+@subsection @code{Forbidden_Pragmas}
+@cindex @code{Forbidden_Pragmas} rule (for @command{gnatcheck})
@noindent
-The easiest way to build a library is to use the Project Manager,
-which supports a special type of projects called Library Projects
-(see @ref{Library Projects}).
+Flag each use of the specified pragmas. The pragmas to be detected
+are named in the rule's parameters.
-A project is considered a library project, when two project-level attributes
-are defined in it: @code{Library_Name} and @code{Library_Dir}. In order to
-control different aspects of library configuration, additional optional
-project-level attributes can be specified:
-@table @code
-@item Library_Kind
-This attribute controls whether the library is to be static or shared
+This rule has the following parameters:
-@item Library_Version
-This attribute specifies what is the library version; this value is used
-during dynamic linking of shared libraries to determine if the currently
-installed versions of the binaries are compatible.
+@itemize @bullet
+@item For the @option{+R} option
-@item Library_Options
-@item Library_GCC
-These attributes specify additional low-level options to be used during
-library generation, and redefine the actual application used to generate
-library.
+@table @asis
+@item @emph{Pragma_Name}
+Adds the specified pragma to the set of pragmas to be
+checked and sets the checks for all the specified pragmas
+ON. @emph{Pragma_Name} is treated as a name of a pragma. If it
+does not correspond to any pragma name defined in the Ada
+standard or to the name of a GNAT-specific pragma defined
+in @ref{Implementation Defined Pragmas,,, gnat_rm, GNAT Reference
+Manual}, it is treated as the name of unknown pragma.
+
+@item @code{GNAT}
+All the GNAT-specific pragmas are detected; this sets
+the checks for all the specified pragmas ON.
+
+@item @code{ALL}
+All pragmas are detected; this sets the rule ON.
+@end table
+
+@item For the @option{-R} option
+@table @asis
+@item @emph{Pragma_Name}
+Removes the specified pragma from the set of pragmas to be
+checked without affecting checks for
+other pragmas. @emph{Pragma_Name} is treated as a name
+of a pragma. If it does not correspond to any pragma
+defined in the Ada standard or to any name defined in
+@ref{Implementation Defined Pragmas,,, gnat_rm, GNAT Reference Manual},
+this option is treated as turning OFF detection of all unknown pragmas.
+
+@item GNAT
+Turn OFF detection of all GNAT-specific pragmas
+
+@item ALL
+Clear the list of the pragmas to be detected and
+turn the rule OFF.
@end table
+@end itemize
@noindent
-The GNAT Project Manager takes full care of the library maintenance task,
-including recompilation of the source files for which objects do not exist
-or are not up to date, assembly of the library archive, and installation of
-the library, i.e. copying associated source, object and @file{ALI} files
-to the specified location.
+Parameters are not case sensitive. If @emph{Pragma_Name} does not have
+the syntax of an Ada identifier and therefore can not be considered
+as a pragma name, a diagnostic message is generated and the corresponding
+parameter is ignored.
-It is not entirely trivial to correctly perform all the steps required to
-produce a library. We recommend that you use the GNAT Project Manager
-for this task. In special cases where this is not desired, the necessary
-steps are discussed below.
+When more then one parameter is given in the same rule option, the parameters
+must be separated by a comma.
-There are various possibilities for compiling the units that make up the
-library: for example with a Makefile (see @ref{Using the GNU make Utility})
-or with a conventional script.
-For simple libraries, it is also possible to create a
-dummy main program which depends upon all the packages that comprise the
-interface of the library. This dummy main program can then be given to
-@command{gnatmake}, which will ensure that all necessary objects are built.
+If more then one option for this rule is specified for the @command{gnatcheck}
+call, a new option overrides the previous one(s).
-After this task is accomplished, you should follow the standard procedure
-of the underlying operating system to produce the static or shared library.
+The @option{+R} option with no parameters turns the rule ON with the set of
+pragmas to be detected defined by the previous rule options.
+(By default this set is empty, so if the only option specified for the rule is
+@option{+RForbidden_Pragmas} (with
+no parameter), then the rule is enabled, but it does not detect anything).
+The @option{-R} option with no parameter turns the rule OFF, but it does not
+affect the set of pragmas to be detected.
-Here is an example of such a dummy program:
-@smallexample @c ada
-@group
-with My_Lib.Service1;
-with My_Lib.Service2;
-with My_Lib.Service3;
-procedure My_Lib_Dummy is
-begin
- null;
-end;
-@end group
-@end smallexample
-@noindent
-Here are the generic commands that will build an archive or a shared library.
-@smallexample
-# compiling the library
-$ gnatmake -c my_lib_dummy.adb
-# we don't need the dummy object itself
-$ rm my_lib_dummy.o my_lib_dummy.ali
+@node Function_Style_Procedures
+@subsection @code{Function_Style_Procedures}
+@cindex @code{Function_Style_Procedures} rule (for @command{gnatcheck})
-# create an archive with the remaining objects
-$ ar rc libmy_lib.a *.o
-# some systems may require "ranlib" to be run as well
+@noindent
+Flag each procedure that can be rewritten as a function. A procedure can be
+converted into a function if it has exactly one parameter of mode @code{out}
+and no parameters of mode @code{in out}. Procedure declarations,
+formal procedure declarations, and generic procedure declarations are always
+checked. Procedure
+bodies and body stubs are flagged only if they do not have corresponding
+separate declarations. Procedure renamings and procedure instantiations are
+not flagged.
-# or create a shared library
-$ gcc -shared -o libmy_lib.so *.o
-# some systems may require the code to have been compiled with -fPIC
+If a procedure can be rewritten as a function, but its @code{out} parameter is
+of a limited type, it is not flagged.
-# remove the object files that are now in the library
-$ rm *.o
+Protected procedures are not flagged. Null procedures also are not flagged.
-# Make the ALI files read-only so that gnatmake will not try to
-# regenerate the objects that are in the library
-$ chmod -w *.ali
-@end smallexample
+This rule has no parameters.
-@noindent
-Please note that the library must have a name of the form @file{libxxx.a} or
-@file{libxxx.so} in order to be accessed by the directive @option{-lxxx}
-at link time.
-@node Installing the library
-@subsection Installing the library
+@node Generics_In_Subprograms
+@subsection @code{Generics_In_Subprograms}
+@cindex @code{Generics_In_Subprograms} rule (for @command{gnatcheck})
@noindent
-In the GNAT model, installing a library consists in copying into a specific
-location the files that make up this library. When the library is built using
-projects, it is automatically installed in the location specified in the
-project by means of the attribute @code{Library_Dir},
-otherwise the user must specify the destination.
-GNAT also supports installing the sources in a
-different directory from the other files (@file{ALI}, objects, archives)
-since the source path and the object path can be specified separately.
+Flag each declaration of a generic unit in a subprogram. Generic
+declarations in the bodies of generic subprograms are also flagged.
+A generic unit nested in another generic unit is not flagged.
+If a generic unit is
+declared in a local package that is declared in a subprogram body, the
+generic unit is flagged.
-The system administrator can place general purpose libraries in the default
-compiler paths, by specifying the libraries' location in the configuration
-files @file{ada_source_path} and @file{ada_object_path}.
-These configuration files must be located in the GNAT
-installation tree at the same place as the gcc spec file. The location of
-the gcc spec file can be determined as follows:
-@smallexample
-$ gcc -v
-@end smallexample
+This rule has no parameters.
-@noindent
-The configuration files mentioned above have a simple format: each line
-must contain one unique directory name.
-Those names are added to the corresponding path
-in their order of appearance in the file. The names can be either absolute
-or relative; in the latter case, they are relative to where theses files
-are located.
-The files @file{ada_source_path} and @file{ada_object_path} might not be
-present in a
-GNAT installation, in which case, GNAT will look for its run-time library in
-the directories @file{adainclude} (for the sources) and @file{adalib} (for the
-objects and @file{ALI} files). When the files exist, the compiler does not
-look in @file{adainclude} and @file{adalib}, and thus the
-@file{ada_source_path} file
-must contain the location for the GNAT run-time sources (which can simply
-be @file{adainclude}). In the same way, the @file{ada_object_path} file must
-contain the location for the GNAT run-time objects (which can simply
-be @file{adalib}).
+@node GOTO_Statements
+@subsection @code{GOTO_Statements}
+@cindex @code{GOTO_Statements} rule (for @command{gnatcheck})
-You can also specify a new default path to the run-time library at compilation
-time with the switch @option{--RTS=rts-path}. You can thus choose / change
-the run-time library you want your program to be compiled with. This switch is
-recognized by @command{gcc}, @command{gnatmake}, @command{gnatbind},
-@command{gnatls}, @command{gnatfind} and @command{gnatxref}.
+@noindent
+Flag each occurrence of a @code{goto} statement.
-It is possible to install a library before or after the standard GNAT
-library, by reordering the lines in the configuration files. In general, a
-library must be installed before the GNAT library if it redefines
-any part of it.
+This rule has no parameters.
-@node Using the library
-@subsection Using the library
+@node Implicit_IN_Mode_Parameters
+@subsection @code{Implicit_IN_Mode_Parameters}
+@cindex @code{Implicit_IN_Mode_Parameters} rule (for @command{gnatcheck})
@noindent
-Once again, the project facility greatly simplifies the addition of libraries
-to the compilation. If the project file for an application lists a library
-project in its @code{with} clause, the Project Manager will ensure that the
-library files are consistent, and that they are considered during the
-compilation and linking of the application.
+Flag each occurrence of a formal parameter with an implicit @code{in} mode.
+Note that @code{access} parameters, although they technically behave
+like @code{in} parameters, are not flagged.
-Even if you have a third-party, non-Ada library, you can still use GNAT's
-Project Manager facility to provide a wrapper for it. The following project for
-example, when @code{with}ed in your main project, will link with the
-third-party library @file{liba.a}:
+This rule has no parameters.
-@smallexample @c projectfile
-@group
-project Liba is
- for Source_Dirs use ();
- for Library_Dir use "lib";
- for Library_Name use "a";
- for Library_Kind use "static";
-end Liba;
-@end group
-@end smallexample
+
+@node Implicit_SMALL_For_Fixed_Point_Types
+@subsection @code{Implicit_SMALL_For_Fixed_Point_Types}
+@cindex @code{Implicit_SMALL_For_Fixed_Point_Types} rule (for @command{gnatcheck})
@noindent
-In order to use an Ada library manually, you need to make sure that this
-library is on both your source and object path
-(see @ref{Search Paths and the Run-Time Library (RTL)},
-and @ref{Search Paths for gnatbind}). Furthermore, when the objects are grouped
-in an archive or a shared library, you need to specify the desired
-library at link time.
+Flag each fixed point type declaration that lacks an explicit
+representation clause to define its @code{'Small} value.
+Since @code{'Small} can be defined only for ordinary fixed point types,
+decimal fixed point type declarations are not checked.
-For example, you can use the library @file{mylib} installed in
-@file{/dir/my_lib_src} and @file{/dir/my_lib_obj} with the following commands:
+This rule has no parameters.
-@smallexample
-$ gnatmake -aI/dir/my_lib_src -aO/dir/my_lib_obj my_appl \
- -largs -lmy_lib
-@end smallexample
+
+@node Improperly_Located_Instantiations
+@subsection @code{Improperly_Located_Instantiations}
+@cindex @code{Improperly_Located_Instantiations} rule (for @command{gnatcheck})
@noindent
-This can be expressed more simply:
-@smallexample
-$ gnatmake my_appl
-@end smallexample
+Flag all generic instantiations in library-level package specs
+(including library generic packages) and in all subprogram bodies.
+
+Instantiations in task and entry bodies are not flagged. Instantiations in the
+bodies of protected subprograms are flagged.
+
+This rule has no parameters.
+
+
+
+@node Improper_Returns
+@subsection @code{Improper_Returns}
+@cindex @code{Improper_Returns} rule (for @command{gnatcheck})
+
@noindent
-when the following conditions are met:
-@itemize @bullet
-@item
-@file{/dir/my_lib_src} has been added by the user to the environment
-variable @code{ADA_INCLUDE_PATH}, or by the administrator to the file
-@file{ada_source_path}
-@item
-@file{/dir/my_lib_obj} has been added by the user to the environment
-variable @code{ADA_OBJECTS_PATH}, or by the administrator to the file
-@file{ada_object_path}
-@item
-a pragma @code{Linker_Options} has been added to one of the sources.
-For example:
+Flag each explicit @code{return} statement in procedures, and
+multiple @code{return} statements in functions.
+Diagnostic messages are generated for all @code{return} statements
+in a procedure (thus each procedure must be written so that it
+returns implicitly at the end of its statement part),
+and for all @code{return} statements in a function after the first one.
+This rule supports the stylistic convention that each subprogram
+should have no more than one point of normal return.
-@smallexample @c ada
-pragma Linker_Options ("-lmy_lib");
-@end smallexample
-@end itemize
+This rule has no parameters.
-@node Stand-alone Ada Libraries
-@section Stand-alone Ada Libraries
-@cindex Stand-alone library, building, using
+@node Library_Level_Subprograms
+@subsection @code{Library_Level_Subprograms}
+@cindex @code{Library_Level_Subprograms} rule (for @command{gnatcheck})
-@menu
-* Introduction to Stand-alone Libraries::
-* Building a Stand-alone Library::
-* Creating a Stand-alone Library to be used in a non-Ada context::
-* Restrictions in Stand-alone Libraries::
-@end menu
+@noindent
+Flag all library-level subprograms (including generic subprogram instantiations).
+
+This rule has no parameters.
-@node Introduction to Stand-alone Libraries
-@subsection Introduction to Stand-alone Libraries
+
+@node Local_Packages
+@subsection @code{Local_Packages}
+@cindex @code{Local_Packages} rule (for @command{gnatcheck})
@noindent
-A Stand-alone Library (SAL) is a library that contains the necessary code to
-elaborate the Ada units that are included in the library. In contrast with
-an ordinary library, which consists of all sources, objects and @file{ALI}
-files of the
-library, a SAL may specify a restricted subset of compilation units
-to serve as a library interface. In this case, the fully
-self-sufficient set of files will normally consist of an objects
-archive, the sources of interface units' specs, and the @file{ALI}
-files of interface units.
-If an interface spec contains a generic unit or an inlined subprogram,
-the body's
-source must also be provided; if the units that must be provided in the source
-form depend on other units, the source and @file{ALI} files of those must
-also be provided.
+Flag all local packages declared in package and generic package
+specs.
+Local packages in bodies are not flagged.
-The main purpose of a SAL is to minimize the recompilation overhead of client
-applications when a new version of the library is installed. Specifically,
-if the interface sources have not changed, client applications do not need to
-be recompiled. If, furthermore, a SAL is provided in the shared form and its
-version, controlled by @code{Library_Version} attribute, is not changed,
-then the clients do not need to be relinked.
+This rule has no parameters.
-SALs also allow the library providers to minimize the amount of library source
-text exposed to the clients. Such ``information hiding'' might be useful or
-necessary for various reasons.
+@ignore
+@node Improperly_Called_Protected_Entries
+@subsection @code{Improperly_Called_Protected_Entries} (under construction, GLOBAL)
+@cindex @code{Improperly_Called_Protected_Entries} rule (for @command{gnatcheck})
-Stand-alone libraries are also well suited to be used in an executable whose
-main routine is not written in Ada.
+@noindent
+Flag each protected entry that can be called from more than one task.
-@node Building a Stand-alone Library
-@subsection Building a Stand-alone Library
+This rule has no parameters.
+@end ignore
+
+@node Metrics
+@subsection @code{Metrics}
+@cindex @code{Metrics} rule (for @command{gnatcheck})
+
+@noindent
+There is a set of checks based on computing a metric value and comparing the
+result with the specified upper (or lower, depending on a specific metric)
+value specified for a given metric. A construct is flagged if a given metric
+is applicable (can be computed) for it and the computed value is greater
+then (lover then) the specified upper (lower) bound.
+
+The name of any metric-based rule consists of the prefix @code{Metrics_}
+followed by the name of the corresponding metric (see the table below).
+For @option{+R} option, each metric-based rule has a numeric parameter
+specifying the bound (integer or real, depending on a metric), @option{-R}
+option for metric rules does not have a parameter.
+
+The following table shows the metric names for that the corresponding
+metrics-based checks are supported by gnatcheck, including the
+constraint that must be satisfied by the bound that is specified for the check
+and what bound - upper (U) or lower (L) - should be specified.
+
+@multitable {@code{Cyclomatic_Complexity}}{Cyclomatic complexity}{Positive integer}
+@ifnothtml
+@headitem Check Name @tab Description @tab Bounds Value
+@end ifnothtml
+@ifhtml
+@item @b{Check Name} @tab @b{Description} @tab @b{Bounds Value}
+@end ifhtml
+@c Above conditional code is workaround to bug in texi2html (Feb 2008)
+@item @code{Essential_Complexity} @tab Essential complexity @tab Positive integer (U)
+@item @code{Cyclomatic_Complexity} @tab Cyclomatic complexity @tab Positive integer (U)
+@item @code{LSLOC} @tab Logical Source Lines of Code @tab Positive integer (U)
+@end multitable
@noindent
-GNAT's Project facility provides a simple way of building and installing
-stand-alone libraries; see @ref{Stand-alone Library Projects}.
-To be a Stand-alone Library Project, in addition to the two attributes
-that make a project a Library Project (@code{Library_Name} and
-@code{Library_Dir}; see @ref{Library Projects}), the attribute
-@code{Library_Interface} must be defined. For example:
+The meaning and the computed values for all these metrics are exactly
+the same as for the corresponding metrics in @command{gnatmetric}.
-@smallexample @c projectfile
-@group
- for Library_Dir use "lib_dir";
- for Library_Name use "dummy";
- for Library_Interface use ("int1", "int1.child");
-@end group
+@emph{Example:} the rule
+@smallexample
++RMetrics_Cyclomatic_Complexity : 7
@end smallexample
-
@noindent
-Attribute @code{Library_Interface} has a non empty string list value,
-each string in the list designating a unit contained in an immediate source
-of the project file.
+means that all bodies with cyclomatic complexity exceeding 7 will be flagged.
-When a Stand-alone Library is built, first the binder is invoked to build
-a package whose name depends on the library name
-(@file{^b~dummy.ads/b^B$DUMMY.ADS/B^} in the example above).
-This binder-generated package includes initialization and
-finalization procedures whose
-names depend on the library name (@code{dummyinit} and @code{dummyfinal}
-in the example
-above). The object corresponding to this package is included in the library.
+To turn OFF the check for cyclomatic complexity metric, use the following option:
+@smallexample
+-RMetrics_Cyclomatic_Complexity
+@end smallexample
-You must ensure timely (e.g., prior to any use of interfaces in the SAL)
-calling of these procedures if a static SAL is built, or if a shared SAL
-is built
-with the project-level attribute @code{Library_Auto_Init} set to
-@code{"false"}.
+@node Misnamed_Identifiers
+@subsection @code{Misnamed_Identifiers}
+@cindex @code{Misnamed_Identifiers} rule (for @command{gnatcheck})
-For a Stand-Alone Library, only the @file{ALI} files of the Interface Units
-(those that are listed in attribute @code{Library_Interface}) are copied to
-the Library Directory. As a consequence, only the Interface Units may be
-imported from Ada units outside of the library. If other units are imported,
-the binding phase will fail.
+@noindent
+Flag the declaration of each identifier that does not have a suffix
+corresponding to the kind of entity being declared.
+The following declarations are checked:
-The attribute @code{Library_Src_Dir} may be specified for a
-Stand-Alone Library. @code{Library_Src_Dir} is a simple attribute that has a
-single string value. Its value must be the path (absolute or relative to the
-project directory) of an existing directory. This directory cannot be the
-object directory or one of the source directories, but it can be the same as
-the library directory. The sources of the Interface
-Units of the library that are needed by an Ada client of the library will be
-copied to the designated directory, called the Interface Copy directory.
-These sources includes the specs of the Interface Units, but they may also
-include bodies and subunits, when pragmas @code{Inline} or @code{Inline_Always}
-are used, or when there is a generic unit in the spec. Before the sources
-are copied to the Interface Copy directory, an attempt is made to delete all
-files in the Interface Copy directory.
+@itemize @bullet
+@item
+type declarations
+
+@item
+constant declarations (but not number declarations)
+
+@item
+package renaming declarations (but not generic package renaming
+declarations)
+@end itemize
+
+@noindent
+This rule may have parameters. When used without parameters, the rule enforces
+the following checks:
-Building stand-alone libraries by hand is somewhat tedious, but for those
-occasions when it is necessary here are the steps that you need to perform:
@itemize @bullet
@item
-Compile all library sources.
-
+type-defining names end with @code{_T}, unless the type is an access type,
+in which case the suffix must be @code{_A}
@item
-Invoke the binder with the switch @option{-n} (No Ada main program),
-with all the @file{ALI} files of the interfaces, and
-with the switch @option{-L} to give specific names to the @code{init}
-and @code{final} procedures. For example:
-@smallexample
- gnatbind -n int1.ali int2.ali -Lsal1
-@end smallexample
-
+constant names end with @code{_C}
@item
-Compile the binder generated file:
-@smallexample
- gcc -c b~int2.adb
-@end smallexample
+names defining package renamings end with @code{_R}
+@end itemize
+@noindent
+For a private or incomplete type declaration the following checks are
+made for the defining name suffix:
+
+@itemize @bullet
@item
-Link the dynamic library with all the necessary object files,
-indicating to the linker the names of the @code{init} (and possibly
-@code{final}) procedures for automatic initialization (and finalization).
-The built library should be placed in a directory different from
-the object directory.
+For an incomplete type declaration: if the corresponding full type
+declaration is available, the defining identifier from the full type
+declaration is checked, but the defining identifier from the incomplete type
+declaration is not; otherwise the defining identifier from the incomplete
+type declaration is checked against the suffix specified for type
+declarations.
@item
-Copy the @code{ALI} files of the interface to the library directory,
-add in this copy an indication that it is an interface to a SAL
-(i.e. add a word @option{SL} on the line in the @file{ALI} file that starts
-with letter ``P'') and make the modified copy of the @file{ALI} file
-read-only.
+For a private type declaration (including private extensions), the defining
+identifier from the private type declaration is checked against the type
+suffix (even if the corresponding full declaration is an access type
+declaration), and the defining identifier from the corresponding full type
+declaration is not checked.
@end itemize
@noindent
-Using SALs is not different from using other libraries
-(see @ref{Using the library}).
+For a deferred constant, the defining name in the corresponding full constant
+declaration is not checked.
-@node Creating a Stand-alone Library to be used in a non-Ada context
-@subsection Creating a Stand-alone Library to be used in a non-Ada context
+Defining names of formal types are not checked.
-@noindent
-It is easy to adapt the SAL build procedure discussed above for use of a SAL in
-a non-Ada context.
+The rule may have the following parameters:
-The only extra step required is to ensure that library interface subprograms
-are compatible with the main program, by means of @code{pragma Export}
-or @code{pragma Convention}.
+@itemize @bullet
+@item
+For the @option{+R} option:
+@table @code
+@item Default
+Sets the default listed above for all the names to be checked.
-Here is an example of simple library interface for use with C main program:
+@item Type_Suffix=@emph{string}
+Specifies the suffix for a type name.
-@smallexample @c ada
-package Interface is
+@item Access_Suffix=@emph{string}
+Specifies the suffix for an access type name. If
+this parameter is set, it overrides for access
+types the suffix set by the @code{Type_Suffix} parameter.
- procedure Do_Something;
- pragma Export (C, Do_Something, "do_something");
+@item Constant_Suffix=@emph{string}
+Specifies the suffix for a constant name.
- procedure Do_Something_Else;
- pragma Export (C, Do_Something_Else, "do_something_else");
+@item Renaming_Suffix=@emph{string}
+Specifies the suffix for a package renaming name.
+@end table
-end Interface;
-@end smallexample
+@item
+For the @option{-R} option:
+@table @code
+@item All_Suffixes
+Remove all the suffixes specified for the
+identifier suffix checks, whether by default or
+as specified by other rule parameters. All the
+checks for this rule are disabled as a result.
+
+@item Type_Suffix
+Removes the suffix specified for types. This
+disables checks for types but does not disable
+any other checks for this rule (including the
+check for access type names if @code{Access_Suffix} is
+set).
+
+@item Access_Suffix
+Removes the suffix specified for access types.
+This disables checks for access type names but
+does not disable any other checks for this rule.
+If @code{Type_Suffix} is set, access type names are
+checked as ordinary type names.
+
+@item Constant_Suffix
+Removes the suffix specified for constants. This
+disables checks for constant names but does not
+disable any other checks for this rule.
+
+@item Renaming_Suffix
+Removes the suffix specified for package
+renamings. This disables checks for package
+renamings but does not disable any other checks
+for this rule.
+@end table
+@end itemize
@noindent
-On the foreign language side, you must provide a ``foreign'' view of the
-library interface; remember that it should contain elaboration routines in
-addition to interface subprograms.
+If more than one parameter is used, parameters must be separated by commas.
-The example below shows the content of @code{mylib_interface.h} (note
-that there is no rule for the naming of this file, any name can be used)
-@smallexample
-/* the library elaboration procedure */
-extern void mylibinit (void);
+If more than one option is specified for the @command{gnatcheck} invocation,
+a new option overrides the previous one(s).
-/* the library finalization procedure */
-extern void mylibfinal (void);
+The @option{+RMisnamed_Identifiers} option (with no parameter) enables
+checks for all the
+name suffixes specified by previous options used for this rule.
-/* the interface exported by the library */
-extern void do_something (void);
-extern void do_something_else (void);
-@end smallexample
+The @option{-RMisnamed_Identifiers} option (with no parameter) disables
+all the checks but keeps
+all the suffixes specified by previous options used for this rule.
-@noindent
-Libraries built as explained above can be used from any program, provided
-that the elaboration procedures (named @code{mylibinit} in the previous
-example) are called before the library services are used. Any number of
-libraries can be used simultaneously, as long as the elaboration
-procedure of each library is called.
+The @emph{string} value must be a valid suffix for an Ada identifier (after
+trimming all the leading and trailing space characters, if any).
+Parameters are not case sensitive, except the @emph{string} part.
-Below is an example of C program that uses the @code{mylib} library.
+If any error is detected in a rule parameter, the parameter is ignored.
+In such a case the options that are set for the rule are not
+specified.
-@smallexample
-#include "mylib_interface.h"
-int
-main (void)
-@{
- /* First, elaborate the library before using it */
- mylibinit ();
- /* Main program, using the library exported entities */
- do_something ();
- do_something_else ();
+@node Multiple_Entries_In_Protected_Definitions
+@subsection @code{Multiple_Entries_In_Protected_Definitions}
+@cindex @code{Multiple_Entries_In_Protected_Definitions} rule (for @command{gnatcheck})
- /* Library finalization at the end of the program */
- mylibfinal ();
- return 0;
-@}
-@end smallexample
+@noindent
+Flag each protected definition (i.e., each protected object/type declaration)
+that defines more than one entry.
+Diagnostic messages are generated for all the entry declarations
+except the first one. An entry family is counted as one entry. Entries from
+the private part of the protected definition are also checked.
+
+This rule has no parameters.
+
+@node Name_Clashes
+@subsection @code{Name_Clashes}
+@cindex @code{Name_Clashes} rule (for @command{gnatcheck})
@noindent
-Note that invoking any library finalization procedure generated by
-@code{gnatbind} shuts down the Ada run-time environment.
-Consequently, the
-finalization of all Ada libraries must be performed at the end of the program.
-No call to these libraries nor to the Ada run-time library should be made
-after the finalization phase.
+Check that certain names are not used as defining identifiers. To activate
+this rule, you need to supply a reference to the dictionary file(s) as a rule
+parameter(s) (more then one dictionary file can be specified). If no
+dictionary file is set, this rule will not cause anything to be flagged.
+Only defining occurrences, not references, are checked.
+The check is not case-sensitive.
-@node Restrictions in Stand-alone Libraries
-@subsection Restrictions in Stand-alone Libraries
+This rule is enabled by default, but without setting any corresponding
+dictionary file(s); thus the default effect is to do no checks.
+
+A dictionary file is a plain text file. The maximum line length for this file
+is 1024 characters. If the line is longer then this limit, extra characters
+are ignored.
+
+Each line can be either an empty line, a comment line, or a line containing
+a list of identifiers separated by space or HT characters.
+A comment is an Ada-style comment (from @code{--} to end-of-line).
+Identifiers must follow the Ada syntax for identifiers.
+A line containing one or more identifiers may end with a comment.
+
+@node Non_Qualified_Aggregates
+@subsection @code{Non_Qualified_Aggregates}
+@cindex @code{Non_Qualified_Aggregates} rule (for @command{gnatcheck})
@noindent
-The pragmas listed below should be used with caution inside libraries,
-as they can create incompatibilities with other Ada libraries:
-@itemize @bullet
-@item pragma @code{Locking_Policy}
-@item pragma @code{Queuing_Policy}
-@item pragma @code{Task_Dispatching_Policy}
-@item pragma @code{Unreserve_All_Interrupts}
-@end itemize
+Flag each non-qualified aggregate.
+A non-qualified aggregate is an
+aggregate that is not the expression of a qualified expression. A
+string literal is not considered an aggregate, but an array
+aggregate of a string type is considered as a normal aggregate.
+Aggregates of anonymous array types are not flagged.
+
+This rule has no parameters.
+
+
+@node Non_Short_Circuit_Operators
+@subsection @code{Non_Short_Circuit_Operators}
+@cindex @code{Non_Short_Circuit_Operators} rule (for @command{gnatcheck})
@noindent
-When using a library that contains such pragmas, the user must make sure
-that all libraries use the same pragmas with the same values. Otherwise,
-@code{Program_Error} will
-be raised during the elaboration of the conflicting
-libraries. The usage of these pragmas and its consequences for the user
-should therefore be well documented.
+Flag all calls to predefined @code{and} and @code{or} operators for
+any boolean type. Calls to
+user-defined @code{and} and @code{or} and to operators defined by renaming
+declarations are not flagged. Calls to predefined @code{and} and @code{or}
+operators for modular types or boolean array types are not flagged.
-Similarly, the traceback in the exception occurrence mechanism should be
-enabled or disabled in a consistent manner across all libraries.
-Otherwise, Program_Error will be raised during the elaboration of the
-conflicting libraries.
+This rule has no parameters.
-If the @code{Version} or @code{Body_Version}
-attributes are used inside a library, then you need to
-perform a @code{gnatbind} step that specifies all @file{ALI} files in all
-libraries, so that version identifiers can be properly computed.
-In practice these attributes are rarely used, so this is unlikely
-to be a consideration.
-@node Rebuilding the GNAT Run-Time Library
-@section Rebuilding the GNAT Run-Time Library
-@cindex GNAT Run-Time Library, rebuilding
+
+@node Non_SPARK_Attributes
+@subsection @code{Non_SPARK_Attributes}
+@cindex @code{Non_SPARK_Attributes} rule (for @command{gnatcheck})
@noindent
-It may be useful to recompile the GNAT library in various contexts, the
-most important one being the use of partition-wide configuration pragmas
-such as @code{Normalize_Scalars}. A special Makefile called
-@code{Makefile.adalib} is provided to that effect and can be found in
-the directory containing the GNAT library. The location of this
-directory depends on the way the GNAT environment has been installed and can
-be determined by means of the command:
+The SPARK language defines the following subset of Ada 95 attribute
+designators as those that can be used in SPARK programs. The use of
+any other attribute is flagged.
-@smallexample
-$ gnatls -v
-@end smallexample
+@itemize @bullet
+@item @code{'Adjacent}
+@item @code{'Aft}
+@item @code{'Base}
+@item @code{'Ceiling}
+@item @code{'Component_Size}
+@item @code{'Compose}
+@item @code{'Copy_Sign}
+@item @code{'Delta}
+@item @code{'Denorm}
+@item @code{'Digits}
+@item @code{'Exponent}
+@item @code{'First}
+@item @code{'Floor}
+@item @code{'Fore}
+@item @code{'Fraction}
+@item @code{'Last}
+@item @code{'Leading_Part}
+@item @code{'Length}
+@item @code{'Machine}
+@item @code{'Machine_Emax}
+@item @code{'Machine_Emin}
+@item @code{'Machine_Mantissa}
+@item @code{'Machine_Overflows}
+@item @code{'Machine_Radix}
+@item @code{'Machine_Rounds}
+@item @code{'Max}
+@item @code{'Min}
+@item @code{'Model}
+@item @code{'Model_Emin}
+@item @code{'Model_Epsilon}
+@item @code{'Model_Mantissa}
+@item @code{'Model_Small}
+@item @code{'Modulus}
+@item @code{'Pos}
+@item @code{'Pred}
+@item @code{'Range}
+@item @code{'Remainder}
+@item @code{'Rounding}
+@item @code{'Safe_First}
+@item @code{'Safe_Last}
+@item @code{'Scaling}
+@item @code{'Signed_Zeros}
+@item @code{'Size}
+@item @code{'Small}
+@item @code{'Succ}
+@item @code{'Truncation}
+@item @code{'Unbiased_Rounding}
+@item @code{'Val}
+@item @code{'Valid}
+@end itemize
@noindent
-The last entry in the object search path usually contains the
-gnat library. This Makefile contains its own documentation and in
-particular the set of instructions needed to rebuild a new library and
-to use it.
+This rule has no parameters.
-@node Using the GNU make Utility
-@chapter Using the GNU @code{make} Utility
-@findex make
+@node Non_Tagged_Derived_Types
+@subsection @code{Non_Tagged_Derived_Types}
+@cindex @code{Non_Tagged_Derived_Types} rule (for @command{gnatcheck})
@noindent
-This chapter offers some examples of makefiles that solve specific
-problems. It does not explain how to write a makefile (see the GNU make
-documentation), nor does it try to replace the @code{gnatmake} utility
-(@pxref{The GNAT Make Program gnatmake}).
+Flag all derived type declarations that do not have a record extension part.
-All the examples in this section are specific to the GNU version of
-make. Although @code{make} is a standard utility, and the basic language
-is the same, these examples use some advanced features found only in
-@code{GNU make}.
+This rule has no parameters.
-@menu
-* Using gnatmake in a Makefile::
-* Automatically Creating a List of Directories::
-* Generating the Command Line Switches::
-* Overcoming Command Line Length Limits::
-@end menu
-@node Using gnatmake in a Makefile
-@section Using gnatmake in a Makefile
-@findex makefile
-@cindex GNU make
+
+@node Non_Visible_Exceptions
+@subsection @code{Non_Visible_Exceptions}
+@cindex @code{Non_Visible_Exceptions} rule (for @command{gnatcheck})
@noindent
-Complex project organizations can be handled in a very powerful way by
-using GNU make combined with gnatmake. For instance, here is a Makefile
-which allows you to build each subsystem of a big project into a separate
-shared library. Such a makefile allows you to significantly reduce the link
-time of very big applications while maintaining full coherence at
-each step of the build process.
+Flag constructs leading to the possibility of propagating an exception
+out of the scope in which the exception is declared.
+Two cases are detected:
-The list of dependencies are handled automatically by
-@code{gnatmake}. The Makefile is simply used to call gnatmake in each of
-the appropriate directories.
+@itemize @bullet
+@item
+An exception declaration in a subprogram body, task body or block
+statement is flagged if the body or statement does not contain a handler for
+that exception or a handler with an @code{others} choice.
-Note that you should also read the example on how to automatically
-create the list of directories
-(@pxref{Automatically Creating a List of Directories})
-which might help you in case your project has a lot of subdirectories.
+@item
+A @code{raise} statement in an exception handler of a subprogram body,
+task body or block statement is flagged if it (re)raises a locally
+declared exception. This may occur under the following circumstances:
+@itemize @minus
+@item
+it explicitly raises a locally declared exception, or
+@item
+it does not specify an exception name (i.e., it is simply @code{raise;})
+and the enclosing handler contains a locally declared exception in its
+exception choices.
+@end itemize
+@end itemize
-@smallexample
-@iftex
-@leftskip=0cm
-@font@heightrm=cmr8
-@heightrm
-@end iftex
-## This Makefile is intended to be used with the following directory
-## configuration:
-## - The sources are split into a series of csc (computer software components)
-## Each of these csc is put in its own directory.
-## Their name are referenced by the directory names.
-## They will be compiled into shared library (although this would also work
-## with static libraries
-## - The main program (and possibly other packages that do not belong to any
-## csc is put in the top level directory (where the Makefile is).
-## toplevel_dir __ first_csc (sources) __ lib (will contain the library)
-## \_ second_csc (sources) __ lib (will contain the library)
-## \_ ...
-## Although this Makefile is build for shared library, it is easy to modify
-## to build partial link objects instead (modify the lines with -shared and
-## gnatlink below)
-##
-## With this makefile, you can change any file in the system or add any new
-## file, and everything will be recompiled correctly (only the relevant shared
-## objects will be recompiled, and the main program will be re-linked).
+@noindent
+Renamings of local exceptions are not flagged.
-# The list of computer software component for your project. This might be
-# generated automatically.
-CSC_LIST=aa bb cc
+This rule has no parameters.
-# Name of the main program (no extension)
-MAIN=main
-# If we need to build objects with -fPIC, uncomment the following line
-#NEED_FPIC=-fPIC
+@node Numeric_Literals
+@subsection @code{Numeric_Literals}
+@cindex @code{Numeric_Literals} rule (for @command{gnatcheck})
-# The following variable should give the directory containing libgnat.so
-# You can get this directory through 'gnatls -v'. This is usually the last
-# directory in the Object_Path.
-GLIB=...
+@noindent
+Flag each use of a numeric literal in an index expression, and in any
+circumstance except for the following:
-# The directories for the libraries
-# (This macro expands the list of CSC to the list of shared libraries, you
-# could simply use the expanded form :
-# LIB_DIR=aa/lib/libaa.so bb/lib/libbb.so cc/lib/libcc.so
-LIB_DIR=$@{foreach dir,$@{CSC_LIST@},$@{dir@}/lib/lib$@{dir@}.so@}
+@itemize @bullet
+@item
+a literal occurring in the initialization expression for a constant
+declaration or a named number declaration, or
-$@{MAIN@}: objects $@{LIB_DIR@}
- gnatbind $@{MAIN@} $@{CSC_LIST:%=-aO%/lib@} -shared
- gnatlink $@{MAIN@} $@{CSC_LIST:%=-l%@}
+@item
+an integer literal that is less than or equal to a value
+specified by the @option{N} rule parameter.
+@end itemize
-objects::
- # recompile the sources
- gnatmake -c -i $@{MAIN@}.adb $@{NEED_FPIC@} $@{CSC_LIST:%=-I%@}
+@noindent
+This rule may have the following parameters for the @option{+R} option:
-# Note: In a future version of GNAT, the following commands will be simplified
-# by a new tool, gnatmlib
-$@{LIB_DIR@}:
- mkdir -p $@{dir $@@ @}
- cd $@{dir $@@ @}; gcc -shared -o $@{notdir $@@ @} ../*.o -L$@{GLIB@} -lgnat
- cd $@{dir $@@ @}; cp -f ../*.ali .
+@table @asis
+@item @emph{N}
+@emph{N} is an integer literal used as the maximal value that is not flagged
+(i.e., integer literals not exceeding this value are allowed)
-# The dependencies for the modules
-# Note that we have to force the expansion of *.o, since in some cases
-# make won't be able to do it itself.
-aa/lib/libaa.so: $@{wildcard aa/*.o@}
-bb/lib/libbb.so: $@{wildcard bb/*.o@}
-cc/lib/libcc.so: $@{wildcard cc/*.o@}
+@item @code{ALL}
+All integer literals are flagged
+@end table
-# Make sure all of the shared libraries are in the path before starting the
-# program
-run::
- LD_LIBRARY_PATH=`pwd`/aa/lib:`pwd`/bb/lib:`pwd`/cc/lib ./$@{MAIN@}
+@noindent
+If no parameters are set, the maximum unflagged value is 1.
-clean::
- $@{RM@} -rf $@{CSC_LIST:%=%/lib@}
- $@{RM@} $@{CSC_LIST:%=%/*.ali@}
- $@{RM@} $@{CSC_LIST:%=%/*.o@}
- $@{RM@} *.o *.ali $@{MAIN@}
-@end smallexample
+The last specified check limit (or the fact that there is no limit at
+all) is used when multiple @option{+R} options appear.
-@node Automatically Creating a List of Directories
-@section Automatically Creating a List of Directories
+The @option{-R} option for this rule has no parameters.
+It disables the rule but retains the last specified maximum unflagged value.
+If the @option{+R} option subsequently appears, this value is used as the
+threshold for the check.
+
+
+@node OTHERS_In_Aggregates
+@subsection @code{OTHERS_In_Aggregates}
+@cindex @code{OTHERS_In_Aggregates} rule (for @command{gnatcheck})
@noindent
-In most makefiles, you will have to specify a list of directories, and
-store it in a variable. For small projects, it is often easier to
-specify each of them by hand, since you then have full control over what
-is the proper order for these directories, which ones should be
-included...
+Flag each use of an @code{others} choice in extension aggregates.
+In record and array aggregates, an @code{others} choice is flagged unless
+it is used to refer to all components, or to all but one component.
-However, in larger projects, which might involve hundreds of
-subdirectories, it might be more convenient to generate this list
-automatically.
+If, in case of a named array aggregate, there are two associations, one
+with an @code{others} choice and another with a discrete range, the
+@code{others} choice is flagged even if the discrete range specifies
+exactly one component; for example, @code{(1..1 => 0, others => 1)}.
-The example below presents two methods. The first one, although less
-general, gives you more control over the list. It involves wildcard
-characters, that are automatically expanded by @code{make}. Its
-shortcoming is that you need to explicitly specify some of the
-organization of your project, such as for instance the directory tree
-depth, whether some directories are found in a separate tree,...
+This rule has no parameters.
-The second method is the most general one. It requires an external
-program, called @code{find}, which is standard on all Unix systems. All
-the directories found under a given root directory will be added to the
-list.
+@node OTHERS_In_CASE_Statements
+@subsection @code{OTHERS_In_CASE_Statements}
+@cindex @code{OTHERS_In_CASE_Statements} rule (for @command{gnatcheck})
-@smallexample
-@iftex
-@leftskip=0cm
-@font@heightrm=cmr8
-@heightrm
-@end iftex
-# The examples below are based on the following directory hierarchy:
-# All the directories can contain any number of files
-# ROOT_DIRECTORY -> a -> aa -> aaa
-# -> ab
-# -> ac
-# -> b -> ba -> baa
-# -> bb
-# -> bc
-# This Makefile creates a variable called DIRS, that can be reused any time
-# you need this list (see the other examples in this section)
+@noindent
+Flag any use of an @code{others} choice in a @code{case} statement.
-# The root of your project's directory hierarchy
-ROOT_DIRECTORY=.
+This rule has no parameters.
-####
-# First method: specify explicitly the list of directories
-# This allows you to specify any subset of all the directories you need.
-####
+@node OTHERS_In_Exception_Handlers
+@subsection @code{OTHERS_In_Exception_Handlers}
+@cindex @code{OTHERS_In_Exception_Handlers} rule (for @command{gnatcheck})
-DIRS := a/aa/ a/ab/ b/ba/
+@noindent
+Flag any use of an @code{others} choice in an exception handler.
-####
-# Second method: use wildcards
-# Note that the argument(s) to wildcard below should end with a '/'.
-# Since wildcards also return file names, we have to filter them out
-# to avoid duplicate directory names.
-# We thus use make's @code{dir} and @code{sort} functions.
-# It sets DIRs to the following value (note that the directories aaa and baa
-# are not given, unless you change the arguments to wildcard).
-# DIRS= ./a/a/ ./b/ ./a/aa/ ./a/ab/ ./a/ac/ ./b/ba/ ./b/bb/ ./b/bc/
-####
+This rule has no parameters.
-DIRS := $@{sort $@{dir $@{wildcard $@{ROOT_DIRECTORY@}/*/
- $@{ROOT_DIRECTORY@}/*/*/@}@}@}
-####
-# Third method: use an external program
-# This command is much faster if run on local disks, avoiding NFS slowdowns.
-# This is the most complete command: it sets DIRs to the following value:
-# DIRS= ./a ./a/aa ./a/aa/aaa ./a/ab ./a/ac ./b ./b/ba ./b/ba/baa ./b/bb ./b/bc
-####
+@node Outer_Loop_Exits
+@subsection @code{Outer_Loop_Exits}
+@cindex @code{Outer_Loop_Exits} rule (for @command{gnatcheck})
-DIRS := $@{shell find $@{ROOT_DIRECTORY@} -type d -print@}
+@noindent
+Flag each @code{exit} statement containing a loop name that is not the name
+of the immediately enclosing @code{loop} statement.
-@end smallexample
+This rule has no parameters.
-@node Generating the Command Line Switches
-@section Generating the Command Line Switches
+
+@node Overloaded_Operators
+@subsection @code{Overloaded_Operators}
+@cindex @code{Overloaded_Operators} rule (for @command{gnatcheck})
@noindent
-Once you have created the list of directories as explained in the
-previous section (@pxref{Automatically Creating a List of Directories}),
-you can easily generate the command line arguments to pass to gnatmake.
+Flag each function declaration that overloads an operator symbol.
+A function body is checked only if the body does not have a
+separate spec. Formal functions are also checked. For a
+renaming declaration, only renaming-as-declaration is checked
-For the sake of completeness, this example assumes that the source path
-is not the same as the object path, and that you have two separate lists
-of directories.
+This rule has no parameters.
-@smallexample
-# see "Automatically creating a list of directories" to create
-# these variables
-SOURCE_DIRS=
-OBJECT_DIRS=
-GNATMAKE_SWITCHES := $@{patsubst %,-aI%,$@{SOURCE_DIRS@}@}
-GNATMAKE_SWITCHES += $@{patsubst %,-aO%,$@{OBJECT_DIRS@}@}
+@node Overly_Nested_Control_Structures
+@subsection @code{Overly_Nested_Control_Structures}
+@cindex @code{Overly_Nested_Control_Structures} rule (for @command{gnatcheck})
-all:
- gnatmake $@{GNATMAKE_SWITCHES@} main_unit
-@end smallexample
+@noindent
+Flag each control structure whose nesting level exceeds the value provided
+in the rule parameter.
-@node Overcoming Command Line Length Limits
-@section Overcoming Command Line Length Limits
+The control structures checked are the following:
+
+@itemize @bullet
+@item @code{if} statement
+@item @code{case} statement
+@item @code{loop} statement
+@item Selective accept statement
+@item Timed entry call statement
+@item Conditional entry call
+@item Asynchronous select statement
+@end itemize
@noindent
-One problem that might be encountered on big projects is that many
-operating systems limit the length of the command line. It is thus hard to give
-gnatmake the list of source and object directories.
+The rule has the following parameter for the @option{+R} option:
-This example shows how you can set up environment variables, which will
-make @code{gnatmake} behave exactly as if the directories had been
-specified on the command line, but have a much higher length limit (or
-even none on most systems).
+@table @emph
+@item N
+Positive integer specifying the maximal control structure nesting
+level that is not flagged
+@end table
-It assumes that you have created a list of directories in your Makefile,
-using one of the methods presented in
-@ref{Automatically Creating a List of Directories}.
-For the sake of completeness, we assume that the object
-path (where the ALI files are found) is different from the sources patch.
+@noindent
+If the parameter for the @option{+R} option is not specified or
+if it is not a positive integer, @option{+R} option is ignored.
-Note a small trick in the Makefile below: for efficiency reasons, we
-create two temporary variables (SOURCE_LIST and OBJECT_LIST), that are
-expanded immediately by @code{make}. This way we overcome the standard
-make behavior which is to expand the variables only when they are
-actually used.
+If more then one option is specified for the gnatcheck call, the later option and
+new parameter override the previous one(s).
-On Windows, if you are using the standard Windows command shell, you must
-replace colons with semicolons in the assignments to these variables.
-@smallexample
-@iftex
-@leftskip=0cm
-@font@heightrm=cmr8
-@heightrm
-@end iftex
-# In this example, we create both ADA_INCLUDE_PATH and ADA_OBJECT_PATH.
-# This is the same thing as putting the -I arguments on the command line.
-# (the equivalent of using -aI on the command line would be to define
-# only ADA_INCLUDE_PATH, the equivalent of -aO is ADA_OBJECT_PATH).
-# You can of course have different values for these variables.
-#
-# Note also that we need to keep the previous values of these variables, since
-# they might have been set before running 'make' to specify where the GNAT
-# library is installed.
+@node Parameters_Out_Of_Order
+@subsection @code{Parameters_Out_Of_Order}
+@cindex @code{Parameters_Out_Of_Order} rule (for @command{gnatcheck})
-# see "Automatically creating a list of directories" to create these
-# variables
-SOURCE_DIRS=
-OBJECT_DIRS=
+@noindent
+Flag each subprogram and entry declaration whose formal parameters are not
+ordered according to the following scheme:
-empty:=
-space:=$@{empty@} $@{empty@}
-SOURCE_LIST := $@{subst $@{space@},:,$@{SOURCE_DIRS@}@}
-OBJECT_LIST := $@{subst $@{space@},:,$@{OBJECT_DIRS@}@}
-ADA_INCLUDE_PATH += $@{SOURCE_LIST@}
-ADA_OBJECT_PATH += $@{OBJECT_LIST@}
-export ADA_INCLUDE_PATH
-export ADA_OBJECT_PATH
+@itemize @bullet
-all:
- gnatmake main_unit
-@end smallexample
-@end ifclear
+@item @code{in} and @code{access} parameters first,
+then @code{in out} parameters,
+and then @code{out} parameters;
+
+@item for @code{in} mode, parameters with default initialization expressions
+occur last
+@end itemize
+
+@noindent
+Only the first violation of the described order is flagged.
+The following constructs are checked:
-@node Finding Memory Problems
-@chapter Finding Memory Problems
+@itemize @bullet
+@item subprogram declarations (including null procedures);
+@item generic subprogram declarations;
+@item formal subprogram declarations;
+@item entry declarations;
+@item subprogram bodies and subprogram body stubs that do not
+have separate specifications
+@end itemize
@noindent
-This chapter describes
-@ifclear vms
-the @command{gnatmem} tool, which can be used to track down
-``memory leaks'', and
-@end ifclear
-the GNAT Debug Pool facility, which can be used to detect incorrect uses of
-access values (including ``dangling references'').
+Subprogram renamings are not checked.
-@menu
-@ifclear vms
-* The gnatmem Tool::
-@end ifclear
-* The GNAT Debug Pool Facility::
-@end menu
+This rule has no parameters.
-@ifclear vms
-@node The gnatmem Tool
-@section The @command{gnatmem} Tool
-@findex gnatmem
+@node Positional_Actuals_For_Defaulted_Generic_Parameters
+@subsection @code{Positional_Actuals_For_Defaulted_Generic_Parameters}
+@cindex @code{Positional_Actuals_For_Defaulted_Generic_Parameters} rule (for @command{gnatcheck})
@noindent
-The @code{gnatmem} utility monitors dynamic allocation and
-deallocation activity in a program, and displays information about
-incorrect deallocations and possible sources of memory leaks.
-It provides three type of information:
-@itemize @bullet
-@item
-General information concerning memory management, such as the total
-number of allocations and deallocations, the amount of allocated
-memory and the high water mark, i.e. the largest amount of allocated
-memory in the course of program execution.
+Flag each generic actual parameter corresponding to a generic formal
+parameter with a default initialization, if positional notation is used.
-@item
-Backtraces for all incorrect deallocations, that is to say deallocations
-which do not correspond to a valid allocation.
+This rule has no parameters.
-@item
-Information on each allocation that is potentially the origin of a memory
-leak.
-@end itemize
+@node Positional_Actuals_For_Defaulted_Parameters
+@subsection @code{Positional_Actuals_For_Defaulted_Parameters}
+@cindex @code{Positional_Actuals_For_Defaulted_Parameters} rule (for @command{gnatcheck})
-@menu
-* Running gnatmem::
-* Switches for gnatmem::
-* Example of gnatmem Usage::
-@end menu
+@noindent
+Flag each actual parameter to a subprogram or entry call where the
+corresponding formal parameter has a default expression, if positional
+notation is used.
-@node Running gnatmem
-@subsection Running @code{gnatmem}
+This rule has no parameters.
+
+@node Positional_Components
+@subsection @code{Positional_Components}
+@cindex @code{Positional_Components} rule (for @command{gnatcheck})
@noindent
-@code{gnatmem} makes use of the output created by the special version of
-allocation and deallocation routines that record call information. This
-allows to obtain accurate dynamic memory usage history at a minimal cost to
-the execution speed. Note however, that @code{gnatmem} is not supported on
-all platforms (currently, it is supported on AIX, HP-UX, GNU/Linux x86,
-Solaris (sparc and x86) and Windows NT/2000/XP (x86).
+Flag each array, record and extension aggregate that includes positional
+notation.
+
+This rule has no parameters.
+
+
+@node Positional_Generic_Parameters
+@subsection @code{Positional_Generic_Parameters}
+@cindex @code{Positional_Generic_Parameters} rule (for @command{gnatcheck})
@noindent
-The @code{gnatmem} command has the form
+Flag each instantiation using positional parameter notation.
+
+This rule has no parameters.
-@smallexample
- $ gnatmem [switches] user_program
-@end smallexample
+
+@node Positional_Parameters
+@subsection @code{Positional_Parameters}
+@cindex @code{Positional_Parameters} rule (for @command{gnatcheck})
@noindent
-The program must have been linked with the instrumented version of the
-allocation and deallocation routines. This is done by linking with the
-@file{libgmem.a} library. For correct symbolic backtrace information,
-the user program should be compiled with debugging options
-@ref{Switches for gcc}. For example to build @file{my_program}:
+Flag each subprogram or entry call using positional parameter notation,
+except for the following:
-@smallexample
-$ gnatmake -g my_program -largs -lgmem
-@end smallexample
+@itemize @bullet
+@item
+Invocations of prefix or infix operators are not flagged
+@item
+If the called subprogram or entry has only one formal parameter,
+the call is not flagged;
+@item
+If a subprogram call uses the @emph{Object.Operation} notation, then
+@itemize @minus
+@item
+the first parameter (that is, @emph{Object}) is not flagged;
+@item
+if the called subprogram has only two parameters, the second parameter
+of the call is not flagged;
+@end itemize
+@end itemize
@noindent
-When running @file{my_program} the file @file{gmem.out} is produced. This file
-contains information about all allocations and deallocations done by the
-program. It is produced by the instrumented allocations and
-deallocations routines and will be used by @code{gnatmem}.
+This rule has no parameters.
+
+
+
+
+@node Predefined_Numeric_Types
+@subsection @code{Predefined_Numeric_Types}
+@cindex @code{Predefined_Numeric_Types} rule (for @command{gnatcheck})
@noindent
-Gnatmem must be supplied with the @file{gmem.out} file and the executable to
-examine. If the location of @file{gmem.out} file was not explicitly supplied by
-@code{-i} switch, gnatmem will assume that this file can be found in the
-current directory. For example, after you have executed @file{my_program},
-@file{gmem.out} can be analyzed by @code{gnatmem} using the command:
+Flag each explicit use of the name of any numeric type or subtype defined
+in package @code{Standard}.
-@smallexample
-$ gnatmem my_program
+The rationale for this rule is to detect when the
+program may depend on platform-specific characteristics of the implementation
+of the predefined numeric types. Note that this rule is over-pessimistic;
+for example, a program that uses @code{String} indexing
+likely needs a variable of type @code{Integer}.
+Another example is the flagging of predefined numeric types with explicit
+constraints:
+
+@smallexample @c ada
+ subtype My_Integer is Integer range Left .. Right;
+ Vy_Var : My_Integer;
@end smallexample
@noindent
-This will produce the output with the following format:
+This rule detects only numeric types and subtypes defined in
+@code{Standard}. The use of numeric types and subtypes defined in other
+predefined packages (such as @code{System.Any_Priority} or
+@code{Ada.Text_IO.Count}) is not flagged
-*************** debut cc
-@smallexample
-$ gnatmem my_program
+This rule has no parameters.
-Global information
-------------------
- Total number of allocations : 45
- Total number of deallocations : 6
- Final Water Mark (non freed mem) : 11.29 Kilobytes
- High Water Mark : 11.40 Kilobytes
-.
-.
-.
-Allocation Root # 2
--------------------
- Number of non freed allocations : 11
- Final Water Mark (non freed mem) : 1.16 Kilobytes
- High Water Mark : 1.27 Kilobytes
- Backtrace :
- my_program.adb:23 my_program.alloc
-.
-.
-.
-@end smallexample
-The first block of output gives general information. In this case, the
-Ada construct ``@code{@b{new}}'' was executed 45 times, and only 6 calls to an
-Unchecked_Deallocation routine occurred.
+@node Raising_External_Exceptions
+@subsection @code{Raising_External_Exceptions}
+@cindex @code{Raising_External_Exceptions} rule (for @command{gnatcheck})
+
+@noindent
+Flag any @code{raise} statement, in a program unit declared in a library
+package or in a generic library package, for an exception that is
+neither a predefined exception nor an exception that is also declared (or
+renamed) in the visible part of the package.
+
+This rule has no parameters.
+
+
+
+@node Raising_Predefined_Exceptions
+@subsection @code{Raising_Predefined_Exceptions}
+@cindex @code{Raising_Predefined_Exceptions} rule (for @command{gnatcheck})
@noindent
-Subsequent paragraphs display information on all allocation roots.
-An allocation root is a specific point in the execution of the program
-that generates some dynamic allocation, such as a ``@code{@b{new}}''
-construct. This root is represented by an execution backtrace (or subprogram
-call stack). By default the backtrace depth for allocations roots is 1, so
-that a root corresponds exactly to a source location. The backtrace can
-be made deeper, to make the root more specific.
+Flag each @code{raise} statement that raises a predefined exception
+(i.e., one of the exceptions @code{Constraint_Error}, @code{Numeric_Error},
+@code{Program_Error}, @code{Storage_Error}, or @code{Tasking_Error}).
-@node Switches for gnatmem
-@subsection Switches for @code{gnatmem}
+This rule has no parameters.
+
+@node Separate_Numeric_Error_Handlers
+@subsection @code{Separate_Numeric_Error_Handlers}
+@cindex @code{Separate_Numeric_Error_Handlers} rule (for @command{gnatcheck})
@noindent
-@code{gnatmem} recognizes the following switches:
+Flags each exception handler that contains a choice for
+the predefined @code{Constraint_Error} exception, but does not contain
+the choice for the predefined @code{Numeric_Error} exception, or
+that contains the choice for @code{Numeric_Error}, but does not contain the
+choice for @code{Constraint_Error}.
-@table @option
+This rule has no parameters.
-@item -q
-@cindex @option{-q} (@code{gnatmem})
-Quiet. Gives the minimum output needed to identify the origin of the
-memory leaks. Omits statistical information.
+@ignore
+@node Recursion
+@subsection @code{Recursion} (under construction, GLOBAL)
+@cindex @code{Recursion} rule (for @command{gnatcheck})
-@item @var{N}
-@cindex @var{N} (@code{gnatmem})
-N is an integer literal (usually between 1 and 10) which controls the
-depth of the backtraces defining allocation root. The default value for
-N is 1. The deeper the backtrace, the more precise the localization of
-the root. Note that the total number of roots can depend on this
-parameter. This parameter must be specified @emph{before} the name of the
-executable to be analyzed, to avoid ambiguity.
+@noindent
+Flag recursive subprograms (cycles in the call graph). Declarations, and not
+calls, of recursive subprograms are detected.
-@item -b n
-@cindex @option{-b} (@code{gnatmem})
-This switch has the same effect as just depth parameter.
+This rule has no parameters.
+@end ignore
-@item -i @var{file}
-@cindex @option{-i} (@code{gnatmem})
-Do the @code{gnatmem} processing starting from @file{file}, rather than
-@file{gmem.out} in the current directory.
+@ignore
+@node Side_Effect_Functions
+@subsection @code{Side_Effect_Functions} (under construction, GLOBAL)
+@cindex @code{Side_Effect_Functions} rule (for @command{gnatcheck})
-@item -m n
-@cindex @option{-m} (@code{gnatmem})
-This switch causes @code{gnatmem} to mask the allocation roots that have less
-than n leaks. The default value is 1. Specifying the value of 0 will allow to
-examine even the roots that didn't result in leaks.
+@noindent
+Flag functions with side effects.
-@item -s order
-@cindex @option{-s} (@code{gnatmem})
-This switch causes @code{gnatmem} to sort the allocation roots according to the
-specified order of sort criteria, each identified by a single letter. The
-currently supported criteria are @code{n, h, w} standing respectively for
-number of unfreed allocations, high watermark, and final watermark
-corresponding to a specific root. The default order is @code{nwh}.
+We define a side effect as changing any data object that is not local for the
+body of this function.
-@end table
+At the moment, we do NOT consider a side effect any input-output operations
+(changing a state or a content of any file).
-@node Example of gnatmem Usage
-@subsection Example of @code{gnatmem} Usage
+We do not consider protected functions for this rule (???)
-@noindent
-The following example shows the use of @code{gnatmem}
-on a simple memory-leaking program.
-Suppose that we have the following Ada program:
+There are the following sources of side effect:
-@smallexample @c ada
-@group
-@cartouche
-with Unchecked_Deallocation;
-procedure Test_Gm is
+@enumerate
+@item Explicit (or direct) side-effect:
- type T is array (1..1000) of Integer;
- type Ptr is access T;
- procedure Free is new Unchecked_Deallocation (T, Ptr);
- A : Ptr;
+@itemize @bullet
+@item
+direct assignment to a non-local variable;
- procedure My_Alloc is
- begin
- A := new T;
- end My_Alloc;
+@item
+direct call to an entity that is known to change some data object that is
+ not local for the body of this function (Note, that if F1 calls F2 and F2
+ does have a side effect, this does not automatically mean that F1 also
+ have a side effect, because it may be the case that F2 is declared in
+ F1's body and it changes some data object that is global for F2, but
+ local for F1);
+@end itemize
- procedure My_DeAlloc is
- B : Ptr := A;
- begin
- Free (B);
- end My_DeAlloc;
+@item Indirect side-effect:
+@itemize @bullet
+@item
+Subprogram calls implicitly issued by:
+@itemize @bullet
+@item
+computing initialization expressions from type declarations as a part
+ of object elaboration or allocator evaluation;
+@item
+computing implicit parameters of subprogram or entry calls or generic
+ instantiations;
+@end itemize
-begin
- My_Alloc;
- for I in 1 .. 5 loop
- for J in I .. 5 loop
- My_Alloc;
- end loop;
- My_Dealloc;
- end loop;
-end;
-@end cartouche
-@end group
-@end smallexample
+@item
+activation of a task that change some non-local data object (directly or
+ indirectly);
-@noindent
-The program needs to be compiled with debugging option and linked with
-@code{gmem} library:
+@item
+elaboration code of a package that is a result of a package instantiation;
-@smallexample
-$ gnatmake -g test_gm -largs -lgmem
-@end smallexample
+@item
+controlled objects;
+@end itemize
+
+@item Situations when we can suspect a side-effect, but the full static check
+is either impossible or too hard:
+@itemize @bullet
+@item
+assignment to access variables or to the objects pointed by access
+ variables;
+
+@item
+call to a subprogram pointed by access-to-subprogram value
+
+@item
+dispatching calls;
+@end itemize
+@end enumerate
@noindent
-Then we execute the program as usual:
+This rule has no parameters.
+@end ignore
-@smallexample
-$ test_gm
-@end smallexample
+@node Slices
+@subsection @code{Slices}
+@cindex @code{Slices} rule (for @command{gnatcheck})
@noindent
-Then @code{gnatmem} is invoked simply with
-@smallexample
-$ gnatmem test_gm
-@end smallexample
+Flag all uses of array slicing
+
+This rule has no parameters.
+
+
+@node Unassigned_OUT_Parameters
+@subsection @code{Unassigned_OUT_Parameters}
+@cindex @code{Unassigned_OUT_Parameters} rule (for @command{gnatcheck})
@noindent
-which produces the following output (result may vary on different platforms):
+Flags procedures' @code{out} parameters that are not assigned, and
+identifies the contexts in which the assignments are missing.
-@smallexample
-Global information
-------------------
- Total number of allocations : 18
- Total number of deallocations : 5
- Final Water Mark (non freed mem) : 53.00 Kilobytes
- High Water Mark : 56.90 Kilobytes
+An @code{out} parameter is flagged in the statements in the procedure
+body's handled sequence of statements (before the procedure body's
+@code{exception} part, if any) if this sequence of statements contains
+no assignments to the parameter.
-Allocation Root # 1
--------------------
- Number of non freed allocations : 11
- Final Water Mark (non freed mem) : 42.97 Kilobytes
- High Water Mark : 46.88 Kilobytes
- Backtrace :
- test_gm.adb:11 test_gm.my_alloc
+An @code{out} parameter is flagged in an exception handler in the exception
+part of the procedure body's handled sequence of statements if the handler
+contains no assignment to the parameter.
-Allocation Root # 2
--------------------
- Number of non freed allocations : 1
- Final Water Mark (non freed mem) : 10.02 Kilobytes
- High Water Mark : 10.02 Kilobytes
- Backtrace :
- s-secsta.adb:81 system.secondary_stack.ss_init
+Bodies of generic procedures are also considered.
-Allocation Root # 3
--------------------
- Number of non freed allocations : 1
- Final Water Mark (non freed mem) : 12 Bytes
- High Water Mark : 12 Bytes
- Backtrace :
- s-secsta.adb:181 system.secondary_stack.ss_init
-@end smallexample
+The following are treated as assignments to an @code{out} parameter:
-@noindent
-Note that the GNAT run time contains itself a certain number of
-allocations that have no corresponding deallocation,
-as shown here for root #2 and root
-#3. This is a normal behavior when the number of non freed allocations
-is one, it allocates dynamic data structures that the run time needs for
-the complete lifetime of the program. Note also that there is only one
-allocation root in the user program with a single line back trace:
-test_gm.adb:11 test_gm.my_alloc, whereas a careful analysis of the
-program shows that 'My_Alloc' is called at 2 different points in the
-source (line 21 and line 24). If those two allocation roots need to be
-distinguished, the backtrace depth parameter can be used:
+@itemize @bullet
+@item
+an assignment statement, with the parameter or some component as the target;
-@smallexample
-$ gnatmem 3 test_gm
-@end smallexample
+@item
+passing the parameter (or one of its components) as an @code{out} or
+@code{in out} parameter.
+@end itemize
@noindent
-which will give the following output:
+This rule does not have any parameters.
-@smallexample
-Global information
-------------------
- Total number of allocations : 18
- Total number of deallocations : 5
- Final Water Mark (non freed mem) : 53.00 Kilobytes
- High Water Mark : 56.90 Kilobytes
-Allocation Root # 1
--------------------
- Number of non freed allocations : 10
- Final Water Mark (non freed mem) : 39.06 Kilobytes
- High Water Mark : 42.97 Kilobytes
- Backtrace :
- test_gm.adb:11 test_gm.my_alloc
- test_gm.adb:24 test_gm
- b_test_gm.c:52 main
-Allocation Root # 2
--------------------
- Number of non freed allocations : 1
- Final Water Mark (non freed mem) : 10.02 Kilobytes
- High Water Mark : 10.02 Kilobytes
- Backtrace :
- s-secsta.adb:81 system.secondary_stack.ss_init
- s-secsta.adb:283 <system__secondary_stack___elabb>
- b_test_gm.c:33 adainit
+@node Uncommented_BEGIN_In_Package_Bodies
+@subsection @code{Uncommented_BEGIN_In_Package_Bodies}
+@cindex @code{Uncommented_BEGIN_In_Package_Bodies} rule (for @command{gnatcheck})
-Allocation Root # 3
--------------------
- Number of non freed allocations : 1
- Final Water Mark (non freed mem) : 3.91 Kilobytes
- High Water Mark : 3.91 Kilobytes
- Backtrace :
- test_gm.adb:11 test_gm.my_alloc
- test_gm.adb:21 test_gm
- b_test_gm.c:52 main
+@noindent
+Flags each package body with declarations and a statement part that does not
+include a trailing comment on the line containing the @code{begin} keyword;
+this trailing comment needs to specify the package name and nothing else.
+The @code{begin} is not flagged if the package body does not
+contain any declarations.
-Allocation Root # 4
--------------------
- Number of non freed allocations : 1
- Final Water Mark (non freed mem) : 12 Bytes
- High Water Mark : 12 Bytes
- Backtrace :
- s-secsta.adb:181 system.secondary_stack.ss_init
- s-secsta.adb:283 <system__secondary_stack___elabb>
- b_test_gm.c:33 adainit
-@end smallexample
+If the @code{begin} keyword is placed on the
+same line as the last declaration or the first statement, it is flagged
+independently of whether the line contains a trailing comment. The
+diagnostic message is attached to the line containing the first statement.
-@noindent
-The allocation root #1 of the first example has been split in 2 roots #1
-and #3 thanks to the more precise associated backtrace.
+This rule has no parameters.
-@end ifclear
+@node Unconstrained_Array_Returns
+@subsection @code{Unconstrained_Array_Returns}
+@cindex @code{Unconstrained_Array_Returns} rule (for @command{gnatcheck})
-@node The GNAT Debug Pool Facility
-@section The GNAT Debug Pool Facility
-@findex Debug Pool
-@cindex storage, pool, memory corruption
+@noindent
+Flag each function returning an unconstrained array. Function declarations,
+function bodies (and body stubs) having no separate specifications,
+and generic function instantiations are checked.
+Generic function declarations, function calls and function renamings are
+not checked.
+
+This rule has no parameters.
+
+@node Universal_Ranges
+@subsection @code{Universal_Ranges}
+@cindex @code{Universal_Ranges} rule (for @command{gnatcheck})
@noindent
-The use of unchecked deallocation and unchecked conversion can easily
-lead to incorrect memory references. The problems generated by such
-references are usually difficult to tackle because the symptoms can be
-very remote from the origin of the problem. In such cases, it is
-very helpful to detect the problem as early as possible. This is the
-purpose of the Storage Pool provided by @code{GNAT.Debug_Pools}.
+Flag discrete ranges that are a part of an index constraint, constrained
+array definition, or @code{for}-loop parameter specification, and whose bounds
+are both of type @i{universal_integer}. Ranges that have at least one
+bound of a specific type (such as @code{1 .. N}, where @code{N} is a variable
+or an expression of non-universal type) are not flagged.
-In order to use the GNAT specific debugging pool, the user must
-associate a debug pool object with each of the access types that may be
-related to suspected memory problems. See Ada Reference Manual 13.11.
-@smallexample @c ada
-type Ptr is access Some_Type;
-Pool : GNAT.Debug_Pools.Debug_Pool;
-for Ptr'Storage_Pool use Pool;
-@end smallexample
+This rule has no parameters.
+
+
+@node Unnamed_Blocks_And_Loops
+@subsection @code{Unnamed_Blocks_And_Loops}
+@cindex @code{Unnamed_Blocks_And_Loops} rule (for @command{gnatcheck})
@noindent
-@code{GNAT.Debug_Pools} is derived from a GNAT-specific kind of
-pool: the @code{Checked_Pool}. Such pools, like standard Ada storage pools,
-allow the user to redefine allocation and deallocation strategies. They
-also provide a checkpoint for each dereference, through the use of
-the primitive operation @code{Dereference} which is implicitly called at
-each dereference of an access value.
+Flag each unnamed block statement and loop statement.
+
+The rule has no parameters.
-Once an access type has been associated with a debug pool, operations on
-values of the type may raise four distinct exceptions,
-which correspond to four potential kinds of memory corruption:
-@itemize @bullet
-@item
-@code{GNAT.Debug_Pools.Accessing_Not_Allocated_Storage}
-@item
-@code{GNAT.Debug_Pools.Accessing_Deallocated_Storage}
-@item
-@code{GNAT.Debug_Pools.Freeing_Not_Allocated_Storage}
-@item
-@code{GNAT.Debug_Pools.Freeing_Deallocated_Storage }
-@end itemize
+
+
+@ignore
+@node Unused_Subprograms
+@subsection @code{Unused_Subprograms} (under construction, GLOBAL)
+@cindex @code{Unused_Subprograms} rule (for @command{gnatcheck})
@noindent
-For types associated with a Debug_Pool, dynamic allocation is performed using
-the standard
-GNAT allocation routine. References to all allocated chunks of memory
-are kept in an internal dictionary.
-Several deallocation strategies are provided, whereupon the user can choose
-to release the memory to the system, keep it allocated for further invalid
-access checks, or fill it with an easily recognizable pattern for debug
-sessions.
-The memory pattern is the old IBM hexadecimal convention: @code{16#DEADBEEF#}.
+Flag all unused subprograms.
-See the documentation in the file g-debpoo.ads for more information on the
-various strategies.
+This rule has no parameters.
+@end ignore
-Upon each dereference, a check is made that the access value denotes a
-properly allocated memory location. Here is a complete example of use of
-@code{Debug_Pools}, that includes typical instances of memory corruption:
-@smallexample @c ada
-@iftex
-@leftskip=0cm
-@end iftex
-with Gnat.Io; use Gnat.Io;
-with Unchecked_Deallocation;
-with Unchecked_Conversion;
-with GNAT.Debug_Pools;
-with System.Storage_Elements;
-with Ada.Exceptions; use Ada.Exceptions;
-procedure Debug_Pool_Test is
- type T is access Integer;
- type U is access all T;
- P : GNAT.Debug_Pools.Debug_Pool;
- for T'Storage_Pool use P;
- procedure Free is new Unchecked_Deallocation (Integer, T);
- function UC is new Unchecked_Conversion (U, T);
- A, B : aliased T;
+@node USE_PACKAGE_Clauses
+@subsection @code{USE_PACKAGE_Clauses}
+@cindex @code{USE_PACKAGE_Clauses} rule (for @command{gnatcheck})
- procedure Info is new GNAT.Debug_Pools.Print_Info(Put_Line);
+@noindent
+Flag all @code{use} clauses for packages; @code{use type} clauses are
+not flagged.
-begin
- Info (P);
- A := new Integer;
- B := new Integer;
- B := A;
- Info (P);
- Free (A);
- begin
- Put_Line (Integer'Image(B.all));
- exception
- when E : others => Put_Line ("raised: " & Exception_Name (E));
- end;
- begin
- Free (B);
- exception
- when E : others => Put_Line ("raised: " & Exception_Name (E));
- end;
- B := UC(A'Access);
- begin
- Put_Line (Integer'Image(B.all));
- exception
- when E : others => Put_Line ("raised: " & Exception_Name (E));
- end;
- begin
- Free (B);
- exception
- when E : others => Put_Line ("raised: " & Exception_Name (E));
- end;
- Info (P);
-end Debug_Pool_Test;
-@end smallexample
+This rule has no parameters.
+
+
+
+@node Volatile_Objects_Without_Address_Clauses
+@subsection @code{Volatile_Objects_Without_Address_Clauses}
+@cindex @code{Volatile_Objects_Without_Address_Clauses} rule (for @command{gnatcheck})
@noindent
-The debug pool mechanism provides the following precise diagnostics on the
-execution of this erroneous program:
-@smallexample
-Debug Pool info:
- Total allocated bytes : 0
- Total deallocated bytes : 0
- Current Water Mark: 0
- High Water Mark: 0
+Flag each volatile object that does not have an address clause.
-Debug Pool info:
- Total allocated bytes : 8
- Total deallocated bytes : 0
- Current Water Mark: 8
- High Water Mark: 8
+The following check is made: if the pragma @code{Volatile} is applied to a
+data object or to its type, then an address clause must
+be supplied for this object.
-raised: GNAT.DEBUG_POOLS.ACCESSING_DEALLOCATED_STORAGE
-raised: GNAT.DEBUG_POOLS.FREEING_DEALLOCATED_STORAGE
-raised: GNAT.DEBUG_POOLS.ACCESSING_NOT_ALLOCATED_STORAGE
-raised: GNAT.DEBUG_POOLS.FREEING_NOT_ALLOCATED_STORAGE
-Debug Pool info:
- Total allocated bytes : 8
- Total deallocated bytes : 4
- Current Water Mark: 4
- High Water Mark: 8
-@end smallexample
+This rule does not check the components of data objects,
+array components that are volatile as a result of the pragma
+@code{Volatile_Components}, or objects that are volatile because
+they are atomic as a result of pragmas @code{Atomic} or
+@code{Atomic_Components}.
+
+Only variable declarations, and not constant declarations, are checked.
+This rule has no parameters.
+
+@c *********************************
@node Creating Sample Bodies Using gnatstub
@chapter Creating Sample Bodies Using @command{gnatstub}
@findex gnatstub
@command{gnatstub} creates body stubs, that is, empty but compilable bodies
for library unit declarations.
+Note: to invoke @code{gnatstub} with a project file, use the @code{gnat}
+driver (see @ref{The GNAT Driver and Project Files}).
+
To create a body stub, @command{gnatstub} has to compile the library
unit declaration. Therefore, bodies can be created only for legal
library units. Moreover, if a library unit depends semantically upon
the source search path when calling @command{gnatstub}, see the description
of @command{gnatstub} switches below.
+By default, all the program unit body stubs generated by @code{gnatstub}
+raise the predefined @code{Program_Error} exception, which will catch
+accidental calls of generated stubs. This behavior can be changed with
+option @option{^--no-exception^/NO_EXCEPTION^} (see below).
+
@menu
* Running gnatstub::
* Switches for gnatstub::
@command{gnatstub} has the command-line interface of the form
@smallexample
-$ gnatstub [switches] filename [directory]
+$ gnatstub @ovar{switches} @var{filename} @ovar{directory}
@end smallexample
@noindent
where
-@table @emph
+@table @var
@item filename
is the name of the source file that contains a library unit declaration
for which a body must be created. The file name may contain the path
@cindex @option{^-hg^/HEADER=GENERAL^} (@command{gnatstub})
Put a sample comment header into the body stub.
+@item ^--header-file=@var{filename}^/FROM_HEADER_FILE=@var{filename}^
+@cindex @option{^--header-file^/FROM_HEADER_FILE=^} (@command{gnatstub})
+Use the content of the file as the comment header for a generated body stub.
+
@ifclear vms
@item -IDIR
@cindex @option{-IDIR} (@command{gnatstub})
@command{gcc} issued
by @command{gnatstub} to compile an argument source file.
-@item ^-gnatyM^/MAX_LINE_LENGTH=^@var{n}
-@cindex @option{^-gnatyM^/MAX_LINE_LENGTH^} (@command{gnatstub})
-(@var{n} is a non-negative integer). Set the maximum line length in the
-body stub to @var{n}; the default is 79. The maximum value that can be
-specified is 32767. Note that in the special case of configuration
-pragma files, the maximum is always 32767 regardless of whether or
-not this switch appears.
+@item ^-gnatyM^/MAX_LINE_LENGTH=^@var{n}
+@cindex @option{^-gnatyM^/MAX_LINE_LENGTH^} (@command{gnatstub})
+(@var{n} is a non-negative integer). Set the maximum line length in the
+body stub to @var{n}; the default is 79. The maximum value that can be
+specified is 32767. Note that in the special case of configuration
+pragma files, the maximum is always 32767 regardless of whether or
+not this switch appears.
+
+@item ^-gnaty^/STYLE_CHECKS=^@var{n}
+@cindex @option{^-gnaty^/STYLE_CHECKS=^} (@command{gnatstub})
+(@var{n} is a non-negative integer from 1 to 9). Set the indentation level in
+the generated body sample to @var{n}.
+The default indentation is 3.
+
+@item ^-gnatyo^/ORDERED_SUBPROGRAMS^
+@cindex @option{^-gnato^/ORDERED_SUBPROGRAMS^} (@command{gnatstub})
+Order local bodies alphabetically. (By default local bodies are ordered
+in the same way as the corresponding local specs in the argument spec file.)
+
+@item ^-i^/INDENTATION=^@var{n}
+@cindex @option{^-i^/INDENTATION^} (@command{gnatstub})
+Same as @option{^-gnaty^/STYLE_CHECKS=^@var{n}}
+
+@item ^-k^/TREE_FILE=SAVE^
+@cindex @option{^-k^/TREE_FILE=SAVE^} (@command{gnatstub})
+Do not remove the tree file (i.e., the snapshot of the compiler internal
+structures used by @command{gnatstub}) after creating the body stub.
+
+@item ^-l^/LINE_LENGTH=^@var{n}
+@cindex @option{^-l^/LINE_LENGTH^} (@command{gnatstub})
+Same as @option{^-gnatyM^/MAX_LINE_LENGTH=^@var{n}}
+
+@item ^--no-exception^/NO_EXCEPTION^
+@cindex @option{^--no-exception^/NO_EXCEPTION^} (@command{gnatstub})
+Avoind raising PROGRAM_ERROR in the generated bodies of program unit stubs.
+This is not always possible for function stubs.
+
+@item ^-o ^/BODY=^@var{body-name}
+@cindex @option{^-o^/BODY^} (@command{gnatstub})
+Body file name. This should be set if the argument file name does not
+follow
+the GNAT file naming
+conventions. If this switch is omitted the default name for the body will be
+obtained
+from the argument file name according to the GNAT file naming conventions.
+
+@item ^-q^/QUIET^
+@cindex @option{^-q^/QUIET^} (@command{gnatstub})
+Quiet mode: do not generate a confirmation when a body is
+successfully created, and do not generate a message when a body is not
+required for an
+argument unit.
+
+@item ^-r^/TREE_FILE=REUSE^
+@cindex @option{^-r^/TREE_FILE=REUSE^} (@command{gnatstub})
+Reuse the tree file (if it exists) instead of creating it. Instead of
+creating the tree file for the library unit declaration, @command{gnatstub}
+tries to find it in the current directory and use it for creating
+a body. If the tree file is not found, no body is created. This option
+also implies @option{^-k^/SAVE^}, whether or not
+the latter is set explicitly.
+
+@item ^-t^/TREE_FILE=OVERWRITE^
+@cindex @option{^-t^/TREE_FILE=OVERWRITE^} (@command{gnatstub})
+Overwrite the existing tree file. If the current directory already
+contains the file which, according to the GNAT file naming rules should
+be considered as a tree file for the argument source file,
+@command{gnatstub}
+will refuse to create the tree file needed to create a sample body
+unless this option is set.
+
+@item ^-v^/VERBOSE^
+@cindex @option{^-v^/VERBOSE^} (@command{gnatstub})
+Verbose mode: generate version information.
+
+@end table
+
+@c *********************************
+@node Generating Ada Bindings for C and C++ headers
+@chapter Generating Ada Bindings for C and C++ headers
+@findex binding
+
+@noindent
+GNAT now comes with a new experimental binding generator for C and C++
+headers which is intended to do 95% of the tedious work of generating
+Ada specs from C or C++ header files. Note that this still is a work in
+progress, not designed to generate 100% correct Ada specs.
+
+The code generated is using the Ada 2005 syntax, which makes it
+easier to interface with other languages than previous versions of Ada.
+
+@menu
+* Running the binding generator::
+* Generating bindings for C++ headers::
+* Switches::
+@end menu
+
+@node Running the binding generator
+@section Running the binding generator
+
+@noindent
+The binding generator is part of the @command{gcc} compiler and can be
+invoked via the @option{-fdump-ada-spec} switch, which will generate Ada
+spec files for the header files specified on the command line, and all
+header files needed by these files transitivitely. For example:
+
+@smallexample
+$ g++ -c -fdump-ada-spec -C /usr/include/time.h
+$ gcc -c -gnat05 *.ads
+@end smallexample
+
+will generate, under GNU/Linux, the following files: @file{time_h.ads},
+@file{bits_time_h.ads}, @file{stddef_h.ads}, @file{bits_types_h.ads} which
+correspond to the files @file{/usr/include/time.h},
+@file{/usr/include/bits/time.h}, etc@dots{}, and will then compile in Ada 2005
+mode these Ada specs.
+
+The @code{-C} switch tells @command{gcc} to extract comments from headers,
+and will attempt to generate corresponding Ada comments.
+
+If you want to generate a single Ada file and not the transitive closure, you
+can use instead the @option{-fdump-ada-spec-slim} switch.
+
+Note that we recommend when possible to use the @command{g++} driver to
+generate bindings, even for most C headers, since this will in general
+generate better Ada specs. For generating bindings for C++ headers, it is
+mandatory to use the @command{g++} command, or @command{gcc -x c++} which
+is equivalent in this case. If @command{g++} cannot work on your C headers
+because of incompatibilities between C and C++, then you can fallback to
+@command{gcc} instead.
+
+For an example of better bindings generated from the C++ front-end,
+the name of the parameters (when available) are actually ignored by the C
+front-end. Consider the following C header:
+
+@smallexample
+extern void foo (int variable);
+@end smallexample
+
+with the C front-end, @code{variable} is ignored, and the above is handled as:
+
+@smallexample
+extern void foo (int);
+@end smallexample
+
+generating a generic:
+
+@smallexample
+procedure foo (param1 : int);
+@end smallexample
+
+with the C++ front-end, the name is available, and we generate:
+
+@smallexample
+procedure foo (variable : int);
+@end smallexample
+
+In some cases, the generated bindings will be more complete or more meaningful
+when defining some macros, which you can do via the @option{-D} switch. This
+is for example the case with @file{Xlib.h} under GNU/Linux:
+
+@smallexample
+g++ -c -fdump-ada-spec -DXLIB_ILLEGAL_ACCESS -C /usr/include/X11/Xlib.h
+@end smallexample
+
+The above will generate more complete bindings than a straight call without
+the @option{-DXLIB_ILLEGAL_ACCESS} switch.
+
+In other cases, it is not possible to parse a header file in a stand alone
+manner, because other include files need to be included first. In this
+case, the solution is to create a small header file including the needed
+@code{#include} and possible @code{#define} directives. For example, to
+generate Ada bindings for @file{readline/readline.h}, you need to first
+include @file{stdio.h}, so you can create a file with the following two
+lines in e.g. @file{readline1.h}:
+
+@smallexample
+#include <stdio.h>
+#include <readline/readline.h>
+@end smallexample
+
+and then generate Ada bindings from this file:
+
+@smallexample
+$ g++ -c -fdump-ada-spec readline1.h
+@end smallexample
+
+@node Generating bindings for C++ headers
+@section Generating bindings for C++ headers
+
+@noindent
+Generating bindings for C++ headers is done using the same options, always
+with the @command{g++} compiler.
+
+In this mode, C++ classes will be mapped to Ada tagged types, constructors
+will be mapped using the @code{CPP_Constructor} pragma, and when possible,
+multiple inheritance of abstract classes will be mapped to Ada interfaces
+(@xref{Interfacing to C++,,,gnat_rm, GNAT Reference Manual}, for additional
+information on interfacing to C++).
+
+For example, given the following C++ header file:
+
+@smallexample
+@group
+@cartouche
+class Carnivore @{
+public:
+ virtual int Number_Of_Teeth () = 0;
+@};
+
+class Domestic @{
+public:
+ virtual void Set_Owner (char* Name) = 0;
+@};
+
+class Animal @{
+public:
+ int Age_Count;
+ virtual void Set_Age (int New_Age);
+@};
+
+class Dog : Animal, Carnivore, Domestic @{
+ public:
+ int Tooth_Count;
+ char *Owner;
+
+ virtual int Number_Of_Teeth ();
+ virtual void Set_Owner (char* Name);
+
+ Dog();
+@};
+@end cartouche
+@end group
+@end smallexample
+
+The corresponding Ada code is generated:
-@item ^-gnaty^/STYLE_CHECKS=^@var{n}
-@cindex @option{^-gnaty^/STYLE_CHECKS=^} (@command{gnatstub})
-(@var{n} is a non-negative integer from 1 to 9). Set the indentation level in
-the generated body sample to @var{n}.
-The default indentation is 3.
+@smallexample @c ada
+@group
+@cartouche
+ package Class_Carnivore is
+ type Carnivore is limited interface;
+ pragma Import (CPP, Carnivore);
-@item ^-gnatyo^/ORDERED_SUBPROGRAMS^
-@cindex @option{^-gnato^/ORDERED_SUBPROGRAMS^} (@command{gnatstub})
-Order local bodies alphabetically. (By default local bodies are ordered
-in the same way as the corresponding local specs in the argument spec file.)
+ function Number_Of_Teeth (this : access Carnivore) return int is abstract;
+ end;
+ use Class_Carnivore;
-@item ^-i^/INDENTATION=^@var{n}
-@cindex @option{^-i^/INDENTATION^} (@command{gnatstub})
-Same as @option{^-gnaty^/STYLE_CHECKS=^@var{n}}
+ package Class_Domestic is
+ type Domestic is limited interface;
+ pragma Import (CPP, Domestic);
-@item ^-k^/TREE_FILE=SAVE^
-@cindex @option{^-k^/TREE_FILE=SAVE^} (@command{gnatstub})
-Do not remove the tree file (i.e., the snapshot of the compiler internal
-structures used by @command{gnatstub}) after creating the body stub.
+ procedure Set_Owner
+ (this : access Domestic;
+ Name : Interfaces.C.Strings.chars_ptr) is abstract;
+ end;
+ use Class_Domestic;
-@item ^-l^/LINE_LENGTH=^@var{n}
-@cindex @option{^-l^/LINE_LENGTH^} (@command{gnatstub})
-Same as @option{^-gnatyM^/MAX_LINE_LENGTH=^@var{n}}
+ package Class_Animal is
+ type Animal is tagged limited record
+ Age_Count : aliased int;
+ end record;
+ pragma Import (CPP, Animal);
-@item ^-o^/BODY=^@var{body-name}
-@cindex @option{^-o^/BODY^} (@command{gnatstub})
-Body file name. This should be set if the argument file name does not
-follow
-the GNAT file naming
-conventions. If this switch is omitted the default name for the body will be
-obtained
-from the argument file name according to the GNAT file naming conventions.
+ procedure Set_Age (this : access Animal; New_Age : int);
+ pragma Import (CPP, Set_Age, "_ZN6Animal7Set_AgeEi");
+ end;
+ use Class_Animal;
-@item ^-q^/QUIET^
-@cindex @option{^-q^/QUIET^} (@command{gnatstub})
-Quiet mode: do not generate a confirmation when a body is
-successfully created, and do not generate a message when a body is not
-required for an
-argument unit.
+ package Class_Dog is
+ type Dog is new Animal and Carnivore and Domestic with record
+ Tooth_Count : aliased int;
+ Owner : Interfaces.C.Strings.chars_ptr;
+ end record;
+ pragma Import (CPP, Dog);
-@item ^-r^/TREE_FILE=REUSE^
-@cindex @option{^-r^/TREE_FILE=REUSE^} (@command{gnatstub})
-Reuse the tree file (if it exists) instead of creating it. Instead of
-creating the tree file for the library unit declaration, @command{gnatstub}
-tries to find it in the current directory and use it for creating
-a body. If the tree file is not found, no body is created. This option
-also implies @option{^-k^/SAVE^}, whether or not
-the latter is set explicitly.
+ function Number_Of_Teeth (this : access Dog) return int;
+ pragma Import (CPP, Number_Of_Teeth, "_ZN3Dog15Number_Of_TeethEv");
-@item ^-t^/TREE_FILE=OVERWRITE^
-@cindex @option{^-t^/TREE_FILE=OVERWRITE^} (@command{gnatstub})
-Overwrite the existing tree file. If the current directory already
-contains the file which, according to the GNAT file naming rules should
-be considered as a tree file for the argument source file,
-@command{gnatstub}
-will refuse to create the tree file needed to create a sample body
-unless this option is set.
+ procedure Set_Owner
+ (this : access Dog; Name : Interfaces.C.Strings.chars_ptr);
+ pragma Import (CPP, Set_Owner, "_ZN3Dog9Set_OwnerEPc");
-@item ^-v^/VERBOSE^
-@cindex @option{^-v^/VERBOSE^} (@command{gnatstub})
-Verbose mode: generate version information.
+ function New_Dog return Dog'Class;
+ pragma CPP_Constructor (New_Dog);
+ pragma Import (CPP, New_Dog, "_ZN3DogC1Ev");
+ end;
+ use Class_Dog;
+@end cartouche
+@end group
+@end smallexample
-@end table
+@node Switches
+@section Switches
+
+@table @option
+@item -fdump-ada-spec
+@cindex @option{-fdump-ada-spec} (@command{gcc})
+Generate Ada spec files for the given header files transitively (including
+all header files that these headers depend upon).
+
+@item -fdump-ada-spec-slim
+@cindex @option{-fdump-ada-spec-slim} (@command{gcc})
+Generate Ada spec files for the header files specified on the command line
+only.
+@item -C
+@cindex @option{-C} (@command{gcc})
+Extract comments from headers and generate Ada comments in the Ada spec files.
+@end table
@node Other Utility Programs
@chapter Other Utility Programs
@menu
* Using Other Utility Programs with GNAT::
* The External Symbol Naming Scheme of GNAT::
-@ifclear vms
-* Ada Mode for Glide::
-@end ifclear
* Converting Ada Files to html with gnathtml::
* Installing gnathtml::
@ifset vms
@noindent
the external name of this procedure will be @var{_ada_hello}.
-@ifclear vms
-@node Ada Mode for Glide
-@section Ada Mode for @code{Glide}
-@cindex Ada mode (for Glide)
-
-@noindent
-The Glide mode for programming in Ada (both Ada83 and Ada95) helps the
-user to understand and navigate existing code, and facilitates writing
-new code. It furthermore provides some utility functions for easier
-integration of standard Emacs features when programming in Ada.
-
-Its general features include:
-
-@itemize @bullet
-@item
-An Integrated Development Environment with functionality such as the
-following
-
-@itemize @bullet
-@item
-``Project files'' for configuration-specific aspects
-(e.g. directories and compilation options)
-
-@item
-Compiling and stepping through error messages.
-
-@item
-Running and debugging an applications within Glide.
-@end itemize
-
-@item
-Pull-down menus
-
-@item
-User configurability
-@end itemize
-
-Some of the specific Ada mode features are:
-
-@itemize @bullet
-@item
-Functions for easy and quick stepping through Ada code
-
-@item
-Getting cross reference information for identifiers (e.g., finding a
-defining occurrence)
-
-@item
-Displaying an index menu of types and subprograms, allowing
-direct selection for browsing
-
-@item
-Automatic color highlighting of the various Ada entities
-@end itemize
-
-Glide directly supports writing Ada code, via several facilities:
-
-@itemize @bullet
-@item
-Switching between spec and body files with possible
-autogeneration of body files
-
-@item
-Automatic formating of subprogram parameter lists
-
-@item
-Automatic indentation according to Ada syntax
-
-@item
-Automatic completion of identifiers
-
-@item
-Automatic (and configurable) casing of identifiers, keywords, and attributes
-
-@item
-Insertion of syntactic templates
-
-@item
-Block commenting / uncommenting
-@end itemize
-
-@noindent
-For more information, please refer to the online documentation
-available in the @code{Glide} @result{} @code{Help} menu.
-@end ifclear
-
@node Converting Ada Files to html with gnathtml
@section Converting Ada Files to HTML with @code{gnathtml}
The command line is as follow:
@smallexample
-$ perl gnathtml.pl [switches] ada-files
+$ perl gnathtml.pl @ovar{^switches^options^} @var{ada-files}
@end smallexample
@noindent
an html file for every ada file, and a global file called @file{index.htm}.
This file is an index of every identifier defined in the files.
-The available switches are the following ones :
+The available ^switches^options^ are the following ones:
@table @option
@item -83
@cindex @option{-83} (@code{gnathtml})
-Only the subset on the Ada 83 keywords will be highlighted, not the full
-Ada 95 keywords set.
+Only the Ada 83 subset of keywords will be highlighted.
@item -cc @var{color}
@cindex @option{-cc} (@code{gnathtml})
@item -d
@cindex @option{-d} (@code{gnathtml})
-If the ada files depend on some other files (using for instance the
-@code{with} command, the latter will also be converted to html.
+If the Ada files depend on some other files (for instance through
+@code{with} clauses, the latter files will also be converted to html.
Only the files in the user project will be converted to html, not the files
in the run-time library itself.
@item -f
@cindex @option{-f} (@code{gnathtml})
By default, gnathtml will generate html links only for global entities
-('with'ed units, global variables and types,...). If you specify the
+('with'ed units, global variables and types,@dots{}). If you specify
@option{-f} on the command line, then links will be generated for local
entities too.
@item -l @var{number}
@cindex @option{-l} (@code{gnathtml})
-If this switch is provided and @var{number} is not 0, then @code{gnathtml}
-will number the html files every @var{number} line.
+If this ^switch^option^ is provided and @var{number} is not 0, then
+@code{gnathtml} will number the html files every @var{number} line.
@item -I @var{dir}
@cindex @option{-I} (@code{gnathtml})
source files. You can provide several -I switches on the command line,
and the directories will be parsed in the order of the command line.
-@item -o @var{dir}
-@cindex @option{-o} (@code{gnathtml})
-Specify the output directory for html files. By default, gnathtml will
-saved the generated html files in a subdirectory named @file{html/}.
+@item -o @var{dir}
+@cindex @option{-o} (@code{gnathtml})
+Specify the output directory for html files. By default, gnathtml will
+saved the generated html files in a subdirectory named @file{html/}.
+
+@item -p @var{file}
+@cindex @option{-p} (@code{gnathtml})
+If you are using Emacs and the most recent Emacs Ada mode, which provides
+a full Integrated Development Environment for compiling, checking,
+running and debugging applications, you may use @file{.gpr} files
+to give the directories where Emacs can find sources and object files.
+
+Using this ^switch^option^, you can tell gnathtml to use these files.
+This allows you to get an html version of your application, even if it
+is spread over multiple directories.
+
+@item -sc @var{color}
+@cindex @option{-sc} (@code{gnathtml})
+This ^switch^option^ allows you to change the color used for symbol
+definitions.
+The default value is red. The color argument can be any name accepted by html.
+
+@item -t @var{file}
+@cindex @option{-t} (@code{gnathtml})
+This ^switch^option^ provides the name of a file. This file contains a list of
+file names to be converted, and the effect is exactly as though they had
+appeared explicitly on the command line. This
+is the recommended way to work around the command line length limit on some
+systems.
+
+@end table
+
+@node Installing gnathtml
+@section Installing @code{gnathtml}
+
+@noindent
+@code{Perl} needs to be installed on your machine to run this script.
+@code{Perl} is freely available for almost every architecture and
+Operating System via the Internet.
+
+On Unix systems, you may want to modify the first line of the script
+@code{gnathtml}, to explicitly tell the Operating system where Perl
+is. The syntax of this line is:
+@smallexample
+#!full_path_name_to_perl
+@end smallexample
+
+@noindent
+Alternatively, you may run the script using the following command line:
+
+@smallexample
+$ perl gnathtml.pl @ovar{switches} @var{files}
+@end smallexample
+
+@ifset vms
+@node LSE
+@section LSE
+@findex LSE
+
+@noindent
+The GNAT distribution provides an Ada 95 template for the HP Language
+Sensitive Editor (LSE), a component of DECset. In order to
+access it, invoke LSE with the qualifier /ENVIRONMENT=GNU:[LIB]ADA95.ENV.
+
+@node Profiling
+@section Profiling
+@findex PCA
+
+@noindent
+GNAT supports The HP Performance Coverage Analyzer (PCA), a component
+of DECset. To use it proceed as outlined under ``HELP PCA'', except for running
+the collection phase with the /DEBUG qualifier.
+
+@smallexample
+$ GNAT MAKE /DEBUG <PROGRAM_NAME>
+$ DEFINE LIB$DEBUG PCA$COLLECTOR
+$ RUN/DEBUG <PROGRAM_NAME>
+@end smallexample
+@noindent
+@end ifset
+
+@ifclear vms
+@c ******************************
+@node Code Coverage and Profiling
+@chapter Code Coverage and Profiling
+@cindex Code Coverage
+@cindex Profiling
+
+@noindent
+This chapter describes how to use @code{gcov} - coverage testing tool - and
+@code{gprof} - profiler tool - on your Ada programs.
+
+@menu
+* Code Coverage of Ada Programs using gcov::
+* Profiling an Ada Program using gprof::
+@end menu
+
+@node Code Coverage of Ada Programs using gcov
+@section Code Coverage of Ada Programs using gcov
+@cindex gcov
+@cindex -fprofile-arcs
+@cindex -ftest-coverage
+@cindex -coverage
+@cindex Code Coverage
+
+@noindent
+@code{gcov} is a test coverage program: it analyzes the execution of a given
+program on selected tests, to help you determine the portions of the program
+that are still untested.
+
+@code{gcov} is part of the GCC suite, and is described in detail in the GCC
+User's Guide. You can refer to this documentation for a more complete
+description.
+
+This chapter provides a quick startup guide, and
+details some Gnat-specific features.
+
+@menu
+* Quick startup guide::
+* Gnat specifics::
+@end menu
+
+@node Quick startup guide
+@subsection Quick startup guide
+
+In order to perform coverage analysis of a program using @code{gcov}, 3
+steps are needed:
+
+@itemize @bullet
+@item
+Code instrumentation during the compilation process
+@item
+Execution of the instrumented program
+@item
+Execution of the @code{gcov} tool to generate the result.
+@end itemize
+
+The code instrumentation needed by gcov is created at the object level:
+The source code is not modified in any way, because the instrumentation code is
+inserted by gcc during the compilation process. To compile your code with code
+coverage activated, you need to recompile your whole project using the
+switches
+@code{-fprofile-arcs} and @code{-ftest-coverage}, and link it using
+@code{-fprofile-arcs}.
+
+@smallexample
+$ gnatmake -P my_project.gpr -f -cargs -fprofile-arcs -ftest-coverage \
+ -largs -fprofile-arcs
+@end smallexample
+
+This compilation process will create @file{.gcno} files together with
+the usual object files.
+
+Once the program is compiled with coverage instrumentation, you can
+run it as many times as needed - on portions of a test suite for
+example. The first execution will produce @file{.gcda} files at the
+same location as the @file{.gcno} files. The following executions
+will update those files, so that a cumulative result of the covered
+portions of the program is generated.
+
+Finally, you need to call the @code{gcov} tool. The different options of
+@code{gcov} are available in the GCC User's Guide, section 'Invoking gcov'.
+
+This will create annotated source files with a @file{.gcov} extension:
+@file{my_main.adb} file will be analysed in @file{my_main.adb.gcov}.
+
+@node Gnat specifics
+@subsection Gnat specifics
+
+Because Ada semantics, portions of the source code may be shared among
+several object files. This is the case for example when generics are
+involved, when inlining is active or when declarations generate initialisation
+calls. In order to take
+into account this shared code, you need to call @code{gcov} on all
+source files of the tested program at once.
+
+The list of source files might exceed the system's maximum command line
+length. In order to bypass this limitation, a new mechanism has been
+implemented in @code{gcov}: you can now list all your project's files into a
+text file, and provide this file to gcov as a parameter, preceded by a @@
+(e.g. @samp{gcov @@mysrclist.txt}).
+
+Note that on AIX compiling a static library with @code{-fprofile-arcs} is
+not supported as there can be unresolved symbols during the final link.
+
+@node Profiling an Ada Program using gprof
+@section Profiling an Ada Program using gprof
+@cindex gprof
+@cindex -pg
+@cindex Profiling
+
+@noindent
+This section is not meant to be an exhaustive documentation of @code{gprof}.
+Full documentation for it can be found in the GNU Profiler User's Guide
+documentation that is part of this GNAT distribution.
+
+Profiling a program helps determine the parts of a program that are executed
+most often, and are therefore the most time-consuming.
+
+@code{gprof} is the standard GNU profiling tool; it has been enhanced to
+better handle Ada programs and multitasking.
+It is currently supported on the following platforms
+@itemize @bullet
+@item
+linux x86/x86_64
+@item
+solaris sparc/sparc64/x86
+@item
+windows x86
+@end itemize
+
+@noindent
+In order to profile a program using @code{gprof}, 3 steps are needed:
+
+@itemize @bullet
+@item
+Code instrumentation, requiring a full recompilation of the project with the
+proper switches.
+@item
+Execution of the program under the analysis conditions, i.e. with the desired
+input.
+@item
+Analysis of the results using the @code{gprof} tool.
+@end itemize
+
+@noindent
+The following sections detail the different steps, and indicate how
+to interpret the results:
+@menu
+* Compilation for profiling::
+* Program execution::
+* Running gprof::
+* Interpretation of profiling results::
+@end menu
+
+@node Compilation for profiling
+@subsection Compilation for profiling
+@cindex -pg
+@cindex Profiling
+
+In order to profile a program the first step is to tell the compiler
+to generate the necessary profiling information. The compiler switch to be used
+is @code{-pg}, which must be added to other compilation switches. This
+switch needs to be specified both during compilation and link stages, and can
+be specified once when using gnatmake:
-@item -p @var{file}
-@cindex @option{-p} (@code{gnathtml})
-If you are using Emacs and the most recent Emacs Ada mode, which provides
-a full Integrated Development Environment for compiling, checking,
-running and debugging applications, you may use @file{.gpr} files
-to give the directories where Emacs can find sources and object files.
+@smallexample
+gnatmake -f -pg -P my_project
+@end smallexample
-Using this switch, you can tell gnathtml to use these files. This allows
-you to get an html version of your application, even if it is spread
-over multiple directories.
+@noindent
+Note that only the objects that were compiled with the @samp{-pg} switch will be
+profiled; if you need to profile your whole project, use the
+@samp{-f} gnatmake switch to force full recompilation.
-@item -sc @var{color}
-@cindex @option{-sc} (@code{gnathtml})
-This option allows you to change the color used for symbol definitions.
-The default value is red. The color argument can be any name accepted by html.
+@node Program execution
+@subsection Program execution
-@item -t @var{file}
-@cindex @option{-t} (@code{gnathtml})
-This switch provides the name of a file. This file contains a list of
-file names to be converted, and the effect is exactly as though they had
-appeared explicitly on the command line. This
-is the recommended way to work around the command line length limit on some
-systems.
+@noindent
+Once the program has been compiled for profiling, you can run it as usual.
-@end table
+The only constraint imposed by profiling is that the program must terminate
+normally. An interrupted program (via a Ctrl-C, kill, etc.) will not be
+properly analyzed.
-@node Installing gnathtml
-@section Installing @code{gnathtml}
+Once the program completes execution, a data file called @file{gmon.out} is
+generated in the directory where the program was launched from. If this file
+already exists, it will be overwritten.
+
+@node Running gprof
+@subsection Running gprof
@noindent
-@code{Perl} needs to be installed on your machine to run this script.
-@code{Perl} is freely available for almost every architecture and
-Operating System via the Internet.
+The @code{gprof} tool is called as follow:
-On Unix systems, you may want to modify the first line of the script
-@code{gnathtml}, to explicitly tell the Operating system where Perl
-is. The syntax of this line is :
@smallexample
-#!full_path_name_to_perl
+gprof my_prog gmon.out
@end smallexample
@noindent
-Alternatively, you may run the script using the following command line:
+or simpler:
@smallexample
-$ perl gnathtml.pl [switches] files
+gprof my_prog
@end smallexample
-@ifset vms
-@node LSE
-@section LSE
-@findex LSE
-
@noindent
-The GNAT distribution provides an Ada 95 template for the Digital Language
-Sensitive Editor (LSE), a component of DECset. In order to
-access it, invoke LSE with the qualifier /ENVIRONMENT=GNU:[LIB]ADA95.ENV.
+The complete form of the gprof command line is the following:
-@node Profiling
-@section Profiling
-@findex PCA
+@smallexample
+gprof [^switches^options^] [executable [data-file]]
+@end smallexample
@noindent
-GNAT supports The Digital Performance Coverage Analyzer (PCA), a component
-of DECset. To use it proceed as outlined under ``HELP PCA'', except for running
-the collection phase with the /DEBUG qualifier.
+@code{gprof} supports numerous ^switch^options^. The order of these
+^switch^options^ does not matter. The full list of options can be found in
+the GNU Profiler User's Guide documentation that comes with this documentation.
+
+The following is the subset of those switches that is most relevant:
+
+@table @option
+
+@item --demangle[=@var{style}]
+@itemx --no-demangle
+@cindex @option{--demangle} (@code{gprof})
+These options control whether symbol names should be demangled when
+printing output. The default is to demangle C++ symbols. The
+@code{--no-demangle} option may be used to turn off demangling. Different
+compilers have different mangling styles. The optional demangling style
+argument can be used to choose an appropriate demangling style for your
+compiler, in particular Ada symbols generated by GNAT can be demangled using
+@code{--demangle=gnat}.
+
+@item -e @var{function_name}
+@cindex @option{-e} (@code{gprof})
+The @samp{-e @var{function}} option tells @code{gprof} not to print
+information about the function @var{function_name} (and its
+children@dots{}) in the call graph. The function will still be listed
+as a child of any functions that call it, but its index number will be
+shown as @samp{[not printed]}. More than one @samp{-e} option may be
+given; only one @var{function_name} may be indicated with each @samp{-e}
+option.
+
+@item -E @var{function_name}
+@cindex @option{-E} (@code{gprof})
+The @code{-E @var{function}} option works like the @code{-e} option, but
+execution time spent in the function (and children who were not called from
+anywhere else), will not be used to compute the percentages-of-time for
+the call graph. More than one @samp{-E} option may be given; only one
+@var{function_name} may be indicated with each @samp{-E} option.
+
+@item -f @var{function_name}
+@cindex @option{-f} (@code{gprof})
+The @samp{-f @var{function}} option causes @code{gprof} to limit the
+call graph to the function @var{function_name} and its children (and
+their children@dots{}). More than one @samp{-f} option may be given;
+only one @var{function_name} may be indicated with each @samp{-f}
+option.
+
+@item -F @var{function_name}
+@cindex @option{-F} (@code{gprof})
+The @samp{-F @var{function}} option works like the @code{-f} option, but
+only time spent in the function and its children (and their
+children@dots{}) will be used to determine total-time and
+percentages-of-time for the call graph. More than one @samp{-F} option
+may be given; only one @var{function_name} may be indicated with each
+@samp{-F} option. The @samp{-F} option overrides the @samp{-E} option.
+
+@end table
+
+@node Interpretation of profiling results
+@subsection Interpretation of profiling results
-@smallexample
-$ GNAT MAKE /DEBUG <PROGRAM_NAME>
-$ DEFINE LIB$DEBUG PCA$COLLECTOR
-$ RUN/DEBUG <PROGRAM_NAME>
-@end smallexample
@noindent
-@end ifset
+The results of the profiling analysis are represented by two arrays: the
+'flat profile' and the 'call graph'. Full documentation of those outputs
+can be found in the GNU Profiler User's Guide.
+
+The flat profile shows the time spent in each function of the program, and how
+many time it has been called. This allows you to locate easily the most
+time-consuming functions.
+
+The call graph shows, for each subprogram, the subprograms that call it,
+and the subprograms that it calls. It also provides an estimate of the time
+spent in each of those callers/called subprograms.
+@end ifclear
+
+@c ******************************
@node Running and Debugging Ada Programs
@chapter Running and Debugging Ada Programs
@cindex Debugging
@noindent
-This chapter discusses how to debug Ada programs. An incorrect Ada program
-may be handled in three ways by the GNAT compiler:
+This chapter discusses how to debug Ada programs.
+@ifset vms
+It applies to GNAT on the Alpha OpenVMS platform;
+for I64 OpenVMS please refer to the @cite{OpenVMS Debugger Manual},
+since HP has implemented Ada support in the OpenVMS debugger on I64.
+@end ifset
+
+An incorrect Ada program may be handled in three ways by the GNAT compiler:
@enumerate
@item
@noindent
@code{GDB} is a general purpose, platform-independent debugger that
-can be used to debug mixed-language programs compiled with @code{GCC},
+can be used to debug mixed-language programs compiled with @command{gcc},
and in particular is capable of debugging Ada programs compiled with
GNAT. The latest versions of @code{GDB} are Ada-aware and can handle
complex Ada data structures.
-The manual @cite{Debugging with GDB}
+@xref{Top,, Debugging with GDB, gdb, Debugging with GDB},
@ifset vms
-, located in the GNU:[DOCS] directory,
+located in the GNU:[DOCS] directory,
@end ifset
-contains full details on the usage of @code{GDB}, including a section on
+for full details on the usage of @code{GDB}, including a section on
its usage on programs. This manual should be consulted for full
details. The section that follows is a brief introduction to the
philosophy and use of @code{GDB}.
larger, but it does not add to the size of the actual executable that
will be loaded into memory, and has no impact on run-time performance. The
generation of debug information is triggered by the use of the
-^-g^/DEBUG^ switch in the gcc or gnatmake command used to carry out
-the compilations. It is important to emphasize that the use of these
-options does not change the generated code.
+^-g^/DEBUG^ switch in the @command{gcc} or @command{gnatmake} command
+used to carry out the compilations. It is important to emphasize that
+the use of these options does not change the generated code.
The debugging information is written in standard system formats that
are used by many tools, including debuggers and profilers. The format
@section Running GDB
@noindent
-The debugger can be launched directly and simply from @code{glide} or
-through its graphical interface: @code{gvd}. It can also be used
-directly in text mode. Here is described the basic use of @code{GDB}
-in text mode. All the commands described below can be used in the
-@code{gvd} console window even though there is usually other more
-graphical ways to achieve the same goals.
+This section describes how to initiate the debugger.
+@c The above sentence is really just filler, but it was otherwise
+@c clumsy to get the first paragraph nonindented given the conditional
+@c nature of the description
@ifclear vms
-@noindent
-The command to run the graphical interface of the debugger is
-@smallexample
-$ gvd program
-@end smallexample
+The debugger can be launched from a @code{GPS} menu or
+directly from the command line. The description below covers the latter use.
+All the commands shown can be used in the @code{GPS} debug console window,
+but there are usually more GUI-based ways to achieve the same effect.
@end ifclear
-@noindent
-The command to run @code{GDB} in text mode is
+The command to run @code{GDB} is
@smallexample
-$ ^gdb program^$ GDB PROGRAM^
+$ ^gdb program^GDB PROGRAM^
@end smallexample
@noindent
exactly as if the debugger were not present. The following section
describes some of the additional commands that can be given to @code{GDB}.
-
@c *******************************
@node Introduction to GDB Commands
@section Introduction to GDB Commands
@noindent
-@code{GDB} contains a large repertoire of commands. The manual
-@cite{Debugging with GDB}
+@code{GDB} contains a large repertoire of commands. @xref{Top,,
+Debugging with GDB, gdb, Debugging with GDB},
@ifset vms
-, located in the GNU:[DOCS] directory,
+located in the GNU:[DOCS] directory,
@end ifset
-includes extensive documentation on the use
+for extensive documentation on the use
of these commands, together with examples of their use. Furthermore,
-the command @var{help} invoked from within @code{GDB} activates a simple help
+the command @command{help} invoked from within GDB activates a simple help
facility which summarizes the available commands and their options.
In this section we summarize a few of the most commonly
used commands to give an idea of what @code{GDB} is about. You should create
@end table
+@noindent
The above list is a very short introduction to the commands that
@code{GDB} provides. Important additional capabilities, including conditional
breakpoints, the ability to execute command sequences on a breakpoint,
the ability to debug at the machine instruction level and many other
-features are described in detail in @cite{Debugging with GDB}.
-Note that most commands can be abbreviated
+features are described in detail in @ref{Top,, Debugging with GDB, gdb,
+Debugging with GDB}. Note that most commands can be abbreviated
(for example, c for continue, bt for backtrace).
@node Using Ada Expressions
That brevity is important to the @code{GDB} user.
@end itemize
+@noindent
Thus, for brevity, the debugger acts as if there were
implicit @code{with} and @code{use} clauses in effect for all user-written
packages, thus making it unnecessary to fully qualify most names with
their packages, regardless of context. Where this causes ambiguity,
@code{GDB} asks the user's intent.
-For details on the supported Ada syntax, see @cite{Debugging with GDB}.
+For details on the supported Ada syntax, see @ref{Top,, Debugging with
+GDB, gdb, Debugging with GDB}.
@node Calling User-Defined Subprograms
@section Calling User-Defined Subprograms
particular, This allows to browse the backtrace of the specified
task. It is advised to switch back to the original task before
continuing execution otherwise the scheduling of the program may be
-perturbated.
+perturbed.
@end table
@noindent
For more detailed information on the tasking support,
-see @cite{Debugging with GDB}.
+see @ref{Top,, Debugging with GDB, gdb, Debugging with GDB}.
@node Debugging Generic Units
@section Debugging Generic Units
@enumerate
@item
-Run @code{gcc} with the @option{-gnatf}. This first
+Run @command{gcc} with the @option{-gnatf}. This first
switch causes all errors on a given line to be reported. In its absence,
only the first error on a line is displayed.
message displayed may help to pinpoint the culprit.
@item
-Run @code{gcc} with the @option{^-v (verbose)^/VERBOSE^} switch. In this mode,
-@code{gcc} produces ongoing information about the progress of the
+Run @command{gcc} with the @option{^-v (verbose)^/VERBOSE^} switch. In this
+mode, @command{gcc} produces ongoing information about the progress of the
compilation and provides the name of each procedure as code is
generated. This switch allows you to find which Ada procedure was being
compiled when it encountered a code generation problem.
@item
@cindex @option{-gnatdc} switch
-Run @code{gcc} with the @option{-gnatdc} switch. This is a GNAT specific
+Run @command{gcc} with the @option{-gnatdc} switch. This is a GNAT specific
switch that does for the front-end what @option{^-v^VERBOSE^} does
for the back end. The system prints the name of each unit,
either a compilation unit or nested unit, as it is being analyzed.
Finally, you can start
@code{gdb} directly on the @code{gnat1} executable. @code{gnat1} is the
front-end of GNAT, and can be run independently (normally it is just
-called from @code{gcc}). You can use @code{gdb} on @code{gnat1} as you
+called from @command{gcc}). You can use @code{gdb} on @code{gnat1} as you
would on a C program (but @pxref{The GNAT Debugger GDB} for caveats). The
@code{where} command is the first line of attack; the variable
@code{lineno} (seen by @code{print lineno}), used by the second phase of
-@code{gnat1} and by the @code{gcc} backend, indicates the source line at
+@code{gnat1} and by the @command{gcc} backend, indicates the source line at
which the execution stopped, and @code{input_file name} indicates the name of
the source file.
@end enumerate
@item
All files prefixed with @file{^par^PAR^} are components of the parser. The
-numbers correspond to chapters of the Ada 95 Reference Manual. For example,
+numbers correspond to chapters of the Ada Reference Manual. For example,
parsing of select statements can be found in @file{par-ch9.adb}.
@item
@item
@findex GNAT
Files with prefix @file{^g-^G-^} are children of @code{GNAT}. These are useful
-general-purpose packages, fully documented in their specifications. All
-the other @file{.c} files are modifications of common @code{gcc} files.
+general-purpose packages, fully documented in their specs. All
+the other @file{.c} files are modifications of common @command{gcc} files.
@end itemize
@node Getting Internal Debugging Information
0040138B at d:/stb/stb.adb:10
0040139C at d:/stb/stb.adb:14
00401335 at d:/stb/b~stb.adb:104
-004011C4 at /build/.../crt1.c:200
-004011F1 at /build/.../crt1.c:222
+004011C4 at /build/@dots{}/crt1.c:200
+004011F1 at /build/@dots{}/crt1.c:222
77E892A4 in ?? at ??:0
@end smallexample
0040138B in stb.p2 at d:/stb/stb.adb:10
0040139C in stb at d:/stb/stb.adb:14
00401335 in main at d:/stb/b~stb.adb:104
-004011C4 in <__mingw_CRTStartup> at /build/.../crt1.c:200
-004011F1 in <mainCRTStartup> at /build/.../crt1.c:222
+004011C4 in <__mingw_CRTStartup> at /build/@dots{}/crt1.c:200
+004011F1 in <mainCRTStartup> at /build/@dots{}/crt1.c:222
@end smallexample
@noindent
@file{stb.adb} at line 5, which was reached from a procedure call in
@file{stb.adb} at line 10, and so on. The @file{b~std.adb} is the binder file,
which contains the call to the main program.
-@pxref{Running gnatbind}. The remaining entries are assorted runtime routines,
+@xref{Running gnatbind}. The remaining entries are assorted runtime routines,
and the output will vary from platform to platform.
It is also possible to use @code{GDB} with these traceback addresses to debug
Non-symbolic tracebacks are obtained by using the @option{-E} binder argument.
The stack traceback is attached to the exception information string, and can
be retrieved in an exception handler within the Ada program, by means of the
-Ada95 facilities defined in @code{Ada.Exceptions}. Here is a simple example:
+Ada facilities defined in @code{Ada.Exceptions}. Here is a simple example:
@smallexample @c ada
with Ada.Text_IO;
tool as described earlier (note that the hexadecimal addresses
need to be specified in C format, with a leading ``0x'').
-
@node Symbolic Traceback
@subsection Symbolic Traceback
@cindex traceback, symbolic
end STB;
@end smallexample
+@c ******************************
@ifset vms
-@node Compatibility with DEC Ada
-@chapter Compatibility with DEC Ada
+@node Compatibility with HP Ada
+@chapter Compatibility with HP Ada
@cindex Compatibility
@noindent
-This section of the manual compares DEC Ada for OpenVMS Alpha and GNAT
-OpenVMS Alpha. GNAT achieves a high level of compatibility
-with DEC Ada, and it should generally be straightforward to port code
-from the DEC Ada environment to GNAT. However, there are a few language
+@cindex DEC Ada
+@cindex HP Ada
+@cindex Compatibility between GNAT and HP Ada
+This chapter compares HP Ada (formerly known as ``DEC Ada'')
+for OpenVMS Alpha and GNAT for OpenVMS for Alpha and for I64.
+GNAT is highly compatible
+with HP Ada, and it should generally be straightforward to port code
+from the HP Ada environment to GNAT. However, there are a few language
and implementation differences of which the user must be aware. These
-differences are discussed in this section. In
+differences are discussed in this chapter. In
addition, the operating environment and command structure for the
compiler are different, and these differences are also discussed.
-Note that this discussion addresses specifically the implementation
-of Ada 83 for DIGITAL OpenVMS Alpha Systems. In cases where the implementation
-of DEC Ada differs between OpenVMS Alpha Systems and OpenVMS VAX Systems,
+For further details on these and other compatibility issues,
+see Appendix E of the HP publication
+@cite{HP Ada, Technical Overview and Comparison on HP Platforms}.
+
+Except where otherwise indicated, the description of GNAT for OpenVMS
+applies to both the Alpha and I64 platforms.
+
+For information on porting Ada code from GNAT on Alpha OpenVMS to GNAT on
+I64 OpenVMS, see @ref{Transitioning to 64-Bit GNAT for OpenVMS}.
+
+The discussion in this chapter addresses specifically the implementation
+of Ada 83 for HP OpenVMS Alpha Systems. In cases where the implementation
+of HP Ada differs between OpenVMS Alpha Systems and OpenVMS VAX Systems,
GNAT always follows the Alpha implementation.
+For GNAT running on other than VMS systems, all the HP Ada 83 pragmas and
+attributes are recognized, although only a subset of them can sensibly
+be implemented. The description of pragmas in
+@xref{Implementation Defined Pragmas,,, gnat_rm, GNAT Reference Manual}
+indicates whether or not they are applicable to non-VMS systems.
+
@menu
-* Ada 95 Compatibility::
+* Ada Language Compatibility::
* Differences in the Definition of Package System::
* Language-Related Features::
* The Package STANDARD::
* The Package SYSTEM::
* Tasking and Task-Related Features::
-* Implementation of Tasks in DEC Ada for OpenVMS Alpha Systems::
* Pragmas and Pragma-Related Features::
* Library of Predefined Units::
* Bindings::
* Program Compilation and Library Management::
* Input-Output::
* Implementation Limits::
-* Tools::
+* Tools and Utilities::
@end menu
-@node Ada 95 Compatibility
-@section Ada 95 Compatibility
+@node Ada Language Compatibility
+@section Ada Language Compatibility
@noindent
-GNAT is an Ada 95 compiler, and DEC Ada is an Ada 83
-compiler. Ada 95 is almost completely upwards compatible
+GNAT handles Ada 95 and Ada 2005 as well as Ada 83, whereas HP Ada is only
+for Ada 83. Ada 95 and Ada 2005 are almost completely upwards compatible
with Ada 83, and therefore Ada 83 programs will compile
and run under GNAT with
-no changes or only minor changes. The Ada 95 Reference
-Manual (ANSI/ISO/IEC-8652:1995) provides details on specific
-incompatibilities.
+no changes or only minor changes. The @cite{Annotated Ada Reference Manual}
+provides details on specific incompatibilities.
-GNAT provides the switch /83 on the GNAT COMPILE command,
-as well as the pragma ADA_83, to force the compiler to
+GNAT provides the switch @option{/83} on the @command{GNAT COMPILE} command,
+as well as the pragma @code{ADA_83}, to force the compiler to
operate in Ada 83 mode. This mode does not guarantee complete
conformance to Ada 83, but in practice is sufficient to
eliminate most sources of incompatibilities.
In particular, it eliminates the recognition of the
-additional Ada 95 keywords, so that their use as identifiers
-in Ada83 program is legal, and handles the cases of packages
+additional Ada 95 and Ada 2005 keywords, so that their use as identifiers
+in Ada 83 programs is legal, and handles the cases of packages
with optional bodies, and generics that instantiate unconstrained
types without the use of @code{(<>)}.
@node Differences in the Definition of Package System
-@section Differences in the Definition of Package System
+@section Differences in the Definition of Package @code{System}
@noindent
-Both the Ada 95 and Ada 83 reference manuals permit a compiler to add
-implementation-dependent declarations to package System. In normal mode,
-GNAT does not take advantage of this permission, and the version of System
-provided by GNAT exactly matches that in the Ada 95 Reference Manual.
+An Ada compiler is allowed to add
+implementation-dependent declarations to package @code{System}.
+In normal mode,
+GNAT does not take advantage of this permission, and the version of
+@code{System} provided by GNAT exactly matches that defined in the Ada
+Reference Manual.
-However, DEC Ada adds an extensive set of declarations to package System,
-as fully documented in the DEC Ada manuals. To minimize changes required
+However, HP Ada adds an extensive set of declarations to package
+@code{System},
+as fully documented in the HP Ada manuals. To minimize changes required
for programs that make use of these extensions, GNAT provides the pragma
-Extend_System for extending the definition of package System. By using:
+@code{Extend_System} for extending the definition of package System. By using:
+@cindex pragma @code{Extend_System}
+@cindex @code{Extend_System} pragma
@smallexample @c ada
@group
@end smallexample
@noindent
-The set of definitions in System is extended to include those in package
-@code{System.Aux_DEC}.
-These definitions are incorporated directly into package
-System, as though they had been declared there in the first place. For a
-list of the declarations added, see the specification of this package,
-which can be found in the file @code{s-auxdec.ads} in the GNAT library.
-The pragma Extend_System is a configuration pragma, which means that
+the set of definitions in @code{System} is extended to include those in
+package @code{System.Aux_DEC}.
+@cindex @code{System.Aux_DEC} package
+@cindex @code{Aux_DEC} package (child of @code{System})
+These definitions are incorporated directly into package @code{System},
+as though they had been declared there. For a
+list of the declarations added, see the spec of this package,
+which can be found in the file @file{s-auxdec.ads} in the GNAT library.
+@cindex @file{s-auxdec.ads} file
+The pragma @code{Extend_System} is a configuration pragma, which means that
it can be placed in the file @file{gnat.adc}, so that it will automatically
-apply to all subsequent compilations. See the section on Configuration
-Pragmas for further details.
+apply to all subsequent compilations. See @ref{Configuration Pragmas},
+for further details.
An alternative approach that avoids the use of the non-standard
-Extend_System pragma is to add a context clause to the unit that
+@code{Extend_System} pragma is to add a context clause to the unit that
references these facilities:
@smallexample @c ada
-@group
@cartouche
with System.Aux_DEC;
use System.Aux_DEC;
@end cartouche
-@end group
@end smallexample
@noindent
The effect is not quite semantically identical to incorporating
the declarations directly into package @code{System},
but most programs will not notice a difference
-unless they use prefix notation (e.g. @code{System.Integer_8})
-to reference the
-entities directly in package @code{System}.
+unless they use prefix notation (e.g.@: @code{System.Integer_8})
+to reference the entities directly in package @code{System}.
For units containing such references,
the prefixes must either be removed, or the pragma @code{Extend_System}
must be used.
@subsection Integer Types and Representations
@noindent
-The set of predefined integer types is identical in DEC Ada and GNAT.
+The set of predefined integer types is identical in HP Ada and GNAT.
Furthermore the representation of these integer types is also identical,
including the capability of size clauses forcing biased representation.
In addition,
-DEC Ada for OpenVMS Alpha systems has defined the
-following additional integer types in package System:
+HP Ada for OpenVMS Alpha systems has defined the
+following additional integer types in package @code{System}:
@itemize @bullet
@item
-INTEGER_8
+@code{INTEGER_8}
@item
-INTEGER_16
+@code{INTEGER_16}
@item
-INTEGER_32
+@code{INTEGER_32}
@item
-INTEGER_64
+@code{INTEGER_64}
@item
-LARGEST_INTEGER
+@code{LARGEST_INTEGER}
@end itemize
@noindent
-When using GNAT, the first four of these types may be obtained from the
-standard Ada 95 package @code{Interfaces}.
-Alternatively, by use of the pragma
-@code{Extend_System}, identical
+In GNAT, the first four of these types may be obtained from the
+standard Ada package @code{Interfaces}.
+Alternatively, by use of the pragma @code{Extend_System}, identical
declarations can be referenced directly in package @code{System}.
-On both GNAT and DEC Ada, the maximum integer size is 64 bits.
+On both GNAT and HP Ada, the maximum integer size is 64 bits.
@node Floating-Point Types and Representations
@subsection Floating-Point Types and Representations
@cindex Floating-Point types
@noindent
-The set of predefined floating-point types is identical in DEC Ada and GNAT.
+The set of predefined floating-point types is identical in HP Ada and GNAT.
Furthermore the representation of these floating-point
types is also identical. One important difference is that the default
-representation for DEC Ada is VAX_Float, but the default representation
+representation for HP Ada is @code{VAX_Float}, but the default representation
for GNAT is IEEE.
-Specific types may be declared to be VAX_Float or IEEE, using the pragma
-@code{Float_Representation} as described in the DEC Ada documentation.
+Specific types may be declared to be @code{VAX_Float} or IEEE, using the
+pragma @code{Float_Representation} as described in the HP Ada
+documentation.
For example, the declarations:
@smallexample @c ada
-@group
@cartouche
type F_Float is digits 6;
pragma Float_Representation (VAX_Float, F_Float);
@end cartouche
-@end group
@end smallexample
@noindent
-declare a type F_Float that will be represented in VAX_Float format.
-This set of declarations actually appears in System.Aux_DEC, which provides
+declares a type @code{F_Float} that will be represented in @code{VAX_Float}
+format.
+This set of declarations actually appears in @code{System.Aux_DEC},
+which contains
the full set of additional floating-point declarations provided in
-the DEC Ada version of package
-System. This and similar declarations may be accessed in a user program
+the HP Ada version of package @code{System}.
+This and similar declarations may be accessed in a user program
by using pragma @code{Extend_System}. The use of this
pragma, and the related pragma @code{Long_Float} is described in further
detail in the following section.
@node Pragmas Float_Representation and Long_Float
-@subsection Pragmas Float_Representation and Long_Float
+@subsection Pragmas @code{Float_Representation} and @code{Long_Float}
@noindent
-DEC Ada provides the pragma @code{Float_Representation}, which
+HP Ada provides the pragma @code{Float_Representation}, which
acts as a program library switch to allow control over
the internal representation chosen for the predefined
floating-point types declared in the package @code{Standard}.
The format of this pragma is as follows:
-@smallexample
-@group
+@smallexample @c ada
@cartouche
-@b{pragma} @code{Float_Representation}(VAX_Float | IEEE_Float);
+pragma Float_Representation(VAX_Float | IEEE_Float);
@end cartouche
-@end group
@end smallexample
@noindent
@itemize @bullet
@item
@code{VAX_Float} specifies that floating-point
-types are represented by default with the VAX hardware types
-F-floating, D-floating, G-floating. Note that the H-floating
-type is available only on DIGITAL Vax systems, and is not available
-in either DEC Ada or GNAT for Alpha systems.
+types are represented by default with the VAX system hardware types
+@code{F-floating}, @code{D-floating}, @code{G-floating}.
+Note that the @code{H-floating}
+type was available only on VAX systems, and is not available
+in either HP Ada or GNAT.
@item
@code{IEEE_Float} specifies that floating-point
@noindent
GNAT provides an identical implementation of the pragma
@code{Float_Representation}, except that it functions as a
-configuration pragma, as defined by Ada 95. Note that the
+configuration pragma. Note that the
notion of configuration pragma corresponds closely to the
-DEC Ada notion of a program library switch.
+HP Ada notion of a program library switch.
-When no pragma is used in GNAT, the default is IEEE_Float, which is different
-from DEC Ada 83, where the default is VAX_Float. In addition, the
-predefined libraries in GNAT are built using IEEE_Float, so it is not
+When no pragma is used in GNAT, the default is @code{IEEE_Float},
+which is different
+from HP Ada 83, where the default is @code{VAX_Float}. In addition, the
+predefined libraries in GNAT are built using @code{IEEE_Float}, so it is not
advisable to change the format of numbers passed to standard library
routines, and if necessary explicit type conversions may be needed.
-The use of IEEE_Float is recommended in GNAT since it is more efficient,
-and (given that it conforms to an international standard) potentially more
-portable. The situation in which VAX_Float may be useful is in interfacing
-to existing code and data that expects the use of VAX_Float. There are
-two possibilities here. If the requirement for the use of VAX_Float is
-localized, then the best approach is to use the predefined VAX_Float
+The use of @code{IEEE_Float} is recommended in GNAT since it is more
+efficient, and (given that it conforms to an international standard)
+potentially more portable.
+The situation in which @code{VAX_Float} may be useful is in interfacing
+to existing code and data that expect the use of @code{VAX_Float}.
+In such a situation use the predefined @code{VAX_Float}
types in package @code{System}, as extended by
@code{Extend_System}. For example, use @code{System.F_Float}
to specify the 32-bit @code{F-Float} format.
-Alternatively, if an entire program depends heavily on the use of
-the @code{VAX_Float} and in particular assumes that the types in
-package @code{Standard} are in @code{Vax_Float} format, then it
-may be desirable to reconfigure GNAT to assume Vax_Float by default.
-This is done by using the GNAT LIBRARY command to rebuild the library, and
-then using the general form of the @code{Float_Representation}
-pragma to ensure that this default format is used throughout.
-The form of the GNAT LIBRARY command is:
-
-@smallexample
-GNAT LIBRARY /CONFIG=@i{file} /CREATE=@i{directory}
-@end smallexample
-
-@noindent
-where @i{file} contains the new configuration pragmas
-and @i{directory} is the directory to be created to contain
-the new library.
-
@noindent
-On OpenVMS systems, DEC Ada provides the pragma @code{Long_Float}
+On OpenVMS systems, HP Ada provides the pragma @code{Long_Float}
to allow control over the internal representation chosen
for the predefined type @code{Long_Float} and for floating-point
type declarations with digits specified in the range 7 .. 15.
@subsection Fixed-Point Types and Representations
@noindent
-On DEC Ada for OpenVMS Alpha systems, rounding is
+On HP Ada for OpenVMS Alpha systems, rounding is
away from zero for both positive and negative numbers.
-Therefore, +0.5 rounds to 1 and -0.5 rounds to -1.
+Therefore, @code{+0.5} rounds to @code{1},
+and @code{-0.5} rounds to @code{-1}.
-On GNAT for OpenVMS Alpha, the results of operations
-on fixed-point types are in accordance with the Ada 95
+On GNAT the results of operations
+on fixed-point types are in accordance with the Ada
rules. In particular, results of operations on decimal
fixed-point types are truncated.
@subsection Record and Array Component Alignment
@noindent
-On DEC Ada for OpenVMS Alpha, all non composite components
+On HP Ada for OpenVMS Alpha, all non-composite components
are aligned on natural boundaries. For example, 1-byte
components are aligned on byte boundaries, 2-byte
components on 2-byte boundaries, 4-byte components on 4-byte
byte boundaries, and so on. The OpenVMS Alpha hardware
runs more efficiently with naturally aligned data.
-ON GNAT for OpenVMS Alpha, alignment rules are compatible
-with DEC Ada for OpenVMS Alpha.
+On GNAT, alignment rules are compatible
+with HP Ada for OpenVMS Alpha.
@node Address Clauses
@subsection Address Clauses
@noindent
-In DEC Ada and GNAT, address clauses are supported for
+In HP Ada and GNAT, address clauses are supported for
objects and imported subprograms.
The predefined type @code{System.Address} is a private type
-in both compilers, with the same representation (it is simply
-a machine pointer). Addition, subtraction, and comparison
-operations are available in the standard Ada 95 package
+in both compilers on Alpha OpenVMS, with the same representation
+(it is simply a machine pointer). Addition, subtraction, and comparison
+operations are available in the standard Ada package
@code{System.Storage_Elements}, or in package @code{System}
if it is extended to include @code{System.Aux_DEC} using a
pragma @code{Extend_System} as previously described.
-Note that code that with's both this extended package @code{System}
+Note that code that @code{with}'s both this extended package @code{System}
and the package @code{System.Storage_Elements} should not @code{use}
both packages, or ambiguities will result. In general it is better
-not to mix these two sets of facilities. The Ada 95 package was
-designed specifically to provide the kind of features that DEC Ada
+not to mix these two sets of facilities. The Ada package was
+designed specifically to provide the kind of features that HP Ada
adds directly to package @code{System}.
-GNAT is compatible with DEC Ada in its handling of address
+The type @code{System.Address} is a 64-bit integer type in GNAT for
+I64 OpenVMS. For more information,
+see @ref{Transitioning to 64-Bit GNAT for OpenVMS}.
+
+GNAT is compatible with HP Ada in its handling of address
clauses, except for some limitations in
the form of address clauses for composite objects with
initialization. Such address clauses are easily replaced
by the use of an explicitly-defined constant as described
-in the Ada 95 Reference Manual (13.1(22)). For example, the sequence
+in the Ada Reference Manual (13.1(22)). For example, the sequence
of declarations:
@smallexample @c ada
@cartouche
X, Y : Integer := Init_Func;
Q : String (X .. Y) := "abc";
-...
+@dots{}
for Q'Address use Compute_Address;
@end cartouche
@end smallexample
@noindent
will be rejected by GNAT, since the address cannot be computed at the time
-that Q is declared. To achieve the intended effect, write instead:
+that @code{Q} is declared. To achieve the intended effect, write instead:
@smallexample @c ada
@group
X, Y : Integer := Init_Func;
Q_Address : constant Address := Compute_Address;
Q : String (X .. Y) := "abc";
-...
+@dots{}
for Q'Address use Q_Address;
@end cartouche
@end group
@end smallexample
@noindent
-which will be accepted by GNAT (and other Ada 95 compilers), and is also
-backwards compatible with Ada 83. A fuller description of the restrictions
-on address specifications is found in the GNAT Reference Manual.
+which will be accepted by GNAT (and other Ada compilers), and is also
+compatible with Ada 83. A fuller description of the restrictions
+on address specifications is found in @ref{Top, GNAT Reference Manual,
+About This Guide, gnat_rm, GNAT Reference Manual}.
@node Other Representation Clauses
@subsection Other Representation Clauses
@noindent
-GNAT supports in a compatible manner all the representation
-clauses supported by DEC Ada. In addition, it
-supports representation clause forms that are new in Ada 95
-including COMPONENT_SIZE and SIZE clauses for objects.
+GNAT implements in a compatible manner all the representation
+clauses supported by HP Ada. In addition, GNAT
+implements the representation clause forms that were introduced in Ada 95,
+including @code{COMPONENT_SIZE} and @code{SIZE} clauses for objects.
@node The Package STANDARD
-@section The Package STANDARD
+@section The Package @code{STANDARD}
@noindent
-The package STANDARD, as implemented by DEC Ada, is fully
-described in the Reference Manual for the Ada Programming
-Language (ANSI/MIL-STD-1815A-1983) and in the DEC Ada
-Language Reference Manual. As implemented by GNAT, the
-package STANDARD is described in the Ada 95 Reference
-Manual.
+The package @code{STANDARD}, as implemented by HP Ada, is fully
+described in the @cite{Ada Reference Manual} and in the
+@cite{HP Ada Language Reference Manual}. As implemented by GNAT, the
+package @code{STANDARD} is described in the @cite{Ada Reference Manual}.
-In addition, DEC Ada supports the Latin-1 character set in
-the type CHARACTER. GNAT supports the Latin-1 character set
-in the type CHARACTER and also Unicode (ISO 10646 BMP) in
-the type WIDE_CHARACTER.
+In addition, HP Ada supports the Latin-1 character set in
+the type @code{CHARACTER}. GNAT supports the Latin-1 character set
+in the type @code{CHARACTER} and also Unicode (ISO 10646 BMP) in
+the type @code{WIDE_CHARACTER}.
The floating-point types supported by GNAT are those
-supported by DEC Ada, but defaults are different, and are controlled by
-pragmas. See @pxref{Floating-Point Types and Representations} for details.
+supported by HP Ada, but the defaults are different, and are controlled by
+pragmas. See @ref{Floating-Point Types and Representations}, for details.
@node The Package SYSTEM
-@section The Package SYSTEM
+@section The Package @code{SYSTEM}
@noindent
-DEC Ada provides a system-specific version of the package
-SYSTEM for each platform on which the language ships.
-For the complete specification of the package SYSTEM, see
-Appendix F of the DEC Ada Language Reference Manual.
+HP Ada provides a specific version of the package
+@code{SYSTEM} for each platform on which the language is implemented.
+For the complete spec of the package @code{SYSTEM}, see
+Appendix F of the @cite{HP Ada Language Reference Manual}.
-On DEC Ada, the package SYSTEM includes the following conversion functions:
+On HP Ada, the package @code{SYSTEM} includes the following conversion
+functions:
@itemize @bullet
-@item TO_ADDRESS(INTEGER)
+@item @code{TO_ADDRESS(INTEGER)}
-@item TO_ADDRESS(UNSIGNED_LONGWORD)
+@item @code{TO_ADDRESS(UNSIGNED_LONGWORD)}
-@item TO_ADDRESS(universal_integer)
+@item @code{TO_ADDRESS(}@i{universal_integer}@code{)}
-@item TO_INTEGER(ADDRESS)
+@item @code{TO_INTEGER(ADDRESS)}
-@item TO_UNSIGNED_LONGWORD(ADDRESS)
+@item @code{TO_UNSIGNED_LONGWORD(ADDRESS)}
-@item Function IMPORT_VALUE return UNSIGNED_LONGWORD and the
- functions IMPORT_ADDRESS and IMPORT_LARGEST_VALUE
+@item Function @code{IMPORT_VALUE return UNSIGNED_LONGWORD} and the
+functions @code{IMPORT_ADDRESS} and @code{IMPORT_LARGEST_VALUE}
@end itemize
@noindent
-By default, GNAT supplies a version of SYSTEM that matches
-the definition given in the Ada 95 Reference Manual.
+By default, GNAT supplies a version of @code{SYSTEM} that matches
+the definition given in the @cite{Ada Reference Manual}.
This
-is a subset of the DIGITAL system definitions, which is as
+is a subset of the HP system definitions, which is as
close as possible to the original definitions. The only difference
-is that the definition of SYSTEM_NAME is different:
+is that the definition of @code{SYSTEM_NAME} is different:
@smallexample @c ada
-@group
@cartouche
type Name is (SYSTEM_NAME_GNAT);
System_Name : constant Name := SYSTEM_NAME_GNAT;
@end cartouche
-@end group
@end smallexample
@noindent
-Also, GNAT adds the new Ada 95 declarations for
-BIT_ORDER and DEFAULT_BIT_ORDER.
+Also, GNAT adds the Ada declarations for
+@code{BIT_ORDER} and @code{DEFAULT_BIT_ORDER}.
However, the use of the following pragma causes GNAT
-to extend the definition of package SYSTEM so that it
-encompasses the full set of DIGITAL-specific extensions,
+to extend the definition of package @code{SYSTEM} so that it
+encompasses the full set of HP-specific extensions,
including the functions listed above:
@smallexample @c ada
@end smallexample
@noindent
-The pragma Extend_System is a configuration pragma that
-is most conveniently placed in the @file{gnat.adc} file. See the
-GNAT Reference Manual for further details.
+The pragma @code{Extend_System} is a configuration pragma that
+is most conveniently placed in the @file{gnat.adc} file. @xref{Pragma
+Extend_System,,, gnat_rm, GNAT Reference Manual} for further details.
-DEC Ada does not allow the recompilation of the package
-SYSTEM. Instead DEC Ada provides several pragmas (SYSTEM_
-NAME, STORAGE_UNIT, and MEMORY_SIZE) to modify values in
-the package SYSTEM. On OpenVMS Alpha systems, the pragma
-SYSTEM_NAME takes the enumeration literal OPENVMS_AXP as
+HP Ada does not allow the recompilation of the package
+@code{SYSTEM}. Instead HP Ada provides several pragmas
+(@code{SYSTEM_NAME}, @code{STORAGE_UNIT}, and @code{MEMORY_SIZE})
+to modify values in the package @code{SYSTEM}.
+On OpenVMS Alpha systems, the pragma
+@code{SYSTEM_NAME} takes the enumeration literal @code{OPENVMS_AXP} as
its single argument.
-GNAT does permit the recompilation of package SYSTEM using
-a special switch (@option{-gnatg}) and this switch can be used if
-it is necessary to modify the definitions in SYSTEM. GNAT does
-not permit the specification of SYSTEM_NAME, STORAGE_UNIT
-or MEMORY_SIZE by any other means.
+GNAT does permit the recompilation of package @code{SYSTEM} using
+the special switch @option{-gnatg}, and this switch can be used if
+it is necessary to modify the definitions in @code{SYSTEM}. GNAT does
+not permit the specification of @code{SYSTEM_NAME}, @code{STORAGE_UNIT}
+or @code{MEMORY_SIZE} by any other means.
-On GNAT systems, the pragma SYSTEM_NAME takes the
-enumeration literal SYSTEM_NAME_GNAT.
+On GNAT systems, the pragma @code{SYSTEM_NAME} takes the
+enumeration literal @code{SYSTEM_NAME_GNAT}.
The definitions provided by the use of
@end smallexample
@noindent
-are virtually identical to those provided by the DEC Ada 83 package
-System. One important difference is that the name of the TO_ADDRESS
-function for type UNSIGNED_LONGWORD is changed to TO_ADDRESS_LONG.
-See the GNAT Reference manual for a discussion of why this change was
-necessary.
+are virtually identical to those provided by the HP Ada 83 package
+@code{SYSTEM}. One important difference is that the name of the
+@code{TO_ADDRESS}
+function for type @code{UNSIGNED_LONGWORD} is changed to
+@code{TO_ADDRESS_LONG}.
+@xref{Address Clauses,,, gnat_rm, GNAT Reference Manual} for a
+discussion of why this change was necessary.
@noindent
-The version of TO_ADDRESS taking a universal integer argument is in fact
+The version of @code{TO_ADDRESS} taking a @i{universal_integer} argument
+is in fact
an extension to Ada 83 not strictly compatible with the reference manual.
-In GNAT, we are constrained to be exactly compatible with the standard,
-and this means we cannot provide this capability. In DEC Ada 83, the
+GNAT, in order to be exactly compatible with the standard,
+does not provide this capability. In HP Ada 83, the
point of this definition is to deal with a call like:
@smallexample @c ada
@end smallexample
@noindent
-Normally, according to the Ada 83 standard, one would expect this to be
-ambiguous, since it matches both the INTEGER and UNSIGNED_LONGWORD forms
-of TO_ADDRESS. However, in DEC Ada 83, there is no ambiguity, since the
-definition using universal_integer takes precedence.
+Normally, according to Ada 83 semantics, one would expect this to be
+ambiguous, since it matches both the @code{INTEGER} and
+@code{UNSIGNED_LONGWORD} forms of @code{TO_ADDRESS}.
+However, in HP Ada 83, there is no ambiguity, since the
+definition using @i{universal_integer} takes precedence.
-In GNAT, since the version with universal_integer cannot be supplied, it is
+In GNAT, since the version with @i{universal_integer} cannot be supplied,
+it is
not possible to be 100% compatible. Since there are many programs using
-numeric constants for the argument to TO_ADDRESS, the decision in GNAT was
-to change the name of the function in the UNSIGNED_LONGWORD case, so the
-declarations provided in the GNAT version of AUX_Dec are:
+numeric constants for the argument to @code{TO_ADDRESS}, the decision in
+GNAT was
+to change the name of the function in the @code{UNSIGNED_LONGWORD} case,
+so the declarations provided in the GNAT version of @code{AUX_Dec} are:
@smallexample @c ada
function To_Address (X : Integer) return Address;
@end smallexample
@noindent
-This means that programs using TO_ADDRESS for UNSIGNED_LONGWORD must
-change the name to TO_ADDRESS_LONG.
+This means that programs using @code{TO_ADDRESS} for
+@code{UNSIGNED_LONGWORD} must change the name to @code{TO_ADDRESS_LONG}.
@node Tasking and Task-Related Features
@section Tasking and Task-Related Features
@noindent
-The concepts relevant to a comparison of tasking on GNAT
-and on DEC Ada for OpenVMS Alpha systems are discussed in
-the following sections.
-
-For detailed information on concepts related to tasking in
-DEC Ada, see the DEC Ada Language Reference Manual and the
+This section compares the treatment of tasking in GNAT
+and in HP Ada for OpenVMS Alpha.
+The GNAT description applies to both Alpha and I64 OpenVMS.
+For detailed information on tasking in
+HP Ada, see the @cite{HP Ada Language Reference Manual} and the
relevant run-time reference manual.
-@node Implementation of Tasks in DEC Ada for OpenVMS Alpha Systems
-@section Implementation of Tasks in DEC Ada for OpenVMS Alpha Systems
+@menu
+* Implementation of Tasks in HP Ada for OpenVMS Alpha Systems::
+* Assigning Task IDs::
+* Task IDs and Delays::
+* Task-Related Pragmas::
+* Scheduling and Task Priority::
+* The Task Stack::
+* External Interrupts::
+@end menu
+
+@node Implementation of Tasks in HP Ada for OpenVMS Alpha Systems
+@subsection Implementation of Tasks in HP Ada for OpenVMS Alpha Systems
@noindent
On OpenVMS Alpha systems, each Ada task (except a passive
task) is implemented as a single stream of execution
that is created and managed by the kernel. On these
-systems, DEC Ada tasking support is based on DECthreads,
+systems, HP Ada tasking support is based on DECthreads,
an implementation of the POSIX standard for threads.
-Although tasks are implemented as threads, all tasks in
-an Ada program are part of the same process. As a result,
-resources such as open files and virtual memory can be
-shared easily among tasks. Having all tasks in one process
-allows better integration with the programming environment
-(the shell and the debugger, for example).
-
-Also, on OpenVMS Alpha systems, DEC Ada tasks and foreign
+Also, on OpenVMS Alpha systems, HP Ada tasks and foreign
code that calls DECthreads routines can be used together.
The interaction between Ada tasks and DECthreads routines
can have some benefits. For example when on OpenVMS Alpha,
-DEC Ada can call C code that is already threaded.
-GNAT on OpenVMS Alpha uses the facilities of DECthreads,
-and Ada tasks are mapped to threads.
+HP Ada can call C code that is already threaded.
-@menu
-* Assigning Task IDs::
-* Task IDs and Delays::
-* Task-Related Pragmas::
-* Scheduling and Task Priority::
-* The Task Stack::
-* External Interrupts::
-@end menu
+GNAT uses the facilities of DECthreads,
+and Ada tasks are mapped to threads.
@node Assigning Task IDs
@subsection Assigning Task IDs
@noindent
-The DEC Ada Run-Time Library always assigns %TASK 1 to
+The HP Ada Run-Time Library always assigns @code{%TASK 1} to
the environment task that executes the main program. On
-OpenVMS Alpha systems, %TASK 0 is often used for tasks
+OpenVMS Alpha systems, @code{%TASK 0} is often used for tasks
that have been created but are not yet activated.
On OpenVMS Alpha systems, task IDs are assigned at
activation. On GNAT systems, task IDs are also assigned at
task creation but do not have the same form or values as
-task ID values in DEC Ada. There is no null task, and the
+task ID values in HP Ada. There is no null task, and the
environment task does not have a specific task ID value.
@node Task IDs and Delays
@noindent
On OpenVMS Alpha systems, tasking delays are implemented
using Timer System Services. The Task ID is used for the
-identification of the timer request (the REQIDT parameter).
+identification of the timer request (the @code{REQIDT} parameter).
If Timers are used in the application take care not to use
-0 for the identification, because cancelling such a timer
+@code{0} for the identification, because cancelling such a timer
will cancel all timers and may lead to unpredictable results.
@node Task-Related Pragmas
@subsection Task-Related Pragmas
@noindent
-Ada supplies the pragma TASK_STORAGE, which allows
+Ada supplies the pragma @code{TASK_STORAGE}, which allows
specification of the size of the guard area for a task
stack. (The guard area forms an area of memory that has no
read or write access and thus helps in the detection of
stack overflow.) On OpenVMS Alpha systems, if the pragma
-TASK_STORAGE specifies a value of zero, a minimal guard
-area is created. In the absence of a pragma TASK_STORAGE, a default guard
-area is created.
+@code{TASK_STORAGE} specifies a value of zero, a minimal guard
+area is created. In the absence of a pragma @code{TASK_STORAGE},
+a default guard area is created.
GNAT supplies the following task-related pragmas:
@itemize @bullet
-@item TASK_INFO
+@item @code{TASK_INFO}
- This pragma appears within a task definition and
- applies to the task in which it appears. The argument
- must be of type SYSTEM.TASK_INFO.TASK_INFO_TYPE.
+This pragma appears within a task definition and
+applies to the task in which it appears. The argument
+must be of type @code{SYSTEM.TASK_INFO.TASK_INFO_TYPE}.
-@item TASK_STORAGE
+@item @code{TASK_STORAGE}
- GNAT implements pragma TASK_STORAGE in the same way as
- DEC Ada.
- Both DEC Ada and GNAT supply the pragmas PASSIVE,
- SUPPRESS, and VOLATILE.
+GNAT implements pragma @code{TASK_STORAGE} in the same way as HP Ada.
+Both HP Ada and GNAT supply the pragmas @code{PASSIVE},
+@code{SUPPRESS}, and @code{VOLATILE}.
@end itemize
@node Scheduling and Task Priority
@subsection Scheduling and Task Priority
@noindent
-DEC Ada implements the Ada language requirement that
+HP Ada implements the Ada language requirement that
when two tasks are eligible for execution and they have
different priorities, the lower priority task does not
-execute while the higher priority task is waiting. The DEC
+execute while the higher priority task is waiting. The HP
Ada Run-Time Library keeps a task running until either the
task is suspended or a higher priority task becomes ready.
On OpenVMS Alpha systems, the default strategy is round-
robin with preemption. Tasks of equal priority take turns
at the processor. A task is run for a certain period of
-time and then placed at the rear of the ready queue for
+time and then placed at the tail of the ready queue for
its priority level.
-DEC Ada provides the implementation-defined pragma TIME_SLICE,
+HP Ada provides the implementation-defined pragma @code{TIME_SLICE},
which can be used to enable or disable round-robin
scheduling of tasks with the same priority.
-See the relevant DEC Ada run-time reference manual for
-information on using the pragmas to control DEC Ada task
+See the relevant HP Ada run-time reference manual for
+information on using the pragmas to control HP Ada task
scheduling.
-GNAT follows the scheduling rules of Annex D (real-time
-Annex) of the Ada 95 Reference Manual. In general, this
-scheduling strategy is fully compatible with DEC Ada
+GNAT follows the scheduling rules of Annex D (Real-Time
+Annex) of the @cite{Ada Reference Manual}. In general, this
+scheduling strategy is fully compatible with HP Ada
although it provides some additional constraints (as
fully documented in Annex D).
GNAT implements time slicing control in a manner compatible with
-DEC Ada 83, by means of the pragma Time_Slice, whose semantics are identical
-to the DEC Ada 83 pragma of the same name.
+HP Ada 83, by means of the pragma @code{Time_Slice}, whose semantics
+are identical to the HP Ada 83 pragma of the same name.
Note that it is not possible to mix GNAT tasking and
-DEC Ada 83 tasking in the same program, since the two run times are
-not compatible.
+HP Ada 83 tasking in the same program, since the two run-time
+libraries are not compatible.
@node The Task Stack
@subsection The Task Stack
@noindent
-In DEC Ada, a task stack is allocated each time a
-non passive task is activated. As soon as the task is
+In HP Ada, a task stack is allocated each time a
+non-passive task is activated. As soon as the task is
terminated, the storage for the task stack is deallocated.
-If you specify a size of zero (bytes) with T'STORAGE_SIZE,
+If you specify a size of zero (bytes) with @code{T'STORAGE_SIZE},
a default stack size is used. Also, regardless of the size
specified, some additional space is allocated for task
management purposes. On OpenVMS Alpha systems, at least
one page is allocated.
-GNAT handles task stacks in a similar manner. According to
-the Ada 95 rules, it provides the pragma STORAGE_SIZE as
+GNAT handles task stacks in a similar manner. In accordance with
+the Ada rules, it provides the pragma @code{STORAGE_SIZE} as
an alternative method for controlling the task stack size.
-The specification of the attribute T'STORAGE_SIZE is also
-supported in a manner compatible with DEC Ada.
+The specification of the attribute @code{T'STORAGE_SIZE} is also
+supported in a manner compatible with HP Ada.
@node External Interrupts
@subsection External Interrupts
@noindent
-On DEC Ada, external interrupts can be associated with task entries.
-GNAT is compatible with DEC Ada in its handling of external interrupts.
+On HP Ada, external interrupts can be associated with task entries.
+GNAT is compatible with HP Ada in its handling of external interrupts.
@node Pragmas and Pragma-Related Features
@section Pragmas and Pragma-Related Features
@noindent
-Both DEC Ada and GNAT supply all language-defined pragmas
+Both HP Ada and GNAT supply all language-defined pragmas
as specified by the Ada 83 standard. GNAT also supplies all
-language-defined pragmas specified in the Ada 95 Reference Manual.
+language-defined pragmas introduced by Ada 95 and Ada 2005.
In addition, GNAT implements the implementation-defined pragmas
-from DEC Ada 83.
+from HP Ada 83.
@itemize @bullet
-@item AST_ENTRY
+@item @code{AST_ENTRY}
-@item COMMON_OBJECT
+@item @code{COMMON_OBJECT}
-@item COMPONENT_ALIGNMENT
+@item @code{COMPONENT_ALIGNMENT}
-@item EXPORT_EXCEPTION
+@item @code{EXPORT_EXCEPTION}
-@item EXPORT_FUNCTION
+@item @code{EXPORT_FUNCTION}
-@item EXPORT_OBJECT
+@item @code{EXPORT_OBJECT}
-@item EXPORT_PROCEDURE
+@item @code{EXPORT_PROCEDURE}
-@item EXPORT_VALUED_PROCEDURE
+@item @code{EXPORT_VALUED_PROCEDURE}
-@item FLOAT_REPRESENTATION
+@item @code{FLOAT_REPRESENTATION}
-@item IDENT
+@item @code{IDENT}
-@item IMPORT_EXCEPTION
+@item @code{IMPORT_EXCEPTION}
-@item IMPORT_FUNCTION
+@item @code{IMPORT_FUNCTION}
-@item IMPORT_OBJECT
+@item @code{IMPORT_OBJECT}
-@item IMPORT_PROCEDURE
+@item @code{IMPORT_PROCEDURE}
-@item IMPORT_VALUED_PROCEDURE
+@item @code{IMPORT_VALUED_PROCEDURE}
-@item INLINE_GENERIC
+@item @code{INLINE_GENERIC}
-@item INTERFACE_NAME
+@item @code{INTERFACE_NAME}
-@item LONG_FLOAT
+@item @code{LONG_FLOAT}
-@item MAIN_STORAGE
+@item @code{MAIN_STORAGE}
-@item PASSIVE
+@item @code{PASSIVE}
-@item PSET_OBJECT
+@item @code{PSECT_OBJECT}
-@item SHARE_GENERIC
+@item @code{SHARE_GENERIC}
-@item SUPPRESS_ALL
+@item @code{SUPPRESS_ALL}
-@item TASK_STORAGE
+@item @code{TASK_STORAGE}
-@item TIME_SLICE
+@item @code{TIME_SLICE}
-@item TITLE
+@item @code{TITLE}
@end itemize
@noindent
-These pragmas are all fully implemented, with the exception of @code{Title},
-@code{Passive}, and @code{Share_Generic}, which are
+These pragmas are all fully implemented, with the exception of @code{TITLE},
+@code{PASSIVE}, and @code{SHARE_GENERIC}, which are
recognized, but which have no
-effect in GNAT. The effect of @code{Passive} may be obtained by the
-use of protected objects in Ada 95. In GNAT, all generics are inlined.
+effect in GNAT. The effect of @code{PASSIVE} may be obtained by the
+use of Ada protected objects. In GNAT, all generics are inlined.
-Unlike DEC Ada, the GNAT 'EXPORT_@i{subprogram}' pragmas require
+Unlike HP Ada, the GNAT ``@code{EXPORT_}@i{subprogram}'' pragmas require
a separate subprogram specification which must appear before the
subprogram body.
GNAT also supplies a number of implementation-defined pragmas as follows:
@itemize @bullet
-@item C_PASS_BY_COPY
-
-@item EXTEND_SYSTEM
+@item @code{ABORT_DEFER}
-@item SOURCE_FILE_NAME
+@item @code{ADA_83}
-@item UNSUPPRESS
+@item @code{ADA_95}
-@item WARNINGS
+@item @code{ADA_05}
-@item ABORT_DEFER
+@item @code{ANNOTATE}
-@item ADA_83
+@item @code{ASSERT}
-@item ADA_95
+@item @code{C_PASS_BY_COPY}
-@item ANNOTATE
+@item @code{CPP_CLASS}
-@item ASSERT
+@item @code{CPP_CONSTRUCTOR}
-@item CPP_CLASS
+@item @code{CPP_DESTRUCTOR}
-@item CPP_CONSTRUCTOR
+@item @code{DEBUG}
-@item CPP_DESTRUCTOR
+@item @code{EXTEND_SYSTEM}
-@item CPP_VIRTUAL
+@item @code{LINKER_ALIAS}
-@item CP_VTABLE
+@item @code{LINKER_SECTION}
-@item DEBUG
+@item @code{MACHINE_ATTRIBUTE}
-@item LINKER_ALIAS
+@item @code{NO_RETURN}
-@item LINKER_SECTION
+@item @code{PURE_FUNCTION}
-@item MACHINE_ATTRIBUTE
+@item @code{SOURCE_FILE_NAME}
-@item NO_RETURN
+@item @code{SOURCE_REFERENCE}
-@item PURE_FUNCTION
+@item @code{TASK_INFO}
-@item SOURCE_REFERENCE
+@item @code{UNCHECKED_UNION}
-@item TASK_INFO
+@item @code{UNIMPLEMENTED_UNIT}
-@item UNCHECKED_UNION
+@item @code{UNIVERSAL_DATA}
-@item UNIMPLEMENTED_UNIT
+@item @code{UNSUPPRESS}
-@item UNIVERSAL_DATA
+@item @code{WARNINGS}
-@item WEAK_EXTERNAL
+@item @code{WEAK_EXTERNAL}
@end itemize
@noindent
-For full details on these GNAT implementation-defined pragmas, see
-the GNAT Reference Manual.
+For full details on these GNAT implementation-defined pragmas,
+see @ref{Implementation Defined Pragmas,,, gnat_rm, GNAT Reference
+Manual}.
@menu
* Restrictions on the Pragma INLINE::
@end menu
@node Restrictions on the Pragma INLINE
-@subsection Restrictions on the Pragma INLINE
+@subsection Restrictions on Pragma @code{INLINE}
@noindent
-DEC Ada applies the following restrictions to the pragma INLINE:
+HP Ada enforces the following restrictions on the pragma @code{INLINE}:
@itemize @bullet
-@item Parameters cannot be a task type.
+@item Parameters cannot have a task type.
@item Function results cannot be task types, unconstrained
array types, or unconstrained types with discriminants.
@end itemize
@noindent
-In GNAT, the only restriction on pragma INLINE is that the
+In GNAT, the only restriction on pragma @code{INLINE} is that the
body must occur before the call if both are in the same
unit, and the size must be appropriately small. There are
no other specific restrictions which cause subprograms to
be incapable of being inlined.
@node Restrictions on the Pragma INTERFACE
-@subsection Restrictions on the Pragma INTERFACE
+@subsection Restrictions on Pragma @code{INTERFACE}
@noindent
-The following lists and describes the restrictions on the
-pragma INTERFACE on DEC Ada and GNAT:
+The following restrictions on pragma @code{INTERFACE}
+are enforced by both HP Ada and GNAT:
@itemize @bullet
@item Languages accepted: Ada, Bliss, C, Fortran, Default.
Default is the default on OpenVMS Alpha systems.
@item Parameter passing: Language specifies default
-mechanisms but can be overridden with an EXPORT pragma.
+mechanisms but can be overridden with an @code{EXPORT} pragma.
@itemize @bullet
@item Ada: Use internal Ada rules.
record or task type. Result cannot be a string, an
array, or a record.
-@item Fortran: Parameters cannot be a task. Result cannot
+@item Fortran: Parameters cannot have a task type. Result cannot
be a string, an array, or a record.
@end itemize
@end itemize
@noindent
-GNAT is entirely upwards compatible with DEC Ada, and in addition allows
+GNAT is entirely upwards compatible with HP Ada, and in addition allows
record parameters for all languages.
@node Restrictions on the Pragma SYSTEM_NAME
-@subsection Restrictions on the Pragma SYSTEM_NAME
+@subsection Restrictions on Pragma @code{SYSTEM_NAME}
@noindent
-For DEC Ada for OpenVMS Alpha, the enumeration literal
-for the type NAME is OPENVMS_AXP. In GNAT, the enumeration
-literal for the type NAME is SYSTEM_NAME_GNAT.
+For HP Ada for OpenVMS Alpha, the enumeration literal
+for the type @code{NAME} is @code{OPENVMS_AXP}.
+In GNAT, the enumeration
+literal for the type @code{NAME} is @code{SYSTEM_NAME_GNAT}.
@node Library of Predefined Units
@section Library of Predefined Units
@noindent
A library of predefined units is provided as part of the
-DEC Ada and GNAT implementations. DEC Ada does not provide
-the package MACHINE_CODE but instead recommends importing
+HP Ada and GNAT implementations. HP Ada does not provide
+the package @code{MACHINE_CODE} but instead recommends importing
assembler code.
-The GNAT versions of the DEC Ada Run-Time Library (ADA$PREDEFINED:)
+The GNAT versions of the HP Ada Run-Time Library (@code{ADA$PREDEFINED:})
units are taken from the OpenVMS Alpha version, not the OpenVMS VAX
-version. During GNAT installation, the DEC Ada Predefined
-Library units are copied into the GNU:[LIB.OPENVMS7_x.2_8_x.DECLIB]
-(aka DECLIB) directory and patched to remove Ada 95 incompatibilities
-and to make them interoperable with GNAT, @pxref{Changes to DECLIB}
-for details.
+version.
+The HP Ada Predefined Library units are modified to remove post-Ada 83
+incompatibilities and to make them interoperable with GNAT
+(@pxref{Changes to DECLIB}, for details).
+The units are located in the @file{DECLIB} directory.
The GNAT RTL is contained in
-the GNU:[LIB.OPENVMS7_x.2_8_x.ADALIB] (aka ADALIB) directory and
-the default search path is set up to find DECLIB units in preference
-to ADALIB units with the same name (TEXT_IO, SEQUENTIAL_IO, and DIRECT_IO,
-for example).
-
-However, it is possible to change the default so that the
-reverse is true, or even to mix them using child package
-notation. The DEC Ada 83 units are available as DEC.xxx where xxx
-is the package name, and the Ada units are available in the
-standard manner defined for Ada 95, that is to say as Ada.xxx. To
-change the default, set ADA_INCLUDE_PATH and ADA_OBJECTS_PATH
-appropriately. For example, to change the default to use the Ada95
-versions do:
-
-@smallexample
-$ DEFINE ADA_INCLUDE_PATH GNU:[LIB.OPENVMS7_1.2_8_1.ADAINCLUDE],-
- GNU:[LIB.OPENVMS7_1.2_8_1.DECLIB]
-$ DEFINE ADA_OBJECTS_PATH GNU:[LIB.OPENVMS7_1.2_8_1.ADALIB],-
- GNU:[LIB.OPENVMS7_1.2_8_1.DECLIB]
-@end smallexample
+the @file{ADALIB} directory, and
+the default search path is set up to find @code{DECLIB} units in preference
+to @code{ADALIB} units with the same name (@code{TEXT_IO},
+@code{SEQUENTIAL_IO}, and @code{DIRECT_IO}, for example).
@menu
* Changes to DECLIB::
@end menu
@node Changes to DECLIB
-@subsection Changes to DECLIB
+@subsection Changes to @code{DECLIB}
@noindent
-The changes made to the DEC Ada predefined library for GNAT and Ada 95
+The changes made to the HP Ada predefined library for GNAT and post-Ada 83
compatibility are minor and include the following:
@itemize @bullet
@item Adjusting the location of pragmas and record representation
-clauses to obey Ada 95 rules
+clauses to obey Ada 95 (and thus Ada 2005) rules
@item Adding the proper notation to generic formal parameters
that take unconstrained types in instantiation
-@item Adding pragma ELABORATE_BODY to package specifications
+@item Adding pragma @code{ELABORATE_BODY} to package specs
that have package bodies not otherwise allowed
-@item Occurrences of the identifier @code{"PROTECTED"} are renamed to
-@code{"PROTECTD"}.
-Currently these are found only in the STARLET package spec.
+@item Replacing occurrences of the identifier ``@code{PROTECTED}'' by
+``@code{PROTECTD}''.
+Currently these are found only in the @code{STARLET} package spec.
+
+@item Changing @code{SYSTEM.ADDRESS} to @code{SYSTEM.SHORT_ADDRESS}
+where the address size is constrained to 32 bits.
@end itemize
@noindent
@section Bindings
@noindent
-On OpenVMS Alpha, DEC Ada provides the following strongly-typed bindings:
+On OpenVMS Alpha, HP Ada provides the following strongly-typed bindings:
@itemize @bullet
@item Command Language Interpreter (CLI interface)
@end itemize
@noindent
-GNAT provides implementations of these DEC bindings in the DECLIB directory.
+GNAT provides implementations of these HP bindings in the @code{DECLIB}
+directory, on both the Alpha and I64 OpenVMS platforms.
-The X/Motif bindings used to build DECLIB are whatever versions are in the
-DEC Ada @file{ADA$PREDEFINED} directory with extension @file{.ADC}.
-The build script will
-automatically add a pragma Linker_Options to packages @code{Xm}, @code{Xt},
-and @code{X_Lib}
+The X/Motif bindings used to build @code{DECLIB} are whatever versions are
+in the
+HP Ada @file{ADA$PREDEFINED} directory with extension @file{.ADC}.
+A pragma @code{Linker_Options} has been added to packages @code{Xm},
+@code{Xt}, and @code{X_Lib}
causing the default X/Motif sharable image libraries to be linked in. This
is done via options files named @file{xm.opt}, @file{xt.opt}, and
@file{x_lib.opt} (also located in the @file{DECLIB} directory).
@subsection Shared Libraries and Options Files
@noindent
-When using the DEC Ada
+When using the HP Ada
predefined X and Motif bindings, the linking with their sharable images is
done automatically by @command{GNAT LINK}.
When using other X and Motif bindings, you need
@subsection Interfaces to C
@noindent
-DEC Ada
+HP Ada
provides the following Ada types and operations:
@itemize @bullet
-@item C types package (C_TYPES)
+@item C types package (@code{C_TYPES})
-@item C strings (C_TYPES.NULL_TERMINATED)
+@item C strings (@code{C_TYPES.NULL_TERMINATED})
-@item Other_types (SHORT_INT)
+@item Other_types (@code{SHORT_INT})
@end itemize
@noindent
-Interfacing to C with GNAT, one can use the above approach
-described for DEC Ada or the facilities of Annex B of
-the Ada 95 Reference Manual (packages INTERFACES.C,
-INTERFACES.C.STRINGS and INTERFACES.C.POINTERS). For more
-information, see the section ``Interfacing to C'' in the
-@cite{GNAT Reference Manual}.
+Interfacing to C with GNAT, you can use the above approach
+described for HP Ada or the facilities of Annex B of
+the @cite{Ada Reference Manual} (packages @code{INTERFACES.C},
+@code{INTERFACES.C.STRINGS} and @code{INTERFACES.C.POINTERS}). For more
+information, see @ref{Interfacing to C,,, gnat_rm, GNAT Reference Manual}.
The @option{-gnatF} qualifier forces default and explicit
-@code{External_Name} parameters in pragmas Import and Export
+@code{External_Name} parameters in pragmas @code{Import} and @code{Export}
to be uppercased for compatibility with the default behavior
-of Compaq C. The qualifier has no effect on @code{Link_Name} parameters.
+of HP C. The qualifier has no effect on @code{Link_Name} parameters.
@node Main Program Definition
@section Main Program Definition
@noindent
The following section discusses differences in the
-definition of main programs on DEC Ada and GNAT.
-On DEC Ada, main programs are defined to meet the
+definition of main programs on HP Ada and GNAT.
+On HP Ada, main programs are defined to meet the
following conditions:
@itemize @bullet
-@item Procedure with no formal parameters (returns 0 upon
- normal completion)
+@item Procedure with no formal parameters (returns @code{0} upon
+normal completion)
-@item Procedure with no formal parameters (returns 42 when
- unhandled exceptions are raised)
+@item Procedure with no formal parameters (returns @code{42} when
+an unhandled exception is raised)
@item Function with no formal parameters whose returned value
- is of a discrete type
+is of a discrete type
-@item Procedure with one OUT formal of a discrete type for
- which a specification of pragma EXPORT_VALUED_PROCEDURE is given.
+@item Procedure with one @code{out} formal of a discrete type for
+which a specification of pragma @code{EXPORT_VALUED_PROCEDURE} is given.
@end itemize
@noindent
-When declared with the pragma EXPORT_VALUED_PROCEDURE,
+When declared with the pragma @code{EXPORT_VALUED_PROCEDURE},
a main function or main procedure returns a discrete
value whose size is less than 64 bits (32 on VAX systems),
the value is zero- or sign-extended as appropriate.
On GNAT, main programs are defined as follows:
@itemize @bullet
-@item Must be a non-generic, parameter-less subprogram that
+@item Must be a non-generic, parameterless subprogram that
is either a procedure or function returning an Ada
-STANDARD.INTEGER (the predefined type)
+@code{STANDARD.INTEGER} (the predefined type)
@item Cannot be a generic subprogram or an instantiation of a
generic subprogram
@section Implementation-Defined Attributes
@noindent
-GNAT provides all DEC Ada implementation-defined
+GNAT provides all HP Ada implementation-defined
attributes.
@node Compiler and Run-Time Interfacing
@section Compiler and Run-Time Interfacing
@noindent
-DEC Ada provides the following ways to pass options to the linker
+HP Ada provides the following qualifiers to pass options to the linker
(ACS LINK):
@itemize @bullet
-@item /WAIT and /SUBMIT qualifiers
+@item @option{/WAIT} and @option{/SUBMIT}
-@item /COMMAND qualifier
+@item @option{/COMMAND}
-@item /[NO]MAP qualifier
+@item @option{/@r{[}NO@r{]}MAP}
-@item /OUTPUT=file-spec
+@item @option{/OUTPUT=@var{file-spec}}
-@item /[NO]DEBUG and /[NO]TRACEBACK qualifiers
+@item @option{/@r{[}NO@r{]}DEBUG} and @option{/@r{[}NO@r{]}TRACEBACK}
@end itemize
@noindent
switches:
@itemize @bullet
-@item @option{/EXECUTABLE=exec-name}
+@item @option{/EXECUTABLE=@var{exec-name}}
-@item @option{/VERBOSE qualifier}
+@item @option{/VERBOSE}
-@item @option{/[NO]DEBUG} and @option{/[NO]TRACEBACK} qualifiers
+@item @option{/@r{[}NO@r{]}DEBUG} and @option{/@r{[}NO@r{]}TRACEBACK}
@end itemize
@noindent
For more information on these switches, see
@ref{Switches for gnatlink}.
-In DEC Ada, the command-line switch @option{/OPTIMIZE} is available
-to control optimization. DEC Ada also supplies the
+In HP Ada, the command-line switch @option{/OPTIMIZE} is available
+to control optimization. HP Ada also supplies the
following pragmas:
@itemize @bullet
@item @code{OPTIMIZE}
@noindent
In GNAT, optimization is controlled strictly by command
line parameters, as described in the corresponding section of this guide.
-The DIGITAL pragmas for control of optimization are
+The HP pragmas for control of optimization are
recognized but ignored.
-Note that in GNAT, the default is optimization off, whereas in DEC Ada 83,
+Note that in GNAT, the default is optimization off, whereas in HP Ada
the default is that optimization is turned on.
@node Program Compilation and Library Management
@section Program Compilation and Library Management
@noindent
-DEC Ada and GNAT provide a comparable set of commands to
-build programs. DEC Ada also provides a program library,
+HP Ada and GNAT provide a comparable set of commands to
+build programs. HP Ada also provides a program library,
which is a concept that does not exist on GNAT. Instead,
GNAT provides directories of sources that are compiled as
needed.
The following table summarizes
-the DEC Ada commands and provides
+the HP Ada commands and provides
equivalent GNAT commands. In this table, some GNAT
equivalents reflect the fact that GNAT does not use the
concept of a program library. Instead, it uses a model
Fortran. Therefore, standard system file commands are used
to manipulate these elements. Those GNAT commands are marked with
an asterisk.
-Note that, unlike DEC Ada, none of the GNAT commands accepts wild cards.
+Note that, unlike HP Ada, none of the GNAT commands accepts wild cards.
@need 1500
@multitable @columnfractions .35 .65
-@item @emph{DEC Ada Command}
+@item @emph{HP Ada Command}
@tab @emph{GNAT Equivalent / Description}
@item @command{ADA}
@item @command{ACS ENTER FOREIGN}
@tab Copy (*)@*
Allows the import of a foreign body as an Ada library
-specification and enters a reference to a pointer.
+spec and enters a reference to a pointer.
@item @command{ACS ENTER UNIT}
@tab Copy (*)@*
@section Input-Output
@noindent
-On OpenVMS Alpha systems, DEC Ada uses OpenVMS Record
+On OpenVMS Alpha systems, HP Ada uses OpenVMS Record
Management Services (RMS) to perform operations on
external files.
@noindent
-DEC Ada and GNAT predefine an identical set of input-
+HP Ada and GNAT predefine an identical set of input-
output packages. To make the use of the
-generic TEXT_IO operations more convenient, DEC Ada
+generic @code{TEXT_IO} operations more convenient, HP Ada
provides predefined library packages that instantiate the
integer and floating-point operations for the predefined
integer and floating-point types as shown in the following table.
@end multitable
@noindent
-The DEC Ada predefined packages and their operations
-are implemented using OpenVMS Alpha files and input-
-output facilities. DEC Ada supports asynchronous input-
-output on OpenVMS Alpha. Familiarity with the following is
-recommended:
+The HP Ada predefined packages and their operations
+are implemented using OpenVMS Alpha files and input-output
+facilities. HP Ada supports asynchronous input-output on OpenVMS Alpha.
+Familiarity with the following is recommended:
@itemize @bullet
@item RMS file organizations and access methods
@noindent
GNAT provides I/O facilities that are completely
-compatible with DEC Ada. The distribution includes the
-standard DEC Ada versions of all I/O packages, operating
-in a manner compatible with DEC Ada. In particular, the
-following packages are by default the DEC Ada (Ada 83)
+compatible with HP Ada. The distribution includes the
+standard HP Ada versions of all I/O packages, operating
+in a manner compatible with HP Ada. In particular, the
+following packages are by default the HP Ada (Ada 83)
versions of these packages rather than the renamings
-suggested in annex J of the Ada 95 Reference Manual:
+suggested in Annex J of the Ada Reference Manual:
@itemize @bullet
@item @code{TEXT_IO}
@end itemize
@noindent
-The use of the standard Ada 95 syntax for child packages (for
-example, @code{ADA.TEXT_IO}) retrieves the Ada 95 versions of these
-packages, as defined in the Ada 95 Reference Manual.
-GNAT provides DIGITAL-compatible predefined instantiations
+The use of the standard child package syntax (for
+example, @code{ADA.TEXT_IO}) retrieves the post-Ada 83 versions of these
+packages.
+GNAT provides HP-compatible predefined instantiations
of the @code{TEXT_IO} packages, and also
provides the standard predefined instantiations required
-by the Ada 95 Reference Manual.
+by the @cite{Ada Reference Manual}.
For further information on how GNAT interfaces to the file
system or how I/O is implemented in programs written in
-mixed languages, see the chapter ``Implementation of the
-Standard I/O'' in the @cite{GNAT Reference Manual}.
+mixed languages, see @ref{Implementation of the Standard I/O,,,
+gnat_rm, GNAT Reference Manual}.
This chapter covers the following:
@itemize @bullet
@item Standard I/O packages
@section Implementation Limits
@noindent
-The following table lists implementation limits for DEC Ada
+The following table lists implementation limits for HP Ada
and GNAT systems.
@multitable @columnfractions .60 .20 .20
@sp 1
@item @emph{Compilation Parameter}
-@tab @emph{DEC Ada}
+@tab @emph{HP Ada}
@tab @emph{GNAT}
@sp 1
@item In a subprogram or entry declaration, maximum number of
- formal parameters that are of an unconstrained record type
+formal parameters that are of an unconstrained record type
@tab 32
@tab No set limit
@sp 1
@item Maximum identifier length (number of characters)
@tab 255
-@tab 255
+@tab 32766
@sp 1
@item Maximum number of characters in a source line
@tab 255
-@tab 255
+@tab 32766
@sp 1
@item Maximum collection size (number of bytes)
@sp 1
@item Maximum number of formal parameters in an entry or
- subprogram declaration
+subprogram declaration
@tab 246
@tab No set limit
@sp 1
@sp 1
@item Maximum number of objects declared with the pragma @code{COMMON_OBJECT}
- or @code{PSECT_OBJECT}
+or @code{PSECT_OBJECT}
@tab 32757
@tab No set limit
@sp 1
@item Maximum number of enumeration literals in an enumeration type
- definition
+definition
@tab 65535
@tab No set limit
@sp 1
@tab 2**31-1
@end multitable
-@node Tools
-@section Tools
+@node Tools and Utilities
+@section Tools and Utilities
-@end ifset
+@noindent
+The following table lists some of the OpenVMS development tools
+available for HP Ada, and the corresponding tools for
+use with @value{EDITION} on Alpha and I64 platforms.
+Aside from the debugger, all the OpenVMS tools identified are part
+of the DECset package.
+
+@iftex
+@c Specify table in TeX since Texinfo does a poor job
+@tex
+\smallskip
+\smallskip
+\settabs\+Language-Sensitive Editor\quad
+ &Product with HP Ada\quad
+ &\cr
+\+\it Tool
+ &\it Product with HP Ada
+ & \it Product with GNAT Pro\cr
+\smallskip
+\+Code Management System
+ &HP CMS
+ & HP CMS\cr
+\smallskip
+\+Language-Sensitive Editor
+ &HP LSE
+ & emacs or HP LSE (Alpha)\cr
+\+
+ &
+ & HP LSE (I64)\cr
+\smallskip
+\+Debugger
+ &OpenVMS Debug
+ & gdb (Alpha),\cr
+\+
+ &
+ & OpenVMS Debug (I64)\cr
+\smallskip
+\+Source Code Analyzer /
+ &HP SCA
+ & GNAT XREF\cr
+\+Cross Referencer
+ &
+ &\cr
+\smallskip
+\+Test Manager
+ &HP Digital Test
+ & HP DTM\cr
+\+
+ &Manager (DTM)
+ &\cr
+\smallskip
+\+Performance and
+ & HP PCA
+ & HP PCA\cr
+\+Coverage Analyzer
+ &
+ &\cr
+\smallskip
+\+Module Management
+ & HP MMS
+ & Not applicable\cr
+\+ System
+ &
+ &\cr
+\smallskip
+\smallskip
+@end tex
+@end iftex
+
+@ifnottex
+@c This is the Texinfo version of the table. It renders poorly in pdf, hence
+@c the TeX version above for the printed version
+@flushleft
+@c @multitable @columnfractions .3 .4 .4
+@multitable {Source Code Analyzer /}{Tool with HP Ada}{Tool with GNAT Pro}
+@item @i{Tool}
+@tab @i{Tool with HP Ada}
+@tab @i{Tool with @value{EDITION}}
+@item Code Management@*System
+@tab HP CMS
+@tab HP CMS
+@item Language-Sensitive@*Editor
+@tab HP LSE
+@tab emacs or HP LSE (Alpha)
+@item
+@tab
+@tab HP LSE (I64)
+@item Debugger
+@tab OpenVMS Debug
+@tab gdb (Alpha),
+@item
+@tab
+@tab OpenVMS Debug (I64)
+@item Source Code Analyzer /@*Cross Referencer
+@tab HP SCA
+@tab GNAT XREF
+@item Test Manager
+@tab HP Digital Test@*Manager (DTM)
+@tab HP DTM
+@item Performance and@*Coverage Analyzer
+@tab HP PCA
+@tab HP PCA
+@item Module Management@*System
+@tab HP MMS
+@tab Not applicable
+@end multitable
+@end flushleft
+@end ifnottex
+@end ifset
@c **************************************
@node Platform-Specific Information for the Run-Time Libraries
@cindex Run-time libraries (platform-specific information)
@noindent
-The GNAT run-time implementation
-may vary with respect to both the underlying threads library and
-the exception handling scheme.
+The GNAT run-time implementation may vary with respect to both the
+underlying threads library and the exception handling scheme.
For threads support, one or more of the following are supplied:
@itemize @bullet
@item @b{native threads library}, a binding to the thread package from
the underlying operating system
-@item @b{FSU threads library}, a binding to the Florida State University
-threads implementation, which complies fully with the requirements of Annex D
-
@item @b{pthreads library} (Sparc Solaris only), a binding to the Solaris
POSIX thread package
@end itemize
@menu
* Summary of Run-Time Configurations::
* Specifying a Run-Time Library::
-* Choosing between Native and FSU Threads Libraries::
* Choosing the Scheduling Policy::
* Solaris-Specific Considerations::
-* IRIX-Specific Considerations::
* Linux-Specific Considerations::
* AIX-Specific Considerations::
+* Irix-Specific Considerations::
+* RTX-Specific Considerations::
@end menu
-
@node Summary of Run-Time Configurations
@section Summary of Run-Time Configurations
-
@multitable @columnfractions .30 .70
@item @b{alpha-openvms}
@item @code{@ @ }@i{rts-native (default)}
@item @code{@ @ @ @ }Tasking @tab native VMS threads
@item @code{@ @ @ @ }Exceptions @tab ZCX
@*
-@item @b{pa-hpux}
+@item @b{alpha-tru64}
@item @code{@ @ }@i{rts-native (default)}
-@item @code{@ @ @ @ }Tasking @tab native HP threads library
+@item @code{@ @ @ @ }Tasking @tab native TRU64 threads
@item @code{@ @ @ @ }Exceptions @tab ZCX
@*
@item @code{@ @ }@i{rts-sjlj}
-@item @code{@ @ @ @ }Tasking @tab native HP threads library
+@item @code{@ @ @ @ }Tasking @tab native TRU64 threads
@item @code{@ @ @ @ }Exceptions @tab SJLJ
@*
-@item @b{sparc-solaris} @tab
+@item @b{ia64-hp_linux}
@item @code{@ @ }@i{rts-native (default)}
-@item @code{@ @ @ @ }Tasking @tab native Solaris threads library
+@item @code{@ @ @ @ }Tasking @tab pthread library
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @b{ia64-hpux}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native HP-UX threads
+@item @code{@ @ @ @ }Exceptions @tab SJLJ
+@*
+@item @b{ia64-openvms}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native VMS threads
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @b{ia64-sgi_linux}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab pthread library
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @b{mips-irix}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native IRIX threads
@item @code{@ @ @ @ }Exceptions @tab ZCX
@*
-@item @code{@ @ }@i{rts-fsu} @tab
-@item @code{@ @ @ @ }Tasking @tab FSU threads library
+@item @b{pa-hpux}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native HP-UX threads
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @code{@ @ }@i{rts-sjlj}
+@item @code{@ @ @ @ }Tasking @tab native HP-UX threads
+@item @code{@ @ @ @ }Exceptions @tab SJLJ
+@*
+@item @b{ppc-aix}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native AIX threads
@item @code{@ @ @ @ }Exceptions @tab SJLJ
@*
-@item @code{@ @ }@i{rts-m64}
-@item @code{@ @ @ @ }Tasking @tab native Solaris threads library
-@item @code{@ @ @ @ }Exceptions @tab ZCX
-@item @code{@ @ @ @ }Constraints @tab Use only when compiling in 64-bit mode;
-@item @tab Use only on Solaris 8 or later.
-@item @tab @xref{Building and Debugging 64-bit Applications}, for details.
+@item @b{ppc-darwin}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native MacOS threads
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @b{sparc-solaris} @tab
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native Solaris threads library
+@item @code{@ @ @ @ }Exceptions @tab ZCX
@*
@item @code{@ @ }@i{rts-pthread}
-@item @code{@ @ @ @ }Tasking @tab pthreads library
+@item @code{@ @ @ @ }Tasking @tab pthread library
@item @code{@ @ @ @ }Exceptions @tab ZCX
@*
@item @code{@ @ }@i{rts-sjlj}
@item @code{@ @ @ @ }Tasking @tab native Solaris threads library
@item @code{@ @ @ @ }Exceptions @tab SJLJ
@*
+@item @b{sparc64-solaris} @tab
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native Solaris threads library
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
@item @b{x86-linux}
@item @code{@ @ }@i{rts-native (default)}
-@item @code{@ @ @ @ }Tasking @tab LinuxThread library
+@item @code{@ @ @ @ }Tasking @tab pthread library
@item @code{@ @ @ @ }Exceptions @tab ZCX
@*
-@item @code{@ @ }@i{rts-fsu}
-@item @code{@ @ @ @ }Tasking @tab FSU threads library
+@item @code{@ @ }@i{rts-sjlj}
+@item @code{@ @ @ @ }Tasking @tab pthread library
+@item @code{@ @ @ @ }Exceptions @tab SJLJ
+@*
+@item @b{x86-lynx}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native LynxOS threads
@item @code{@ @ @ @ }Exceptions @tab SJLJ
@*
-@item @code{@ @ }@i{rts-sjlj}
-@item @code{@ @ @ @ }Tasking @tab LinuxThread library
+@item @b{x86-solaris}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab native Solaris threads
@item @code{@ @ @ @ }Exceptions @tab SJLJ
@*
@item @b{x86-windows}
@item @code{@ @ }@i{rts-native (default)}
@item @code{@ @ @ @ }Tasking @tab native Win32 threads
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @code{@ @ }@i{rts-sjlj (default)}
+@item @code{@ @ @ @ }Tasking @tab native Win32 threads
+@item @code{@ @ @ @ }Exceptions @tab SJLJ
+@*
+@item @b{x86-windows-rtx}
+@item @code{@ @ }@i{rts-rtx-rtss (default)}
+@item @code{@ @ @ @ }Tasking @tab RTX real-time subsystem RTSS threads (kernel mode)
+@item @code{@ @ @ @ }Exceptions @tab SJLJ
+@*
+@item @code{@ @ }@i{rts-rtx-w32}
+@item @code{@ @ @ @ }Tasking @tab RTX Win32 threads (user mode)
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @b{x86_64-linux}
+@item @code{@ @ }@i{rts-native (default)}
+@item @code{@ @ @ @ }Tasking @tab pthread library
+@item @code{@ @ @ @ }Exceptions @tab ZCX
+@*
+@item @code{@ @ }@i{rts-sjlj}
+@item @code{@ @ @ @ }Tasking @tab pthread library
@item @code{@ @ @ @ }Exceptions @tab SJLJ
@*
@end multitable
-
-
@node Specifying a Run-Time Library
@section Specifying a Run-Time Library
in the gcc target-dependent area:
@smallexample
-target=$prefix/lib/gcc-lib/gcc-@i{dumpmachine}/gcc-@i{dumpversion}/
+target=$prefix/lib/gcc/gcc-@i{dumpmachine}/gcc-@i{dumpversion}/
@end smallexample
@noindent
| | |
| +--- adalib <----+
|
- +--- rts-fsu
- | |
- | +--- adainclude
- | |
- | +--- adalib
- |
+--- rts-sjlj
|
+--- adainclude
- |
- +--- adalib
-@end group
-@end smallexample
-
-@noindent
-If the @i{rts-fsu} library is to be selected on a permanent basis,
-these soft links can be modified with the following commands:
-
-@smallexample
-$ cd $target
-$ rm -f adainclude adalib
-$ ln -s rts-fsu/adainclude adainclude
-$ ln -s rts-fsu/adalib adalib
-@end smallexample
-
-@noindent
-Alternatively, you can specify @file{rts-fsu/adainclude} in the file
-@file{$target/ada_source_path} and @file{rts-fsu/adalib} in
-@file{$target/ada_object_path}.
-
-Selecting another run-time library temporarily can be
-achieved by the regular mechanism for GNAT object or source path selection:
-
-@itemize @bullet
-@item
-Set the environment variables:
-
-@smallexample
-$ ADA_INCLUDE_PATH=$target/rts-fsu/adainclude:$ADA_INCLUDE_PATH
-$ ADA_OBJECTS_PATH=$target/rts-fsu/adalib:$ADA_OBJECTS_PATH
-$ export ADA_INCLUDE_PATH ADA_OBJECTS_PATH
-@end smallexample
-
-@item
-Use @option{-aI$target/rts-fsu/adainclude}
-and @option{-aO$target/rts-fsu/adalib}
-on the @command{gnatmake} command line
-
-@item
-Use the switch @option{--RTS}; e.g., @option{--RTS=fsu}
-@cindex @option{--RTS} option
-@end itemize
-
-@noindent
-You can similarly switch to @emph{rts-sjlj}.
-
-@node Choosing between Native and FSU Threads Libraries
-@section Choosing between Native and FSU Threads Libraries
-@cindex Native threads library
-@cindex FSU threads library
-
-@noindent
-Some GNAT implementations offer a choice between
-native threads and FSU threads.
-
-@itemize @bullet
-@item
-The @emph{native threads} library correspond to the standard system threads
-implementation (e.g. LinuxThreads on GNU/Linux,
-@cindex LinuxThreads library
-POSIX threads on AIX, or
-Solaris threads on Solaris). When this option is chosen, GNAT provides
-a full and accurate implementation of the core language tasking model
-as described in Chapter 9 of the Ada Reference Manual,
-but might not (and probably does not) implement
-the exact semantics as specified in @w{Annex D} (the Real-Time Systems Annex).
-@cindex Annex D (Real-Time Systems Annex) compliance
-@cindex Real-Time Systems Annex compliance
-Indeed, the reason that a choice of libraries is offered
-on a given target is because some of the
-ACATS tests for @w{Annex D} fail using the native threads library.
-As far as possible, this library is implemented
-in accordance with Ada semantics (e.g., modifying priorities as required
-to simulate ceiling locking),
-but there are often slight inaccuracies, most often in the area of
-absolutely respecting the priority rules on a single
-processor.
-Moreover, it is not possible in general to define the exact behavior,
-because the native threads implementations
-are not well enough documented.
-
-On systems where the @code{SCHED_FIFO} POSIX scheduling policy is supported,
-@cindex POSIX scheduling policies
-@cindex @code{SCHED_FIFO} scheduling policy
-native threads will provide a behavior very close to the @w{Annex D}
-requirements (i.e., a run-till-blocked scheduler with fixed priorities), but
-on some systems (in particular GNU/Linux and Solaris), you need to have root
-privileges to use the @code{SCHED_FIFO} policy.
-
-@item
-The @emph{FSU threads} library provides a completely accurate implementation
-of @w{Annex D}.
-Thus, operating with this library, GNAT is 100% compliant with both the core
-and all @w{Annex D}
-requirements.
-The formal validations for implementations offering
-a choice of threads packages are always carried out using the FSU
-threads option.
-@end itemize
+ |
+ +--- adalib
+@end group
+@end smallexample
@noindent
-From these considerations, it might seem that FSU threads are the
-better choice,
-but that is by no means always the case. The FSU threads package
-operates with all Ada tasks appearing to the system to be a single
-thread. This is often considerably more efficient than operating
-with separate threads, since for example, switching between tasks
-can be accomplished without the (in some cases considerable)
-overhead of a context switch between two system threads. However,
-it means that you may well lose concurrency at the system
-level. Notably, some system operations (such as I/O) may block all
-tasks in a program and not just the calling task. More
-significantly, the FSU threads approach likely means you cannot
-take advantage of multiple processors, since for this you need
-separate threads (or even separate processes) to operate on
-different processors.
+If the @i{rts-sjlj} library is to be selected on a permanent basis,
+these soft links can be modified with the following commands:
-For most programs, the native threads library is
-usually the better choice. Use the FSU threads if absolute
-conformance to @w{Annex D} is important for your application, or if
-you find that the improved efficiency of FSU threads is significant to you.
+@smallexample
+$ cd $target
+$ rm -f adainclude adalib
+$ ln -s rts-sjlj/adainclude adainclude
+$ ln -s rts-sjlj/adalib adalib
+@end smallexample
-Note also that to take full advantage of Florist and Glade, it is highly
-recommended that you use native threads.
+@noindent
+Alternatively, you can specify @file{rts-sjlj/adainclude} in the file
+@file{$target/ada_source_path} and @file{rts-sjlj/adalib} in
+@file{$target/ada_object_path}.
+Selecting another run-time library temporarily can be
+achieved by using the @option{--RTS} switch, e.g., @option{--RTS=sjlj}
+@cindex @option{--RTS} option
@node Choosing the Scheduling Policy
@section Choosing the Scheduling Policy
value greater than @code{0.0}, or else use the corresponding @option{-T}
binder option.
-
-
@node Solaris-Specific Considerations
@section Solaris-Specific Considerations
@cindex Solaris Sparc threads libraries
@noindent
This section addresses some topics related to the various threads libraries
-on Sparc Solaris and then provides some information on building and
-debugging 64-bit applications.
+on Sparc Solaris.
@menu
* Solaris Threads Issues::
-* Building and Debugging 64-bit Applications::
@end menu
-
@node Solaris Threads Issues
@subsection Solaris Threads Issues
@noindent
-Starting with version 3.14, GNAT under Solaris comes with a new tasking
-run-time library based on POSIX threads --- @emph{rts-pthread}.
+GNAT under Solaris/Sparc 32 bits comes with an alternate tasking run-time
+library based on POSIX threads --- @emph{rts-pthread}.
@cindex rts-pthread threads library
This run-time library has the advantage of being mostly shared across all
POSIX-compliant thread implementations, and it also provides under
As explained above, the native run-time library is based on the Solaris thread
library (@code{libthread}) and is the default library.
-The FSU run-time library is based on the FSU threads.
-@cindex FSU threads library
-Starting with Solaris 2.5.1, when the Solaris threads library is used
-(this is the default), programs
+When the Solaris threads library is used (this is the default), programs
compiled with GNAT can automatically take advantage of
and can thus execute on multiple processors.
The user can alternatively specify a processor on which the program should run
to emulate a single-processor system. The multiprocessor / uniprocessor choice
is made by
-setting the environment variable @code{GNAT_PROCESSOR}
-@cindex @code{GNAT_PROCESSOR} environment variable (on Sparc Solaris)
+setting the environment variable @env{GNAT_PROCESSOR}
+@cindex @env{GNAT_PROCESSOR} environment variable (on Sparc Solaris)
to one of the following:
@table @code
@item -2
Use the default configuration (run the program on all
- available processors) - this is the same as having
- @code{GNAT_PROCESSOR} unset
+available processors) - this is the same as having @code{GNAT_PROCESSOR}
+unset
@item -1
Let the run-time implementation choose one processor and run the program on
- that processor
+that processor
@item 0 .. Last_Proc
Run the program on the specified processor.
- @code{Last_Proc} is equal to @code{_SC_NPROCESSORS_CONF - 1}
+@code{Last_Proc} is equal to @code{_SC_NPROCESSORS_CONF - 1}
(where @code{_SC_NPROCESSORS_CONF} is a system variable).
@end table
-
-@node Building and Debugging 64-bit Applications
-@subsection Building and Debugging 64-bit Applications
-
-@noindent
-In a 64-bit application, all the sources involved must be compiled with the
-@option{-m64} command-line option, and a specific GNAT library (compiled with
-this option) is required.
-The easiest way to build a 64bit application is to add
-@option{-m64 --RTS=m64} to the @command{gnatmake} flags.
-
-To debug these applications, dwarf-2 debug information is required, so you
-have to add @option{-gdwarf-2} to your gnatmake arguments.
-In addition, a special
-version of gdb, called @command{gdb64}, needs to be used.
-
-To summarize, building and debugging a ``Hello World'' program in 64-bit mode
-amounts to:
-
-@smallexample
- $ gnatmake -m64 -gdwarf-2 --RTS=m64 hello.adb
- $ gdb64 hello
-@end smallexample
-
-
-
-@node IRIX-Specific Considerations
-@section IRIX-Specific Considerations
-@cindex IRIX thread library
-
-@noindent
-On SGI IRIX, the thread library depends on which compiler is used.
-The @emph{o32 ABI} compiler comes with a run-time library based on the
-user-level @code{athread}
-library. Thus kernel-level capabilities such as nonblocking system
-calls or time slicing can only be achieved reliably by specifying different
-@code{sprocs} via the pragma @code{Task_Info}
-@cindex pragma Task_Info (and IRIX threads)
-and the
-@code{System.Task_Info} package.
-@cindex @code{System.Task_Info} package (and IRIX threads)
-See the @cite{GNAT Reference Manual} for further information.
-
-The @emph{n32 ABI} compiler comes with a run-time library based on the
-kernel POSIX threads and thus does not have the limitations mentioned above.
-
-
@node Linux-Specific Considerations
@section Linux-Specific Considerations
@cindex Linux threads libraries
@noindent
-The default thread library under GNU/Linux has the following disadvantages
-compared to other native thread libraries:
-
-@itemize @bullet
-@item The size of the task's stack is limited to 2 megabytes.
-@item The signal model is not POSIX compliant, which means that to send a
- signal to the process, you need to send the signal to all threads,
- e.g. by using @code{killpg()}.
-@end itemize
+On GNU/Linux without NPTL support (usually system with GNU C Library
+older than 2.3), the signal model is not POSIX compliant, which means
+that to send a signal to the process, you need to send the signal to all
+threads, e.g.@: by using @code{killpg()}.
@node AIX-Specific Considerations
@section AIX-Specific Considerations
On AIX, the resolver library initializes some internal structure on
the first call to @code{get*by*} functions, which are used to implement
@code{GNAT.Sockets.Get_Host_By_Name} and
-@code{GNAT.Sockets.Get_Host_By_Addrss}.
+@code{GNAT.Sockets.Get_Host_By_Address}.
If such initialization occurs within an Ada task, and the stack size for
the task is the default size, a stack overflow may occur.
specify a sufficiently large size for the stack of the task that contains
this call.
+@node Irix-Specific Considerations
+@section Irix-Specific Considerations
+@cindex Irix libraries
+
+@noindent
+The GCC support libraries coming with the Irix compiler have moved to
+their canonical place with respect to the general Irix ABI related
+conventions. Running applications built with the default shared GNAT
+run-time now requires the LD_LIBRARY_PATH environment variable to
+include this location. A possible way to achieve this is to issue the
+following command line on a bash prompt:
+
+@smallexample
+@group
+$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`dirname \`gcc --print-file-name=libgcc_s.so\``
+@end group
+@end smallexample
+
+@node RTX-Specific Considerations
+@section RTX-Specific Considerations
+@cindex RTX libraries
+
+@noindent
+The Real-time Extension (RTX) to Windows is based on the Windows Win32
+API. Applications can be built to work in two different modes:
+
+@itemize @bullet
+@item
+Windows executables that run in Ring 3 to utilize memory protection
+(@emph{rts-rtx-w32}).
+
+@item
+Real-time subsystem (RTSS) executables that run in Ring 0, where
+performance can be optimized with RTSS applications taking precedent
+over all Windows applications (@emph{rts-rtx-rtss}).
+
+@end itemize
+
@c *******************************
@node Example of Binder Output File
@appendix Example of Binder Output File
file generated for a simple ``Hello World'' program.
Comments have been added for clarification purposes.
-
@smallexample @c adanocomment
@iftex
@leftskip=0cm
pragma Import (C, gnat_exit_status);
GNAT_Version : constant String :=
- "GNAT Version: 3.15w (20010315)";
+ "GNAT Version: 6.0.0w (20061115)";
pragma Export (C, GNAT_Version, "__gnat_version");
-- This is the generated adafinal routine that performs
-- a-except.ads/adb for full details of how zero cost
-- exception handling works. This procedure, the call to
-- it, and the two following tables are all omitted if the
- -- build is in longjmp/setjump exception mode.
+ -- build is in longjmp/setjmp exception mode.
@findex SDP_Table_Build
@findex Zero Cost Exceptions
-- Call SDP_Table_Build to build the top level procedure
-- table for zero cost exception handling (omitted in
- -- longjmp/setjump mode).
+ -- longjmp/setjmp mode).
SDP_Table_Build (ST'Address, 23, EA'Address, 23);
-- pragma Import because if we try to with the unit and
-- call it Ada style, then not only do we waste time
-- recompiling it, but also, we don't really know the right
- -- switches (e.g. identifier character set) to be used
+ -- switches (e.g.@: identifier character set) to be used
-- to compile it.
procedure Ada_Main_Program;
the problem might be (more usually of course you would be debugging
elaboration code in your own application).
-
@node Elaboration Order Handling in GNAT
@appendix Elaboration Order Handling in GNAT
@cindex Order of elaboration
@cindex Elaboration control
@menu
-* Elaboration Code in Ada 95::
-* Checking the Elaboration Order in Ada 95::
-* Controlling the Elaboration Order in Ada 95::
+* Elaboration Code::
+* Checking the Elaboration Order::
+* Controlling the Elaboration Order::
* Controlling Elaboration in GNAT - Internal Calls::
* Controlling Elaboration in GNAT - External Calls::
* Default Behavior in GNAT - Ensuring Safety::
@end menu
@noindent
-This chapter describes the handling of elaboration code in Ada 95 and
+This chapter describes the handling of elaboration code in Ada and
in GNAT, and discusses how the order of elaboration of program units can
be controlled in GNAT, either automatically or with explicit programming
features.
-@node Elaboration Code in Ada 95
-@section Elaboration Code in Ada 95
+@node Elaboration Code
+@section Elaboration Code
@noindent
-Ada 95 provides rather general mechanisms for executing code at elaboration
+Ada provides rather general mechanisms for executing code at elaboration
time, that is to say before the main program starts executing. Such code arises
in three contexts:
@group
@cartouche
with Unit_1;
-package Unit_2 is ...
+package Unit_2 is @dots{}
@end cartouche
@end group
@end smallexample
If one of the two expressions is true, and the other is false, then one
of the above orders is correct, and the other is incorrect. For example,
-if @code{expression_1} = 1 and @code{expression_2} /= 2,
-then the call to @code{Func_2}
-will occur, but not the call to @code{Func_1.}
+if @code{expression_1} /= 1 and @code{expression_2} = 2,
+then the call to @code{Func_1}
+will occur, but not the call to @code{Func_2.}
This means that it is essential
to elaborate the body of @code{Unit_1} before
the body of @code{Unit_2}, so the first
to figure out which of these expressions will be true, and hence it
is impossible to guarantee a safe order of elaboration at run time.
-@node Checking the Elaboration Order in Ada 95
-@section Checking the Elaboration Order in Ada 95
+@node Checking the Elaboration Order
+@section Checking the Elaboration Order
@noindent
In some languages that involve the same kind of elaboration problems,
-e.g. Java and C++, the programmer is expected to worry about these
+e.g.@: Java and C++, the programmer is expected to worry about these
ordering problems himself, and it is common to
write a program in which an incorrect elaboration order gives
surprising results, because it references variables before they
are initialized.
-Ada 95 is designed to be a safe language, and a programmer-beware approach is
+Ada is designed to be a safe language, and a programmer-beware approach is
clearly not sufficient. Consequently, the language provides three lines
of defense:
dynamic checking. One possible rule would be simply to say that the
exception is raised if you access a variable which has not yet been
elaborated. The trouble with this approach is that it could require
-expensive checks on every variable reference. Instead Ada 95 has two
+expensive checks on every variable reference. Instead Ada has two
rules which are a little more restrictive, but easier to check, and
easier to state:
does such optimizations, but still the easiest conceptual model is to
think of there being one variable per subprogram.
-@node Controlling the Elaboration Order in Ada 95
-@section Controlling the Elaboration Order in Ada 95
+@node Controlling the Elaboration Order
+@section Controlling the Elaboration Order
@noindent
-In the previous section we discussed the rules in Ada 95 which ensure
+In the previous section we discussed the rules in Ada which ensure
that @code{Program_Error} is raised if an incorrect elaboration order is
chosen. This prevents erroneous executions, but we need mechanisms to
specify a correct execution and avoid the exception altogether.
-To achieve this, Ada 95 provides a number of features for controlling
+To achieve this, Ada provides a number of features for controlling
the order of elaboration. We discuss these features in this section.
First, there are several ways of indicating to the compiler that a given
@table @asis
@item packages that do not require a body
-In Ada 95, a library package that does not require a body does not permit
-a body. This means that if we have a such a package, as in:
+A library package that does not require a body does not permit
+a body (this rule was introduced in Ada 95).
+Thus if we have a such a package, as in:
@smallexample @c ada
@group
clearly there would be no possible elaboration order.
The above pragmas allow a server to guarantee safe use by clients, and
-clearly this is the preferable approach. Consequently a good rule in
-Ada 95 is to mark units as @code{Pure} or @code{Preelaborate} if possible,
+clearly this is the preferable approach. Consequently a good rule
+is to mark units as @code{Pure} or @code{Preelaborate} if possible,
and if this is not possible,
mark them as @code{Elaborate_Body} if possible.
As we have seen, there are situations where neither of these
@end table
@noindent
-We are now in a position to give a usage rule in Ada 95 for avoiding
+We are now in a position to give a usage rule in Ada for avoiding
elaboration problems, at least if dynamic dispatching and access to
subprogram values are not used. We will handle these cases separately
later.
The rule is simple. If a unit has elaboration code that can directly or
indirectly make a call to a subprogram in a @code{with}'ed unit, or instantiate
-a generic unit in a @code{with}'ed unit,
+a generic package in a @code{with}'ed unit,
then if the @code{with}'ed unit does not have
pragma @code{Pure} or @code{Preelaborate}, then the client should have
a pragma @code{Elaborate_All}
for the @code{with}'ed unit. By following this rule a client is
assured that calls can be made without risk of an exception.
+
+For generic subprogram instantiations, the rule can be relaxed to
+require only a pragma @code{Elaborate} since elaborating the body
+of a subprogram cannot cause any transitive elaboration (we are
+not calling the subprogram in this case, just elaborating its
+declaration).
+
If this rule is not followed, then a program may be in one of four
states:
No order of elaboration exists which follows the rules, taking into
account any @code{Elaborate}, @code{Elaborate_All},
or @code{Elaborate_Body} pragmas. In
-this case, an Ada 95 compiler must diagnose the situation at bind
+this case, an Ada compiler must diagnose the situation at bind
time, and refuse to build an executable program.
@item One or more orders exist, all incorrect
-One or more acceptable elaboration orders exists, and all of them
+One or more acceptable elaboration orders exist, and all of them
generate an elaboration order problem. In this case, the binder
can build an executable program, but @code{Program_Error} will be raised
when the program is run.
@end table
@noindent
-Note that one additional advantage of following our Elaborate_All rule
+Note that one additional advantage of following our rules on the use
+of @code{Elaborate} and @code{Elaborate_All}
is that the program continues to stay in the ideal (all orders OK) state
even if maintenance
-changes some bodies of some subprograms. Conversely, if a program that does
+changes some bodies of some units. Conversely, if a program that does
not follow this rule happens to be safe at some point, this state of affairs
may deteriorate silently as a result of maintenance changes.
@section Controlling Elaboration in GNAT - Internal Calls
@noindent
-In the case of internal calls, i.e. calls within a single package, the
+In the case of internal calls, i.e., calls within a single package, the
programmer has full control over the order of elaboration, and it is up
to the programmer to elaborate declarations in an appropriate order. For
example writing:
@noindent
Note that in this particular case, it is likely that the call is safe, because
the function @code{One} does not access any global variables.
-Nevertheless in Ada 95, we do not want the validity of the check to depend on
+Nevertheless in Ada, we do not want the validity of the check to depend on
the contents of the body (think about the separate compilation case), so this
is still wrong, as we discussed in the previous sections.
The error is easily corrected by rearranging the declarations so that the
-body of One appears before the declaration containing the call
-(note that in Ada 95,
+body of @code{One} appears before the declaration containing the call
+(note that in Ada 95 and Ada 2005,
declarations can appear in any order, so there is no restriction that
would prevent this reordering, and if we write:
package body Math is
function Sqrt (Arg : Float) return Float is
begin
- ...
+ @dots{}
end Sqrt;
end Math;
@end group
with Stuff;
procedure Main is
begin
- ...
+ @dots{}
end Main;
@end group
@end cartouche
@smallexample @c ada
@group
@cartouche
-package X is ...
+package X is @dots{}
-package Y is ...
+package Y is @dots{}
with X;
-package body Y is ...
+package body Y is @dots{}
with Y;
-package body X is ...
+package body X is @dots{}
@end cartouche
@end group
@end smallexample
which means you would have to
elaborate the body of @code{Y} first, but that @code{with}'s @code{X},
which means
-you have to elaborate the body of @code{X} first, but ... and we have a
+you have to elaborate the body of @code{X} first, but @dots{} and we have a
loop that cannot be broken.
It is true that the binder can in many cases guess an order of elaboration
@itemize
@item
@emph{If a unit has elaboration code that can directly or indirectly make a
-call to a subprogram in a @code{with}'ed unit, or instantiate a generic unit
-in a @code{with}'ed unit, then if the @code{with}'ed unit
+call to a subprogram in a @code{with}'ed unit, or instantiate a generic
+package in a @code{with}'ed unit, then if the @code{with}'ed unit
does not have pragma @code{Pure} or
@code{Preelaborate}, then the client should have an
-@code{Elaborate_All} for the @code{with}'ed unit.}
+@code{Elaborate_All} pragma for the @code{with}'ed unit.}
+
+@emph{In the case of instantiating a generic subprogram, it is always
+sufficient to have only an @code{Elaborate} pragma for the
+@code{with}'ed unit.}
@end itemize
@noindent
can be made without risk of an exception.
In this mode GNAT traces all calls that are potentially made from
-elaboration code, and puts in any missing implicit @code{Elaborate_All}
-pragmas.
+elaboration code, and puts in any missing implicit @code{Elaborate}
+and @code{Elaborate_All} pragmas.
The advantage of this approach is that no elaboration problems
are possible if the binder can find an elaboration order that is
-consistent with these implicit @code{Elaborate_All} pragmas. The
+consistent with these implicit @code{Elaborate} and
+@code{Elaborate_All} pragmas. The
disadvantage of this approach is that no such order may exist.
-If the binder does not generate any diagnostics, then it means that it
-has found an elaboration order that is guaranteed to be safe. However,
-the binder may still be relying on implicitly generated
-@code{Elaborate_All} pragmas so portability to other compilers than
-GNAT is not guaranteed.
+If the binder does not generate any diagnostics, then it means that it has
+found an elaboration order that is guaranteed to be safe. However, the binder
+may still be relying on implicitly generated @code{Elaborate} and
+@code{Elaborate_All} pragmas so portability to other compilers than GNAT is not
+guaranteed.
If it is important to guarantee portability, then the compilations should
use the
@option{-gnatwl}
(warn on elaboration problems) switch. This will cause warning messages
-to be generated indicating the missing @code{Elaborate_All} pragmas.
+to be generated indicating the missing @code{Elaborate} and
+@code{Elaborate_All} pragmas.
Consider the following source program:
@smallexample @c ada
the missing pragmas. It is usually a bad idea to use this warning
option during development. That's because it will warn you when
you need to put in a pragma, but cannot warn you when it is time
-to take it out. So the use of pragma Elaborate_All may lead to
+to take it out. So the use of pragma @code{Elaborate_All} may lead to
unnecessary dependencies and even false circularities.
This default mode is more restrictive than the Ada Reference
standard dynamic model of elaboration with run-time checks.
In GNAT, this standard mode can be achieved either by the use of
-the @option{-gnatE} switch on the compiler (@code{gcc} or @code{gnatmake})
-command, or by the use of the configuration pragma:
+the @option{-gnatE} switch on the compiler (@command{gcc} or
+@command{gnatmake}) command, or by the use of the configuration pragma:
@smallexample @c ada
pragma Elaboration_Checks (RM);
@noindent
The use of @code{pragma Elaborate}
-should generally be avoided in Ada 95 programs.
-The reason for this is that there is no guarantee that transitive calls
+should generally be avoided in Ada 95 and Ada 2005 programs,
+since there is no guarantee that transitive calls
will be properly handled. Indeed at one point, this pragma was placed
in Annex J (Obsolescent Features), on the grounds that it is never useful.
In the body of @code{Decls} a call is made from within the body of a library
task to a subprogram in the package @code{Utils}. Since this call may
occur at elaboration time (given that the task is activated at elaboration
-time), we have to assume the worst, i.e. that the
+time), we have to assume the worst, i.e., that the
call does happen at elaboration time.
@item
@end enumerate
@noindent
-Indeed, if you add an explicit pragma Elaborate_All for @code{Utils} in
+Indeed, if you add an explicit pragma @code{Elaborate_All} for @code{Utils} in
the body of @code{Decls} you will get a true Ada Reference Manual
circularity that makes the program illegal.
A significant part of the problem arises because of the use of the
single task declaration form. This means that the elaboration of
-the task type, and the elaboration of the task itself (i.e. the
+the task type, and the elaboration of the task itself (i.e.@: the
creation of the task) happen at the same time. A good rule
-of style in Ada 95 is to always create explicit task types. By
+of style in Ada is to always create explicit task types. By
following the additional step of placing task objects in separate
packages from the task type declaration, many elaboration problems
are avoided. Here is another modified example of the example program:
@item Perform dynamic checks
If the compilations are done using the
@option{-gnatE}
-(dynamic elaboration check) switch, then GNAT behaves in
-a quite different manner. Dynamic checks are generated for all calls
-that could possibly result in raising an exception. With this switch,
-the compiler does not generate implicit @code{Elaborate_All} pragmas.
-The behavior then is exactly as specified in the Ada 95 Reference Manual.
-The binder will generate an executable program that may or may not
-raise @code{Program_Error}, and then it is the programmer's job to ensure
-that it does not raise an exception. Note that it is important to
-compile all units with the switch, it cannot be used selectively.
+(dynamic elaboration check) switch, then GNAT behaves in a quite different
+manner. Dynamic checks are generated for all calls that could possibly result
+in raising an exception. With this switch, the compiler does not generate
+implicit @code{Elaborate} or @code{Elaborate_All} pragmas. The behavior then is
+exactly as specified in the @cite{Ada Reference Manual}.
+The binder will generate
+an executable program that may or may not raise @code{Program_Error}, and then
+it is the programmer's job to ensure that it does not raise an exception. Note
+that it is important to compile all units with the switch, it cannot be used
+selectively.
@item Suppress checks
The drawback of dynamic checks is that they generate a
example this pragma could be placed in the @file{gnat.adc} file.
@item Suppress checks selectively
-When you know that certain calls in elaboration code cannot possibly
-lead to an elaboration error, and the binder nevertheless generates warnings
-on those calls and inserts Elaborate_All pragmas that lead to elaboration
-circularities, it is possible to remove those warnings locally and obtain
-a program that will bind. Clearly this can be unsafe, and it is the
-responsibility of the programmer to make sure that the resulting program has
-no elaboration anomalies. The pragma @code{Suppress (Elaboration_Check)} can
-be used with different granularity to suppress warnings and break
-elaboration circularities:
+When you know that certain calls or instantiations in elaboration code cannot
+possibly lead to an elaboration error, and the binder nevertheless complains
+about implicit @code{Elaborate} and @code{Elaborate_All} pragmas that lead to
+elaboration circularities, it is possible to remove those warnings locally and
+obtain a program that will bind. Clearly this can be unsafe, and it is the
+responsibility of the programmer to make sure that the resulting program has no
+elaboration anomalies. The pragma @code{Suppress (Elaboration_Check)} can be
+used with different granularity to suppress warnings and break elaboration
+circularities:
@itemize @bullet
@item
@option{^-p (pessimistic elaboration order)^/PESSIMISTIC_ELABORATION_ORDER^}
switch for
@code{gnatbind}.
-Normally the binder tries to find an order that has the best chance of
-of avoiding elaboration problems. With this switch, the binder
+Normally the binder tries to find an order that has the best chance
+of avoiding elaboration problems. However, if this switch is used, the binder
plays a devil's advocate role, and tries to choose the order that
has the best chance of failing. If your program works even with this
switch, then it has a better chance of being error free, but this is still
@cindex Access-to-subprogram
@noindent
-The introduction of access-to-subprogram types in Ada 95 complicates
+Access-to-subprogram types (introduced in Ada 95) complicate
the handling of elaboration. The trouble is that it becomes
impossible to tell at compile time which procedure
is being called. This means that it is not possible for the binder
the program is free of elaboration errors. If it is important that the
program be portable, then use the
@option{-gnatwl}
-switch to generate warnings about missing @code{Elaborate_All}
-pragmas, and supply the missing pragmas.
+switch to generate warnings about missing @code{Elaborate} or
+@code{Elaborate_All} pragmas, and supply the missing pragmas.
If the program fails to bind using the default static elaboration
handling, then you can fix the program to eliminate the binder
@code{Elaborate_All} pragmas, then indeed it is possible that two different
compilers can choose different orders.
+However, GNAT does attempt to diagnose the common situation where there
+are uninitialized variables in the visible part of a package spec, and the
+corresponding package body has an elaboration block that directly or
+indirectly initialized one or more of these variables. This is the situation
+in which a pragma Elaborate_Body is usually desirable, and GNAT will generate
+a warning that suggests this addition if it detects this situation.
+
The @code{gnatbind}
@option{^-p^/PESSIMISTIC_ELABORATION^} switch may be useful in smoking
out problems. This switch causes bodies to be elaborated as late as possible
@end smallexample
@noindent
-It is of course quite unlikely that both these results are correct, so
-it is up to you in a case like this to investigate the source of the
-difference, by looking at the two elaboration orders that are chosen,
-and figuring out which is correct, and then adding the necessary
-@code{Elaborate_All} pragmas to ensure the desired order.
+It is of course quite unlikely that both these results are correct, so
+it is up to you in a case like this to investigate the source of the
+difference, by looking at the two elaboration orders that are chosen,
+and figuring out which is correct, and then adding the necessary
+@code{Elaborate} or @code{Elaborate_All} pragmas to ensure the desired order.
+
+
+
+@c *******************************
+@node Conditional Compilation
+@appendix Conditional Compilation
+@c *******************************
+@cindex Conditional compilation
+
+@noindent
+It is often necessary to arrange for a single source program
+to serve multiple purposes, where it is compiled in different
+ways to achieve these different goals. Some examples of the
+need for this feature are
+
+@itemize @bullet
+@item Adapting a program to a different hardware environment
+@item Adapting a program to a different target architecture
+@item Turning debugging features on and off
+@item Arranging for a program to compile with different compilers
+@end itemize
+
+@noindent
+In C, or C++, the typical approach would be to use the preprocessor
+that is defined as part of the language. The Ada language does not
+contain such a feature. This is not an oversight, but rather a very
+deliberate design decision, based on the experience that overuse of
+the preprocessing features in C and C++ can result in programs that
+are extremely difficult to maintain. For example, if we have ten
+switches that can be on or off, this means that there are a thousand
+separate programs, any one of which might not even be syntactically
+correct, and even if syntactically correct, the resulting program
+might not work correctly. Testing all combinations can quickly become
+impossible.
+
+Nevertheless, the need to tailor programs certainly exists, and in
+this Appendix we will discuss how this can
+be achieved using Ada in general, and GNAT in particular.
+
+@menu
+* Use of Boolean Constants::
+* Debugging - A Special Case::
+* Conditionalizing Declarations::
+* Use of Alternative Implementations::
+* Preprocessing::
+@end menu
+
+@node Use of Boolean Constants
+@section Use of Boolean Constants
+
+@noindent
+In the case where the difference is simply which code
+sequence is executed, the cleanest solution is to use Boolean
+constants to control which code is executed.
+
+@smallexample @c ada
+@group
+FP_Initialize_Required : constant Boolean := True;
+@dots{}
+if FP_Initialize_Required then
+@dots{}
+end if;
+@end group
+@end smallexample
+
+@noindent
+Not only will the code inside the @code{if} statement not be executed if
+the constant Boolean is @code{False}, but it will also be completely
+deleted from the program.
+However, the code is only deleted after the @code{if} statement
+has been checked for syntactic and semantic correctness.
+(In contrast, with preprocessors the code is deleted before the
+compiler ever gets to see it, so it is not checked until the switch
+is turned on.)
+@cindex Preprocessors (contrasted with conditional compilation)
+
+Typically the Boolean constants will be in a separate package,
+something like:
+
+@smallexample @c ada
+@group
+package Config is
+ FP_Initialize_Required : constant Boolean := True;
+ Reset_Available : constant Boolean := False;
+ @dots{}
+end Config;
+@end group
+@end smallexample
+
+@noindent
+The @code{Config} package exists in multiple forms for the various targets,
+with an appropriate script selecting the version of @code{Config} needed.
+Then any other unit requiring conditional compilation can do a @code{with}
+of @code{Config} to make the constants visible.
+
+
+@node Debugging - A Special Case
+@section Debugging - A Special Case
+
+@noindent
+A common use of conditional code is to execute statements (for example
+dynamic checks, or output of intermediate results) under control of a
+debug switch, so that the debugging behavior can be turned on and off.
+This can be done using a Boolean constant to control whether the code
+is active:
+
+@smallexample @c ada
+@group
+if Debugging then
+ Put_Line ("got to the first stage!");
+end if;
+@end group
+@end smallexample
+
+@noindent
+or
+
+@smallexample @c ada
+@group
+if Debugging and then Temperature > 999.0 then
+ raise Temperature_Crazy;
+end if;
+@end group
+@end smallexample
+
+@noindent
+Since this is a common case, there are special features to deal with
+this in a convenient manner. For the case of tests, Ada 2005 has added
+a pragma @code{Assert} that can be used for such tests. This pragma is modeled
+@cindex pragma @code{Assert}
+on the @code{Assert} pragma that has always been available in GNAT, so this
+feature may be used with GNAT even if you are not using Ada 2005 features.
+The use of pragma @code{Assert} is described in
+@ref{Pragma Assert,,, gnat_rm, GNAT Reference Manual}, but as an
+example, the last test could be written:
+
+@smallexample @c ada
+pragma Assert (Temperature <= 999.0, "Temperature Crazy");
+@end smallexample
+
+@noindent
+or simply
+
+@smallexample @c ada
+pragma Assert (Temperature <= 999.0);
+@end smallexample
+
+@noindent
+In both cases, if assertions are active and the temperature is excessive,
+the exception @code{Assert_Failure} will be raised, with the given string in
+the first case or a string indicating the location of the pragma in the second
+case used as the exception message.
+
+You can turn assertions on and off by using the @code{Assertion_Policy}
+pragma.
+@cindex pragma @code{Assertion_Policy}
+This is an Ada 2005 pragma which is implemented in all modes by
+GNAT, but only in the latest versions of GNAT which include Ada 2005
+capability. Alternatively, you can use the @option{-gnata} switch
+@cindex @option{-gnata} switch
+to enable assertions from the command line (this is recognized by all versions
+of GNAT).
+
+For the example above with the @code{Put_Line}, the GNAT-specific pragma
+@code{Debug} can be used:
+@cindex pragma @code{Debug}
+
+@smallexample @c ada
+pragma Debug (Put_Line ("got to the first stage!"));
+@end smallexample
+
+@noindent
+If debug pragmas are enabled, the argument, which must be of the form of
+a procedure call, is executed (in this case, @code{Put_Line} will be called).
+Only one call can be present, but of course a special debugging procedure
+containing any code you like can be included in the program and then
+called in a pragma @code{Debug} argument as needed.
+
+One advantage of pragma @code{Debug} over the @code{if Debugging then}
+construct is that pragma @code{Debug} can appear in declarative contexts,
+such as at the very beginning of a procedure, before local declarations have
+been elaborated.
+
+Debug pragmas are enabled using either the @option{-gnata} switch that also
+controls assertions, or with a separate Debug_Policy pragma.
+@cindex pragma @code{Debug_Policy}
+The latter pragma is new in the Ada 2005 versions of GNAT (but it can be used
+in Ada 95 and Ada 83 programs as well), and is analogous to
+pragma @code{Assertion_Policy} to control assertions.
+
+@code{Assertion_Policy} and @code{Debug_Policy} are configuration pragmas,
+and thus they can appear in @file{gnat.adc} if you are not using a
+project file, or in the file designated to contain configuration pragmas
+in a project file.
+They then apply to all subsequent compilations. In practice the use of
+the @option{-gnata} switch is often the most convenient method of controlling
+the status of these pragmas.
+
+Note that a pragma is not a statement, so in contexts where a statement
+sequence is required, you can't just write a pragma on its own. You have
+to add a @code{null} statement.
+
+@smallexample @c ada
+@group
+if @dots{} then
+ @dots{} -- some statements
+else
+ pragma Assert (Num_Cases < 10);
+ null;
+end if;
+@end group
+@end smallexample
+
+
+@node Conditionalizing Declarations
+@section Conditionalizing Declarations
+
+@noindent
+In some cases, it may be necessary to conditionalize declarations to meet
+different requirements. For example we might want a bit string whose length
+is set to meet some hardware message requirement.
+
+In some cases, it may be possible to do this using declare blocks controlled
+by conditional constants:
+
+@smallexample @c ada
+@group
+if Small_Machine then
+ declare
+ X : Bit_String (1 .. 10);
+ begin
+ @dots{}
+ end;
+else
+ declare
+ X : Large_Bit_String (1 .. 1000);
+ begin
+ @dots{}
+ end;
+end if;
+@end group
+@end smallexample
+
+@noindent
+Note that in this approach, both declarations are analyzed by the
+compiler so this can only be used where both declarations are legal,
+even though one of them will not be used.
+
+Another approach is to define integer constants, e.g.@: @code{Bits_Per_Word}, or
+Boolean constants, e.g.@: @code{Little_Endian}, and then write declarations
+that are parameterized by these constants. For example
+
+@smallexample @c ada
+@group
+for Rec use
+ Field1 at 0 range Boolean'Pos (Little_Endian) * 10 .. Bits_Per_Word;
+end record;
+@end group
+@end smallexample
+
+@noindent
+If @code{Bits_Per_Word} is set to 32, this generates either
+
+@smallexample @c ada
+@group
+for Rec use
+ Field1 at 0 range 0 .. 32;
+end record;
+@end group
+@end smallexample
+
+@noindent
+for the big endian case, or
+
+@smallexample @c ada
+@group
+for Rec use record
+ Field1 at 0 range 10 .. 32;
+end record;
+@end group
+@end smallexample
+
+@noindent
+for the little endian case. Since a powerful subset of Ada expression
+notation is usable for creating static constants, clever use of this
+feature can often solve quite difficult problems in conditionalizing
+compilation (note incidentally that in Ada 95, the little endian
+constant was introduced as @code{System.Default_Bit_Order}, so you do not
+need to define this one yourself).
+
+
+@node Use of Alternative Implementations
+@section Use of Alternative Implementations
+
+@noindent
+In some cases, none of the approaches described above are adequate. This
+can occur for example if the set of declarations required is radically
+different for two different configurations.
+
+In this situation, the official Ada way of dealing with conditionalizing
+such code is to write separate units for the different cases. As long as
+this does not result in excessive duplication of code, this can be done
+without creating maintenance problems. The approach is to share common
+code as far as possible, and then isolate the code and declarations
+that are different. Subunits are often a convenient method for breaking
+out a piece of a unit that is to be conditionalized, with separate files
+for different versions of the subunit for different targets, where the
+build script selects the right one to give to the compiler.
+@cindex Subunits (and conditional compilation)
+
+As an example, consider a situation where a new feature in Ada 2005
+allows something to be done in a really nice way. But your code must be able
+to compile with an Ada 95 compiler. Conceptually you want to say:
+
+@smallexample @c ada
+@group
+if Ada_2005 then
+ @dots{} neat Ada 2005 code
+else
+ @dots{} not quite as neat Ada 95 code
+end if;
+@end group
+@end smallexample
+
+@noindent
+where @code{Ada_2005} is a Boolean constant.
+
+But this won't work when @code{Ada_2005} is set to @code{False},
+since the @code{then} clause will be illegal for an Ada 95 compiler.
+(Recall that although such unreachable code would eventually be deleted
+by the compiler, it still needs to be legal. If it uses features
+introduced in Ada 2005, it will be illegal in Ada 95.)
+
+So instead we write
+
+@smallexample @c ada
+procedure Insert is separate;
+@end smallexample
+
+@noindent
+Then we have two files for the subunit @code{Insert}, with the two sets of
+code.
+If the package containing this is called @code{File_Queries}, then we might
+have two files
+
+@itemize @bullet
+@item @file{file_queries-insert-2005.adb}
+@item @file{file_queries-insert-95.adb}
+@end itemize
+
+@noindent
+and the build script renames the appropriate file to
+
+@smallexample
+file_queries-insert.adb
+@end smallexample
+
+@noindent
+and then carries out the compilation.
+
+This can also be done with project files' naming schemes. For example:
+
+@smallexample @c project
+For Body ("File_Queries.Insert") use "file_queries-insert-2005.ada";
+@end smallexample
+
+@noindent
+Note also that with project files it is desirable to use a different extension
+than @file{ads} / @file{adb} for alternative versions. Otherwise a naming
+conflict may arise through another commonly used feature: to declare as part
+of the project a set of directories containing all the sources obeying the
+default naming scheme.
+
+The use of alternative units is certainly feasible in all situations,
+and for example the Ada part of the GNAT run-time is conditionalized
+based on the target architecture using this approach. As a specific example,
+consider the implementation of the AST feature in VMS. There is one
+spec:
+
+@smallexample
+s-asthan.ads
+@end smallexample
+
+@noindent
+which is the same for all architectures, and three bodies:
+
+@table @file
+@item s-asthan.adb
+used for all non-VMS operating systems
+@item s-asthan-vms-alpha.adb
+used for VMS on the Alpha
+@item s-asthan-vms-ia64.adb
+used for VMS on the ia64
+@end table
+
+@noindent
+The dummy version @file{s-asthan.adb} simply raises exceptions noting that
+this operating system feature is not available, and the two remaining
+versions interface with the corresponding versions of VMS to provide
+VMS-compatible AST handling. The GNAT build script knows the architecture
+and operating system, and automatically selects the right version,
+renaming it if necessary to @file{s-asthan.adb} before the run-time build.
+
+Another style for arranging alternative implementations is through Ada's
+access-to-subprogram facility.
+In case some functionality is to be conditionally included,
+you can declare an access-to-procedure variable @code{Ref} that is initialized
+to designate a ``do nothing'' procedure, and then invoke @code{Ref.all}
+when appropriate.
+In some library package, set @code{Ref} to @code{Proc'Access} for some
+procedure @code{Proc} that performs the relevant processing.
+The initialization only occurs if the library package is included in the
+program.
+The same idea can also be implemented using tagged types and dispatching
+calls.
+
+
+@node Preprocessing
+@section Preprocessing
+@cindex Preprocessing
+
+@noindent
+Although it is quite possible to conditionalize code without the use of
+C-style preprocessing, as described earlier in this section, it is
+nevertheless convenient in some cases to use the C approach. Moreover,
+older Ada compilers have often provided some preprocessing capability,
+so legacy code may depend on this approach, even though it is not
+standard.
+
+To accommodate such use, GNAT provides a preprocessor (modeled to a large
+extent on the various preprocessors that have been used
+with legacy code on other compilers, to enable easier transition).
+
+The preprocessor may be used in two separate modes. It can be used quite
+separately from the compiler, to generate a separate output source file
+that is then fed to the compiler as a separate step. This is the
+@code{gnatprep} utility, whose use is fully described in
+@ref{Preprocessing Using gnatprep}.
+@cindex @code{gnatprep}
+
+The preprocessing language allows such constructs as
+
+@smallexample
+@group
+#if DEBUG or PRIORITY > 4 then
+ bunch of declarations
+#else
+ completely different bunch of declarations
+#end if;
+@end group
+@end smallexample
+
+@noindent
+The values of the symbols @code{DEBUG} and @code{PRIORITY} can be
+defined either on the command line or in a separate file.
+
+The other way of running the preprocessor is even closer to the C style and
+often more convenient. In this approach the preprocessing is integrated into
+the compilation process. The compiler is fed the preprocessor input which
+includes @code{#if} lines etc, and then the compiler carries out the
+preprocessing internally and processes the resulting output.
+For more details on this approach, see @ref{Integrated Preprocessing}.
+@c *******************************
@node Inline Assembler
@appendix Inline Assembler
+@c *******************************
@noindent
If you need to write low-level software that interacts directly
with the hardware, Ada provides two ways to incorporate assembly
language code into your program. First, you can import and invoke
external routines written in assembly language, an Ada feature fully
-supported by GNAT. However, for small sections of code it may be simpler
+supported by GNAT@. However, for small sections of code it may be simpler
or more efficient to include assembly language statements directly
in your Ada source program, using the facilities of the implementation-defined
package @code{System.Machine_Code}, which incorporates the gcc
* Input Variables in Inline Assembler::
* Inlining Inline Assembler Code::
* Other Asm Functionality::
-* A Complete Example::
@end menu
@c ---------------------------------------------------------------------------
The examples in this chapter will illustrate several of the forms
for invoking @code{Asm}; a complete specification of the syntax
-is found in the @cite{GNAT Reference Manual}.
+is found in @ref{Machine Code Insertions,,, gnat_rm, GNAT Reference
+Manual}.
Under the standard GNAT conventions, the @code{Nothing} procedure
should be in a file named @file{nothing.adb}.
@item =
output constraint
@item g
-global (i.e. can be stored anywhere)
+global (i.e.@: can be stored anywhere)
@item m
in memory
@item I
@end smallexample
Compile the program with both optimization (@option{-O2}) and inlining
-enabled (@option{-gnatpn} instead of @option{-gnatp}).
+(@option{-gnatn}) enabled.
The @code{Incr} function is still compiled as usual, but at the
point in @code{Increment} where our function used to be called:
"movl %%ebx, %1",
Inputs => Unsigned_32'Asm_Input ("g", Var_In),
Outputs => Unsigned_32'Asm_Output ("=g", Var_Out),
- Clobber => "ebx",
- Volatile => True);
-@end group
-@end smallexample
-
-By default, @code{Volatile} is set to @code{False} unless there is no
-@code{Outputs} parameter.
-
-Although setting @code{Volatile} to @code{True} prevents unwanted
-optimizations, it will also disable other optimizations that might be
-important for efficiency. In general, you should set @code{Volatile}
-to @code{True} only if the compiler's optimizations have created
-problems.
-
-@c ---------------------------------------------------------------------------
-@node A Complete Example
-@section A Complete Example
-
-@noindent
-This section contains a complete program illustrating a realistic usage
-of GNAT's Inline Assembler capabilities. It comprises a main procedure
-@code{Check_CPU} and a package @code{Intel_CPU}.
-The package declares a collection of functions that detect the properties
-of the 32-bit x86 processor that is running the program.
-The main procedure invokes these functions and displays the information.
-
-The Intel_CPU package could be enhanced by adding functions to
-detect the type of x386 co-processor, the processor caching options and
-special operations such as the SIMD extensions.
-
-Although the Intel_CPU package has been written for 32-bit Intel
-compatible CPUs, it is OS neutral. It has been tested on DOS,
-Windows/NT and GNU/Linux.
-
-@menu
-* Check_CPU Procedure::
-* Intel_CPU Package Specification::
-* Intel_CPU Package Body::
-@end menu
-
-@c ---------------------------------------------------------------------------
-@node Check_CPU Procedure
-@subsection @code{Check_CPU} Procedure
-@cindex Check_CPU procedure
-
-@smallexample @c adanocomment
----------------------------------------------------------------------
--- --
--- Uses the Intel_CPU package to identify the CPU the program is --
--- running on, and some of the features it supports. --
--- --
----------------------------------------------------------------------
-
-with Intel_CPU; -- Intel CPU detection functions
-with Ada.Text_IO; -- Standard text I/O
-with Ada.Command_Line; -- To set the exit status
-
-procedure Check_CPU is
-
- Type_Found : Boolean := False;
- -- Flag to indicate that processor was identified
-
- Features : Intel_CPU.Processor_Features;
- -- The processor features
-
- Signature : Intel_CPU.Processor_Signature;
- -- The processor type signature
-
-begin
-
- -----------------------------------
- -- Display the program banner. --
- -----------------------------------
-
- Ada.Text_IO.Put_Line (Ada.Command_Line.Command_Name &
- ": check Intel CPU version and features, v1.0");
- Ada.Text_IO.Put_Line ("distribute freely, but no warranty whatsoever");
- Ada.Text_IO.New_Line;
-
- -----------------------------------------------------------------------
- -- We can safely start with the assumption that we are on at least --
- -- a x386 processor. If the CPUID instruction is present, then we --
- -- have a later processor type. --
- -----------------------------------------------------------------------
-
- if Intel_CPU.Has_CPUID = False then
-
- -- No CPUID instruction, so we assume this is indeed a x386
- -- processor. We can still check if it has a FP co-processor.
- if Intel_CPU.Has_FPU then
- Ada.Text_IO.Put_Line
- ("x386-type processor with a FP co-processor");
- else
- Ada.Text_IO.Put_Line
- ("x386-type processor without a FP co-processor");
- end if; -- check for FPU
-
- -- Program done
- Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Success);
- return;
-
- end if; -- check for CPUID
-
- -----------------------------------------------------------------------
- -- If CPUID is supported, check if this is a true Intel processor, --
- -- if it is not, display a warning. --
- -----------------------------------------------------------------------
-
- if Intel_CPU.Vendor_ID /= Intel_CPU.Intel_Processor then
- Ada.Text_IO.Put_Line ("*** This is a Intel compatible processor");
- Ada.Text_IO.Put_Line ("*** Some information may be incorrect");
- end if; -- check if Intel
-
- ----------------------------------------------------------------------
- -- With the CPUID instruction present, we can assume at least a --
- -- x486 processor. If the CPUID support level is < 1 then we have --
- -- to leave it at that. --
- ----------------------------------------------------------------------
-
- if Intel_CPU.CPUID_Level < 1 then
-
- -- Ok, this is a x486 processor. we still can get the Vendor ID
- Ada.Text_IO.Put_Line ("x486-type processor");
- Ada.Text_IO.Put_Line ("Vendor ID is " & Intel_CPU.Vendor_ID);
-
- -- We can also check if there is a FPU present
- if Intel_CPU.Has_FPU then
- Ada.Text_IO.Put_Line ("Floating-Point support");
- else
- Ada.Text_IO.Put_Line ("No Floating-Point support");
- end if; -- check for FPU
-
- -- Program done
- Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Success);
- return;
-
- end if; -- check CPUID level
-
- ---------------------------------------------------------------------
- -- With a CPUID level of 1 we can use the processor signature to --
- -- determine it's exact type. --
- ---------------------------------------------------------------------
-
- Signature := Intel_CPU.Signature;
-
- ----------------------------------------------------------------------
- -- Ok, now we go into a lot of messy comparisons to get the --
- -- processor type. For clarity, no attememt to try to optimize the --
- -- comparisons has been made. Note that since Intel_CPU does not --
- -- support getting cache info, we cannot distinguish between P5 --
- -- and Celeron types yet. --
- ----------------------------------------------------------------------
-
- -- x486SL
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0100# and
- Signature.Model = 2#0100# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("x486SL processor");
- end if;
-
- -- x486DX2 Write-Back
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0100# and
- Signature.Model = 2#0111# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("Write-Back Enhanced x486DX2 processor");
- end if;
-
- -- x486DX4
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0100# and
- Signature.Model = 2#1000# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("x486DX4 processor");
- end if;
-
- -- x486DX4 Overdrive
- if Signature.Processor_Type = 2#01# and
- Signature.Family = 2#0100# and
- Signature.Model = 2#1000# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("x486DX4 OverDrive processor");
- end if;
-
- -- Pentium (60, 66)
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0001# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("Pentium processor (60, 66)");
- end if;
-
- -- Pentium (75, 90, 100, 120, 133, 150, 166, 200)
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0010# then
- Type_Found := True;
- Ada.Text_IO.Put_Line
- ("Pentium processor (75, 90, 100, 120, 133, 150, 166, 200)");
- end if;
-
- -- Pentium OverDrive (60, 66)
- if Signature.Processor_Type = 2#01# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0001# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("Pentium OverDrive processor (60, 66)");
- end if;
-
- -- Pentium OverDrive (75, 90, 100, 120, 133, 150, 166, 200)
- if Signature.Processor_Type = 2#01# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0010# then
- Type_Found := True;
- Ada.Text_IO.Put_Line
- ("Pentium OverDrive cpu (75, 90, 100, 120, 133, 150, 166, 200)");
- end if;
-
- -- Pentium OverDrive processor for x486 processor-based systems
- if Signature.Processor_Type = 2#01# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0011# then
- Type_Found := True;
- Ada.Text_IO.Put_Line
- ("Pentium OverDrive processor for x486 processor-based systems");
- end if;
-
- -- Pentium processor with MMX technology (166, 200)
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0100# then
- Type_Found := True;
- Ada.Text_IO.Put_Line
- ("Pentium processor with MMX technology (166, 200)");
- end if;
-
- -- Pentium OverDrive with MMX for Pentium (75, 90, 100, 120, 133)
- if Signature.Processor_Type = 2#01# and
- Signature.Family = 2#0101# and
- Signature.Model = 2#0100# then
- Type_Found := True;
- Ada.Text_IO.Put_Line
- ("Pentium OverDrive processor with MMX " &
- "technology for Pentium processor (75, 90, 100, 120, 133)");
- end if;
-
- -- Pentium Pro processor
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0110# and
- Signature.Model = 2#0001# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("Pentium Pro processor");
- end if;
-
- -- Pentium II processor, model 3
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0110# and
- Signature.Model = 2#0011# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("Pentium II processor, model 3");
- end if;
-
- -- Pentium II processor, model 5 or Celeron processor
- if Signature.Processor_Type = 2#00# and
- Signature.Family = 2#0110# and
- Signature.Model = 2#0101# then
- Type_Found := True;
- Ada.Text_IO.Put_Line
- ("Pentium II processor, model 5 or Celeron processor");
- end if;
-
- -- Pentium Pro OverDrive processor
- if Signature.Processor_Type = 2#01# and
- Signature.Family = 2#0110# and
- Signature.Model = 2#0011# then
- Type_Found := True;
- Ada.Text_IO.Put_Line ("Pentium Pro OverDrive processor");
- end if;
-
- -- If no type recognized, we have an unknown. Display what
- -- we _do_ know
- if Type_Found = False then
- Ada.Text_IO.Put_Line ("Unknown processor");
- end if;
-
- -----------------------------------------
- -- Display processor stepping level. --
- -----------------------------------------
-
- Ada.Text_IO.Put_Line ("Stepping level:" & Signature.Stepping'Img);
-
- ---------------------------------
- -- Display vendor ID string. --
- ---------------------------------
-
- Ada.Text_IO.Put_Line ("Vendor ID: " & Intel_CPU.Vendor_ID);
-
- ------------------------------------
- -- Get the processors features. --
- ------------------------------------
-
- Features := Intel_CPU.Features;
-
- -----------------------------
- -- Check for a FPU unit. --
- -----------------------------
-
- if Features.FPU = True then
- Ada.Text_IO.Put_Line ("Floating-Point unit available");
- else
- Ada.Text_IO.Put_Line ("no Floating-Point unit");
- end if; -- check for FPU
-
- --------------------------------
- -- List processor features. --
- --------------------------------
-
- Ada.Text_IO.Put_Line ("Supported features: ");
-
- -- Virtual Mode Extension
- if Features.VME = True then
- Ada.Text_IO.Put_Line (" VME - Virtual Mode Extension");
- end if;
-
- -- Debugging Extension
- if Features.DE = True then
- Ada.Text_IO.Put_Line (" DE - Debugging Extension");
- end if;
-
- -- Page Size Extension
- if Features.PSE = True then
- Ada.Text_IO.Put_Line (" PSE - Page Size Extension");
- end if;
-
- -- Time Stamp Counter
- if Features.TSC = True then
- Ada.Text_IO.Put_Line (" TSC - Time Stamp Counter");
- end if;
-
- -- Model Specific Registers
- if Features.MSR = True then
- Ada.Text_IO.Put_Line (" MSR - Model Specific Registers");
- end if;
-
- -- Physical Address Extension
- if Features.PAE = True then
- Ada.Text_IO.Put_Line (" PAE - Physical Address Extension");
- end if;
-
- -- Machine Check Extension
- if Features.MCE = True then
- Ada.Text_IO.Put_Line (" MCE - Machine Check Extension");
- end if;
-
- -- CMPXCHG8 instruction supported
- if Features.CX8 = True then
- Ada.Text_IO.Put_Line (" CX8 - CMPXCHG8 instruction");
- end if;
-
- -- on-chip APIC hardware support
- if Features.APIC = True then
- Ada.Text_IO.Put_Line (" APIC - on-chip APIC hardware support");
- end if;
-
- -- Fast System Call
- if Features.SEP = True then
- Ada.Text_IO.Put_Line (" SEP - Fast System Call");
- end if;
-
- -- Memory Type Range Registers
- if Features.MTRR = True then
- Ada.Text_IO.Put_Line (" MTTR - Memory Type Range Registers");
- end if;
-
- -- Page Global Enable
- if Features.PGE = True then
- Ada.Text_IO.Put_Line (" PGE - Page Global Enable");
- end if;
-
- -- Machine Check Architecture
- if Features.MCA = True then
- Ada.Text_IO.Put_Line (" MCA - Machine Check Architecture");
- end if;
-
- -- Conditional Move Instruction Supported
- if Features.CMOV = True then
- Ada.Text_IO.Put_Line
- (" CMOV - Conditional Move Instruction Supported");
- end if;
-
- -- Page Attribute Table
- if Features.PAT = True then
- Ada.Text_IO.Put_Line (" PAT - Page Attribute Table");
- end if;
-
- -- 36-bit Page Size Extension
- if Features.PSE_36 = True then
- Ada.Text_IO.Put_Line (" PSE_36 - 36-bit Page Size Extension");
- end if;
-
- -- MMX technology supported
- if Features.MMX = True then
- Ada.Text_IO.Put_Line (" MMX - MMX technology supported");
- end if;
-
- -- Fast FP Save and Restore
- if Features.FXSR = True then
- Ada.Text_IO.Put_Line (" FXSR - Fast FP Save and Restore");
- end if;
-
- ---------------------
- -- Program done. --
- ---------------------
-
- Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Success);
-
-exception
-
- when others =>
- Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
- raise;
-
-end Check_CPU;
-@end smallexample
-
-@c ---------------------------------------------------------------------------
-@node Intel_CPU Package Specification
-@subsection @code{Intel_CPU} Package Specification
-@cindex Intel_CPU package specification
-
-@smallexample @c adanocomment
--------------------------------------------------------------------------
--- --
--- file: intel_cpu.ads --
--- --
--- ********************************************* --
--- * WARNING: for 32-bit Intel processors only * --
--- ********************************************* --
--- --
--- This package contains a number of subprograms that are useful in --
--- determining the Intel x86 CPU (and the features it supports) on --
--- which the program is running. --
--- --
--- The package is based upon the information given in the Intel --
--- Application Note AP-485: "Intel Processor Identification and the --
--- CPUID Instruction" as of April 1998. This application note can be --
--- found on www.intel.com. --
--- --
--- It currently deals with 32-bit processors only, will not detect --
--- features added after april 1998, and does not guarantee proper --
--- results on Intel-compatible processors. --
--- --
--- Cache info and x386 fpu type detection are not supported. --
--- --
--- This package does not use any privileged instructions, so should --
--- work on any OS running on a 32-bit Intel processor. --
--- --
--------------------------------------------------------------------------
-
-with Interfaces; use Interfaces;
--- for using unsigned types
-
-with System.Machine_Code; use System.Machine_Code;
--- for using inline assembler code
-
-with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
--- for inserting control characters
-
-package Intel_CPU is
-
- ----------------------
- -- Processor bits --
- ----------------------
-
- subtype Num_Bits is Natural range 0 .. 31;
- -- the number of processor bits (32)
-
- --------------------------
- -- Processor register --
- --------------------------
-
- -- define a processor register type for easy access to
- -- the individual bits
-
- type Processor_Register is array (Num_Bits) of Boolean;
- pragma Pack (Processor_Register);
- for Processor_Register'Size use 32;
-
- -------------------------
- -- Unsigned register --
- -------------------------
-
- -- define a processor register type for easy access to
- -- the individual bytes
-
- type Unsigned_Register is
- record
- L1 : Unsigned_8;
- H1 : Unsigned_8;
- L2 : Unsigned_8;
- H2 : Unsigned_8;
- end record;
-
- for Unsigned_Register use
- record
- L1 at 0 range 0 .. 7;
- H1 at 0 range 8 .. 15;
- L2 at 0 range 16 .. 23;
- H2 at 0 range 24 .. 31;
- end record;
-
- for Unsigned_Register'Size use 32;
-
- ---------------------------------
- -- Intel processor vendor ID --
- ---------------------------------
-
- Intel_Processor : constant String (1 .. 12) := "GenuineIntel";
- -- indicates an Intel manufactured processor
-
- ------------------------------------
- -- Processor signature register --
- ------------------------------------
-
- -- a register type to hold the processor signature
-
- type Processor_Signature is
- record
- Stepping : Natural range 0 .. 15;
- Model : Natural range 0 .. 15;
- Family : Natural range 0 .. 15;
- Processor_Type : Natural range 0 .. 3;
- Reserved : Natural range 0 .. 262143;
- end record;
-
- for Processor_Signature use
- record
- Stepping at 0 range 0 .. 3;
- Model at 0 range 4 .. 7;
- Family at 0 range 8 .. 11;
- Processor_Type at 0 range 12 .. 13;
- Reserved at 0 range 14 .. 31;
- end record;
-
- for Processor_Signature'Size use 32;
-
- -----------------------------------
- -- Processor features register --
- -----------------------------------
-
- -- a processor register to hold the processor feature flags
-
- type Processor_Features is
- record
- FPU : Boolean; -- floating point unit on chip
- VME : Boolean; -- virtual mode extension
- DE : Boolean; -- debugging extension
- PSE : Boolean; -- page size extension
- TSC : Boolean; -- time stamp counter
- MSR : Boolean; -- model specific registers
- PAE : Boolean; -- physical address extension
- MCE : Boolean; -- machine check extension
- CX8 : Boolean; -- cmpxchg8 instruction
- APIC : Boolean; -- on-chip apic hardware
- Res_1 : Boolean; -- reserved for extensions
- SEP : Boolean; -- fast system call
- MTRR : Boolean; -- memory type range registers
- PGE : Boolean; -- page global enable
- MCA : Boolean; -- machine check architecture
- CMOV : Boolean; -- conditional move supported
- PAT : Boolean; -- page attribute table
- PSE_36 : Boolean; -- 36-bit page size extension
- Res_2 : Natural range 0 .. 31; -- reserved for extensions
- MMX : Boolean; -- MMX technology supported
- FXSR : Boolean; -- fast FP save and restore
- Res_3 : Natural range 0 .. 127; -- reserved for extensions
- end record;
-
- for Processor_Features use
- record
- FPU at 0 range 0 .. 0;
- VME at 0 range 1 .. 1;
- DE at 0 range 2 .. 2;
- PSE at 0 range 3 .. 3;
- TSC at 0 range 4 .. 4;
- MSR at 0 range 5 .. 5;
- PAE at 0 range 6 .. 6;
- MCE at 0 range 7 .. 7;
- CX8 at 0 range 8 .. 8;
- APIC at 0 range 9 .. 9;
- Res_1 at 0 range 10 .. 10;
- SEP at 0 range 11 .. 11;
- MTRR at 0 range 12 .. 12;
- PGE at 0 range 13 .. 13;
- MCA at 0 range 14 .. 14;
- CMOV at 0 range 15 .. 15;
- PAT at 0 range 16 .. 16;
- PSE_36 at 0 range 17 .. 17;
- Res_2 at 0 range 18 .. 22;
- MMX at 0 range 23 .. 23;
- FXSR at 0 range 24 .. 24;
- Res_3 at 0 range 25 .. 31;
- end record;
-
- for Processor_Features'Size use 32;
-
- -------------------
- -- Subprograms --
- -------------------
-
- function Has_FPU return Boolean;
- -- return True if a FPU is found
- -- use only if CPUID is not supported
-
- function Has_CPUID return Boolean;
- -- return True if the processor supports the CPUID instruction
-
- function CPUID_Level return Natural;
- -- return the CPUID support level (0, 1 or 2)
- -- can only be called if the CPUID instruction is supported
-
- function Vendor_ID return String;
- -- return the processor vendor identification string
- -- can only be called if the CPUID instruction is supported
-
- function Signature return Processor_Signature;
- -- return the processor signature
- -- can only be called if the CPUID instruction is supported
-
- function Features return Processor_Features;
- -- return the processors features
- -- can only be called if the CPUID instruction is supported
-
-private
-
- ------------------------
- -- EFLAGS bit names --
- ------------------------
-
- ID_Flag : constant Num_Bits := 21;
- -- ID flag bit
-
-end Intel_CPU;
-@end smallexample
-
-@c ---------------------------------------------------------------------------
-@node Intel_CPU Package Body
-@subsection @code{Intel_CPU} Package Body
-@cindex Intel_CPU package body
-
-@smallexample @c adanocomment
-package body Intel_CPU is
-
- ---------------------------
- -- Detect FPU presence --
- ---------------------------
-
- -- There is a FPU present if we can set values to the FPU Status
- -- and Control Words.
-
- function Has_FPU return Boolean is
-
- Register : Unsigned_16;
- -- processor register to store a word
-
- begin
-
- -- check if we can change the status word
- Asm (
-
- -- the assembler code
- "finit" & LF & HT & -- reset status word
- "movw $0x5A5A, %%ax" & LF & HT & -- set value status word
- "fnstsw %0" & LF & HT & -- save status word
- "movw %%ax, %0", -- store status word
-
- -- output stored in Register
- -- register must be a memory location
- Outputs => Unsigned_16'Asm_output ("=m", Register),
-
- -- tell compiler that we used eax
- Clobber => "eax");
-
- -- if the status word is zero, there is no FPU
- if Register = 0 then
- return False; -- no status word
- end if; -- check status word value
-
- -- check if we can get the control word
- Asm (
-
- -- the assembler code
- "fnstcw %0", -- save the control word
-
- -- output into Register
- -- register must be a memory location
- Outputs => Unsigned_16'Asm_output ("=m", Register));
-
- -- check the relevant bits
- if (Register and 16#103F#) /= 16#003F# then
- return False; -- no control word
- end if; -- check control word value
-
- -- FPU found
- return True;
-
- end Has_FPU;
-
- --------------------------------
- -- Detect CPUID instruction --
- --------------------------------
-
- -- The processor supports the CPUID instruction if it is possible
- -- to change the value of ID flag bit in the EFLAGS register.
-
- function Has_CPUID return Boolean is
-
- Original_Flags, Modified_Flags : Processor_Register;
- -- EFLAG contents before and after changing the ID flag
-
- begin
-
- -- try flipping the ID flag in the EFLAGS register
- Asm (
-
- -- the assembler code
- "pushfl" & LF & HT & -- push EFLAGS on stack
- "pop %%eax" & LF & HT & -- pop EFLAGS into eax
- "movl %%eax, %0" & LF & HT & -- save EFLAGS content
- "xor $0x200000, %%eax" & LF & HT & -- flip ID flag
- "push %%eax" & LF & HT & -- push EFLAGS on stack
- "popfl" & LF & HT & -- load EFLAGS register
- "pushfl" & LF & HT & -- push EFLAGS on stack
- "pop %1", -- save EFLAGS content
-
- -- output values, may be anything
- -- Original_Flags is %0
- -- Modified_Flags is %1
- Outputs =>
- (Processor_Register'Asm_output ("=g", Original_Flags),
- Processor_Register'Asm_output ("=g", Modified_Flags)),
-
- -- tell compiler eax is destroyed
- Clobber => "eax");
-
- -- check if CPUID is supported
- if Original_Flags(ID_Flag) /= Modified_Flags(ID_Flag) then
- return True; -- ID flag was modified
- else
- return False; -- ID flag unchanged
- end if; -- check for CPUID
-
- end Has_CPUID;
-
- -------------------------------
- -- Get CPUID support level --
- -------------------------------
-
- function CPUID_Level return Natural is
-
- Level : Unsigned_32;
- -- returned support level
-
- begin
-
- -- execute CPUID, storing the results in the Level register
- Asm (
-
- -- the assembler code
- "cpuid", -- execute CPUID
-
- -- zero is stored in eax
- -- returning the support level in eax
- Inputs => Unsigned_32'Asm_input ("a", 0),
-
- -- eax is stored in Level
- Outputs => Unsigned_32'Asm_output ("=a", Level),
-
- -- tell compiler ebx, ecx and edx registers are destroyed
- Clobber => "ebx, ecx, edx");
-
- -- return the support level
- return Natural (Level);
-
- end CPUID_Level;
-
- --------------------------------
- -- Get CPU Vendor ID String --
- --------------------------------
-
- -- The vendor ID string is returned in the ebx, ecx and edx register
- -- after executing the CPUID instruction with eax set to zero.
- -- In case of a true Intel processor the string returned is
- -- "GenuineIntel"
-
- function Vendor_ID return String is
-
- Ebx, Ecx, Edx : Unsigned_Register;
- -- registers containing the vendor ID string
-
- Vendor_ID : String (1 .. 12);
- -- the vendor ID string
-
- begin
-
- -- execute CPUID, storing the results in the processor registers
- Asm (
-
- -- the assembler code
- "cpuid", -- execute CPUID
-
- -- zero stored in eax
- -- vendor ID string returned in ebx, ecx and edx
- Inputs => Unsigned_32'Asm_input ("a", 0),
-
- -- ebx is stored in Ebx
- -- ecx is stored in Ecx
- -- edx is stored in Edx
- Outputs => (Unsigned_Register'Asm_output ("=b", Ebx),
- Unsigned_Register'Asm_output ("=c", Ecx),
- Unsigned_Register'Asm_output ("=d", Edx)));
-
- -- now build the vendor ID string
- Vendor_ID( 1) := Character'Val (Ebx.L1);
- Vendor_ID( 2) := Character'Val (Ebx.H1);
- Vendor_ID( 3) := Character'Val (Ebx.L2);
- Vendor_ID( 4) := Character'Val (Ebx.H2);
- Vendor_ID( 5) := Character'Val (Edx.L1);
- Vendor_ID( 6) := Character'Val (Edx.H1);
- Vendor_ID( 7) := Character'Val (Edx.L2);
- Vendor_ID( 8) := Character'Val (Edx.H2);
- Vendor_ID( 9) := Character'Val (Ecx.L1);
- Vendor_ID(10) := Character'Val (Ecx.H1);
- Vendor_ID(11) := Character'Val (Ecx.L2);
- Vendor_ID(12) := Character'Val (Ecx.H2);
-
- -- return string
- return Vendor_ID;
-
- end Vendor_ID;
-
- -------------------------------
- -- Get processor signature --
- -------------------------------
-
- function Signature return Processor_Signature is
-
- Result : Processor_Signature;
- -- processor signature returned
-
- begin
-
- -- execute CPUID, storing the results in the Result variable
- Asm (
-
- -- the assembler code
- "cpuid", -- execute CPUID
-
- -- one is stored in eax
- -- processor signature returned in eax
- Inputs => Unsigned_32'Asm_input ("a", 1),
-
- -- eax is stored in Result
- Outputs => Processor_Signature'Asm_output ("=a", Result),
-
- -- tell compiler that ebx, ecx and edx are also destroyed
- Clobber => "ebx, ecx, edx");
-
- -- return processor signature
- return Result;
-
- end Signature;
-
- ------------------------------
- -- Get processor features --
- ------------------------------
-
- function Features return Processor_Features is
-
- Result : Processor_Features;
- -- processor features returned
-
- begin
-
- -- execute CPUID, storing the results in the Result variable
- Asm (
-
- -- the assembler code
- "cpuid", -- execute CPUID
-
- -- one stored in eax
- -- processor features returned in edx
- Inputs => Unsigned_32'Asm_input ("a", 1),
-
- -- edx is stored in Result
- Outputs => Processor_Features'Asm_output ("=d", Result),
-
- -- tell compiler that ebx and ecx are also destroyed
- Clobber => "ebx, ecx");
-
- -- return processor signature
- return Result;
+ Clobber => "ebx",
+ Volatile => True);
+@end group
+@end smallexample
- end Features;
+By default, @code{Volatile} is set to @code{False} unless there is no
+@code{Outputs} parameter.
-end Intel_CPU;
-@end smallexample
+Although setting @code{Volatile} to @code{True} prevents unwanted
+optimizations, it will also disable other optimizations that might be
+important for efficiency. In general, you should set @code{Volatile}
+to @code{True} only if the compiler's optimizations have created
+problems.
@c END OF INLINE ASSEMBLER CHAPTER
@c ===============================
-
-
@c ***********************************
@c * Compatibility and Porting Guide *
@c ***********************************
@noindent
This chapter describes the compatibility issues that may arise between
-GNAT and other Ada 83 and Ada 95 compilation systems, and shows how GNAT
-can expedite porting
+GNAT and other Ada compilation systems (including those for Ada 83),
+and shows how GNAT can expedite porting
applications developed in other Ada environments.
@menu
* Compatibility with Ada 83::
+* Compatibility between Ada 95 and Ada 2005::
* Implementation-dependent characteristics::
-* Compatibility with DEC Ada 83::
-* Compatibility with Other Ada 95 Systems::
+* Compatibility with Other Ada Systems::
* Representation Clauses::
+@ifclear vms
+@c Brief section is only in non-VMS version
+@c Full chapter is in VMS version
+* Compatibility with HP Ada 83::
+@end ifclear
+@ifset vms
+* Transitioning to 64-Bit GNAT for OpenVMS::
+@end ifset
@end menu
@node Compatibility with Ada 83
@section Compatibility with Ada 83
-@cindex Compatibility (between Ada 83 and Ada 95)
+@cindex Compatibility (between Ada 83 and Ada 95 / Ada 2005)
@noindent
-Ada 95 is designed to be highly upwards compatible with Ada 83. In
-particular, the design intention is that the difficulties associated
-with moving from Ada 83 to Ada 95 should be no greater than those
+Ada 95 and Ada 2005 are highly upwards compatible with Ada 83. In
+particular, the design intention was that the difficulties associated
+with moving from Ada 83 to Ada 95 or Ada 2005 should be no greater than those
that occur when moving from one Ada 83 system to another.
However, there are a number of points at which there are minor
@node Legal Ada 83 programs that are illegal in Ada 95
@subsection Legal Ada 83 programs that are illegal in Ada 95
-@table @asis
+Some legal Ada 83 programs are illegal (i.e., they will fail to compile) in
+Ada 95 and thus also in Ada 2005:
+
+@table @emph
@item Character literals
Some uses of character literals are ambiguous. Since Ada 95 has introduced
@code{Wide_Character} as a new predefined character type, some uses of
character literals that were legal in Ada 83 are illegal in Ada 95.
For example:
@smallexample @c ada
- for Char in 'A' .. 'Z' loop ... end loop;
+ for Char in 'A' .. 'Z' loop @dots{} end loop;
@end smallexample
+
@noindent
The problem is that @code{'A'} and @code{'Z'} could be from either
@code{Character} or @code{Wide_Character}. The simplest correction
is to make the type explicit; e.g.:
@smallexample @c ada
- for Char in Character range 'A' .. 'Z' loop ... end loop;
+ for Char in Character range 'A' .. 'Z' loop @dots{} end loop;
@end smallexample
@item New reserved words
A particular case is that representation pragmas
@ifset vms
(including the
-extended DEC Ada 83 compatibility pragmas such as @code{Export_Procedure})
+extended HP Ada 83 compatibility pragmas such as @code{Export_Procedure})
@end ifset
cannot be applied to a subprogram body. If necessary, a separate subprogram
declaration must be introduced to which the pragma can be applied.
@node More deterministic semantics
@subsection More deterministic semantics
-@table @asis
+@table @emph
@item Conversions
Conversions from real types to integer types round away from 0. In Ada 83
the conversion Integer(2.5) could deliver either 2 or 3 as its value. This
situation that you should be alert to is the change in the predefined type
@code{Character} from 7-bit ASCII to 8-bit Latin-1.
-@table @asis
-@item range of @code{Character}
+@table @emph
+@item Range of type @code{Character}
The range of @code{Standard.Character} is now the full 256 characters
of Latin-1, whereas in most Ada 83 implementations it was restricted
to 128 characters. Although some of the effects of
@node Other language compatibility issues
@subsection Other language compatibility issues
-@table @asis
-@item @option{-gnat83 switch}
+
+@table @emph
+@item @option{-gnat83} switch
All implementations of GNAT provide a switch that causes GNAT to operate
in Ada 83 mode. In this mode, some but not all compatibility problems
of the type described above are handled automatically. For example, the
-new Ada 95 reserved words are treated simply as identifiers as in Ada 83.
+new reserved words introduced in Ada 95 and Ada 2005 are treated simply
+as identifiers as in Ada 83.
However,
in practice, it is usually advisable to make the necessary modifications
to the program to remove the need for using this switch.
-See @ref{Compiling Ada 83 Programs}.
+See @ref{Compiling Different Versions of Ada}.
@item Support for removed Ada 83 pragmas and attributes
-A number of pragmas and attributes from Ada 83 have been removed from Ada 95,
-generally because they have been replaced by other mechanisms. Ada 95
+A number of pragmas and attributes from Ada 83 were removed from Ada 95,
+generally because they were replaced by other mechanisms. Ada 95 and Ada 2005
compilers are allowed, but not required, to implement these missing
-elements. In contrast with some other Ada 95 compilers, GNAT implements all
+elements. In contrast with some other compilers, GNAT implements all
such pragmas and attributes, eliminating this compatibility concern. These
include @code{pragma Interface} and the floating point type attributes
(@code{Emax}, @code{Mantissa}, etc.), among other items.
@end table
+@node Compatibility between Ada 95 and Ada 2005
+@section Compatibility between Ada 95 and Ada 2005
+@cindex Compatibility between Ada 95 and Ada 2005
+
+@noindent
+Although Ada 2005 was designed to be upwards compatible with Ada 95, there are
+a number of incompatibilities. Several are enumerated below;
+for a complete description please see the
+Annotated Ada 2005 Reference Manual, or section 9.1.1 in
+@cite{Rationale for Ada 2005}.
+
+@table @emph
+@item New reserved words.
+The words @code{interface}, @code{overriding} and @code{synchronized} are
+reserved in Ada 2005.
+A pre-Ada 2005 program that uses any of these as an identifier will be
+illegal.
+
+@item New declarations in predefined packages.
+A number of packages in the predefined environment contain new declarations:
+@code{Ada.Exceptions}, @code{Ada.Real_Time}, @code{Ada.Strings},
+@code{Ada.Strings.Fixed}, @code{Ada.Strings.Bounded},
+@code{Ada.Strings.Unbounded}, @code{Ada.Strings.Wide_Fixed},
+@code{Ada.Strings.Wide_Bounded}, @code{Ada.Strings.Wide_Unbounded},
+@code{Ada.Tags}, @code{Ada.Text_IO}, and @code{Interfaces.C}.
+If an Ada 95 program does a @code{with} and @code{use} of any of these
+packages, the new declarations may cause name clashes.
+
+@item Access parameters.
+A nondispatching subprogram with an access parameter cannot be renamed
+as a dispatching operation. This was permitted in Ada 95.
+
+@item Access types, discriminants, and constraints.
+Rule changes in this area have led to some incompatibilities; for example,
+constrained subtypes of some access types are not permitted in Ada 2005.
+
+@item Aggregates for limited types.
+The allowance of aggregates for limited types in Ada 2005 raises the
+possibility of ambiguities in legal Ada 95 programs, since additional types
+now need to be considered in expression resolution.
+
+@item Fixed-point multiplication and division.
+Certain expressions involving ``*'' or ``/'' for a fixed-point type, which
+were legal in Ada 95 and invoked the predefined versions of these operations,
+are now ambiguous.
+The ambiguity may be resolved either by applying a type conversion to the
+expression, or by explicitly invoking the operation from package
+@code{Standard}.
+
+@item Return-by-reference types.
+The Ada 95 return-by-reference mechanism has been removed. Instead, the user
+can declare a function returning a value from an anonymous access type.
+@end table
+
+
@node Implementation-dependent characteristics
@section Implementation-dependent characteristics
@noindent
* Target-specific aspects::
@end menu
-
@node Implementation-defined pragmas
@subsection Implementation-defined pragmas
@noindent
Ada compilers are allowed to supplement the language-defined pragmas, and
these are a potential source of non-portability. All GNAT-defined pragmas
-are described in the GNAT Reference Manual, and these include several that
-are specifically intended to correspond to other vendors' Ada 83 pragmas.
+are described in @ref{Implementation Defined Pragmas,,, gnat_rm, GNAT
+Reference Manual}, and these include several that are specifically
+intended to correspond to other vendors' Ada 83 pragmas.
For migrating from VADS, the pragma @code{Use_VADS_Size} may be useful.
-For
-compatibility with DEC Ada 83, GNAT supplies the pragmas
+For compatibility with HP Ada 83, GNAT supplies the pragmas
@code{Extend_System}, @code{Ident}, @code{Inline_Generic},
@code{Interface_Name}, @code{Passive}, @code{Suppress_All},
and @code{Volatile}.
@subsection Implementation-defined attributes
Analogous to pragmas, the set of attributes may be extended by an
-implementation. All GNAT-defined attributes are described in the
-@cite{GNAT Reference Manual}, and these include several that are specifically
-intended
+implementation. All GNAT-defined attributes are described in
+@ref{Implementation Defined Attributes,,, gnat_rm, GNAT Reference
+Manual}, and these include several that are specifically intended
to correspond to other vendors' Ada 83 attributes. For migrating from VADS,
-the attribute @code{VADS_Size} may be useful. For compatibility with DEC
+the attribute @code{VADS_Size} may be useful. For compatibility with HP
Ada 83, GNAT supplies the attributes @code{Bit}, @code{Machine_Size} and
@code{Type_Class}.
@noindent
Vendors may supply libraries to supplement the standard Ada API. If Ada 83
code uses vendor-specific libraries then there are several ways to manage
-this in Ada 95:
+this in Ada 95 or Ada 2005:
@enumerate
@item
-If the source code for the libraries (specifications and bodies) are
+If the source code for the libraries (specs and bodies) are
available, then the libraries can be migrated in the same way as the
application.
@item
-If the source code for the specifications but not the bodies are
+If the source code for the specs but not the bodies are
available, then you can reimplement the bodies.
@item
-Some new Ada 95 features obviate the need for library support. For
+Some features introduced by Ada 95 obviate the need for library support. For
example most Ada 83 vendors supplied a package for unsigned integers. The
Ada 95 modular type feature is the preferred way to handle this need, so
instead of migrating or reimplementing the unsigned integer package it may
to invoke a subprogram its body has been elaborated, or to instantiate a
generic before the generic body has been elaborated. By default GNAT
attempts to choose a safe order (one that will not encounter access before
-elaboration problems) by implicitly inserting Elaborate_All pragmas where
+elaboration problems) by implicitly inserting @code{Elaborate} or
+@code{Elaborate_All} pragmas where
needed. However, this can lead to the creation of elaboration circularities
and a resulting rejection of the program by gnatbind. This issue is
thoroughly described in @ref{Elaboration Order Handling in GNAT}.
@itemize @bullet
@item
-Modify the program to eliminate the circularities, e.g. by moving
+Modify the program to eliminate the circularities, e.g.@: by moving
elaboration-time code into explicitly-invoked procedures
@item
Constrain the elaboration order by including explicit @code{Elaborate_Body} or
such an Ada 83 application is being ported to different target hardware (for
example where the byte endianness has changed) then you will need to
carefully examine the program logic; the porting effort will heavily depend
-on the robustness of the original design. Moreover, Ada 95 is sometimes
+on the robustness of the original design. Moreover, Ada 95 (and thus
+Ada 2005) are sometimes
incompatible with typical Ada 83 compiler practices regarding implicit
packing, the meaning of the Size attribute, and the size of access values.
GNAT's approach to these issues is described in @ref{Representation Clauses}.
-
-@node Compatibility with Other Ada 95 Systems
-@section Compatibility with Other Ada 95 Systems
+@node Compatibility with Other Ada Systems
+@section Compatibility with Other Ada Systems
@noindent
-Providing that programs avoid the use of implementation dependent and
-implementation defined features of Ada 95, as documented in the Ada 95
-reference manual, there should be a high degree of portability between
-GNAT and other Ada 95 systems. The following are specific items which
-have proved troublesome in moving GNAT programs to other Ada 95
+If programs avoid the use of implementation dependent and
+implementation defined features, as documented in the @cite{Ada
+Reference Manual}, there should be a high degree of portability between
+GNAT and other Ada systems. The following are specific items which
+have proved troublesome in moving Ada 95 programs from GNAT to other Ada 95
compilers, but do not affect porting code to GNAT@.
+(As of @value{NOW}, GNAT is the only compiler available for Ada 2005;
+the following issues may or may not arise for Ada 2005 programs
+when other compilers appear.)
-@table @asis
+@table @emph
@item Ada 83 Pragmas and Attributes
Ada 95 compilers are allowed, but not required, to implement the missing
Ada 83 pragmas and attributes that are no longer defined in Ada 95.
a compatibility concern, but some other Ada 95 compilers reject these
pragmas and attributes.
-@item Special-needs Annexes
+@item Specialized Needs Annexes
GNAT implements the full set of special needs annexes. At the
current time, it is the only Ada 95 compiler to do so. This means that
programs making use of these features may not be portable to other Ada
@noindent
The Ada 83 reference manual was quite vague in describing both the minimal
required implementation of representation clauses, and also their precise
-effects. The Ada 95 reference manual is much more explicit, but the minimal
-set of capabilities required in Ada 95 is quite limited.
+effects. Ada 95 (and thus also Ada 2005) are much more explicit, but the
+minimal set of capabilities required is still quite limited.
-GNAT implements the full required set of capabilities described in the
-Ada 95 reference manual, but also goes much beyond this, and in particular
+GNAT implements the full required set of capabilities in
+Ada 95 and Ada 2005, but also goes much further, and in particular
an effort has been made to be compatible with existing Ada 83 usage to the
greatest extent possible.
A few cases exist in which Ada 83 compiler behavior is incompatible with
-requirements in the Ada 95 reference manual. These are instances of
+the requirements in Ada 95 (and thus also Ada 2005). These are instances of
intentional or accidental dependence on specific implementation dependent
characteristics of these Ada 83 compilers. The following is a list of
-the cases most likely to arise in existing legacy Ada 83 code.
+the cases most likely to arise in existing Ada 83 code.
-@table @asis
+@table @emph
@item Implicit Packing
Some Ada 83 compilers allowed a Size specification to cause implicit
packing of an array or record. This could cause expensive implicit
types, and the Ada design intends to avoid this possibility.
Subsequent AI's were issued to make it clear that such implicit
change of representation in response to a Size clause is inadvisable,
-and this recommendation is represented explicitly in the Ada 95 RM
-as implementation advice that is followed by GNAT@.
+and this recommendation is represented explicitly in the Ada 95 (and Ada 2005)
+Reference Manuals as implementation advice that is followed by GNAT@.
The problem will show up as an error
message rejecting the size clause. The fix is simply to provide
the explicit pragma @code{Pack}, or for more fine tuned control, provide
a Component_Size clause.
@item Meaning of Size Attribute
-The Size attribute in Ada 95 for discrete types is defined as being the
-minimal number of bits required to hold values of the type. For example,
-on a 32-bit machine, the size of Natural will typically be 31 and not
+The Size attribute in Ada 95 (and Ada 2005) for discrete types is defined as
+the minimal number of bits required to hold values of the type. For example,
+on a 32-bit machine, the size of @code{Natural} will typically be 31 and not
32 (since no sign bit is required). Some Ada 83 compilers gave 31, and
some 32 in this situation. This problem will usually show up as a compile
time error, but not always. It is a good idea to check all uses of the
or a record representation clause for an access field in a record.
@end table
-@node Compatibility with DEC Ada 83
-@section Compatibility with DEC Ada 83
+@ifclear vms
+@c This brief section is only in the non-VMS version
+@c The complete chapter on HP Ada is in the VMS version
+@node Compatibility with HP Ada 83
+@section Compatibility with HP Ada 83
@noindent
The VMS version of GNAT fully implements all the pragmas and attributes
-provided by DEC Ada 83, as well as providing the standard DEC Ada 83
+provided by HP Ada 83, as well as providing the standard HP Ada 83
libraries, including Starlet. In addition, data layouts and parameter
passing conventions are highly compatible. This means that porting
-existing DEC Ada 83 code to GNAT in VMS systems should be easier than
+existing HP Ada 83 code to GNAT in VMS systems should be easier than
most other porting efforts. The following are some of the most
-significant differences between GNAT and DEC Ada 83.
+significant differences between GNAT and HP Ada 83.
-@table @asis
+@table @emph
@item Default floating-point representation
-In GNAT, the default floating-point format is IEEE, whereas in DEC Ada 83,
+In GNAT, the default floating-point format is IEEE, whereas in HP Ada 83,
it is VMS format. GNAT does implement the necessary pragmas
(Long_Float, Float_Representation) for changing this default.
@item System
The package System in GNAT exactly corresponds to the definition in the
Ada 95 reference manual, which means that it excludes many of the
-DEC Ada 83 extensions. However, a separate package Aux_DEC is provided
+HP Ada 83 extensions. However, a separate package Aux_DEC is provided
that contains the additional definitions, and a special pragma,
Extend_System allows this package to be treated transparently as an
extension of package System.
@item To_Address
The definitions provided by Aux_DEC are exactly compatible with those
-in the DEC Ada 83 version of System, with one exception.
-DEC Ada provides the following declarations:
+in the HP Ada 83 version of System, with one exception.
+HP Ada provides the following declarations:
@smallexample @c ada
TO_ADDRESS (INTEGER)
TO_ADDRESS (UNSIGNED_LONGWORD)
-TO_ADDRESS (universal_integer)
+TO_ADDRESS (@i{universal_integer})
@end smallexample
@noindent
-The version of TO_ADDRESS taking a universal integer argument is in fact
+The version of TO_ADDRESS taking a @i{universal integer} argument is in fact
an extension to Ada 83 not strictly compatible with the reference manual.
In GNAT, we are constrained to be exactly compatible with the standard,
-and this means we cannot provide this capability. In DEC Ada 83, the
+and this means we cannot provide this capability. In HP Ada 83, the
point of this definition is to deal with a call like:
@smallexample @c ada
@noindent
Normally, according to the Ada 83 standard, one would expect this to be
ambiguous, since it matches both the INTEGER and UNSIGNED_LONGWORD forms
-of TO_ADDRESS@. However, in DEC Ada 83, there is no ambiguity, since the
-definition using universal_integer takes precedence.
+of TO_ADDRESS@. However, in HP Ada 83, there is no ambiguity, since the
+definition using @i{universal_integer} takes precedence.
-In GNAT, since the version with universal_integer cannot be supplied, it is
-not possible to be 100% compatible. Since there are many programs using
+In GNAT, since the version with @i{universal_integer} cannot be supplied, it
+is not possible to be 100% compatible. Since there are many programs using
numeric constants for the argument to TO_ADDRESS, the decision in GNAT was
to change the name of the function in the UNSIGNED_LONGWORD case, so the
declarations provided in the GNAT version of AUX_Dec are:
which in GNAT is treated like any other declared task.
@end table
+@noindent
For full details on these and other less significant compatibility issues,
-see appendix E of the Digital publication entitled @cite{DEC Ada, Technical
-Overview and Comparison on DIGITAL Platforms}.
+see appendix E of the HP publication entitled @cite{HP Ada, Technical
+Overview and Comparison on HP Platforms}.
-For GNAT running on other than VMS systems, all the DEC Ada 83 pragmas and
+For GNAT running on other than VMS systems, all the HP Ada 83 pragmas and
attributes are recognized, although only a subset of them can sensibly
-be implemented. The description of pragmas in this reference manual
+be implemented. The description of pragmas in @ref{Implementation
+Defined Pragmas,,, gnat_rm, GNAT Reference Manual}
indicates whether or not they are applicable to non-VMS systems.
+@end ifclear
+
+@ifset vms
+@node Transitioning to 64-Bit GNAT for OpenVMS
+@section Transitioning to 64-Bit @value{EDITION} for OpenVMS
+
+@noindent
+This section is meant to assist users of pre-2006 @value{EDITION}
+for Alpha OpenVMS who are transitioning to 64-bit @value{EDITION},
+the version of the GNAT technology supplied in 2006 and later for
+OpenVMS on both Alpha and I64.
+
+@menu
+* Introduction to transitioning::
+* Migration of 32 bit code::
+* Taking advantage of 64 bit addressing::
+* Technical details::
+@end menu
+
+@node Introduction to transitioning
+@subsection Introduction
+
+@noindent
+64-bit @value{EDITION} for Open VMS has been designed to meet
+three main goals:
+
+@enumerate
+@item
+Providing a full conforming implementation of Ada 95 and Ada 2005
+
+@item
+Allowing maximum backward compatibility, thus easing migration of existing
+Ada source code
+
+@item
+Supplying a path for exploiting the full 64-bit address range
+@end enumerate
+
+@noindent
+Ada's strong typing semantics has made it
+impractical to have different 32-bit and 64-bit modes. As soon as
+one object could possibly be outside the 32-bit address space, this
+would make it necessary for the @code{System.Address} type to be 64 bits.
+In particular, this would cause inconsistencies if 32-bit code is
+called from 64-bit code that raises an exception.
+
+This issue has been resolved by always using 64-bit addressing
+at the system level, but allowing for automatic conversions between
+32-bit and 64-bit addresses where required. Thus users who
+do not currently require 64-bit addressing capabilities, can
+recompile their code with only minimal changes (and indeed
+if the code is written in portable Ada, with no assumptions about
+the size of the @code{Address} type, then no changes at all are necessary).
+At the same time,
+this approach provides a simple, gradual upgrade path to future
+use of larger memories than available for 32-bit systems.
+Also, newly written applications or libraries will by default
+be fully compatible with future systems exploiting 64-bit
+addressing capabilities.
+
+@ref{Migration of 32 bit code}, will focus on porting applications
+that do not require more than 2 GB of
+addressable memory. This code will be referred to as
+@emph{32-bit code}.
+For applications intending to exploit the full 64-bit address space,
+@ref{Taking advantage of 64 bit addressing},
+will consider further changes that may be required.
+Such code will be referred to below as @emph{64-bit code}.
+
+@node Migration of 32 bit code
+@subsection Migration of 32-bit code
+
+@menu
+* Address types::
+* Access types::
+* Unchecked conversions::
+* Predefined constants::
+* Interfacing with C::
+* Experience with source compatibility::
+@end menu
+
+@node Address types
+@subsubsection Address types
+
+@noindent
+To solve the problem of mixing 64-bit and 32-bit addressing,
+while maintaining maximum backward compatibility, the following
+approach has been taken:
+
+@itemize @bullet
+@item
+@code{System.Address} always has a size of 64 bits
+
+@item
+@code{System.Short_Address} is a 32-bit subtype of @code{System.Address}
+@end itemize
+
+@noindent
+Since @code{System.Short_Address} is a subtype of @code{System.Address},
+a @code{Short_Address}
+may be used where an @code{Address} is required, and vice versa, without
+needing explicit type conversions.
+By virtue of the Open VMS parameter passing conventions,
+even imported
+and exported subprograms that have 32-bit address parameters are
+compatible with those that have 64-bit address parameters.
+(See @ref{Making code 64 bit clean} for details.)
+
+The areas that may need attention are those where record types have
+been defined that contain components of the type @code{System.Address}, and
+where objects of this type are passed to code expecting a record layout with
+32-bit addresses.
+
+Different compilers on different platforms cannot be
+expected to represent the same type in the same way,
+since alignment constraints
+and other system-dependent properties affect the compiler's decision.
+For that reason, Ada code
+generally uses representation clauses to specify the expected
+layout where required.
+
+If such a representation clause uses 32 bits for a component having
+the type @code{System.Address}, 64-bit @value{EDITION} for OpenVMS
+will detect that error and produce a specific diagnostic message.
+The developer should then determine whether the representation
+should be 64 bits or not and make either of two changes:
+change the size to 64 bits and leave the type as @code{System.Address}, or
+leave the size as 32 bits and change the type to @code{System.Short_Address}.
+Since @code{Short_Address} is a subtype of @code{Address}, no changes are
+required in any code setting or accessing the field; the compiler will
+automatically perform any needed conversions between address
+formats.
+
+@node Access types
+@subsubsection Access types
+
+@noindent
+By default, objects designated by access values are always
+allocated in the 32-bit
+address space. Thus legacy code will never contain
+any objects that are not addressable with 32-bit addresses, and
+the compiler will never raise exceptions as result of mixing
+32-bit and 64-bit addresses.
+
+However, the access values themselves are represented in 64 bits, for optimum
+performance and future compatibility with 64-bit code. As was
+the case with @code{System.Address}, the compiler will give an error message
+if an object or record component has a representation clause that
+requires the access value to fit in 32 bits. In such a situation,
+an explicit size clause for the access type, specifying 32 bits,
+will have the desired effect.
+
+General access types (declared with @code{access all}) can never be
+32 bits, as values of such types must be able to refer to any object
+of the designated type,
+including objects residing outside the 32-bit address range.
+Existing Ada 83 code will not contain such type definitions,
+however, since general access types were introduced in Ada 95.
+
+@node Unchecked conversions
+@subsubsection Unchecked conversions
+
+@noindent
+In the case of an @code{Unchecked_Conversion} where the source type is a
+64-bit access type or the type @code{System.Address}, and the target
+type is a 32-bit type, the compiler will generate a warning.
+Even though the generated code will still perform the required
+conversions, it is highly recommended in these cases to use
+respectively a 32-bit access type or @code{System.Short_Address}
+as the source type.
+
+@node Predefined constants
+@subsubsection Predefined constants
+
+@noindent
+The following table shows the correspondence between pre-2006 versions of
+@value{EDITION} on Alpha OpenVMS (``Old'') and 64-bit @value{EDITION}
+(``New''):
+
+@multitable {@code{System.Short_Memory_Size}} {2**32} {2**64}
+@item @b{Constant} @tab @b{Old} @tab @b{New}
+@item @code{System.Word_Size} @tab 32 @tab 64
+@item @code{System.Memory_Size} @tab 2**32 @tab 2**64
+@item @code{System.Short_Memory_Size} @tab 2**32 @tab 2**32
+@item @code{System.Address_Size} @tab 32 @tab 64
+@end multitable
+
+@noindent
+If you need to refer to the specific
+memory size of a 32-bit implementation, instead of the
+actual memory size, use @code{System.Short_Memory_Size}
+rather than @code{System.Memory_Size}.
+Similarly, references to @code{System.Address_Size} may need
+to be replaced by @code{System.Short_Address'Size}.
+The program @command{gnatfind} may be useful for locating
+references to the above constants, so that you can verify that they
+are still correct.
+
+@node Interfacing with C
+@subsubsection Interfacing with C
+
+@noindent
+In order to minimize the impact of the transition to 64-bit addresses on
+legacy programs, some fundamental types in the @code{Interfaces.C}
+package hierarchy continue to be represented in 32 bits.
+These types are: @code{ptrdiff_t}, @code{size_t}, and @code{chars_ptr}.
+This eases integration with the default HP C layout choices, for example
+as found in the system routines in @code{DECC$SHR.EXE}.
+Because of this implementation choice, the type fully compatible with
+@code{chars_ptr} is now @code{Short_Address} and not @code{Address}.
+Depending on the context the compiler will issue a
+warning or an error when type @code{Address} is used, alerting the user to a
+potential problem. Otherwise 32-bit programs that use
+@code{Interfaces.C} should normally not require code modifications
+
+The other issue arising with C interfacing concerns pragma @code{Convention}.
+For VMS 64-bit systems, there is an issue of the appropriate default size
+of C convention pointers in the absence of an explicit size clause. The HP
+C compiler can choose either 32 or 64 bits depending on compiler options.
+GNAT chooses 32-bits rather than 64-bits in the default case where no size
+clause is given. This proves a better choice for porting 32-bit legacy
+applications. In order to have a 64-bit representation, it is necessary to
+specify a size representation clause. For example:
+
+@smallexample @c ada
+type int_star is access Interfaces.C.int;
+pragma Convention(C, int_star);
+for int_star'Size use 64; -- Necessary to get 64 and not 32 bits
+@end smallexample
+
+@node Experience with source compatibility
+@subsubsection Experience with source compatibility
+
+@noindent
+The Security Server and STARLET on I64 provide an interesting ``test case''
+for source compatibility issues, since it is in such system code
+where assumptions about @code{Address} size might be expected to occur.
+Indeed, there were a small number of occasions in the Security Server
+file @file{jibdef.ads}
+where a representation clause for a record type specified
+32 bits for a component of type @code{Address}.
+All of these errors were detected by the compiler.
+The repair was obvious and immediate; to simply replace @code{Address} by
+@code{Short_Address}.
+
+In the case of STARLET, there were several record types that should
+have had representation clauses but did not. In these record types
+there was an implicit assumption that an @code{Address} value occupied
+32 bits.
+These compiled without error, but their usage resulted in run-time error
+returns from STARLET system calls.
+Future GNAT technology enhancements may include a tool that detects and flags
+these sorts of potential source code porting problems.
+
+@c ****************************************
+@node Taking advantage of 64 bit addressing
+@subsection Taking advantage of 64-bit addressing
+
+@menu
+* Making code 64 bit clean::
+* Allocating memory from the 64 bit storage pool::
+* Restrictions on use of 64 bit objects::
+* Using 64 bit storage pools by default::
+* General access types::
+* STARLET and other predefined libraries::
+@end menu
+
+@node Making code 64 bit clean
+@subsubsection Making code 64-bit clean
+
+@noindent
+In order to prevent problems that may occur when (parts of) a
+system start using memory outside the 32-bit address range,
+we recommend some additional guidelines:
+
+@itemize @bullet
+@item
+For imported subprograms that take parameters of the
+type @code{System.Address}, ensure that these subprograms can
+indeed handle 64-bit addresses. If not, or when in doubt,
+change the subprogram declaration to specify
+@code{System.Short_Address} instead.
+
+@item
+Resolve all warnings related to size mismatches in
+unchecked conversions. Failing to do so causes
+erroneous execution if the source object is outside
+the 32-bit address space.
+
+@item
+(optional) Explicitly use the 32-bit storage pool
+for access types used in a 32-bit context, or use
+generic access types where possible
+(@pxref{Restrictions on use of 64 bit objects}).
+@end itemize
+
+@noindent
+If these rules are followed, the compiler will automatically insert
+any necessary checks to ensure that no addresses or access values
+passed to 32-bit code ever refer to objects outside the 32-bit
+address range.
+Any attempt to do this will raise @code{Constraint_Error}.
+
+@node Allocating memory from the 64 bit storage pool
+@subsubsection Allocating memory from the 64-bit storage pool
+
+@noindent
+For any access type @code{T} that potentially requires memory allocations
+beyond the 32-bit address space,
+use the following representation clause:
+
+@smallexample @c ada
+ for T'Storage_Pool use System.Pool_64;
+@end smallexample
+
+@node Restrictions on use of 64 bit objects
+@subsubsection Restrictions on use of 64-bit objects
+
+@noindent
+Taking the address of an object allocated from a 64-bit storage pool,
+and then passing this address to a subprogram expecting
+@code{System.Short_Address},
+or assigning it to a variable of type @code{Short_Address}, will cause
+@code{Constraint_Error} to be raised. In case the code is not 64-bit clean
+(@pxref{Making code 64 bit clean}), or checks are suppressed,
+no exception is raised and execution
+will become erroneous.
+
+@node Using 64 bit storage pools by default
+@subsubsection Using 64-bit storage pools by default
+
+@noindent
+In some cases it may be desirable to have the compiler allocate
+from 64-bit storage pools by default. This may be the case for
+libraries that are 64-bit clean, but may be used in both 32-bit
+and 64-bit contexts. For these cases the following configuration
+pragma may be specified:
+
+@smallexample @c ada
+ pragma Pool_64_Default;
+@end smallexample
+
+@noindent
+Any code compiled in the context of this pragma will by default
+use the @code{System.Pool_64} storage pool. This default may be overridden
+for a specific access type @code{T} by the representation clause:
+
+@smallexample @c ada
+ for T'Storage_Pool use System.Pool_32;
+@end smallexample
+
+@noindent
+Any object whose address may be passed to a subprogram with a
+@code{Short_Address} argument, or assigned to a variable of type
+@code{Short_Address}, needs to be allocated from this pool.
+
+@node General access types
+@subsubsection General access types
+
+@noindent
+Objects designated by access values from a
+general access type (declared with @code{access all}) are never allocated
+from a 64-bit storage pool. Code that uses general access types will
+accept objects allocated in either 32-bit or 64-bit address spaces,
+but never allocate objects outside the 32-bit address space.
+Using general access types ensures maximum compatibility with both
+32-bit and 64-bit code.
+
+@node STARLET and other predefined libraries
+@subsubsection STARLET and other predefined libraries
+
+@noindent
+All code that comes as part of GNAT is 64-bit clean, but the
+restrictions given in @ref{Restrictions on use of 64 bit objects},
+still apply. Look at the package
+specs to see in which contexts objects allocated
+in 64-bit address space are acceptable.
+@node Technical details
+@subsection Technical details
+@noindent
+64-bit @value{EDITION} for Open VMS takes advantage of the freedom given in the
+Ada standard with respect to the type of @code{System.Address}. Previous
+versions of GNAT Pro have defined this type as private and implemented it as a
+modular type.
+
+In order to allow defining @code{System.Short_Address} as a proper subtype,
+and to match the implicit sign extension in parameter passing,
+in 64-bit @value{EDITION} for Open VMS, @code{System.Address} is defined as a
+visible (i.e., non-private) integer type.
+Standard operations on the type, such as the binary operators ``+'', ``-'',
+etc., that take @code{Address} operands and return an @code{Address} result,
+have been hidden by declaring these
+@code{abstract}, a feature introduced in Ada 95 that helps avoid the potential
+ambiguities that would otherwise result from overloading.
+(Note that, although @code{Address} is a visible integer type,
+good programming practice dictates against exploiting the type's
+integer properties such as literals, since this will compromise
+code portability.)
+
+Defining @code{Address} as a visible integer type helps achieve
+maximum compatibility for existing Ada code,
+without sacrificing the capabilities of the 64-bit architecture.
+@end ifset
+@c ************************************************
@ifset unw
@node Microsoft Windows Topics
@appendix Microsoft Windows Topics
* Building DLLs with gnatdll::
* GNAT and Windows Resources::
* Debugging a DLL::
-* GNAT and COM/DCOM Objects::
+* Setting Stack Size from gnatlink::
+* Setting Heap Size from gnatlink::
@end menu
@node Using GNAT on Windows
@noindent
One of the strengths of the GNAT technology is that its tool set
-(@code{gcc}, @code{gnatbind}, @code{gnatlink}, @code{gnatmake}, the
+(@command{gcc}, @command{gnatbind}, @command{gnatlink}, @command{gnatmake}, the
@code{gdb} debugger, etc.) is used in the same way regardless of the
platform.
@noindent
Make sure the system on which GNAT is installed is accessible from the
-current machine, i.e. the install location is shared over the network.
+current machine, i.e., the install location is shared over the network.
Shared resources are accessed on Windows by means of UNC paths, which
have the format @code{\\server\sharename\path}
@noindent
It is possible to control where temporary files gets created by setting
-the TMP environment variable. The file will be created:
+the @env{TMP} environment variable. The file will be created:
@itemize
-@item Under the directory pointed to by the TMP environment variable if
+@item Under the directory pointed to by the @env{TMP} environment variable if
this directory exists.
-@item Under c:\temp, if the TMP environment variable is not set (or not
-pointing to a directory) and if this directory exists.
+@item Under @file{c:\temp}, if the @env{TMP} environment variable is not
+set (or not pointing to a directory) and if this directory exists.
@item Under the current working directory otherwise.
@end itemize
Windows C/C++ development environment conditions your overall
interoperability strategy.
-If you use @code{gcc} to compile the non-Ada part of your application,
+If you use @command{gcc} to compile the non-Ada part of your application,
there are no Windows-specific restrictions that affect the overall
interoperability with your Ada code. If you plan to use
-Microsoft tools (e.g. Microsoft Visual C/C++), you should be aware of
+Microsoft tools (e.g.@: Microsoft Visual C/C++), you should be aware of
the following limitations:
@itemize @bullet
@enumerate
@item
-Encapsulate your non Ada code in a DLL to be linked with your Ada
+Encapsulate your non-Ada code in a DLL to be linked with your Ada
application. In this case, use the Microsoft or whatever environment to
build the DLL and use GNAT to build your executable
(@pxref{Using DLLs with GNAT}).
@menu
* C Calling Convention::
* Stdcall Calling Convention::
+* Win32 Calling Convention::
* DLL Calling Convention::
@end menu
@code{Stdcall} (Microsoft defined)
@item
+@code{Win32} (GNAT specific)
+
+@item
@code{DLL} (GNAT specific)
@end itemize
@noindent
This is the default calling convention used when interfacing to C/C++
-routines compiled with either @code{gcc} or Microsoft Visual C++.
+routines compiled with either @command{gcc} or Microsoft Visual C++.
In the @code{C} calling convention subprogram parameters are pushed on the
stack by the caller from right to left. The caller itself is in charge of
When importing a variable defined in C, you should always use the @code{C}
calling convention unless the object containing the variable is part of a
-DLL (in which case you should use the @code{DLL} calling convention,
-@pxref{DLL Calling Convention}).
+DLL (in which case you should use the @code{Stdcall} calling
+convention, @pxref{Stdcall Calling Convention}).
@node Stdcall Calling Convention
@subsection @code{Stdcall} Calling Convention
caller) is in charge of cleaning the stack on routine exit. In addition,
the name of a routine with @code{Stdcall} calling convention is mangled by
adding a leading underscore (as for the @code{C} calling convention) and a
-trailing @code{@@}@code{@i{nn}}, where @i{nn} is the overall size (in
+trailing @code{@@}@code{@var{nn}}, where @var{nn} is the overall size (in
bytes) of the parameters passed to the routine.
The name to use on the Ada side when importing a C routine with a
@code{Stdcall} calling convention is the name of the C routine. The leading
-underscore and trailing @code{@@}@code{@i{nn}} are added automatically by
+underscore and trailing @code{@@}@code{@var{nn}} are added automatically by
the compiler. For instance the Win32 function:
@smallexample
@end smallexample
@noindent
-then the imported routine is @code{retrieve_val@@4}, that is, there is no
-trailing underscore but the appropriate @code{@@}@code{@i{nn}} is always
-added at the end of the @code{Link_Name} by the compiler.
+then the imported routine is @code{retrieve_val}, that is, there is no
+decoration at all. No leading underscore and no Stdcall suffix
+@code{@@}@code{@var{nn}}.
@noindent
-Note, that in some special cases a DLL's entry point name lacks a trailing
-@code{@@}@code{@i{nn}} while the exported name generated for a call has it.
-The @code{gnatdll} tool, which creates the import library for the DLL, is able
-to handle those cases (see the description of the switches in
-@pxref{Using gnatdll} section).
-
-@node DLL Calling Convention
-@subsection @code{DLL} Calling Convention
+This is especially important as in some special cases a DLL's entry
+point name lacks a trailing @code{@@}@code{@var{nn}} while the exported
+name generated for a call has it.
@noindent
-This convention, which is GNAT-specific, must be used when you want to
-import in Ada a variables defined in a DLL. For functions and procedures
-this convention is equivalent to the @code{Stdcall} convention. As an
-example, if a DLL contains a variable defined as:
+It is also possible to import variables defined in a DLL by using an
+import pragma for a variable. As an example, if a DLL contains a
+variable defined as:
@smallexample
int my_var;
@smallexample @c ada
@group
My_Var : Interfaces.C.int;
-pragma Import (DLL, My_Var);
+pragma Import (Stdcall, My_Var);
@end group
@end smallexample
-The remarks concerning the @code{External_Name} and @code{Link_Name}
-parameters given in the previous sections equally apply to the @code{DLL}
-calling convention.
+@noindent
+Note that to ease building cross-platform bindings this convention
+will be handled as a @code{C} calling convention on non-Windows platforms.
+
+@node Win32 Calling Convention
+@subsection @code{Win32} Calling Convention
+
+@noindent
+This convention, which is GNAT-specific is fully equivalent to the
+@code{Stdcall} calling convention described above.
+
+@node DLL Calling Convention
+@subsection @code{DLL} Calling Convention
+
+@noindent
+This convention, which is GNAT-specific is fully equivalent to the
+@code{Stdcall} calling convention described above.
@node Introduction to Dynamic Link Libraries (DLLs)
@section Introduction to Dynamic Link Libraries (DLLs)
an import library which contains a jump table with an entry for each
routine and variable exported by the DLL. In the Microsoft world this
import library is called @file{API.lib}. When using GNAT this import
-library is called either @file{libAPI.a} or @file{libapi.a} (names are
-case insensitive).
+library is called either @file{libAPI.dll.a}, @file{libapi.dll.a},
+@file{libAPI.a} or @file{libapi.a} (names are case insensitive).
After you have linked your application with the DLL or the import library
and you run your application, here is what happens:
@end itemize
@item
-The entries in the jump table (from the import library @file{libAPI.a}
+The entries in the jump table (from the import library @file{libAPI.dll.a}
or @file{API.lib} or automatically created when linking against a DLL)
which is part of your application are initialized with the addresses
of the routines and variables in @file{API.dll}.
header files provided with the DLL.
@item
-The import library (@file{libAPI.a} or @file{API.lib}). As previously
+The import library (@file{libAPI.dll.a} or @file{API.lib}). As previously
mentioned an import library is a statically linked library containing the
import table which will be filled at load time to point to the actual
@file{API.dll} routines. Sometimes you don't have an import library for the
@end smallexample
@noindent
-The argument @option{-largs -lAPI} at the end of the @code{gnatmake} command
+The argument @option{-largs -lAPI} at the end of the @command{gnatmake} command
tells the GNAT linker to look first for a library named @file{API.lib}
-(Microsoft-style name) and if not found for a library named @file{libAPI.a}
+(Microsoft-style name) and if not found for a libraries named
+@file{libAPI.dll.a}, @file{API.dll.a} or @file{libAPI.a}.
(GNAT-style name). Note that if the Ada package spec for @file{API.dll}
contains the following pragma
@end smallexample
@noindent
-you do not have to add @option{-largs -lAPI} at the end of the @code{gnatmake}
-command.
+you do not have to add @option{-largs -lAPI} at the end of the
+@command{gnatmake} command.
If any one of the items above is missing you will have to create it
yourself. The following sections explain how to do so using as an
@end smallexample
@noindent
-Note that a variable is @strong{always imported with a DLL convention}. A
-function can have @code{C}, @code{Stdcall} or @code{DLL} convention. For
-subprograms, the @code{DLL} convention is a synonym of @code{Stdcall}
+Note that a variable is
+@strong{always imported with a Stdcall convention}. A function
+can have @code{C} or @code{Stdcall} convention.
(@pxref{Windows Calling Conventions}).
@node Creating an Import Library
@noindent
If a Microsoft-style import library @file{API.lib} or a GNAT-style
-import library @file{libAPI.a} is available with @file{API.dll} you
-can skip this section. You can also skip this section if
-@file{API.dll} is built with GNU tools as in this case it is possible
-to link directly against the DLL. Otherwise read on.
+import library @file{libAPI.dll.a} or @file{libAPI.a} is available
+with @file{API.dll} you can skip this section. You can also skip this
+section if @file{API.dll} or @file{libAPI.dll} is built with GNU tools
+as in this case it is possible to link directly against the
+DLL. Otherwise read on.
@node The Definition File
@subsubsection The Definition File
@smallexample
@group
@cartouche
-[LIBRARY @i{name}]
-[DESCRIPTION @i{string}]
+@r{[}LIBRARY @var{name}@r{]}
+@r{[}DESCRIPTION @var{string}@r{]}
EXPORTS
- @i{symbol1}
- @i{symbol2}
- ...
+ @var{symbol1}
+ @var{symbol2}
+ @dots{}
@end cartouche
@end group
@end smallexample
@table @code
-@item LIBRARY @i{name}
+@item LIBRARY @var{name}
This section, which is optional, gives the name of the DLL.
-@item DESCRIPTION @i{string}
+@item DESCRIPTION @var{string}
This section, which is optional, gives a description string that will be
embedded in the import library.
@end table
@noindent
-Note that you must specify the correct suffix (@code{@@}@code{@i{nn}})
+Note that you must specify the correct suffix (@code{@@}@code{@var{nn}})
(@pxref{Windows Calling Conventions}) for a Stdcall
calling convention function in the exported symbols list.
@code{dll2def} is a very simple tool: it takes as input a DLL and prints
to standard output the list of entry points in the DLL. Note that if
some routines in the DLL have the @code{Stdcall} convention
-(@pxref{Windows Calling Conventions}) with stripped @code{@@}@i{nn}
+(@pxref{Windows Calling Conventions}) with stripped @code{@@}@var{nn}
suffix then you'll have to edit @file{api.def} to add it, and specify
-@code{-k} to @code{gnatdll} when creating the import library.
+@option{-k} to @command{gnatdll} when creating the import library.
@noindent
-Here are some hints to find the right @code{@@}@i{nn} suffix.
+Here are some hints to find the right @code{@@}@var{nn} suffix.
@enumerate
@item
@end enumerate
@item
-Build the import library @code{libAPI.a}, using @code{gnatdll}
+Build the import library @code{libAPI.dll.a}, using @code{gnatdll}
(@pxref{Using gnatdll}) as follows:
@smallexample
name of the DLL containing the services listed in the definition file
@file{API.dll}. The name of the static import library generated is
computed from the name of the definition file as follows: if the
-definition file name is @i{xyz}@code{.def}, the import library name will
-be @code{lib}@i{xyz}@code{.a}. Note that in the previous example option
+definition file name is @var{xyz}@code{.def}, the import library name will
+be @code{lib}@var{xyz}@code{.a}. Note that in the previous example option
@option{-e} could have been removed because the name of the definition
file (before the ``@code{.def}'' suffix) is the same as the name of the
DLL (@pxref{Using gnatdll} for more information about @code{gnatdll}).
@item building object files
The first step is to build all objects files that are to be included
-into the DLL. This is done by using the standard @code{gnatmake} tool.
+into the DLL. This is done by using the standard @command{gnatmake} tool.
@item building the DLL
-To build the DLL you must use @code{gcc}'s @code{-shared}
+To build the DLL you must use @command{gcc}'s @option{-shared}
option. It is quite simple to use this method:
@smallexample
-$ gcc -shared -o api.dll obj1.o obj2.o ...
+$ gcc -shared -o api.dll obj1.o obj2.o @dots{}
@end smallexample
It is important to note that in this case all symbols found in the
object files are automatically exported. It is possible to restrict
-the set of symbols to export by passing to @code{gcc} a definition
+the set of symbols to export by passing to @command{gcc} a definition
file, @pxref{The Definition File}. For example:
@smallexample
-$ gcc -shared -o api.dll api.def obj1.o obj2.o ...
+$ gcc -shared -o api.dll api.def obj1.o obj2.o @dots{}
@end smallexample
If you use a definition file you must export the elaboration procedures
At this point it is possible to use the DLL by directly linking
against it. Note that you must use the GNAT shared runtime when using
-GNAT shared libraries. This is achieved by using @code{-shared} binder's
+GNAT shared libraries. This is achieved by using @option{-shared} binder's
option.
@smallexample
@cindex DLLs, building
@noindent
-There is nothing specific to Windows in this area. @pxref{Library Projects}.
+There is nothing specific to Windows in the build process.
+@pxref{Library Projects}.
+
+@noindent
+Due to a system limitation, it is not possible under Windows to create threads
+when inside the @code{DllMain} routine which is used for auto-initialization
+of shared libraries, so it is not possible to have library level tasks in SALs.
@node Building DLLs with gnatdll
@section Building DLLs with gnatdll
@end menu
@noindent
-Note that it is prefered to use the built-in GNAT DLL support
+Note that it is preferred to use the built-in GNAT DLL support
(@pxref{Building DLLs with GNAT}) or GNAT Project files
(@pxref{Building DLLs with GNAT Project files}) to build DLLs.
@item
Your Ada code must export an initialization routine which calls the routine
-@code{adainit} generated by @code{gnatbind} to perform the elaboration of
+@code{adainit} generated by @command{gnatbind} to perform the elaboration of
the Ada code in the DLL (@pxref{Ada DLLs and Elaboration}). The initialization
routine exported by the Ada DLL must be invoked by the clients of the DLL
to initialize the DLL.
@item
When useful, the DLL should also export a finalization routine which calls
-routine @code{adafinal} generated by @code{gnatbind} to perform the
+routine @code{adafinal} generated by @command{gnatbind} to perform the
finalization of the Ada code in the DLL (@pxref{Ada DLLs and Finalization}).
The finalization routine exported by the Ada DLL must be invoked by the
clients of the DLL when the DLL services are no further needed.
@end enumerate
@noindent
-Note that a relocatable DLL stripped using the @code{strip} binutils
-tool will not be relocatable anymore. To build a DLL without debug
-information pass @code{-largs -s} to @code{gnatdll}.
+Note that a relocatable DLL stripped using the @code{strip}
+binutils tool will not be relocatable anymore. To build a DLL without
+debug information pass @code{-largs -s} to @code{gnatdll}. This
+restriction does not apply to a DLL built using a Library Project.
+@pxref{Library Projects}.
@node Limitations When Using Ada DLLs from Ada
@subsection Limitations When Using Ada DLLs from Ada
It is therefore not possible to exchange GNAT run-time objects between the
Ada DLL and the main Ada program. Example of GNAT run-time objects are file
-handles (e.g. @code{Text_IO.File_Type}), tasks types, protected objects
+handles (e.g.@: @code{Text_IO.File_Type}), tasks types, protected objects
types, etc.
It is completely safe to exchange plain elementary, array or record types,
Building a DLL is a way to encapsulate a set of services usable from any
application. As a result, the Ada entities exported by a DLL should be
exported with the @code{C} or @code{Stdcall} calling conventions to avoid
-any Ada name mangling. Please note that the @code{Stdcall} convention
-should only be used for subprograms, not for variables. As an example here
-is an Ada package @code{API}, spec and body, exporting two procedures, a
-function, and a variable:
+any Ada name mangling. As an example here is an Ada package
+@code{API}, spec and body, exporting two procedures, a function, and a
+variable:
@smallexample @c ada
@group
return Fact;
end Factorial;
- ...
+ @dots{}
-- The remainder of this package body is unchanged.
end API;
@end cartouche
@noindent
To use the services exported by the Ada DLL from another programming
-language (e.g. C), you have to translate the specs of the exported Ada
+language (e.g.@: C), you have to translate the specs of the exported Ada
entities in that language. For instance in the case of @code{API.dll},
the corresponding C header file could look like:
@cartouche
package API is
Count : Integer := 0;
- ...
+ @dots{}
-- Remainder of the package omitted.
end API;
@end cartouche
@smallexample
@cartouche
-$ gnatdll [@var{switches}] @var{list-of-files} [-largs @var{opts}]
+$ gnatdll @ovar{switches} @var{list-of-files} @r{[}-largs @var{opts}@r{]}
@end cartouche
@end smallexample
@noindent
-where @i{list-of-files} is a list of ALI and object files. The object
+where @var{list-of-files} is a list of ALI and object files. The object
file list must be the exact list of objects corresponding to the non-Ada
sources whose services are to be included in the DLL. The ALI file list
must be the exact list of ALI files for the corresponding Ada sources
-whose services are to be included in the DLL. If @i{list-of-files} is
+whose services are to be included in the DLL. If @var{list-of-files} is
missing, only the static import library is generated.
@noindent
You may specify any of the following switches to @code{gnatdll}:
@table @code
-@item -a[@var{address}]
+@item -a@ovar{address}
@cindex @option{-a} (@code{gnatdll})
Build a non-relocatable DLL at @var{address}. If @var{address} is not
specified the default address @var{0x11000000} will be used. By default,
@item -b @var{address}
@cindex @option{-b} (@code{gnatdll})
Set the relocatable DLL base address. By default the address is
-@var{0x11000000}.
+@code{0x11000000}.
@item -bargs @var{opts}
@cindex @option{-bargs} (@code{gnatdll})
@code{gnatdll} to do anything. The name of the generated import library is
obtained algorithmically from @var{dllfile} as shown in the following
example: if @var{dllfile} is @code{xyz.dll}, the import library name is
-@code{libxyz.a}. The name of the definition file to use (if not specified
+@code{libxyz.dll.a}. The name of the definition file to use (if not specified
by option @option{-e}) is obtained algorithmically from @var{dllfile}
as shown in the following example:
if @var{dllfile} is @code{xyz.dll}, the definition
@item -k
@cindex @option{-k} (@code{gnatdll})
-Removes the @code{@@}@i{nn} suffix from the import library's exported
+Removes the @code{@@}@var{nn} suffix from the import library's exported
names, but keeps them for the link names. You must specify this
option if you want to use a @code{Stdcall} function in a DLL for which
-the @code{@@}@i{nn} suffix has been removed. This is the case for most
+the @code{@@}@var{nn} suffix has been removed. This is the case for most
of the Windows NT DLL for example. This option has no effect when
@option{-n} option is specified.
@end smallexample
@noindent
-The above command creates two files: @file{libapi.a} (the import
+The above command creates two files: @file{libapi.dll.a} (the import
library) and @file{api.dll} (the actual DLL). If you want to create
only the DLL, just type:
@end smallexample
@noindent
-In addition to the base file, the @code{gnatlink} command generates an
+In addition to the base file, the @command{gnatlink} command generates an
output file @file{api.jnk} which can be discarded. The @option{-mdll} switch
-asks @code{gnatlink} to generate the routines @code{DllMain} and
+asks @command{gnatlink} to generate the routines @code{DllMain} and
@code{DllMainCRTStartup} that are called by the Windows loader when the DLL
is loaded into memory.
@item
@code{gnatdll} builds the base file using the new export table. Note that
-@code{gnatbind} must be called once again since the binder generated file
-has been deleted during the previous call to @code{gnatlink}.
+@command{gnatbind} must be called once again since the binder generated file
+has been deleted during the previous call to @command{gnatlink}.
@smallexample
@group
@item
@code{gnatdll} builds the new export table using the new base file and
-generates the DLL import library @file{libAPI.a}.
+generates the DLL import library @file{libAPI.dll.a}.
@smallexample
@group
is
@smallexample
-$ dlltool [@var{switches}]
+$ dlltool @ovar{switches}
@end smallexample
@noindent
@item -k
@cindex @option{-k} (@command{dlltool})
-Kill @code{@@}@i{nn} from exported names
+Kill @code{@@}@var{nn} from exported names
(@pxref{Windows Calling Conventions}
for a discussion about @code{Stdcall}-style symbols.
Generate an export file @var{exportfile}. The export file contains the
export table (list of symbols in the DLL) and is used to create the DLL.
-@item --output-lib @i{libfile}
+@item --output-lib @var{libfile}
@cindex @option{--output-lib} (@command{dlltool})
Generate a static import library @var{libfile}.
@cindex @option{-v} (@command{dlltool})
Verbose mode.
-@item --as @i{assembler-name}
+@item --as @var{assembler-name}
@cindex @option{--as} (@command{dlltool})
-Use @i{assembler-name} as the assembler. The default is @code{as}.
+Use @var{assembler-name} as the assembler. The default is @code{as}.
@end table
@node GNAT and Windows Resources
@end smallexample
@noindent
-By default @code{windres} will run @code{gcc} to preprocess the @file{.rc}
+By default @code{windres} will run @command{gcc} to preprocess the @file{.rc}
file. You can specify an alternate preprocessor (usually named
@file{cpp.exe}) using the @code{windres} @option{--preprocessor}
parameter. A list of all possible options may be obtained by entering
@noindent
To include the resource file in your program just add the
GNAT-compatible object file for the resource(s) to the linker
-arguments. With @code{gnatmake} this is done by using the @option{-largs}
+arguments. With @command{gnatmake} this is done by using the @option{-largs}
option:
@smallexample
$ gdb -nw ada_main
@end smallexample
-@item Break on the main procedure and run the program.
+@item Start the program and stop at the beginning of the main procedure
@smallexample
-(gdb) break ada_main
-(gdb) run
+(gdb) start
@end smallexample
@noindent
@smallexample
(gdb) break ada_dll
-(gdb) run
+(gdb) cont
@end smallexample
@end enumerate
you can use the standard approach to debug the whole program
(@pxref{Running and Debugging Ada Programs}).
+@ignore
+@c This used to work, probably because the DLLs were non-relocatable
+@c keep this section around until the problem is sorted out.
+
+To break on the @code{DllMain} routine it is not possible to follow
+the procedure above. At the time the program stop on @code{ada_main}
+the @code{DllMain} routine as already been called. Either you can use
+the procedure below @pxref{Debugging the DLL Directly} or this procedure:
+
+@enumerate 1
+@item Launch @code{GDB} on the main program.
+
+@smallexample
+$ gdb ada_main
+@end smallexample
+
+@item Load DLL symbols
+
+@smallexample
+(gdb) add-sym api.dll
+@end smallexample
+
+@item Set a breakpoint inside the DLL
+
+@smallexample
+(gdb) break ada_dll.adb:45
+@end smallexample
+
+Note that at this point it is not possible to break using the routine symbol
+directly as the program is not yet running. The solution is to break
+on the proper line (break in @file{ada_dll.adb} line 45).
+
+@item Start the program
+
+@smallexample
+(gdb) run
+@end smallexample
+
+@end enumerate
+@end ignore
+
@node Program Built with Foreign Tools and DLL Built with GCC/GNAT
@subsection Program Built with Foreign Tools and DLL Built with GCC/GNAT
@enumerate 1
@item
-Launch the debugger on the DLL.
+Find out the executable starting address
@smallexample
-$ gdb -nw test.dll
+$ objdump --file-header main.exe
@end smallexample
-@item Set a breakpoint on a DLL subroutine.
+The starting address is reported on the last line. For example:
@smallexample
-(gdb) break ada_dll
+main.exe: file format pei-i386
+architecture: i386, flags 0x0000010a:
+EXEC_P, HAS_DEBUG, D_PAGED
+start address 0x00401010
@end smallexample
@item
-Specify the executable file to @code{GDB}.
+Launch the debugger on the executable.
@smallexample
-(gdb) exec-file main.exe
+$ gdb main.exe
@end smallexample
@item
-Run the program.
+Set a breakpoint at the starting address, and launch the program.
@smallexample
-(gdb) run
+$ (gdb) break *0x00401010
+$ (gdb) run
+@end smallexample
+
+The program will stop at the given address.
+
+@item
+Set a breakpoint on a DLL subroutine.
+
+@smallexample
+(gdb) break ada_dll.adb:45
+@end smallexample
+
+Or if you want to break using a symbol on the DLL, you need first to
+select the Ada language (language used by the DLL).
+
+@smallexample
+(gdb) set language ada
+(gdb) break ada_dll
+@end smallexample
+
+@item
+Continue the program.
+
+@smallexample
+(gdb) cont
@end smallexample
@noindent
@item Launch gdb.
@smallexample
-$ gdb -nw
+$ gdb
@end smallexample
@item Attach to the running process to be debugged.
@item Continue process execution.
@smallexample
-(gdb) continue
+(gdb) cont
@end smallexample
@end enumerate
approach to debug a program as described in
(@pxref{Running and Debugging Ada Programs}).
-@node GNAT and COM/DCOM Objects
-@section GNAT and COM/DCOM Objects
-@findex COM
-@findex DCOM
+@node Setting Stack Size from gnatlink
+@section Setting Stack Size from @command{gnatlink}
@noindent
-This section is temporarily left blank.
+It is possible to specify the program stack size at link time. On modern
+versions of Windows, starting with XP, this is mostly useful to set the size of
+the main stack (environment task). The other task stacks are set with pragma
+Storage_Size or with the @command{gnatbind -d} command.
-@end ifset
+Since older versions of Windows (2000, NT4, etc.) do not allow setting the
+reserve size of individual tasks, the link-time stack size applies to all
+tasks, and pragma Storage_Size has no effect.
+In particular, Stack Overflow checks are made against this
+link-time specified size.
+
+This setting can be done with
+@command{gnatlink} using either:
+
+@itemize @bullet
+
+@item using @option{-Xlinker} linker option
+
+@smallexample
+$ gnatlink hello -Xlinker --stack=0x10000,0x1000
+@end smallexample
+
+This sets the stack reserve size to 0x10000 bytes and the stack commit
+size to 0x1000 bytes.
+
+@item using @option{-Wl} linker option
+
+@smallexample
+$ gnatlink hello -Wl,--stack=0x1000000
+@end smallexample
+
+This sets the stack reserve size to 0x1000000 bytes. Note that with
+@option{-Wl} option it is not possible to set the stack commit size
+because the coma is a separator for this option.
+
+@end itemize
+
+@node Setting Heap Size from gnatlink
+@section Setting Heap Size from @command{gnatlink}
+
+@noindent
+Under Windows systems, it is possible to specify the program heap size from
+@command{gnatlink} using either:
+
+@itemize @bullet
+
+@item using @option{-Xlinker} linker option
+
+@smallexample
+$ gnatlink hello -Xlinker --heap=0x10000,0x1000
+@end smallexample
+This sets the heap reserve size to 0x10000 bytes and the heap commit
+size to 0x1000 bytes.
+
+@item using @option{-Wl} linker option
+
+@smallexample
+$ gnatlink hello -Wl,--heap=0x1000000
+@end smallexample
+
+This sets the heap reserve size to 0x1000000 bytes. Note that with
+@option{-Wl} option it is not possible to set the heap commit size
+because the coma is a separator for this option.
+
+@end itemize
+
+@end ifset
@c **********************************
@c * GNU Free Documentation License *