Data type and constant definitions

## 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

## Data type and constant definitions

All data types manipulated by Genom are described with a subset of the OMG IDL syntax. Those types map into traditional programming languages types using the specific mappings described in the GenoM IDL mappings section.

### Type specification

The following set of type specifiers to represent typed values is available:

(57) `type-spec ::=` | `simple-type-spec` `|` `constructed-type-spec`
(58) `simple-type-spec ::=` | `base-type-spec` `|` `template-type-spec` `|` `named-type`
(93) `constructed-type-spec ::=` | `constructed-type`

#### Subtopics

- IDL base types: integers, floating point values …​

- IDL template types: sequences, strings …​

- IDL constructed types: structs, unions, enums, …​

### Type declaration

Type defined with the following syntax can then be used in the component interface definition and anywhere a type value is expected.

(59) `type-dcl ::=` | `"typedef"` `type-declarator` `";"` `|` `"native"` `identifier` `";"` `|` `"exception"` `exception-list` `";"` `|` `constructed-type` `";"` `|` `forward-dcl` `";"`
(94) `constructed-type ::=` | `struct-type` `|` `union-type` `|` `enum-type`
(60) `type-declarator ::=` | `(` `type-spec` `|` `type-declarator` `","` `)` `declarator`

#### Typedef

Types are most often given a unique name thanks to a `typedef` declaration; a name is also associated with a data type via the `struct`, `union`, `enum`, `native` and `exception` declarations.

#### Native types

It is possible to hide the actual definition of a data type from Genom (and its IDL parser) when it will never be directly used in the interface of the component, but can nevertheless be needed by codels. These types can be declared using the `native` attribute.

For example: `native foo;`

#### Exceptions

Exceptions are thrown by services in case of error. The `exception` keyword declares an exception, which is an identifier with an optional associated data type.

(61) `exception-list ::=` | `{` `exception-dcl` `","` `}` `exception-dcl`
(62) `exception-dcl ::=` | `exception-name` `opt-member-list`
(63) `opt-member-list ::=` | `[` `"{"` `(` `"}"` `|` `member-list` `"}"` `)` `]`

A simple exception declaration would be :

    exception INVALID_SPEED;

or with an associated type (to store the actual value for instance):

    exception INVALID_SPEED {
      double speed;
    };

### Constant declaration

Constants define read-only values that are used by the component, like the maximal speed allowed for a motor or the physical bounds of a process that will be controlled. The syntax is again very similar to `C` or `C++`:

(69) `const-dcl ::=` | `"const"` `const-type` `identifier` `"="` `const-expr` `";"`
(70) `const-type ::=` | `integer-type` `|` `char-type` `|` `boolean-type` `|` `floating-pt-type` `|` `octet-type` `|` `string-type` `|` `named-type`

For example: `const double max_speed = 72.0;`