Previous: Case Constructions, Up: Project File Reference

5.9.10 Attributes

A project (and its packages) may have `attributes' that define the project's properties. Some attributes have values that are strings; others have values that are string lists.

    attribute_declaration ::=
       simple_attribute_declaration | indexed_attribute_declaration
    simple_attribute_declaration ::= *for* attribute_designator *use* expression ;
    indexed_attribute_declaration ::=
      *for* *<indexed_attribute_>*simple_name ( string_literal) *use* expression ;
    attribute_designator ::=
      | *<indexed_attribute_>*simple_name ( string_literal )

There are two categories of attributes: `simple attributes' and `indexed attributes'. Each simple attribute has a default value: the empty string (for string attributes) and the empty list (for string list attributes). An attribute declaration defines a new value for an attribute, and overrides the previous value. The syntax of a simple attribute declaration is similar to that of an attribute definition clause in Ada.

Some attributes are indexed. These attributes are mappings whose domain is a set of strings. They are declared one association at a time, by specifying a point in the domain and the corresponding image of the attribute. Like untyped variables and simple attributes, indexed attributes may be declared several times. Each declaration supplies a new value for the attribute, and replaces the previous setting.

Here are some examples of attribute declarations:

    --  simple attributes
    for Object_Dir use "objects";
    for Source_Dirs use ("units", "test/drivers");
    --  indexed attributes
    for Body ("main") use "Main.ada";
    for Switches ("main.ada")
        use ("-v", "-gnatv");
    for Switches ("main.ada") use Builder'Switches ("main.ada") & "-g";
    --  indexed attributes copy (from package Builder in project Default)
    --  The package name must always be specified, even if it is the current
    --  package.
    for Default_Switches use Default.Builder'Default_Switches;

Attributes references may appear anywhere in expressions, and are used to retrieve the value previously assigned to the attribute. If an attribute has not been set in a given package or project, its value defaults to the empty string or the empty list, with some exceptions.

    attribute_reference ::=
      attribute_prefix ' *<simple_attribute>_*simple_name [ (string_literal) ]
    attribute_prefix ::= *project*
      | *<project_>*simple_name
      | package_identifier
      | *<project_>*simple_name . package_identifier

Examples are:

    Builder'Default_Switches ("Ada")

The exceptions to the empty defaults are:

The prefix of an attribute may be:

In the following sections, all predefined attributes are succinctly described, first the project level attributes, that is those attributes that are not in a package, then the attributes in the different packages.

It is possible for different tools to dynamically create new packages with attributes, or new attributes in predefined packages. These attributes are not documented here.

The attributes under Configuration headings are usually found only in configuration project files.

The characteristics of each attribute are indicated as follows: