1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
/*
Copyright (C) 1999 Stefan Westerfeld, stefan@space.twc.de
Nicolas Brodu, nicolas.brodu@free.fr
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
%{
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "common.h"
#include "namespace.h"
using namespace std;
using namespace Arts;
extern int idl_line_no;
extern string idl_filename;
extern int yylex();
extern void mcopidlInitFlex( const char *_code );
extern void addEnumTodo( const EnumDef& edef );
extern void addStructTodo( const TypeDef& type );
extern void addInterfaceTodo( const InterfaceDef& iface );
void yyerror( const char *s )
{
printf( "%s:%i: %s\n", idl_filename.c_str(), idl_line_no, s );
exit(1);
// theParser->parse_error( idl_lexFile, s, idl_line_no );
}
static struct ParserGlobals {
vector<string> noHints;
} *g;
%}
%union
{
// generic data types
long _int;
char* _str;
unsigned short _char;
double _float;
vector<char*> *_strs;
// types
vector<TypeComponent> *_typeComponentSeq;
TypeComponent* _typeComponent;
// enums
vector<EnumComponent> *_enumComponentSeq;
// interfaces
InterfaceDef *_interfaceDef;
ParamDef* _paramDef;
vector<ParamDef> *_paramDefSeq;
MethodDef* _methodDef;
vector<MethodDef> *_methodDefSeq;
AttributeDef* _attributeDef;
vector<AttributeDef> *_attributeDefSeq;
}
%token T_STRUCT T_ENUM T_INTERFACE T_MODULE T_VOID
%token T_LEFT_CURLY_BRACKET T_RIGHT_CURLY_BRACKET
%token T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS
%token T_LESS T_GREATER T_EQUAL
%token T_SEMICOLON T_COLON T_COMMA
%token<_str> T_IDENTIFIER T_QUALIFIED_IDENTIFIER
%type<_str> type
%type<_str> simpletype
%type<_str> enumname
%type<_str> interfacelistelem
/*%type<_typeComponent> typecomponentdef*/
%type<_typeComponentSeq> structbody
%type<_paramDef> paramdef
%type<_paramDefSeq> paramdefs
%type<_paramDefSeq> paramdefs1
%type<_methodDef> methoddef
%type<_attributeDefSeq> attributedef
%type<_attributeDefSeq> streamdef
%type<_interfaceDef> classbody
%type<_enumComponentSeq> enumbody
%type<_strs> interfacelist
%type<_strs> identifierlist
%type<_strs> defaultdef
%type<_strs> inheritedinterfaces
%type<_int> maybereadonly
%type<_int> direction
%type<_int> maybeoneway
%type<_int> maybedefault
%token T_INTEGER_LITERAL T_UNKNOWN
%type<_int> T_INTEGER_LITERAL
%token T_BOOLEAN T_STRING T_LONG T_BYTE T_OBJECT T_SEQUENCE T_AUDIO T_FLOAT
%token T_IN T_OUT T_STREAM T_MULTI T_ATTRIBUTE T_READONLY T_ASYNC T_ONEWAY
%token T_DEFAULT
%%
aidlfile: definitions;
definitions: epsilon | definition definitions ;
definition: structdef | interfacedef | moduledef | enumdef ;
structdef:
T_STRUCT T_IDENTIFIER { ModuleHelper::define($2); } T_SEMICOLON
| T_STRUCT T_IDENTIFIER { ModuleHelper::define($2); }
T_LEFT_CURLY_BRACKET
structbody
T_RIGHT_CURLY_BRACKET
T_SEMICOLON
{
char *qualified = ModuleHelper::qualify($2);
addStructTodo(TypeDef(qualified,*$5,g->noHints));
free(qualified);
free($2);
}
;
enumdef:
T_ENUM enumname { ModuleHelper::define($2); }
T_LEFT_CURLY_BRACKET
enumbody
T_RIGHT_CURLY_BRACKET
T_SEMICOLON
{
char *qualified = ModuleHelper::qualify($2);
addEnumTodo(EnumDef(qualified,*$5,g->noHints));
free(qualified);
free($2);
delete $5;
}
;
enumname: T_IDENTIFIER { $$ = $1; } | epsilon { $$ = strdup("_anonymous_"); };
enumbody:
T_IDENTIFIER
{
$$ = new vector<EnumComponent>;
$$->push_back(EnumComponent($1,0,g->noHints));
free($1);
}
| T_IDENTIFIER T_EQUAL T_INTEGER_LITERAL
{
$$ = new vector<EnumComponent>;
$$->push_back(EnumComponent($1,$3,g->noHints));
free($1);
}
| enumbody T_COMMA T_IDENTIFIER
{
EnumComponent& last = (*$1)[$1->size()-1];
$$ = $1;
$$->push_back(EnumComponent($3,last.value+1,g->noHints));
free($3);
}
| enumbody T_COMMA T_IDENTIFIER T_EQUAL T_INTEGER_LITERAL
{
$$ = $1;
$$->push_back(EnumComponent($3,$5,g->noHints));
free($3);
};
interfacedef:
T_INTERFACE T_IDENTIFIER { ModuleHelper::define($2); } T_SEMICOLON
| T_INTERFACE T_IDENTIFIER { ModuleHelper::define($2); } inheritedinterfaces
T_LEFT_CURLY_BRACKET
classbody
T_RIGHT_CURLY_BRACKET
T_SEMICOLON
{
vector<char *>::iterator ii;
for(ii=$4->begin(); ii != $4->end(); ii++)
{
$6->inheritedInterfaces.push_back(*ii);
free(*ii);
}
delete $4;
char *qualified = ModuleHelper::qualify($2);
$6->name = qualified;
free(qualified);
free($2);
addInterfaceTodo(*$6);
delete $6;
}
;
inheritedinterfaces:
epsilon { $$ = new vector<char *>; }
| T_COLON interfacelist { $$ = $2; };
moduledef:
T_MODULE T_IDENTIFIER { ModuleHelper::enter($2); free($2); }
T_LEFT_CURLY_BRACKET
definitions
T_RIGHT_CURLY_BRACKET { ModuleHelper::leave(); }
T_SEMICOLON
;
classbody:
epsilon {
$$ = new InterfaceDef();
}
| methoddef classbody
{
$$ = $2;
$$->methods.insert($$->methods.begin(),*$1);
delete $1;
}
| attributedef classbody
{
$$ = $2;
$$->attributes.insert($$->attributes.begin(),$1->begin(),$1->end());
if ((*$1)[0].flags & streamDefault) {
vector<std::string> sv;
for (vector<AttributeDef>::iterator i=$1->begin(); i!=$1->end(); i++)
sv.push_back(i->name);
$$->defaultPorts.insert($$->defaultPorts.begin(),sv.begin(),sv.end());
}
}
| defaultdef classbody
{
$$ = $2;
for (vector<char *>::iterator i=$1->begin(); i!=$1->end(); i++)
$$->defaultPorts.insert($$->defaultPorts.begin(), *i);
};
attributedef:
streamdef
| maybereadonly T_ATTRIBUTE type identifierlist T_SEMICOLON
{
// 16 == attribute
vector<char *>::iterator i;
$$ = new vector<AttributeDef>;
for(i=$4->begin();i != $4->end();i++)
{
$$->push_back(AttributeDef((*i),$3,(AttributeType)($1 + 16),g->noHints));
free(*i);
}
delete $4;
}
;
maybereadonly:
epsilon { $$ = 1+2; /* in&out (read & write) */ }
| T_READONLY { $$ = 2; /* out (readonly) */ }
;
maybeoneway:
epsilon { $$ = methodTwoway; }
| T_ONEWAY { $$ = methodOneway; }
;
maybedefault:
epsilon { $$ = 0; }
| T_DEFAULT { $$ = streamDefault; }
;
streamdef: maybedefault direction type T_STREAM identifierlist T_SEMICOLON
{
// 8 == stream
vector<char *>::iterator i;
$$ = new vector<AttributeDef>;
for(i=$5->begin();i != $5->end();i++)
{
$$->push_back(AttributeDef((*i),$3,(AttributeType)(($2|$1) + 8),g->noHints));
free(*i);
}
delete $5;
};
defaultdef: T_DEFAULT identifierlist T_SEMICOLON
{
$$ = $2;
};
direction:
T_IN { $$ = streamIn; }
| T_IN T_MULTI { $$ = streamIn|streamMulti; }
| T_OUT { $$ = streamOut; }
| T_OUT T_MULTI { $$ = streamOut|streamMulti; }
| T_ASYNC T_IN { $$ = streamAsync|streamIn; }
| T_ASYNC T_IN T_MULTI { $$ =streamAsync|streamIn|streamMulti }
| T_ASYNC T_OUT { $$ = streamAsync|streamOut; }
| T_ASYNC T_OUT T_MULTI { $$ = streamAsync|streamOut|streamMulti; }
;
// CacheElement getFromCache(string name, bool hit)
methoddef:
maybeoneway type T_IDENTIFIER
T_LEFT_PARANTHESIS paramdefs T_RIGHT_PARANTHESIS T_SEMICOLON
{
$$ = new MethodDef($3,$2,(MethodType)$1,*$5,g->noHints);
free($3);
free($2);
}
;
paramdefs:
epsilon
{
$$ = new vector<ParamDef>;
}
| paramdef paramdefs1
{
$$ = $2;
$$->insert($$->begin(),*$1);
delete $1;
};
// at least one parameter (ex: "long a" or "long a, long b, string c")
paramdefs1:
epsilon
{
$$ = new vector<ParamDef>;
}
| paramdefs1 T_COMMA paramdef
{
$$ = $1;
$$->push_back(*$3);
delete $3;
//$$->insert($$->begin(),$3);
}
;
// one parameter (ex: "long a")
paramdef: type T_IDENTIFIER
{
$$ = new ParamDef(string($1),string($2),g->noHints);
free($1);
free($2);
};
/*
typecomponentdef: type T_IDENTIFIER T_SEMICOLON
{
$$ = new TypeComponent($1,string($2));
free($2);
};
*/
identifierlist:
T_IDENTIFIER { $$ = new vector<char *>; $$->push_back($1); }
| identifierlist T_COMMA T_IDENTIFIER { $$ = $1; $$->push_back($3); }
interfacelist:
interfacelistelem { $$ = new vector<char *>; $$->push_back($1); }
| interfacelist T_COMMA interfacelistelem { $$ = $1; $$->push_back($3); }
interfacelistelem: T_IDENTIFIER {
$$ = ModuleHelper::qualify($1);
free($1);
}
| T_QUALIFIED_IDENTIFIER {
$$ = ModuleHelper::qualify($1);
free($1);
}
;
structbody: epsilon {
// is empty by default
$$ = new vector<TypeComponent>;
}
| type identifierlist T_SEMICOLON structbody {
$$ = $4;
vector<char *>::reverse_iterator i;
for(i = $2->rbegin();i != $2->rend();i++)
{
char *identifier = *i;
$$->insert($$->begin(),TypeComponent($1,identifier,g->noHints));
free(identifier);
}
delete $2;
};
/*
| typecomponentdef structbody {
$$ = $2;
$$->insert($$->begin(),$1);
};
*/
type: simpletype
| T_SEQUENCE T_LESS simpletype T_GREATER
{
// a sequence<long> is for instance coded as *long
// alloc new size: add one for the null byte and one for the '*' char
char *result = (char *)malloc(strlen($3)+2);
result[0] = '*';
strcpy(&result[1],$3);
free($3); /* fails */
$$ = result;
};
simpletype:
T_BOOLEAN { $$ = strdup("boolean"); }
| T_STRING { $$ = strdup("string"); }
| T_LONG { $$ = strdup("long"); }
| T_BYTE { $$ = strdup("byte"); }
| T_OBJECT { $$ = strdup("object"); }
| T_AUDIO { $$ = strdup("float"); }
| T_FLOAT { $$ = strdup("float"); }
| T_VOID { $$ = strdup("void"); }
| T_IDENTIFIER {
$$ = ModuleHelper::qualify($1);
free($1);
}
| T_QUALIFIED_IDENTIFIER {
$$ = ModuleHelper::qualify($1);
free($1);
};
epsilon: /* empty */ ;
%%
void mcopidlParse( const char *_code )
{
g = new ParserGlobals;
mcopidlInitFlex( _code );
yyparse();
delete g;
}
|