Chapter 10. IDL Syntax

Table of Contents

10.1. Basic Syntax Overview
10.2. Tokens
10.2.1. Comments
10.2.2. Identifiers
10.2.3. Keywords
10.2.4. Literals
10.3. Parser Directives
10.4. Massiv IDL Grammar
10.5. Name Lookup and Scoping
10.6. Namespaces
10.7. Enumerations
10.8. Attributes
10.8.1. Attribute Definition
10.8.2. Attribute Types
10.8.3. Attribute Default Values
10.8.4. Attribute Value Assignment
10.8.5. Expressions
10.8.6. Attribute Value Lookup
10.9. Classes
10.9.1. Forward Declaration
10.9.2. Class Definition
10.9.3. Class Attributes
10.9.4. Class Inheritance Specification
10.10. Properties
10.10.1. Property Attributes
10.11. Methods
10.11.1. Method Attributes
10.11.2. Method Arguments and Results
10.12. Special Directives
10.12.1. The include_header Directive
10.13. Property and Argument Types
10.13.1. Boolean
10.13.2. Integers With Fixed-length Serialization
10.13.3. Integers With Variable-length Serialization
10.13.4. Enumeration Type
10.13.5. Floating-Point
10.13.6. Floating-Point With Quantized Serialization
10.13.7. String
10.13.8. Time
10.13.9. Event Handle
10.13.10. Math Vectors
10.13.11. Orientation
10.13.12. Color
10.13.13. Pointers
10.13.14. Managed Class Type
10.13.15. Pair
10.13.16. Array
10.13.17. Set
10.13.18. Dictionary

10.1. Basic Syntax Overview

As mentioned in the IDL introduction, the IDL descriptions must be contained in specific files that typically have the idl extension. You can find these files in the Core source tree as well as in the Demo.

These files are not completely standalone - they can import each other. Almost every IDL file needs some generic declarations that are contained in src/core/object/object.idl. This file defines all class, method and property attributes required by the Core, as well as the description of the Massiv::Core::Object. This file together with all public Core IDL files can be indirectly imported using the file src/core/core.idl.

The most frequent entities contained in the IDL are class descriptions (arbitrary number in each file) of managed classes (see Chapter 4, Managed Objects). Typically the IDL file name corresponds to the name of the header file that contains C++ definitions of the relevant classes.

For each IDL file foo.idl referenced from the idl.list (described in Section D.2, “The idl.list File”), a file foo.h must exist, because it's automatically included by the sources generated from foo.idl. However, classes described in foo.idl may be defined anywhere, as long as the files containing the class definitions are properly referenced from foo.idl using the “include_file” directive, as described in Section 10.12.1, “The include_header Directive”.

Morever, if an IDL file is not referenced from any idl.list, no sources will be generated from it and the header with corresponding name may not exist. Such IDL files should not contain any class definitions. One example of such file in the Core is src/core/core.idl.

The following example should give you an overview of how class descriptions in the IDL look like in general before the detailed syntax description. It contains a complete description for a very simple and academical class FooBar located in the my_application namespace. It's base class is Massiv::Core::Object, it has several properties and methods. Note that the class definition does not need to end with a semicolon character. For more detailed information, see the remarks below the source code. If you don't have even an idea what about what the example actually means, skip it, continue reading and get back at the end of the chapter.

Example 10.1. A class description in the IDL
#import "core.idl"  1

namespace my_application {  2

class  3
    <
    kind = SERVER,  4
    root,
    tracked
    > FooBar : ::Massiv::Core::Object  5
    {
    enum State { }  6

    property< repflags = MIGRATE > State  state;  7
    property weak_pointer< Object >       buddy;
    property strong_pointer< FooBar >     next;
    property value_array< uint32< 8 > >   array;

    method set_buddy  8
        (
        out weak_pointer< Object > old_buddy,
        in weak_pointer< Object >  new_buddy
        );

    method< const > get_buddy() : weak_pointer< Object >  9
    }

} // namespace my_application

1

This imports all public Massiv Core IDL files, the most important being the src/core/object/object.idl file, which defines all required attributes and describes the Massiv::Core::Object.

2

Namespaces can be declared using the same syntax as in C++ and have the same semantics. In this example we define everything in namespace my_application.

3

The class keyword begins a class description in the IDL. The description consists of the class attributes, name, inheritance information and of the class body (properties, methods, etc.)

4

Class attributes specify some basic parameters for the class. In the example, the FooBar class would be a server-only class (kind attribute), garbage collector root (root attribute) and tracked by the object provider (tracked). The meaning of these attributes is described in Section 10.9.3, “Class Attributes”.

5

A C++-like syntax is used to define list of base classes. In the example the class that all managed classes must inherit, Massiv::Core::Object, is inherited directly.

6

This line indicates that an enumeration type State is defined withing the FooBar class. Its enumeration values are not used in the IDL so they are not defined at all. Note that the definition is not terminated by a semicolon character (it's not needed but can be used; in the future versions it might be required to make syntax more C++-like).

7

The FooBar class containts four properties:

  • Property state, of enumeration type State (defined on the line above). The repflags property attribute defines replication behavior of the property - in this case the property will migrate (as all properties do), but it will be never replicated.

  • Property buddy, of type weak_pointer. Using the weak pointer for the reference to the buddy enables the FooBar object and its buddy to be located on different nodes.

  • Property next, of type strong_pointer. The strong pointer ensures that this FooBar and the next FooBar are always located on the same node and migrate together in a single migration group.

  • Property array is an example of a little bit more complex property type - an array of unsigned 32-bit integers. Only the 8 low bits of the integers are replicated.

8

Description of a simple method that can be called using the RPC. It has single out and single in argument. As the name of the method and its arguments indicate, it probably sets the buddy property to new_buddy and returns its old value in old_buddy.

9

Another method, this one probably returns value of the buddy property. This example shows how the return types are defined. The method is marked as const. The meaning of this attribute is a bit different from the C++.