1 #ifndef IDLC_COMPILEDDEFS_H
2 #define IDLC_COMPILEDDEFS_H
6 #if !defined(BITFIELD_LE) && !defined(BITFIELD_BE)
7 #error Please define your bitfield endianness (BITFIELD_LE or BITFIELD_BE).
10 // This is the compiled representation of definitions when stored on
11 // a legacy filesystem (as opposed to native object storage).
12 // Normally, a standard encoding would be used to map objects to
13 // directories and files; however, such encodings cannot be used
14 // before they exist. This special mapping allows the system to be
15 // bootstrapped from a legacy system.
17 // As this is a transitional representation, and IDL management is
18 // not performance critical, emphasis has been placed on simplicity
19 // rather than efficiency. In particular, I don't want to write
20 // throw-away code to compensate for most filesystems' inability to
21 // deal with small files efficiently, nor do I want to muck around
22 // with storing the compiled definitions in textual form (thus
23 // needing to parse them *again*; I want to keep that out of the
24 // ORB). Dot files and directories are used rather than the more
25 // straightforward way of keeping the namespace under its own member
26 // in order to make the compiled definitions easier to browse with
27 // normal utilities (in the final system, you'll be able to use a
28 // custom view that arranges it however you want; however, Unix
29 // doesn't have custom filesystem views).
31 // I have tried to make the definitions close to what could be
32 // emitted by an IDL compiler, minus the hierarchical relationship
33 // (which won't exist on a legacy filesystem). These definitions
34 // require C++ (plus C99 stdint.h); C will choke on the assumed
35 // struct namespace behavior (among other things).
37 // Each definition is represented by a directory. If the definition is
38 // for a non-generic namespace (i.e. it is for a struct, interface,
39 // bitfield, etc.), the definition itself is placed in a file called
40 // ".self" inside the directory. The file contains a CompiledDefHeader
41 // struct followed by the appropriate type-specific struct.
43 // The non-dotted contents of the directory are the contents of the
44 // definition's namespace, if any. Anonymous types are given the
45 // name "_anon_<unique>", where <unique> is an arbitrary non-conflicting
48 // A compiled definition file may be either big or little endian; if
49 // magic_reversed is found, then all integers in the file must be
50 // reversed prior to usage.
52 // Bitfields, on the other hand, must be arranged in a little endian
53 // format (i.e. the first field gets the least significant bits; the byte
54 // order of the containing integer is the same as for non-bitfield
55 // integers). Bitfields generated by idlc will contain padding and
56 // reversed members if the target has big-endian bitfields.
58 struct CompiledDefHeader {
59 static const uint32_t magic_normal = 0x2d29c8a9;
60 static const uint32_t magic_reversed = 0xa9c8292d;
62 uint32_t magic; // magic_normal or magic_reversed
78 // One of the above types; the enum isn't used directly, as the
79 // size is not guaranteed.
83 struct CompiledNameSpace {
84 // The length of the string in bytes (not characters), excluding
85 // the null terminator.
89 // The fully qualified name of the namespace follows, as a
90 // null-terminated UTF-8 string. This allows the namespace
91 // to be mounted by merely supplying its filesystem path,
92 // without having to specify the mount point.
95 // This struct does not appear standalone, but is included in various
96 // structs that can refer to arrays.
97 struct CompiledArray {
98 // Inclusive lower and upper bounds of the array. If the
99 // array has no upper bound, [1] should be -1. If the array
100 // has no lower bound, [0] should be 0. If this is not an
101 // array, both should be 0.
106 struct CompiledBasicType {
107 // Size of the type, as follows:
114 // Bool: 0 (actual size is implementation defined)
116 // Other sizes may be used within bitfields (up to a max of 64 bits).
120 // Unsigned, Float, and Bool are mutually exclusive.
125 unsigned int Unsigned:1;
126 unsigned int Float:1;
128 unsigned int TypeDef:1;
130 unsigned int _pad:28;
132 unsigned int TypeDef:1;
134 unsigned int Float:1;
135 unsigned int Unsigned:1;
142 static const uint32_t Unsigned = 1 << 0;
143 static const uint32_t Float = 1 << 1;
144 static const uint32_t Bool = 1 << 2;
145 static const uint32_t TypeDef = 1 << 3;
155 struct CompiledAlias {
156 // The length of the string in bytes (not characters), excluding
157 // the null terminator.
161 // The name of the aliased symbol follows, as a null-terminated
162 // UTF-8 string. This will be the final symbol, and not an alias.
165 // A CompiledDatum is used for data fields in a structure, bitfield, or
168 struct CompiledDatum {
169 // This is a description of the datum's type, if it is not a named type.
170 // This is ignored (except the array part) if "type" is non-empty.
172 CompiledBasicType basictype;
174 // Const value(s); cast to the appropriate type. For Bool, cast to
175 // Byte; 0 is false, 1 is true. Extend all types to 64-bits.
176 // ucon is also used for bitfield element sizes.
185 // Const can only be used for basic types (both named and unnamed);
186 // Immutable is used for non-initialized const fields. Invalid is
187 // only used internally by idlc; it is reserved in the file format.
192 unsigned int Const:1;
193 unsigned int Invalid:1;
194 unsigned int Inline:1;
195 unsigned int Immutable:1;
197 unsigned int _pad:28;
199 unsigned int Immutable:1;
200 unsigned int Inline:1;
201 unsigned int Invalid:1;
202 unsigned int Const:1;
209 static const uint32_t Const = 1 << 0;
210 static const uint32_t Invalid = 1 << 1;
211 static const uint32_t Inline = 1 << 2;
212 static const uint32_t Immutable = 1 << 3;
216 // If it's a named type, this points to the type.
220 // Methods, member types, member constants, etc. go in the namespace.
221 // Methods are ordered; all others are unordered.
223 struct CompiledInterface {
229 // An array of num_methods + num_supers length of CompiledAliases
230 // representing methods in declared order follows, and then
231 // superclasses in declared order, follows. The names of metods shall
232 // consist only of the final component, with no namespaces prepended.
233 // The names of superclasses are fully namespace-qualified. Each
234 // CompiledAlias shall begin on a 4-byte boundary.
237 // Parameters go in the namespace, and are ordered according to the
238 // list contained in this struct. Exceptions thrown are unordered
239 // Aliases in a subdirectory called ".exceptions", with arbitrary
242 struct CompiledMethod {
246 unsigned int Async:1;
248 unsigned int _pad:31;
250 unsigned int Async:1;
257 static const uint32_t Async = 1 << 0;
263 // An array of num_entries length of CompiledAliases representing
264 // parameters in declared order follows. Each name shall be as in
265 // CompiledInterface, without namespace qualification.
268 // A param isn't a namespace; however, it is a directory. In addition to
269 // the ".self" file, the directory contains a "type" Alias file.
270 struct CompiledParam {
271 // This is a description of the parameter's type, if it is not a
272 // named type. This is ignored (except the array part) if "type"
275 CompiledBasicType basictype;
283 unsigned int Shared:1;
285 unsigned int Inline:1;
286 unsigned int Immutable:1;
288 unsigned int _pad:26;
290 unsigned int Immutable:1;
291 unsigned int Inline:1;
293 unsigned int Shared:1;
303 static const uint32_t In = 1 << 0;
304 static const uint32_t Out = 1 << 1;
305 static const uint32_t Shared = 1 << 2;
306 static const uint32_t Push = 1 << 3;
307 static const uint32_t Inline = 1 << 4;
308 static const uint32_t Immutable = 1 << 5;
313 // If it's a named type, this points to the type.
317 // Fields, member types, member constants, etc. go in the namespace.
318 // All but fields are unordered.
320 struct CompiledStruct {
324 // Struct has a superstruct.
326 unsigned int Super:1;
328 // Struct has run-time type information. This requires that
331 unsigned int Virtual:1;
333 // Struct defaults to "inline" when declared in a struct.
334 // This is mandatory for anonymous structs.
336 unsigned int Inline:1;
338 unsigned int _pad:29;
340 unsigned int Inline:1;
341 unsigned int Virtual:1;
342 unsigned int Super:1;
349 static const uint32_t Super = 1 << 0;
350 static const uint32_t Virtual = 1 << 1;
351 static const uint32_t Inline = 1 << 2;
359 // An array of num_entries length of CompiledAliases representing
360 // fields in declared order follows. Each name shall be as in
361 // CompiledMethod. If the Super flag is set, then another
362 // fully-qualified CompiledAlias is placed at the end of the array.
365 // Enum entries are unsigned BasicDatums of the specified size.
367 struct CompiledEnum {
368 // Size of enumeration type
375 // An array of num_entries length of CompiledAliases representing
376 // values in declared order follows. Each name shall be as in
380 // BitField fields are unsigned BasicDatums and Enum Datums of
381 // arbitrary size, which must add up to at most "bits".
383 struct CompiledBitField {
391 // An array of num_entries length of CompiledAliases representing
392 // fields in declared order follows. Each name shall be as in