Next: , Previous: Variables, Up: Project File Reference


5.9.9 Case Constructions

A `case' construction is used in a project file to effect conditional behavior. Through this construction, you can set the value of attributes and variables depending on the value previously assigned to a typed variable.

All choices in a choice list must be distinct. Unlike Ada, the choice lists of all alternatives do not need to include all values of the type. An others choice must appear last in the list of alternatives.

The syntax of a case construction is based on the Ada case construction (although the null declaration for empty alternatives is optional).

The case expression must be a string variable, either typed or not, whose value is often given by an external reference (see External Values).

Each alternative starts with the reserved word when, either a list of literal strings separated by the "|" character or the reserved word others, and the "=>" token. When the case expression is a typed string variable, each literal string must belong to the string type that is the type of the case variable. After each =>, there are zero or more declarations. The only declarations 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.

    case_construction ::=
      *case* *<variable_>*name *is* {case_item} *end case* ;
    
    case_item ::=
      *when* discrete_choice_list =>
        {case_declaration
          | attribute_declaration
          | variable_declaration
          | empty_declaration}
    
    discrete_choice_list ::= string_literal {| string_literal} | *others*

Here is a typical example, with a typed string variable:

    project MyProj is
       type OS_Type is ("GNU/Linux", "Unix", "NT", "VMS");
       OS : OS_Type := external ("OS", "GNU/Linux");
    
       package Compiler is
         case OS is
           when "GNU/Linux" | "Unix" =>
             for Switches ("Ada")
                 use ("-gnath");
           when "NT" =>
             for Switches ("Ada")
                 use ("-gnatP");
           when others =>
             null;
         end case;
       end Compiler;
    end MyProj;