IDL Constructed types

## Contents

- Your rights

- Introduction

- Component model

- Component description file

  - Preprocessing

  - Elements of a description file

  - Data type and constant definitions

  - Module declaration

  - Component declaration

  - Interface declaration

  - IDS declaration

  - Port declaration

  - Task declaration

  - Service declaration

  - Codel declaration

  - Identifiers and reserved keywords

  - Pragmas

  - Grammar reference

- GenoM IDL mappings

- Running GenoM

- Tutorials

- Templates

## IDL Constructed types

`structs`, `unions` and `enums` are the constructed types. Their syntax is presented in this section:

(94) `constructed-type ::=` | `struct-type` `|` `union-type` `|` `enum-type`

### Structures

(95) `struct-type ::=` | `"struct"` `struct-name` `"{"` `member-list` `"}"`
(53) `struct-name ::=` | `identifier`
(96) `member-list ::=` | `{` `member` `";"` `}` `member` `";"`
(97) `member ::=` | `(` `type-spec` `|` `member` `","` `)` `declarator`

The `identiﬁer` in `struct-type` defines a new legal type. Structure types may also be named using a typedef declaration.

Name scoping rules require that the member declarators in a particular structure be unique.

#### Example

Here is a small structure definition with one integer and one double precision value:

    struct foo {
      long a;
      double x;
    };

### Discriminated unions

(98) `union-type ::=` | `"union"` `union-name` `"switch"` `"("` `switch-type-spec` `")"` `"{"` `switch-body` `"}"`
(54) `union-name ::=` | `identifier`
(99) `switch-type-spec ::=` | `integer-type` `|` `char-type` `|` `boolean-type` `|` `enum-type` `|` `named-type`
(100) `switch-body ::=` | `{` `case` `}` `case`
(101) `case ::=` | `case-label-list` `type-spec` `declarator` `";"`
(102) `case-label-list ::=` | `{` `case-label` `}` `case-label`
(103) `case-label ::=` | `(` `"case"` `const-expr` `|` `"default"` `)` `":"`

Unions are a cross between the C union and switch statements. Unions must be discriminated; that is, the union header must specify a typed tag field that determines which union member to use for the current instance of a call. The `identiﬁer` following the union keyword defines a new legal type. Union types may also be named using a typedef declaration. The `const_exp` in a `case_label` must be consistent with the `switch_type_spec`. A default case can appear at most once. The `named-type` in the `switch-type-spec` production must be a previously defined integer, char, boolean or enum type.

Case labels must match or be automatically castable to the defined type of the discriminator. Name scoping rules require that the element declarators in a particular union be unique. It is not required that all possible values of the union discriminator be listed in the `switch-body`.

#### Example

    union foo switch(long) {
      case 0: long a;
      default: double x;
    };

### Enumerations

Enumerated types consist of ordered lists of identifiers. The syntax is:

(104) `enum-type ::=` | `"enum"` `identifier` `"{"` `enumerator-list` `"}"`
(105) `enumerator-list ::=` | `{` `enumerator` `","` `}` `enumerator`
(106) `enumerator ::=` | `identifier`

A maximum of 232 identifiers may be specified in an enumeration. The order in which the identifiers are named in the specification of an enumeration defines the relative order of the identifiers. The `identiﬁer` following the enum keyword defines a new legal type. Enumerated types may also be named using a typedef declaration.

### Forward declarations

(107) `forward-dcl ::=` | `(` `"struct"` `|` `"union"` `)` `identifier`