File: parser.y

package info (click to toggle)
orbit 0.3.0-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,628 kB
  • ctags: 7,089
  • sloc: ansic: 89,906; sh: 5,226; yacc: 1,292; makefile: 381; lex: 223
file content (1586 lines) | stat: -rw-r--r-- 37,007 bytes parent folder | download
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
/***************************************************************************

    parser.y (IDL yacc parser and tree generation)

    Copyright (C) 1998 Andrew Veliath

    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., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id: parser.y,v 1.97 1998/08/27 07:43:55 andrewtv Exp $

***************************************************************************/
%{
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "rename.h"
#include "util.h"
#include "IDL.h"

#define do_binop(rv,op,a,b)	do {		\
	if (IDL_binop_chktypes(op, a, b))	\
		YYABORT;			\
	if (__IDL_flags & IDLF_EVAL_CONST) {	\
		rv = IDL_binop_eval(op, a, b);	\
		IDL_tree_free(a);		\
		IDL_tree_free(b);		\
		if (!rv) YYABORT;		\
	} else {				\
		rv = IDL_binop_new(op, a, b);	\
	}					\
} while (0)

#define do_unaryop(rv,op,a)	do {		\
	if (IDL_unaryop_chktypes(op, a))	\
		YYABORT;			\
	if (__IDL_flags & IDLF_EVAL_CONST) {	\
		rv = IDL_unaryop_eval(op, a);	\
		IDL_tree_free(a);		\
		if (!rv) YYABORT;		\
	} else {				\
		rv = IDL_unaryop_new(op, a);	\
	}					\
} while (0)

extern int			yylex(void);
static IDL_declspec_t		IDL_parse_declspec(const char *strspec);
static int			IDL_binop_chktypes(enum IDL_binop op, IDL_tree a, IDL_tree b);
static int			IDL_unaryop_chktypes(enum IDL_unaryop op, IDL_tree a);
static IDL_tree			IDL_binop_eval(enum IDL_binop op, IDL_tree a, IDL_tree b);
static IDL_tree			IDL_unaryop_eval(enum IDL_unaryop op, IDL_tree a);
static IDL_tree			list_start(IDL_tree a, gboolean filter_null);
static IDL_tree			list_chain(IDL_tree a, IDL_tree b, gboolean filter_null);
static IDL_tree			zlist_chain(IDL_tree a, IDL_tree b, gboolean filter_null);
static int			do_token_error(IDL_tree p, const char *message, gboolean prev);

%}

%union {
	IDL_tree tree;
	char *str;
	IDL_declspec_t declspec;
	IDL_longlong_t integer;
	double floatp;
	enum IDL_unaryop unaryop;
	enum IDL_param_attr paramattr;
}

/* Terminals */
%token			TOK_ANY
%token			TOK_ATTRIBUTE
%token			TOK_BOOLEAN
%token			TOK_CASE
%token			TOK_CHAR
%token			TOK_CONST
%token			TOK_CONTEXT
%token			TOK_DEFAULT
%token			TOK_DOUBLE
%token			TOK_ENUM
%token			TOK_EXCEPTION
%token			TOK_FALSE
%token			TOK_FIXED
%token			TOK_FLOAT
%token			TOK_IN 
%token			TOK_INOUT
%token			TOK_INTERFACE
%token			TOK_LONG
%token			TOK_MODULE
%token			TOK_NATIVE
%token			TOK_OBJECT
%token			TOK_OCTET
%token			TOK_ONEWAY
%token			TOK_OP_SCOPE
%token			TOK_OP_SHL
%token			TOK_OP_SHR
%token			TOK_OUT
%token			TOK_RAISES
%token			TOK_READONLY 
%token			TOK_SEQUENCE
%token			TOK_SHORT
%token			TOK_STRING
%token			TOK_STRUCT
%token			TOK_SWITCH
%token			TOK_TRUE
%token			TOK_TYPEDEF
%token			TOK_UNION
%token			TOK_UNSIGNED
%token			TOK_VOID
%token			TOK_WCHAR
%token			TOK_WSTRING
%token <floatp>		TOK_FLOATP
%token <integer>	TOK_INTEGER
%token <str>		TOK_DECLSPEC TOK_IDENT TOK_SQSTRING TOK_DQSTRING TOK_FIXEDP

/* Non-Terminals */
%type <tree>		add_expr
%type <tree>		and_expr
%type <tree>		any_type
%type <tree>		array_declarator
%type <tree>		attr_dcl
%type <tree>		base_type_spec
%type <tree>		boolean_lit
%type <tree>		boolean_type
%type <tree>		case_label
%type <tree>		case_label_list
%type <tree>		case_stmt
%type <tree>		case_stmt_list
%type <tree>		char_lit
%type <tree>		char_type
%type <tree>		complex_declarator
%type <tree>		const_dcl
%type <tree>		const_exp
%type <tree>		const_type
%type <tree>		constr_type_spec
%type <tree>		context_expr
%type <tree>		cur_ns_new_or_prev_ident
%type <tree>		declarator
%type <tree>		declarator_list
%type <tree>		definition
%type <tree>		definition_list
%type <tree>		element_spec
%type <tree>		enum_type
%type <tree>		enumerator_list
%type <tree>		except_dcl
%type <tree>		export
%type <tree>		export_list
%type <tree>		fixed_array_size
%type <tree>		fixed_array_size_list
%type <tree>		fixed_pt_const_type
%type <tree>		fixed_pt_lit
%type <tree>		fixed_pt_type
%type <tree>		floating_pt_lit
%type <tree>		floating_pt_type
%type <tree>		ident
%type <tree>		illegal_ident
%type <tree>		integer_lit
%type <tree>		integer_type
%type <tree>		interface
%type <tree>		interface_body
%type <tree>		interface_catch_ident
%type <tree>		is_context_expr
%type <tree>		is_raises_expr
%type <tree>		literal
%type <tree>		member
%type <tree>		member_list
%type <tree>		member_zlist
%type <tree>		module
%type <tree>		mult_expr
%type <tree>		new_ident
%type <tree>		new_or_prev_scope
%type <tree>		new_scope
%type <tree>		ns_global_ident
%type <tree>		ns_new_ident
%type <tree>		ns_prev_ident
%type <tree>		ns_scoped_name
%type <tree>		object_type
%type <tree>		octet_type
%type <tree>		op_dcl
%type <tree>		op_type_spec
%type <tree>		or_expr
%type <tree>		param_dcl
%type <tree>		param_dcl_list
%type <tree>		param_type_spec
%type <tree>		parameter_dcls
%type <tree>		pop_scope
%type <tree>		positive_int_const
%type <tree>		primary_expr
%type <tree>		raises_expr
%type <tree>		scoped_name
%type <tree>		scoped_name_list
%type <tree>		sequence_type
%type <tree>		shift_expr
%type <tree>		simple_declarator
%type <tree>		simple_declarator_list
%type <tree>		simple_type_spec
%type <tree>		specification
%type <tree>		string_lit
%type <tree>		string_lit_list
%type <tree>		string_type
%type <tree>		struct_type
%type <tree>		switch_body
%type <tree>		switch_type_spec
%type <tree>		template_type_spec
%type <tree>		type_dcl
%type <tree>		type_declarator
%type <tree>		type_spec
%type <tree>		unary_expr
%type <tree>		union_type
%type <tree>		useless_semicolon
%type <tree>		wide_char_type
%type <tree>		wide_string_type
%type <tree>		xor_expr
%type <tree>		z_inheritance

%type <declspec>	z_declspec interface_declspec module_declspec
%type <integer>		signed_int unsigned_int is_readonly is_oneway
%type <paramattr>	param_attribute
%type <str>		sqstring dqstring dqstring_cat
%type <unaryop>		unary_op

%%

specification:		/* empty */			{ yyerror("Empty file"); YYABORT; }
|			definition_list			{ __IDL_root = $1; }
	;

definition_list:	definition			{ $$ = list_start($1, TRUE); }
|			definition_list definition	{ $$ = list_chain($1, $2, TRUE); }
	;

check_semicolon:	';'
|			/* empty */			{
	if (do_token_error($<tree>0, "Missing semicolon after", TRUE))
		YYABORT;
}
	;

useless_semicolon:	';'				{
	yyerror("Dangling semicolon has no effect");
	$$ = NULL;
}
	;

check_comma:		','
|			/* empty */			{
	if (do_token_error($<tree>0, "Missing comma after", TRUE))
		YYABORT;
}
	;

illegal_ident:		scoped_name			{
	assert(IDL_NODE_UP($1) != NULL);
	do_token_error(IDL_NODE_UP($1), "Illegal context for", FALSE);
}
	;

definition:		type_dcl check_semicolon
|			const_dcl check_semicolon
|			except_dcl check_semicolon
|			interface check_semicolon
|			module check_semicolon
|			illegal_ident
|			useless_semicolon
	;

module_declspec:	z_declspec TOK_MODULE
	;

module:			module_declspec new_or_prev_scope '{'
				definition_list
			'}' pop_scope			{
	IDL_tree module;

	if (IDL_NODE_UP($2) != NULL &&
	    IDL_NODE_TYPE(IDL_NODE_UP($2)) != IDLN_MODULE) {
		do_token_error(IDL_NODE_UP($2), "Module definition conflicts with", FALSE);
		yyerrornv($2, "Previous declaration");
		YYABORT;
	}

	if (__IDL_flags & IDLF_COMBINE_REOPENED_MODULES) {
		if (IDL_NODE_UP ($2) == NULL)
			module = IDL_module_new($2, $4);
		
		else {
			module = IDL_NODE_UP ($2);
			
			IDL_MODULE(module).definition_list =
				IDL_list_concat(IDL_MODULE(module).definition_list, $4);

			module = NULL;
		}
	} else {
		module = IDL_module_new($2, $4);
	}

	$$ = module;
	IDL_NODE_DECLSPEC($$) = $1;
}
|			module_declspec new_or_prev_scope '{'
			'}' pop_scope			{
	if (IDL_NODE_UP($2) != NULL &&
	    IDL_NODE_TYPE(IDL_NODE_UP($2)) != IDLN_MODULE) {
		do_token_error(IDL_NODE_UP($2), "Module definition conflicts with", FALSE);
		yyerrornv($2, "Previous declaration");
		YYABORT;
	}
	yywarningv(IDL_WARNING1,
		   "Empty module declaration `%s' is not legal IDL",
		   IDL_IDENT($2).str);

	$$ = IDL_NODE_UP ($2) ? NULL : IDL_module_new($2, NULL);
	if ($$)
		IDL_NODE_DECLSPEC($$) = $1;
}
	;

interface_catch_ident:	new_or_prev_scope
|			TOK_OBJECT			{
	yyerror("Interfaces cannot be named `Object'");
	YYABORT;
}
	;

interface_declspec:	z_declspec TOK_INTERFACE
	;

interface:		interface_declspec
			interface_catch_ident
			pop_scope
			z_inheritance			{
	assert($2 != NULL);
	assert(IDL_NODE_TYPE($2) == IDLN_IDENT);
	assert(IDL_IDENT_TO_NS($2) != NULL);
	assert(IDL_NODE_TYPE(IDL_IDENT_TO_NS($2)) == IDLN_GENTREE);
	if (IDL_NODE_UP($2) != NULL &&
	    IDL_NODE_TYPE(IDL_NODE_UP($2)) != IDLN_INTERFACE &&
	    IDL_NODE_TYPE(IDL_NODE_UP($2)) != IDLN_FORWARD_DCL) {
		do_token_error(IDL_NODE_UP($2), "Interface definition conflicts with", FALSE);
		yyerrornv($2, "Previous declaration");
		YYABORT;
	} else if (IDL_NODE_UP($2) != NULL &&
		   IDL_NODE_TYPE(IDL_NODE_UP($2)) != IDLN_FORWARD_DCL) {
		yyerrorv("Cannot redeclare interface `%s'", IDL_IDENT($2).str);
		yyerrornv($2, "Previous declaration of interface `%s'", IDL_IDENT($2).str);
		YYABORT;
	} else if (IDL_NODE_UP($2) != NULL &&
		   IDL_NODE_TYPE(IDL_NODE_UP($2)) == IDLN_FORWARD_DCL) {
		$2->_file = __IDL_cur_filename;
		$2->_line = __IDL_cur_line;
	}
	IDL_GENTREE(IDL_IDENT_TO_NS($2))._import = $4;
	IDL_ns_push_scope(__IDL_root_ns, IDL_IDENT_TO_NS($2));
	if (IDL_ns_check_for_ambiguous_inheritance($2, $4))
		__IDL_is_okay = FALSE;
}
			'{'
				interface_body
			'}' pop_scope			{
	$$ = IDL_interface_new($2, $4, $7);
	IDL_NODE_DECLSPEC($$) = $1;
}
|			interface_declspec
			interface_catch_ident pop_scope	{
	if ($1)
		yywarningv(IDL_WARNING1,
			   "Useless declspec for forward declaration `%s'",
			   IDL_IDENT($2));
	$$ = IDL_forward_dcl_new($2);
}
	;

z_inheritance:		/* empty */			{ $$ = NULL; }
|			':' scoped_name_list		{
	GHashTable *table = g_hash_table_new(g_direct_hash, g_direct_equal);
	gboolean die = FALSE;
	IDL_tree p = $2;

	assert(IDL_NODE_TYPE(p) == IDLN_LIST);
	for (; p != NULL && !die; p = IDL_LIST(p).next) {
		assert(IDL_LIST(p).data != NULL);
		assert(IDL_NODE_TYPE(IDL_LIST(p).data) == IDLN_IDENT);

		if (g_hash_table_lookup_extended(table, IDL_LIST(p).data, NULL, NULL)) {
			char *s = IDL_ns_ident_to_qstring(IDL_LIST(p).data, "::", 0);
			yyerrorv("Cannot inherit from interface `%s' more than once", s);
			free(s);
			die = TRUE;
			break;
		} else
			g_hash_table_insert(table, IDL_LIST(p).data, NULL);

		if (IDL_NODE_TYPE(IDL_NODE_UP(IDL_LIST(p).data)) == IDLN_FORWARD_DCL) {
			char *s = IDL_ns_ident_to_qstring(IDL_LIST(p).data, "::", 0);
			yyerrorv("Incomplete definition of interface `%s'", s);
			yyerrornv(IDL_LIST(p).data,
				 "Previous forward declaration of `%s'", s);
			free(s);
			die = TRUE;
		}
		else if (IDL_NODE_TYPE(IDL_NODE_UP(IDL_LIST(p).data)) != IDLN_INTERFACE) {
			char *s = IDL_ns_ident_to_qstring(IDL_LIST(p).data, "::", 0);
			yyerrorv("`%s' is not an interface", s);
			yyerrornv(IDL_LIST(p).data,
				  "Previous declaration of `%s'", s);
			free(s);
			die = TRUE;
		}
	}

	g_hash_table_destroy(table);

	if (die)
		YYABORT;

	$$ = $2;
}
	;

scoped_name_list:	scoped_name			{ $$ = list_start($1, TRUE); }
|			scoped_name_list
			check_comma scoped_name		{ $$ = list_chain($1, $3, TRUE); }
	;

interface_body:		export_list
	;

export_list:		/* empty */			{ $$ = NULL; }
|			export_list export		{ $$ = zlist_chain($1, $2, TRUE); }
	;

export:			type_dcl check_semicolon
|			except_dcl check_semicolon
|			op_dcl check_semicolon
|			attr_dcl check_semicolon
|			const_dcl check_semicolon
|			useless_semicolon
	;

type_dcl:		TOK_TYPEDEF type_declarator	{ $$ = $2; }
|			struct_type
|			union_type
|			enum_type
|			TOK_NATIVE simple_declarator	{ $$ = IDL_native_new($2); }
	;

type_declarator:	type_spec declarator_list	{ $$ = IDL_type_dcl_new($1, $2); }
	;

type_spec:		simple_type_spec
|			constr_type_spec
	;

simple_type_spec:	base_type_spec
|			template_type_spec
|			scoped_name
	;

constr_type_spec:	struct_type
|			union_type
|			enum_type
	;

struct_type:		TOK_STRUCT new_scope '{'
				member_list
			'}' pop_scope			{ $$ = IDL_type_struct_new($2, $4); }
	;

union_type:		TOK_UNION new_scope TOK_SWITCH '('
				switch_type_spec
			')' '{'
				switch_body
			'}' pop_scope			{ $$ = IDL_type_union_new($2, $5, $8); }
	;

switch_type_spec:	integer_type
|			char_type
|			boolean_type
|			enum_type
|			scoped_name
	;

switch_body:		case_stmt_list
	;

case_stmt_list:		case_stmt			{ $$ = list_start($1, TRUE); }
|			case_stmt_list case_stmt	{ $$ = list_chain($1, $2, TRUE); }
	;

case_stmt:		case_label_list
			element_spec check_semicolon	{ $$ = IDL_case_stmt_new($1, $2); }
	;

element_spec:		type_spec declarator		{ $$ = IDL_member_new($1, list_start($2, TRUE)); }
	;

case_label_list:	case_label			{ $$ = list_start($1, FALSE); }
|			case_label_list case_label	{ $$ = list_chain($1, $2, FALSE); }
	;

case_label:		TOK_CASE const_exp ':'		{ $$ = $2; }
|			TOK_DEFAULT ':'			{ $$ = NULL; }
	;

const_dcl:		TOK_CONST const_type new_ident
			'=' const_exp			{
	$$ = IDL_const_dcl_new($2, $3, $5);
	/* Should probably do some type checking here... */
}
	;

except_dcl:		TOK_EXCEPTION new_scope '{'
				member_zlist
			'}' pop_scope			{ $$ = IDL_except_dcl_new($2, $4); }
	;

member_zlist:		/* empty */			{ $$ = NULL; }
|			member_zlist member		{ $$ = zlist_chain($1, $2, TRUE); }
	;

is_readonly:		/* empty */			{ $$ = FALSE; }
|			TOK_READONLY			{ $$ = TRUE; }
	;

attr_dcl:		is_readonly TOK_ATTRIBUTE
			param_type_spec
			simple_declarator_list		{ $$ = IDL_attr_dcl_new($1, $3, $4); }
	;

param_type_spec:	base_type_spec
|			string_type
|			wide_string_type
|			fixed_pt_type
|			scoped_name
	;

is_oneway:		/* empty */			{ $$ = FALSE; }
|			TOK_ONEWAY			{ $$ = TRUE; }
	;

op_dcl:			is_oneway op_type_spec
			new_scope parameter_dcls pop_scope
			is_raises_expr
			is_context_expr			{ $$ = IDL_op_dcl_new($1, $2, $3, $4, $6, $7); }
	;

op_type_spec:		param_type_spec
|			TOK_VOID			{ $$ = NULL; }
	;

parameter_dcls:		'(' param_dcl_list ')'		{ $$ = $2; }
|			'(' ')'				{ $$ = NULL; }
	;

param_dcl_list:		param_dcl			{ $$ = list_start($1, TRUE); }
|			param_dcl_list
			check_comma param_dcl		{ $$ = list_chain($1, $3, TRUE); }
	;

param_dcl:		param_attribute
			param_type_spec
			simple_declarator		{ $$ = IDL_param_dcl_new($1, $2, $3); }
	;

param_attribute:	TOK_IN				{ $$ = IDL_PARAM_IN; }
|			TOK_OUT				{ $$ = IDL_PARAM_OUT; }
|			TOK_INOUT			{ $$ = IDL_PARAM_INOUT; }
|			param_type_spec			{
	yyerrorv("Missing direction attribute (in, out, inout) before parameter");
	IDL_tree_free($1);
}
	;

is_raises_expr:		/* empty */			{ $$ = NULL; }
|			raises_expr
	;

is_context_expr:	/* empty */			{ $$ = NULL; }
|			context_expr
	;

raises_expr:		TOK_RAISES '('
				scoped_name_list
			')'				{ $$ = $3; }
	;

context_expr:		TOK_CONTEXT '('
				string_lit_list
			')'				{ $$ = $3; }
	;

const_type:		integer_type
|			char_type
|			wide_char_type
|			boolean_type
|			floating_pt_type
|			string_type
|			wide_string_type
|			fixed_pt_const_type
|			scoped_name
	;

const_exp:		or_expr
	;

or_expr:		xor_expr
|			or_expr '|' xor_expr		{ do_binop($$, IDL_BINOP_OR, $1, $3); }
	;

xor_expr:		and_expr
|			xor_expr '^' and_expr		{ do_binop($$, IDL_BINOP_XOR, $1, $3); }
	;

and_expr:		shift_expr
|			and_expr '&' shift_expr		{ do_binop($$, IDL_BINOP_AND, $1, $3); }
	;

shift_expr:		add_expr
|			shift_expr TOK_OP_SHR add_expr	{ do_binop($$, IDL_BINOP_SHR, $1, $3); }
|			shift_expr TOK_OP_SHL add_expr	{ do_binop($$, IDL_BINOP_SHL, $1, $3); }
	;

add_expr:		mult_expr
|			add_expr '+' mult_expr		{ do_binop($$, IDL_BINOP_ADD, $1, $3); }
|			add_expr '-' mult_expr		{ do_binop($$, IDL_BINOP_SUB, $1, $3); }
	;

mult_expr:		unary_expr
|			mult_expr '*' unary_expr	{ do_binop($$, IDL_BINOP_MULT, $1, $3); }
|			mult_expr '/' unary_expr	{ do_binop($$, IDL_BINOP_DIV, $1, $3); }
|			mult_expr '%' unary_expr	{ do_binop($$, IDL_BINOP_MOD, $1, $3); }
	;

unary_expr:		unary_op primary_expr		{ do_unaryop($$, $1, $2); }
|			primary_expr
	;

unary_op:		'-'				{ $$ = IDL_UNARYOP_MINUS; }
|			'+'				{ $$ = IDL_UNARYOP_PLUS; }
|			'~'				{ $$ = IDL_UNARYOP_COMPLEMENT; }
	;

primary_expr:		scoped_name
|			literal
|			'(' const_exp ')'		{ $$ = $2; }
	;

literal:		integer_lit
|			string_lit
|			char_lit
|			fixed_pt_lit
|			floating_pt_lit
|			boolean_lit
	;

enum_type:		TOK_ENUM new_ident '{'
				enumerator_list
			'}'				{ $$ = IDL_type_enum_new($2, $4); }
	;

scoped_name:		ns_scoped_name			{
	assert($1 != NULL);
	assert(IDL_NODE_TYPE($1) == IDLN_GENTREE);
	assert(IDL_NODE_TYPE(IDL_GENTREE($1).data) == IDLN_IDENT);
	$$ = IDL_GENTREE($1).data;
}
	;

ns_scoped_name:		ns_prev_ident
|			TOK_OP_SCOPE ns_global_ident	{ $$ = $2; }
|			ns_scoped_name TOK_OP_SCOPE
			ident				{
	IDL_tree p;

	assert(IDL_NODE_TYPE($1) == IDLN_GENTREE);
	assert(IDL_NODE_TYPE($3) == IDLN_IDENT);

#ifdef YYDEBUG
	if (yydebug)
		printf("looking in %s\n", IDL_IDENT(IDL_GENTREE($1).data).str);
#endif

	if ((p = IDL_ns_lookup_this_scope(__IDL_root_ns, $1, $3, NULL)) == NULL) {
#ifdef YYDEBUG
		if (yydebug)
			printf("'%s'\n", IDL_IDENT($3).str);
#endif
		yyerrorv("`%s' undeclared identifier", IDL_IDENT($3).str);
		IDL_tree_free($3);
		YYABORT;
	}
	IDL_tree_free($3);
	++IDL_NODE_REFS(IDL_GENTREE(p).data);
	$$ = p;
}
	;

enumerator_list:	new_ident			{ $$ = list_start($1, TRUE); }
|			enumerator_list
			check_comma new_ident		{ $$ = list_chain($1, $3, TRUE); }
	;

member_list:		member				{ $$ = list_start($1, TRUE); }
|			member_list member		{ $$ = list_chain($1, $2, TRUE); }
	;

member:			type_spec declarator_list
			check_semicolon			{ $$ = IDL_member_new($1, $2); }
	;

base_type_spec:		floating_pt_type
|			integer_type
|			char_type
|			wide_char_type
|			boolean_type
|			octet_type
|			any_type
|			object_type
	;

template_type_spec:	sequence_type
|			string_type
|			wide_string_type
|			fixed_pt_type
	;

sequence_type:		TOK_SEQUENCE '<'
				simple_type_spec ',' positive_int_const
			'>'				{ $$ = IDL_type_sequence_new($3, $5); }
|			TOK_SEQUENCE '<'
				simple_type_spec
			'>'				{ $$ = IDL_type_sequence_new($3, NULL); }
	;

floating_pt_type:	TOK_FLOAT			{ $$ = IDL_type_float_new(IDL_FLOAT_TYPE_FLOAT); }
|			TOK_DOUBLE			{ $$ = IDL_type_float_new(IDL_FLOAT_TYPE_DOUBLE); }
|			TOK_LONG TOK_DOUBLE		{ $$ = IDL_type_float_new(IDL_FLOAT_TYPE_LONGDOUBLE); }
	;

fixed_pt_type:		TOK_FIXED '<'
				positive_int_const ',' integer_lit
			'>'				{ $$ = IDL_type_fixed_new($3, $5); }
	;

fixed_pt_const_type:	TOK_FIXED			{ $$ = IDL_type_fixed_new(NULL, NULL); }
	;

integer_type:		signed_int			{ $$ = IDL_type_integer_new(TRUE, $1); }
|			unsigned_int			{ $$ = IDL_type_integer_new(FALSE, $1); }
	;

signed_int:		signed_short_int		{ $$ = IDL_INTEGER_TYPE_SHORT; }
|			signed_long_int			{ $$ = IDL_INTEGER_TYPE_LONG; }
|			signed_longlong_int		{ $$ = IDL_INTEGER_TYPE_LONGLONG; }
	;

signed_short_int:	TOK_SHORT
	;

signed_long_int:	TOK_LONG
	;

signed_longlong_int:	TOK_LONG TOK_LONG
	;

unsigned_int:		unsigned_short_int		{ $$ = IDL_INTEGER_TYPE_SHORT; }
|			unsigned_long_int		{ $$ = IDL_INTEGER_TYPE_LONG; }
|			unsigned_longlong_int		{ $$ = IDL_INTEGER_TYPE_LONGLONG; }
	;

unsigned_short_int:	TOK_UNSIGNED TOK_SHORT
	;

unsigned_long_int:	TOK_UNSIGNED TOK_LONG
	;

unsigned_longlong_int:	TOK_UNSIGNED TOK_LONG TOK_LONG
	;

char_type:		TOK_CHAR			{ $$ = IDL_type_char_new(); }
	;

wide_char_type:		TOK_WCHAR			{ $$ = IDL_type_wide_char_new(); }
	;

boolean_type:		TOK_BOOLEAN			{ $$ = IDL_type_boolean_new(); }
	;

octet_type:		TOK_OCTET			{ $$ = IDL_type_octet_new(); }
	;

any_type:		TOK_ANY				{ $$ = IDL_type_any_new(); }
	;

object_type:		TOK_OBJECT			{ $$ = IDL_type_object_new(); }
	;

string_type:		TOK_STRING '<'
				positive_int_const
				'>'			{ $$ = IDL_type_string_new($3); }
|			TOK_STRING			{ $$ = IDL_type_string_new(NULL); }
	;

wide_string_type:	TOK_WSTRING '<'
				positive_int_const
			'>'				{ $$ = IDL_type_wide_string_new($3); }
|			TOK_WSTRING			{ $$ = IDL_type_wide_string_new(NULL); }
	;

declarator_list:	declarator			{ $$ = list_start($1, TRUE); }
|			declarator_list 
			check_comma declarator		{ $$ = list_chain($1, $3, TRUE); }
	;

declarator:		simple_declarator
|			complex_declarator
	;

simple_declarator:	new_ident
	;

complex_declarator:	array_declarator
	;

simple_declarator_list:	simple_declarator		{ $$ = list_start($1, TRUE); }
|			simple_declarator_list
			check_comma simple_declarator	{ $$ = list_chain($1, $3, TRUE); }
	;

array_declarator:	new_ident
			fixed_array_size_list		{ $$ = IDL_type_array_new($1, $2); }
	;

fixed_array_size_list:	fixed_array_size		{ $$ = list_start($1, TRUE); }
|			fixed_array_size_list
			fixed_array_size		{ $$ = list_chain($1, $2, TRUE); }
	;

fixed_array_size:	'[' 
			positive_int_const 
			']'				{ $$ = $2; }
	;

ident:			TOK_IDENT			{ $$ = IDL_ident_new($1); }
	;

new_ident:		ns_new_ident			{
	assert($1 != NULL);
	assert(IDL_NODE_TYPE($1) == IDLN_GENTREE);
	assert(IDL_NODE_TYPE(IDL_GENTREE($1).data) == IDLN_IDENT);
	$$ = IDL_GENTREE($1).data;
}
	;

new_scope:		ns_new_ident			{
	IDL_ns_push_scope(__IDL_root_ns, $1);
#ifdef YYDEBUG
	if (yydebug)
		printf("entering new/prev scope of %s\n", 
		       IDL_IDENT(IDL_GENTREE(IDL_NS(__IDL_root_ns).current).data).str);
#endif
	assert(IDL_NODE_TYPE(IDL_GENTREE($1).data) == IDLN_IDENT);
	$$ = IDL_GENTREE($1).data;
}
	;

new_or_prev_scope:	cur_ns_new_or_prev_ident	{
	IDL_ns_push_scope(__IDL_root_ns, $1);
	assert(IDL_NS(__IDL_root_ns).current != NULL);
	assert(IDL_NODE_TYPE(IDL_NS(__IDL_root_ns).current) == IDLN_GENTREE);
	assert(IDL_GENTREE(IDL_NS(__IDL_root_ns).current).data != NULL);
	assert(IDL_NODE_TYPE(IDL_GENTREE(IDL_NS(__IDL_root_ns).current).data) == IDLN_IDENT);
#ifdef YYDEBUG
	if (yydebug)
		printf("entering new/prev scope of %s\n", 
		       IDL_IDENT(IDL_GENTREE(IDL_NS(__IDL_root_ns).current).data).str);
#endif
	assert(IDL_NODE_TYPE(IDL_GENTREE($1).data) == IDLN_IDENT);
	$$ = IDL_GENTREE($1).data;
}
	;

pop_scope:		/* empty */			{
#ifdef YYDEBUG
	if (yydebug)
		printf("scope to parent of %s\n", 
		       IDL_IDENT(IDL_GENTREE(IDL_NS(__IDL_root_ns).current).data).str);
#endif
	IDL_ns_pop_scope(__IDL_root_ns);
}
	;

ns_new_ident:		ident				{
	IDL_tree p;

	if ((p = IDL_ns_place_new(__IDL_root_ns, $1)) == NULL) {
		IDL_tree q;
		int i;

		p = IDL_ns_lookup_cur_scope(__IDL_root_ns, $1, NULL);

		for (i = 0, q = IDL_GENTREE(p).data;
		     q && (IDL_NODE_TYPE(q) == IDLN_IDENT ||
			   IDL_NODE_TYPE(q) == IDLN_LIST) && i < 4;
		     ++i)
			if (IDL_NODE_UP(q))
				q = IDL_NODE_UP(q);
		
		if (q) {
			do_token_error(q, "Duplicate identifier conflicts with", FALSE);
			yyerrornv(q, "Previous declaration");
		} else
			yyerrorv("`%s' duplicate identifier", IDL_IDENT($1).str);

		IDL_tree_free($1);
		YYABORT;
	}
	assert(IDL_IDENT($1)._ns_ref == p);
	++IDL_NODE_REFS(IDL_GENTREE(p).data);
	$$ = p;
}
	;

ns_prev_ident:		ident				{
	IDL_tree p;

	if ((p = IDL_ns_resolve_ident(__IDL_root_ns, $1)) == NULL) {
		yyerrorv("`%s' undeclared identifier", IDL_IDENT($1).str);
		IDL_tree_free($1);
		YYABORT;
	}
	IDL_tree_free($1);
	assert(IDL_GENTREE(p).data != NULL);
	assert(IDL_IDENT(IDL_GENTREE(p).data)._ns_ref == p);
	++IDL_NODE_REFS(IDL_GENTREE(p).data);
	$$ = p;
}
	;

cur_ns_new_or_prev_ident:
			ident				{
	IDL_tree p;

	if ((p = IDL_ns_lookup_cur_scope(__IDL_root_ns, $1, NULL)) == NULL) {
		p = IDL_ns_place_new(__IDL_root_ns, $1);
		assert(p != NULL);
		assert(IDL_IDENT($1)._ns_ref == p);
	} else {
		IDL_tree_free($1);
		assert(IDL_GENTREE(p).data != NULL);
		assert(IDL_IDENT(IDL_GENTREE(p).data)._ns_ref == p);
	}
	++IDL_NODE_REFS(IDL_GENTREE(p).data);
	$$ = p;
}
	;

ns_global_ident:	ident				{
	IDL_tree p;

	if ((p = IDL_ns_lookup_this_scope(__IDL_root_ns, IDL_NS(__IDL_root_ns).file, $1, NULL)) == NULL) {
		yyerrorv("`%s' undeclared identifier", IDL_IDENT($1).str);
		IDL_tree_free($1);
		YYABORT;
	}
	IDL_tree_free($1);
	assert(IDL_GENTREE(p).data != NULL);
	assert(IDL_IDENT(IDL_GENTREE(p).data)._ns_ref == p);
	++IDL_NODE_REFS(IDL_GENTREE(p).data);
	$$ = p;
}
	;

string_lit_list:	string_lit			{ $$ = list_start($1, TRUE); }
|			string_lit_list
			check_comma string_lit		{ $$ = list_chain($1, $3, TRUE); }
	;

positive_int_const:	TOK_INTEGER			{
	if ($1 < 0) {
		yywarningv(IDL_WARNING1, "Cannot use negative value " 
			   IDL_SB10_FMT ", using " IDL_SB10_FMT, $1, -$1);
		$$ = IDL_integer_new(-$1);
	}
	else
		$$ = IDL_integer_new($1);
}
	;

z_declspec:		/* empty */			{ $$ = 0; }
|			TOK_DECLSPEC			{
	$$ = IDL_parse_declspec($1);
	free($1);
}
	;

integer_lit:		TOK_INTEGER			{ $$ = IDL_integer_new($1); }
	;

string_lit:		dqstring_cat			{ $$ = IDL_string_new($1); }
	;

char_lit:		sqstring			{ $$ = IDL_char_new($1); }
	;

fixed_pt_lit:		TOK_FIXEDP			{ $$ = IDL_fixed_new($1); }
	;

floating_pt_lit:	TOK_FLOATP			{ $$ = IDL_float_new($1); }
	;

boolean_lit:		TOK_TRUE			{ $$ = IDL_boolean_new(TRUE); }
|			TOK_FALSE			{ $$ = IDL_boolean_new(FALSE); }
	;

dqstring_cat:		dqstring
|			dqstring_cat dqstring		{
	char *catstr = (char *)malloc(strlen($1) + strlen($2) + 1);
	strcpy(catstr, $1); free($1);
	strcat(catstr, $2); free($2);
	$$ = catstr;
}
	;

dqstring:		TOK_DQSTRING			{
	char *s = IDL_do_escapes($1);
	free($1);
	$$ = s;
}
	;

sqstring:		TOK_SQSTRING			{
	char *s = IDL_do_escapes($1);
	free($1);
	$$ = s;
}
	;

%%

static const char *IDL_ns_get_cur_prefix(IDL_ns ns)
{
	IDL_tree p;

	p = IDL_NS(ns).current;

	assert(p != NULL);

	while (p && !IDL_GENTREE(p)._cur_prefix)
		p = IDL_NODE_UP(p);

	return p ? IDL_GENTREE(p)._cur_prefix : NULL;
}

char *IDL_ns_ident_make_repo_id(IDL_ns ns, IDL_tree p,
				const char *p_prefix, int *major, int *minor)
{
	GString *s = g_string_new(NULL);
	const char *prefix;
	char *q;

	assert(p != NULL);
	
	if (IDL_NODE_TYPE(p) == IDLN_IDENT)
		p = IDL_IDENT_TO_NS(p);

	assert(p != NULL);

	prefix = p_prefix ? p_prefix : IDL_ns_get_cur_prefix(ns);

	q = IDL_ns_ident_to_qstring(p, "/", 0);
	g_string_sprintf(s, "IDL:%s%s%s:%d.%d",
			 prefix ? prefix : "",
			 prefix && *prefix ? "/" : "",
			 q,
			 major ? *major : 1,
			 minor ? *minor : 0);
	free(q);

	q = s->str;
	g_string_free(s, FALSE);

	return q;
}

static const char *get_name_token(const char *s, char **tok)
{
	const char *begin = s;
	int state = 0;

	if (!s)
		return NULL;

	while (isspace(*s)) ++s;
	
	while (1) switch (state) {
	case 0:		/* Unknown */
		if (*s == ':')
			state = 1;
		else if (isalnum(*s) || *s == '_') {
			begin = s;
			state = 2;
		} else
			return NULL;
		break;
	case 1:		/* Scope */
		if (strncmp(s, "::", 2) == 0) {
			char *r = (char *)malloc(3);
			strcpy(r, "::");
			*tok = r;
			return s + 2;
		} else	/* Invalid */
			return NULL;
		break;
	case 2:
		if (isalnum(*s) || *s == '_')
			++s;
		else {
			char *r = (char *)malloc(s - begin + 1);
			strncpy(r, begin, s - begin + 1);
			r[s - begin] = 0;
			*tok = r;
			return s;
		}
		break;
	}
}

static IDL_tree IDL_ns_pragma_parse_name(IDL_ns ns, const char *s)
{
	IDL_tree p = IDL_NS(ns).current;
	int start = 1;
	char *tok;

	while (p && *s && (s = get_name_token(s, &tok))) {
		if (tok == NULL)
			return NULL;
		if (strcmp(tok, "::") == 0) {
			if (start) {
				/* Globally scoped */
				p = IDL_NS(ns).file;
			}
			free(tok);
		} else {
			IDL_tree ident = IDL_ident_new(tok);
			p = IDL_ns_lookup_this_scope(__IDL_root_ns, p, ident, NULL);
			IDL_tree_free(ident);
		}
		start = 0;
	}
	
	return p;
}

void IDL_ns_ID(IDL_ns ns, const char *s)
{
	char name[1024], id[1024];
	IDL_tree p, ident;
	int n;

	n = sscanf(s, "%1023s \"%1023s\"", name, id);
	if (n < 2 && __IDL_is_parsing) {
		yywarning(IDL_WARNING1, "Malformed pragma ID");
		return;
	}
	if (id[strlen(id) - 1] == '"')
		id[strlen(id) - 1] = 0;

	p = IDL_ns_pragma_parse_name(__IDL_root_ns, name);
	if (!p && __IDL_is_parsing) {
		yywarningv(IDL_WARNING1, "Unknown identifier `%s' in pragma ID", name);
		return;
	}

	/* We have resolved the identifier, so assign the repo id */
	assert(IDL_NODE_TYPE(p) == IDLN_GENTREE);
	assert(IDL_GENTREE(p).data != NULL);
	assert(IDL_NODE_TYPE(IDL_GENTREE(p).data) == IDLN_IDENT);
	ident = IDL_GENTREE(p).data;

	if (IDL_IDENT_REPO_ID(ident) != NULL)
		free(IDL_IDENT_REPO_ID(ident));

	IDL_IDENT_REPO_ID(ident) = g_strdup(id);
}

void IDL_ns_version(IDL_ns ns, const char *s)
{
	char name[1024];
	int n, major, minor;
	IDL_tree p, ident;

	n = sscanf(s, "%1023s %u %u", name, &major, &minor);
	if (n < 3 && __IDL_is_parsing) {
		yywarning(IDL_WARNING1, "Malformed pragma version");
		return;
	}

	p = IDL_ns_pragma_parse_name(__IDL_root_ns, name);
	if (!p && __IDL_is_parsing) {
		yywarningv(IDL_WARNING1, "Unknown identifier `%s' in pragma version", name);
		return;
	}

	/* We have resolved the identifier, so assign the repo id */
	assert(IDL_NODE_TYPE(p) == IDLN_GENTREE);
	assert(IDL_GENTREE(p).data != NULL);
	assert(IDL_NODE_TYPE(IDL_GENTREE(p).data) == IDLN_IDENT);
	ident = IDL_GENTREE(p).data;

	if (IDL_IDENT_REPO_ID(ident) != NULL) {
		char *v = strrchr(IDL_IDENT_REPO_ID(ident), ':');
		if (v) {
			GString *s;

			*v = 0;
			s = g_string_new(NULL);
			g_string_sprintf(s, "%s:%d.%d",
					 IDL_IDENT_REPO_ID(ident), major, minor);
			free(IDL_IDENT_REPO_ID(ident));
			IDL_IDENT_REPO_ID(ident) = s->str;
			g_string_free(s, FALSE);
		} else if (__IDL_is_parsing)
			yywarningv(IDL_WARNING1, "Cannot find RepositoryID OMG IDL version in ID `%s'",
				   IDL_IDENT_REPO_ID(ident));
	} else
		IDL_IDENT_REPO_ID(ident) = IDL_ns_ident_make_repo_id(__IDL_root_ns, p, NULL, &major, &minor);
}

void __IDL_do_pragma(const char *s)
{
	int n;
	char directive[256];

	if (!s)
		return;

	if (sscanf(s, "%255s%n", directive, &n) < 1)
		return;
	s += n;
	while (isspace(*s)) ++s;

	if (strcmp(directive, "prefix") == 0)
		IDL_ns_prefix(__IDL_root_ns, s);
	else if (strcmp(directive, "ID") == 0)
		IDL_ns_ID(__IDL_root_ns, s);
	else if (strcmp(directive, "version") == 0)
		IDL_ns_version(__IDL_root_ns, s);
}

static IDL_declspec_t IDL_parse_declspec(const char *strspec)
{
	IDL_declspec_t flags = IDLF_DECLSPEC_EXIST;

	if (strspec == NULL)
		return flags;

	if (strcmp(strspec, "inhibit") == 0)
		flags |= IDLF_DECLSPEC_INHIBIT;
	else if (__IDL_is_parsing)
		yywarningv(IDL_WARNING1, "Ignoring unknown declspec `%s'", strspec);

	return flags;
}

static int do_token_error(IDL_tree p, const char *message, gboolean prev)
{
	int dienow;
	char *what = NULL, *who = NULL;

	assert(p != NULL);

	dienow = IDL_tree_get_node_info(p, &what, &who);

	assert(what != NULL);
	
	if (who && *who)
		yyerrorlv("%s %s `%s'",
			  prev ? __IDL_prev_token_line - __IDL_cur_token_line : 0,
			  message, what, who);
	else
		yyerrorlv("%s %s",
			  prev ? __IDL_prev_token_line - __IDL_cur_token_line : 0,
			  message, what);
	
	return dienow;
}

static IDL_tree list_start(IDL_tree a, gboolean filter_null)
{
	IDL_tree p;

	if (!a && filter_null)
		return NULL;

	p = IDL_list_new(a);

	return p;
}

static IDL_tree list_chain(IDL_tree a, IDL_tree b, gboolean filter_null)
{
	IDL_tree p;

	if (filter_null) {
		if (!b)
			return a;
		
		if (!a)
			return list_start(b, filter_null);
	}

	p = IDL_list_new(b);
	a = IDL_list_concat(a, p);

	return a;
}

static IDL_tree zlist_chain(IDL_tree a, IDL_tree b, gboolean filter_null)
{
	if (a == NULL)
		return list_start(b, filter_null);
	else
		return list_chain(a, b, filter_null);
}

static int IDL_binop_chktypes(enum IDL_binop op, IDL_tree a, IDL_tree b)
{
	if (IDL_NODE_TYPE(a) != IDLN_BINOP &&
	    IDL_NODE_TYPE(b) != IDLN_BINOP &&
	    IDL_NODE_TYPE(a) != IDLN_UNARYOP &&
	    IDL_NODE_TYPE(b) != IDLN_UNARYOP &&
	    IDL_NODE_TYPE(a) != IDL_NODE_TYPE(b)) {
		yyerror("Invalid mix of types in constant expression");
		return -1;
	}

	switch (op) {
	case IDL_BINOP_MULT:
	case IDL_BINOP_DIV:
	case IDL_BINOP_ADD:
	case IDL_BINOP_SUB:
		break;

	case IDL_BINOP_MOD:
	case IDL_BINOP_SHR:
	case IDL_BINOP_SHL:
	case IDL_BINOP_AND:
	case IDL_BINOP_OR:
	case IDL_BINOP_XOR:
		if ((IDL_NODE_TYPE(a) != IDLN_INTEGER ||
		     IDL_NODE_TYPE(b) != IDLN_INTEGER) &&
		    !(IDL_NODE_TYPE(a) == IDLN_BINOP ||
		      IDL_NODE_TYPE(b) == IDLN_BINOP ||
		      IDL_NODE_TYPE(a) == IDLN_UNARYOP ||
		      IDL_NODE_TYPE(b) == IDLN_UNARYOP)) {
			yyerror("Invalid operation on non-integer value");
			return -1;
		}
		break;
	}

	return 0;
}

static int IDL_unaryop_chktypes(enum IDL_unaryop op, IDL_tree a)
{
	switch (op) {
	case IDL_UNARYOP_PLUS:
	case IDL_UNARYOP_MINUS:
		break;

	case IDL_UNARYOP_COMPLEMENT:
		if (IDL_NODE_TYPE(a) != IDLN_INTEGER &&
		    !(IDL_NODE_TYPE(a) == IDLN_BINOP ||
		      IDL_NODE_TYPE(a) == IDLN_UNARYOP)) {
			yyerror("Operand to complement must be integer");
			return -1;
		}
		break;
	}

	return 0;
}

static IDL_tree IDL_binop_eval_integer(enum IDL_binop op, IDL_tree a, IDL_tree b)
{
	IDL_tree p = NULL;

	assert(IDL_NODE_TYPE(a) == IDLN_INTEGER);

	switch (op) {
	case IDL_BINOP_MULT:
		p = IDL_integer_new(IDL_INTEGER(a).value * IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_DIV:
		if (IDL_INTEGER(b).value == 0) {
			yyerror("Divide by zero in constant expression");
			return NULL;
		}
		p = IDL_integer_new(IDL_INTEGER(a).value / IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_ADD:
		p = IDL_integer_new(IDL_INTEGER(a).value + IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_SUB:
		p = IDL_integer_new(IDL_INTEGER(a).value - IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_MOD:
		if (IDL_INTEGER(b).value == 0) {
			yyerror("modulo by zero in constant expression");
			return NULL;
		}
		p = IDL_integer_new(IDL_INTEGER(a).value % IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_SHR:
		p = IDL_integer_new(IDL_INTEGER(a).value >> IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_SHL:
		p = IDL_integer_new(IDL_INTEGER(a).value << IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_AND:
		p = IDL_integer_new(IDL_INTEGER(a).value & IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_OR:
		p = IDL_integer_new(IDL_INTEGER(a).value | IDL_INTEGER(b).value);
		break;

	case IDL_BINOP_XOR:
		p = IDL_integer_new(IDL_INTEGER(a).value ^ IDL_INTEGER(b).value);
		break;
	}

	return p;
}

static IDL_tree IDL_binop_eval_float(enum IDL_binop op, IDL_tree a, IDL_tree b)
{
	IDL_tree p = NULL;

	assert(IDL_NODE_TYPE(a) == IDLN_FLOAT);

	switch (op) {
	case IDL_BINOP_MULT:
		p = IDL_float_new(IDL_FLOAT(a).value * IDL_FLOAT(b).value);
		break;

	case IDL_BINOP_DIV:
		if (IDL_FLOAT(b).value == 0.0) {
			yyerror("Divide by zero in constant expression");
			return NULL;
		}
		p = IDL_float_new(IDL_FLOAT(a).value / IDL_FLOAT(b).value);
		break;

	case IDL_BINOP_ADD:
		p = IDL_float_new(IDL_FLOAT(a).value + IDL_FLOAT(b).value);
		break;

	case IDL_BINOP_SUB:
		p = IDL_float_new(IDL_FLOAT(a).value - IDL_FLOAT(b).value);
		break;

	default:
		break;
	}

	return p;
}

static IDL_tree IDL_binop_eval(enum IDL_binop op, IDL_tree a, IDL_tree b)
{
	assert(IDL_NODE_TYPE(a) == IDL_NODE_TYPE(b));

	switch (IDL_NODE_TYPE(a)) {
	case IDLN_INTEGER: return IDL_binop_eval_integer(op, a, b);
	case IDLN_FLOAT: return IDL_binop_eval_float(op, a, b);
	default: return NULL;
	}
}

static IDL_tree IDL_unaryop_eval_integer(enum IDL_unaryop op, IDL_tree a)
{
	IDL_tree p = NULL;

	assert(IDL_NODE_TYPE(a) == IDLN_INTEGER);

	switch (op) {
	case IDL_UNARYOP_PLUS:
		p = IDL_integer_new(IDL_INTEGER(a).value);
		break;

	case IDL_UNARYOP_MINUS:
		p = IDL_integer_new(-IDL_INTEGER(a).value);
		break;

	case IDL_UNARYOP_COMPLEMENT:
		p = IDL_integer_new(~IDL_INTEGER(a).value);
		break;
	}
       
	return p;
}

static IDL_tree IDL_unaryop_eval_fixed(enum IDL_unaryop op, IDL_tree a)
{
	IDL_tree p = NULL;

	assert(IDL_NODE_TYPE(a) == IDLN_FIXED);

	switch (op) {
	case IDL_UNARYOP_PLUS:
		p = IDL_fixed_new(IDL_FIXED(a).value);
		break;

	default:
		break;
	}
       
	return p;
}

static IDL_tree IDL_unaryop_eval_float(enum IDL_unaryop op, IDL_tree a)
{
	IDL_tree p = NULL;

	assert(IDL_NODE_TYPE(a) == IDLN_FLOAT);

	switch (op) {
	case IDL_UNARYOP_PLUS:
		p = IDL_float_new(IDL_FLOAT(a).value);
		break;

	case IDL_UNARYOP_MINUS:
		p = IDL_float_new(-IDL_FLOAT(a).value);
		break;

	default:
		break;
	}
       
	return p;
}

static IDL_tree IDL_unaryop_eval(enum IDL_unaryop op, IDL_tree a)
{
	switch (IDL_NODE_TYPE(a)) {
	case IDLN_INTEGER: return IDL_unaryop_eval_integer(op, a);
	case IDLN_FIXED: return IDL_unaryop_eval_fixed(op, a);
	case IDLN_FLOAT: return IDL_unaryop_eval_float(op, a);
	default: return NULL;
	}
}

/*
 * Local variables:
 * mode: C
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 */