Merge pull request #2245 from jwillemsen/jwi-stringviewexception
[ACE_TAO.git] / TAO / TAO_IDL / fe / idl.ypp
blob04662cac902d31d04a89e18a40f3c551994ef944
1 /*
3 COPYRIGHT
5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc.  Printed in the United
6 States of America.  All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in whichlong
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license.  Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California  94043
58 NOTE:
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
63  */
65 /**
66  * \file idl.ypp
67  * \brief Bison grammar for IDL
68  */
70 /* Declarations */
73 #include <utl_identifier.h>
74 #include <utl_err.h>
75 #include <utl_string.h>
76 #include <utl_strlist.h>
77 #include <utl_namelist.h>
78 #include <utl_exprlist.h>
79 #include <utl_labellist.h>
80 #include <utl_decllist.h>
82 #include <global_extern.h>
83 #include <nr_extern.h>
85 #include <ast_argument.h>
86 #include <ast_array.h>
87 #include <ast_attribute.h>
88 #include <ast_field.h>
89 #include <ast_fixed.h>
90 #include <ast_expression.h>
91 #include <ast_operation.h>
92 #include <ast_generator.h>
93 #include <ast_template_module.h>
94 #include <ast_template_module_inst.h>
95 #include <ast_template_module_ref.h>
96 #include <ast_typedef.h>
97 #include <ast_valuebox.h>
98 #include <ast_valuetype.h>
99 #include <ast_valuetype_fwd.h>
100 #include <ast_eventtype.h>
101 #include <ast_eventtype_fwd.h>
102 #include <ast_component.h>
103 #include <ast_component_fwd.h>
104 #include <ast_home.h>
105 #include <ast_porttype.h>
106 #include <ast_connector.h>
107 #include <ast_uses.h>
108 #include <ast_constant.h>
109 #include <ast_union.h>
110 #include <ast_union_fwd.h>
111 #include <ast_structure_fwd.h>
112 #include <ast_extern.h>
113 #include <ast_enum.h>
114 #include <ast_root.h>
115 #include <ast_sequence.h>
116 #include <ast_string.h>
117 #include <ast_factory.h>
118 #include <ast_finder.h>
119 #include <ast_exception.h>
120 #include <ast_param_holder.h>
121 #include <ast_visitor_tmpl_module_inst.h>
122 #include <ast_visitor_tmpl_module_ref.h>
123 #include <ast_visitor_context.h>
124 #include <ast_annotation_appl.h>
125 #include <ast_union_branch.h>
126 #include <ast_enum_val.h>
127 #include <ast_annotation_member.h>
128 #include <ast_provides.h>
129 #include <ast_emits.h>
130 #include <ast_publishes.h>
131 #include <ast_consumes.h>
132 #include <ast_extended_port.h>
133 #include <ast_mirror_port.h>
134 #include <ast_map.h>
136 #include <fe_declarator.h>
137 #include <fe_interface_header.h>
138 #include <fe_obv_header.h>
139 #include <fe_component_header.h>
140 #include <fe_home_header.h>
141 #include <fe_utils.h>
143 void tao_yyerror (const char *);
144 int tao_yylex (void);
145 extern "C" int tao_yywrap (void);
147 extern char tao_yytext[];
148 extern int tao_yyleng;
150 AST_Enum *tao_enum_constant_decl = 0;
151 AST_String *tao_string_decl = 0;
152 AST_Expression::ExprType t_param_const_type = AST_Expression::EV_none;
153 bool stack_based_lookup_for_primary_expr = false;
155 #define TAO_YYDEBUG_LEXER_TEXT (tao_yytext[tao_yyleng] = '\0', tao_yytext)
156 // Compile Optional Tracing Output for Parser, can be enabled with --bison-trace
157 #define YYDEBUG 1
161  * Declare the type of values in the grammar
162  */
164 %union {
165   AST_Decl                      *dcval;         /* Decl value           */
166   UTL_StrList                   *slval;         /* String list          */
167   UTL_NameList                  *nlval;         /* Name list            */
168   UTL_ExprList                  *elval;         /* Expression list      */
169   UTL_LabelList                 *llval;         /* Label list           */
170   UTL_DeclList                  *dlval;         /* Declaration list     */
171   FE_InterfaceHeader            *ihval;         /* Interface header     */
172   FE_OBVHeader                  *vhval;         /* Valuetype header     */
173   FE_ComponentHeader            *chval;         /* Component header     */
174   FE_HomeHeader                 *hhval;         /* Home header          */
175   AST_Expression                *exval;         /* Expression value     */
176   AST_UnionLabel                *ulval;         /* Union label          */
177   AST_Field                     *ffval;         /* Field value          */
178   AST_Field::Visibility         vival;          /* N/A, pub or priv     */
179   AST_Expression::ExprType      etval;          /* Expression type      */
180   AST_Argument::Direction       dival;          /* Argument direction   */
181   AST_Operation::Flags          ofval;          /* Operation flags      */
182   FE_Declarator                 *deval;         /* Declarator value     */
183   ACE_CDR::Boolean              bval;           /* Boolean value        */
184   ACE_CDR::LongLong             ival;           /* Long Long value      */
185   ACE_CDR::ULongLong            uival;          /* Unsigned long long   */
186   ACE_CDR::Double               dval;           /* Double value         */
187   ACE_CDR::Float                fval;           /* Float value          */
188   ACE_CDR::Char                 cval;           /* Char value           */
189   ACE_CDR::WChar                wcval;          /* WChar value          */
190   ACE_CDR::Fixed                fixval;         /* Fixed point value    */
191   UTL_String                    *sval;          /* String value         */
192   char                          *wsval;         /* WString value        */
193   char                          *strval;        /* char * value         */
194   Identifier                    *idval;         /* Identifier           */
195   UTL_IdList                    *idlist;        /* Identifier list      */
196   AST_Decl::NodeType            ntval;          /* Node type value      */
197   FE_Utils::T_Param_Info        *pival;         /* Template interface param */
198   FE_Utils::T_PARAMLIST_INFO    *plval;         /* List of template params */
199   FE_Utils::T_ARGLIST           *alval;         /* List of template args */
200   AST_Annotation_Appl *annotation_val;
201   AST_Annotation_Appls *annotations_val;
202   AST_Annotation_Appl::Param *annotation_param_val;
203   AST_Annotation_Appl::Params *annotation_params_val;
204   AST_Annotation_Decl *annotation_decl_val;
205   AST_Decls *decls_val;
206   Decl_Annotations_Pair *decl_annotations_pair_val;
207   Decl_Annotations_Pair_Pair* decl_annotations_pair_val_pair;
211  * Token types: These are returned by the lexer
212  */
214 %token <strval> IDENTIFIER
216 %token          IDL_CONST
217 %token          IDL_MODULE
218 %token          IDL_INTERFACE
219 %token          IDL_TYPEDEF
220 %token          IDL_LONG
221 %token          IDL_SHORT
222 %token          IDL_UNSIGNED
223 %token          IDL_DOUBLE
224 %token          IDL_FLOAT
225 %token          IDL_CHAR
226 %token          IDL_WCHAR
227 %token          IDL_OCTET
228 %token          IDL_BOOLEAN
229 %token          IDL_FIXED
230 %token          IDL_ANY
231 %token          IDL_OBJECT
232 %token          IDL_STRUCT
233 %token          IDL_UNION
234 %token          IDL_SWITCH
235 %token          IDL_ENUM
236 %token          IDL_SEQUENCE
237 %token          IDL_STRING
238 %token          IDL_WSTRING
239 %token          IDL_EXCEPTION
240 %token          IDL_CASE
241 %token          IDL_DEFAULT
242 %token          IDL_READONLY
243 %token          IDL_ATTRIBUTE
244 %token          IDL_ONEWAY
245 %token          IDL_IDEMPOTENT
246 %token          IDL_VOID
247 %token          IDL_IN
248 %token          IDL_OUT
249 %token          IDL_INOUT
250 %token          IDL_RAISES
251 %token          IDL_CONTEXT
252 %token          IDL_NATIVE
253 %token          IDL_LOCAL
254                 /* OBV tokens */
255 %token          IDL_ABSTRACT
256 %token          IDL_CUSTOM
257 %token          IDL_FACTORY
258 %token          IDL_PRIVATE
259 %token          IDL_PUBLIC
260 %token          IDL_SUPPORTS
261 %token          IDL_TRUNCATABLE
262 %token          IDL_VALUETYPE
263                 /* Component tokens */
264 %token          IDL_COMPONENT
265 %token          IDL_CONSUMES
266 %token          IDL_EMITS
267 %token          IDL_EVENTTYPE
268 %token          IDL_FINDER
269 %token          IDL_GETRAISES
270 %token          IDL_HOME
271 %token          IDL_IMPORT
272 %token          IDL_MULTIPLE
273 %token          IDL_PRIMARYKEY
274 %token          IDL_PROVIDES
275 %token          IDL_PUBLISHES
276 %token          IDL_SETRAISES
277 %token          IDL_TYPEID
278 %token          IDL_TYPEPREFIX
279 %token          IDL_USES
280 %token          IDL_MANAGES
281                 /* Extended ports tokens  */
282 %token          IDL_TYPENAME
283 %token          IDL_PORT
284 %token          IDL_MIRRORPORT
285 %token          IDL_PORTTYPE
286 %token          IDL_CONNECTOR
287 %token          IDL_ALIAS
289 %token <ival>   IDL_INTEGER_LITERAL
290 %token <uival>  IDL_UINTEGER_LITERAL
291 %token <sval>   IDL_STRING_LITERAL
292 %token <cval>   IDL_CHARACTER_LITERAL
293 %token <dval>   IDL_FLOATING_PT_LITERAL
294 %token <fixval> IDL_FIXED_PT_LITERAL
295 %token          IDL_TRUETOK
296 %token          IDL_FALSETOK
298                 /* stdint like types defined in IDL4.2 7.4.13 */
299 %token          IDL_INT8
300 %token          IDL_UINT8
301 %token          IDL_INT16
302 %token          IDL_UINT16
303 %token          IDL_INT32
304 %token          IDL_UINT32
305 %token          IDL_INT64
306 %token          IDL_UINT64
308 %token <strval> IDL_SCOPE_DELIMITOR
309 %token          IDL_LEFT_SHIFT
310 %token          IDL_RIGHT_SHIFT
311 %token <wcval>  IDL_WCHAR_LITERAL
312 %token <wsval>  IDL_WSTRING_LITERAL
314 %token IDL_ANNOTATION_DECL
315 %token IDL_ANNOTATION_SYMBOL
317 %token IDL_BITFIELD
318 %token IDL_BITMASK
319 %token IDL_BITSET
320 %token IDL_MAP
323  * These are production names:
324  */
326 %type <dcval>   type_spec simple_type_spec constructed_type_spec
327 %type <dcval>   template_type_spec sequence_type_spec string_type_spec map_type_spec
328 %type <dcval>   struct_type enum_type switch_type_spec union_type
329 %type <dcval>   array_declarator op_type_spec wstring_type_spec
330 %type <dcval>   param_type_spec type_dcl type_declarator actual_parameter
331 %type <dcval>   fixed_type_spec
332 %type <dcval>   definition fixed_definition module const_dcl struct_forward_type
333 %type <dcval>   interface_def interface interface_forward
334 %type <dcval>   export operation attribute attribute_readonly attribute_readwrite
335 %type <dcval>   template_module template_module_inst annotation_dcl typeid_dcl
336 %type <dcval>   typeprefix_dcl exception component home_decl
337 %type <dcval>   event_decl event_abs_decl event_forward_decl
338 %type <dcval>   event_abs_forward_decl event_concrete_forward_decl
339 %type <dcval>   porttype_decl connector_decl value_def
340 %type <dcval>   valuetype value_abs_decl value_forward_decl value_box_decl
341 %type <dcval>   value_concrete_decl component_forward_decl component_decl
342 %type <dcval>   init_decl provides_decl uses_decl port_export
343 %type <dcval>   component_export emits_decl publishes_decl consumes_decl
344 %type <dcval>   extended_port_decl
346 %type <idlist>  scoped_name interface_type component_inheritance_spec
347 %type <idlist>  home_inheritance_spec primary_key_spec module_header
348 %type <idlist>  template_module_header
350 %type <slval>   opt_context at_least_one_string_literal
351 %type <slval>   string_literals formal_parameter_names
352 %type <slval>   at_least_one_formal_parameter_name
354 %type <nlval>   at_least_one_scoped_name scoped_names inheritance_spec
355 %type <nlval>   opt_raises opt_getraises opt_setraises supports_spec
357 %type <elval>   at_least_one_array_dim array_dims
359 %type <llval>   at_least_one_case_label case_labels
361 %type <dlval>   at_least_one_declarator declarators
362 %type <dlval>   at_least_one_simple_declarator simple_declarators
364 %type <ihval>   interface_header
366 %type <vhval>   value_header event_rest_of_header
368 %type <chval>   component_header
370 %type <hhval>   home_header
372 %type <exval>   expression const_expr or_expr xor_expr and_expr shift_expr
373 %type <exval>   add_expr mult_expr unary_expr primary_expr literal
374 %type <exval>   positive_int_expr array_dim annotation_member_default
376 %type <ulval>   case_label
378 %type <ffval>   element_spec
380 %type <etval>   const_type integer_type char_type boolean_type
381 %type <etval>   floating_pt_type fixed_type any_type signed_int
382 %type <etval>   unsigned_int base_type_spec octet_type object_type
383 %type <etval>   annotation_member_type
385 %type <dival>   direction
387 %type <ofval>   opt_op_attribute
389 %type <deval>   declarator simple_declarator complex_declarator
391 %type <bval>    opt_truncatable opt_multiple uses_opt_multiple
393 %type <idval>   interface_decl value_decl union_decl struct_decl id
394 %type <idval>   defining_id
395 %type <idval>   event_header event_plain_header event_custom_header
396 %type <idval>   event_abs_header
398 %type <ntval>   formal_parameter_type
400 %type <pival>   formal_parameter
401 %type <plval>   formal_parameters at_least_one_formal_parameter
403 %type <sval>    formal_parameter_name
405 %type <alval>   actual_parameters at_least_one_actual_parameter
407 %type <annotations_val> at_least_one_annotation annotations_maybe
408 %type <annotation_val> annotation_appl
409 %type <annotation_params_val> annotation_appl_params_maybe annotation_appl_params
410 %type <annotation_params_val> named_annotation_appl_params more_named_annotation_appl_params
411 %type <annotation_param_val> named_annotation_appl_param
412 %type <decl_annotations_pair_val> seq_head
414 %type <decl_annotations_pair_val_pair> map_head
416 %type <decls_val> member_i state_member value_element
417 %type <vival> visibility
421  * Production starts here.
422  */
423 start : definitions ;
425 definitions
426         : at_least_one_definition
427         | %empty
428         ;
430 at_least_one_definition
431         /*
432          * This is broken up into 2 rules to avoid a grammer ambiguity which
433          * manifests as bison complaining about shift/reduce conflicts.
434          */
435         : definitions at_least_one_annotation definition
436         {
437           AST_Annotation_Appls *&annotations = $2;
438           AST_Decl *&node = $3;
439           if (node)
440             {
441               node->annotation_appls (*annotations);
442             }
443           else
444             {
445               idl_global->err ()-> unsupported_warning (
446                 "Annotating this is not supported");
447             }
448           delete annotations;
449         }
450         | definitions definition
451         ;
453 definition
454         : fixed_definition
455         | template_module ';'
456         | template_module_inst ';'
457         ;
459 fixed_definition
460         : annotation_dcl
461         {
462           idl_global->set_parse_state (IDL_GlobalData::PS_AnnotationDeclSeen);
463         }
464         ';'
465         {
466           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
467         }
468         | type_dcl
469         {
470           idl_global->set_parse_state (IDL_GlobalData::PS_TypeDeclSeen);
471         }
472         ';'
473         {
474           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
475         }
476         | typeid_dcl
477         {
478           idl_global->set_parse_state (IDL_GlobalData::PS_TypeIdDeclSeen);
479         }
480         ';'
481         {
482           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
483         }
484         | typeprefix_dcl
485         {
486           idl_global->set_parse_state (IDL_GlobalData::PS_TypePrefixDeclSeen);
487         }
488         ';'
489         {
490           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
491         }
492         | const_dcl
493         {
494           idl_global->set_parse_state (IDL_GlobalData::PS_ConstDeclSeen);
495         }
496         ';'
497         {
498           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
499         }
500         | exception
501         {
502           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptDeclSeen);
503         }
504         ';'
505         {
506           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
507         }
508         | interface_def
509         {
510           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceDeclSeen);
511         }
512         ';'
513         {
514           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
515         }
516         | module
517         {
518           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleDeclSeen);
519         }
520         ';'
521         {
522           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
523         }
524         | value_def
525         {
526           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeDeclSeen);
527         }
528         ';'
529         {
530           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
531         }
532         | component
533         {
534           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentDeclSeen);
535         }
536         ';'
537         {
538           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
539         }
540         | home_decl
541         {
542           idl_global->set_parse_state (IDL_GlobalData::PS_HomeDeclSeen);
543         }
544         ';'
545         {
546           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
547         }
548         | event
549         {
550           idl_global->set_parse_state (IDL_GlobalData::PS_EventDeclSeen);
551         }
552         ';'
553         {
554           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
555         }
556         | porttype_decl
557         {
558           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeDeclSeen);
559         }
560         ';'
561         {
562           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
563         }
564         | connector_decl
565         {
566           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorDeclSeen);
567         }
568         ';'
569         {
570           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
571         }
572         | error
573         {
574           idl_global->err ()->syntax_error (idl_global->parse_state ());
575         }
576         ';'
577         {
578           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
579           yyerrok;
580           $$ = 0;
581         }
582         ;
584 module_header
585         : IDL_MODULE
586         {
587           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleSeen);
588         }
589         scoped_name
590         {
591           $<idlist>$ = $3;
592         }
593         ;
595 module
596         : module_header
597         {
598           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleIDSeen);
600           // The module_header rule is common to template module, fixed
601           // module and instantiated template module. In the last
602           // case, a fully scoped name is allowed, but here we
603           // allow only an identifier (a scoped name of length
604           // 1). If not satisfied, we output a parse error with
605           // the appropriate message.
606           if ($1->length () != 1)
607             {
608               idl_global->err ()->syntax_error (
609                 IDL_GlobalData::PS_ModuleIDSeen);
610             }
612           AST_Module *m = 0;
613           UTL_Scope *s = idl_global->scopes ().top_non_null ();
615           /*
616            * Make a new module and add it to the enclosing scope
617            */
618           if (s != 0)
619             {
620               m = idl_global->gen ()->create_module (s, $1);
621               (void) s->fe_add_module (m);
622             }
624           $1->destroy ();
625           delete $1;
626           $1 = 0;
628           /*
629            * Push it on the stack
630            */
631           idl_global->scopes ().push (m);
633           $<dcval>$ = m;
634         }
635         '{'
636         {
637           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleSqSeen);
638         }
639         at_least_one_definition
640         {
641           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleBodySeen);
642         }
643         '}'
644         {
645           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleQsSeen);
646           /*
647            * Finished with this module - pop it from the scope stack.
648            */
650           idl_global->scopes ().pop ();
651           $$ = $<dcval>2;
652         }
653         ;
655 template_module_header
656         : module_header '<'
657         {
658           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleIDSeen);
659         }
660         ;
662 template_module
663         : template_module_header
664         {
665           // The module_header rule is common to template module, fixed
666           // module and instantiated template module. In the last
667           // case, a fully scoped name is allowed, but here we
668           // allow only an identifier (a scoped name of length
669           // 1). If not satisfied, we output a syntax error with
670           // the appropriate message.
671           if ($1->length () != 1)
672             {
673               idl_global->err ()->syntax_error (
674                 IDL_GlobalData::PS_ModuleIDSeen);
675             }
676         }
677         at_least_one_formal_parameter
678         {
679           if (FE_Utils::duplicate_param_id ($3))
680             {
681               idl_global->err ()->duplicate_param_id (
682                 $1);
684               return 1;
685             }
686         }
687         '>'
688         {
689           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleParamsSeen);
691           AST_Template_Module *tm =
692             idl_global->gen ()->create_template_module ($1,
693                                                         $3);
695           UTL_Scope *s = idl_global->scopes ().top_non_null ();
696           AST_Module *m = s->fe_add_module (tm);
698           // We've probably tried to reopen a template module,
699           // going further will cause a crash.
700           if (m == 0)
701             {
702               return 1;
703             }
705           /*
706            * Push it on the stack
707            */
708           idl_global->scopes ().push (tm);
710           // Contained items not part of an alias will get flag set.
711           idl_global->in_tmpl_mod_no_alias (true);
713           // Store these for reference as we parse the scope
714           // of the template module.
715           idl_global->current_params ($3);
716         }
717         '{'
718         {
719           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleSqSeen);
720         }
721         at_least_one_tpl_definition
722         {
723           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleBodySeen);
724         }
725         '}'
726         {
727           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleQsSeen);
729           /*
730            * Finished with this module - pop it from the scope stack.
731            */
732           idl_global->scopes ().pop ();
734           // Unset the flag, the no_alias version because any scope
735           // traversal triggered by an alias would have ended by now.
736           idl_global->in_tmpl_mod_no_alias (false);
738           // Clear the pointer so scoped name lookup will know
739           // that we are no longer in a template module scope.
740           idl_global->current_params (0);
742           $$ = 0;
743         }
744         ;
746 at_least_one_tpl_definition
747         : tpl_definition tpl_definitions
748         ;
750 tpl_definitions
751         : tpl_definitions tpl_definition
752         | %empty
753         ;
755 tpl_definition
756         : fixed_definition
757         | template_module_ref ';'
758         ;
760 template_module_ref
761         : IDL_ALIAS scoped_name
762         {
763           idl_global->set_parse_state (
764             IDL_GlobalData::PS_ModuleRefSeen);
765         }
766         '<' at_least_one_formal_parameter_name '>'
767         {
768           idl_global->set_parse_state (
769             IDL_GlobalData::PS_ModuleRefParamsSeen);
770         }
771         defining_id
772         {
773           idl_global->set_parse_state (
774             IDL_GlobalData::PS_ModuleRefIDSeen);
776           UTL_Scope *s = idl_global->scopes ().top_non_null ();
777           AST_Decl *d =
778             s->lookup_by_name ($2);
780           if (d == 0)
781             {
782               idl_global->err ()->lookup_error ($2);
783               return 1;
784             }
786           AST_Template_Module *ref =
787             dynamic_cast<AST_Template_Module*> (d);
789           if (ref == 0)
790             {
791               idl_global->err ()->template_module_expected (d);
792               return 1;
793             }
795           bool refs_match =
796             ref->match_param_refs ($5,
797                                    s);
799           if (! refs_match)
800             {
801               // Error message is already output.
802               return 1;
803             }
805           UTL_ScopedName sn ($8, 0);
807           AST_Template_Module_Ref *tmr =
808             idl_global->gen ()->create_template_module_ref (
809               &sn,
810               ref,
811               $5);
813           (void) s->fe_add_template_module_ref (tmr);
815           sn.destroy ();
816           $2->destroy ();
817           delete $2;
818           $2 = 0;
820           // Save the current flag value to be restored below.
821           bool itmna_flag = idl_global->in_tmpl_mod_no_alias ();
822           idl_global->in_tmpl_mod_no_alias (false);
823           idl_global->in_tmpl_mod_alias (true);
825           ast_visitor_context ctx;
826           ctx.template_params (ref->template_params ());
827           ast_visitor_tmpl_module_ref v (&ctx);
829           // The implied IDL resulting from this reference is
830           // created here, in the template module scope. Upon
831           // instantiation of the enclosing template module, the
832           // visitor copies this implied IDL to the instantiated
833           // module scope. The extra copy is less than ideal, but
834           // otherwise we have ugly lookup issues when the
835           // referenced template module's contents are referenced
836           // using the aliased scoped name.
837           if (v.visit_template_module_ref (tmr) != 0)
838             {
839               ACE_ERROR ((LM_ERROR,
840                           ACE_TEXT ("visit_template_module_ref")
841                           ACE_TEXT (" failed\n")));
843               idl_global->set_err_count (idl_global->err_count () + 1);
844             }
846           idl_global->in_tmpl_mod_no_alias (itmna_flag);
847           idl_global->in_tmpl_mod_alias (false);
848         }
849         ;
851 template_module_inst
852         : template_module_header
853         {
854           idl_global->set_parse_state (
855             IDL_GlobalData::PS_InstModuleSeen);
856         }
857         at_least_one_actual_parameter '>'
858         {
859           idl_global->set_parse_state (
860             IDL_GlobalData::PS_InstModuleArgsSeen);
861         }
862         defining_id
863         {
864           idl_global->set_parse_state (
865             IDL_GlobalData::PS_InstModuleIDSeen);
867           UTL_Scope *s = idl_global->scopes ().top_non_null ();
868           UTL_ScopedName *sn = $1;
869           AST_Template_Module *ref = 0;
870           AST_Decl *d = s->lookup_by_name (sn);
872           if (d == 0)
873             {
874               idl_global->err ()->lookup_error (sn);
875               return 1;
876             }
877           else
878             {
879               ref = dynamic_cast<AST_Template_Module*> (d);
881               if (ref == 0)
882                 {
883                   idl_global->err ()->template_module_expected (d);
884                   return 1;
885                 }
886             }
888           sn->destroy ();
889           delete sn;
890           sn = 0;
891           $1 = 0;
893           if (! ref->match_arg_names ($3))
894             {
895               return 1;
896             }
898           ACE_NEW_RETURN (sn,
899                           UTL_ScopedName ($6,
900                                            0),
901                           1);
903           AST_Template_Module_Inst *tmi =
904             idl_global->gen ()->create_template_module_inst (
905               sn,
906               ref,
907               $3);
909           (void) s->fe_add_template_module_inst (tmi);
911           ast_visitor_context ctx;
912           ctx.template_args ($3);
913           ast_visitor_tmpl_module_inst v (&ctx);
915           if (v.visit_template_module_inst (tmi) != 0)
916             {
917               ACE_ERROR ((LM_ERROR,
918                           ACE_TEXT ("visit_template_module_inst")
919                           ACE_TEXT (" failed\n")));
921               idl_global->set_err_count (idl_global->err_count () + 1);
922             }
924           $$ = 0;
925         }
926         ;
928 interface_def
929         : interface
930         | interface_forward
931         ;
933 interface
934         : interface_header
935         {
936           UTL_Scope *s = idl_global->scopes ().top_non_null ();
937           AST_Interface *i = 0;
939           FE_InterfaceHeader *header = $1;
940           $1 = 0;
942           /*
943            * Make a new interface node and add it to its enclosing scope.
944            */
945           if (s && header)
946             {
947               i = idl_global->gen ()->create_interface (
948                 header->name (),
949                 header->inherits (),
950                 header->n_inherits (),
951                 header->inherits_flat (),
952                 header->n_inherits_flat (),
953                 header->is_local (),
954                 header->is_abstract ()
955               );
956               AST_Interface::fwd_redefinition_helper (i, s);
957               /*
958                * Add the interface to its definition scope.
959                */
960               s->fe_add_interface (i);
962               // This FE_InterfaceHeader class isn't destroyed with the AST.
963               header->destroy ();
964               delete header;
965             }
967           /*
968            * Push it on the scope stack.
969            */
970           idl_global->scopes ().push (i);
971         }
972         '{'
973         {
974           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceSqSeen);
975         }
976         exports
977         {
978           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceBodySeen);
979         }
980         '}'
981         {
982           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceQsSeen);
984           $$ = dynamic_cast<AST_Decl *> (idl_global->scopes ().top_non_null ());
985           /*
986            * Done with this interface - pop it off the scopes stack
987            */
988           idl_global->scopes ().pop ();
989         }
990         ;
992 interface_decl:
993          IDL_INTERFACE
994          {
995            idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceSeen);
996          }
997          defining_id
998          {
999            idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceIDSeen);
1000            $$ = $3;
1001          }
1002         ;
1004 interface_header :
1005         interface_decl inheritance_spec
1006         {
1007           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1009           if ($2 != 0 && $2->truncatable ())
1010             {
1011               idl_global->err ()->syntax_error (
1012                                       IDL_GlobalData::PS_InheritColonSeen
1013                                     );
1014             }
1016           /*
1017            * Create an AST representation of the information in the header
1018            * part of an interface - this representation contains a computed
1019            * list of all interfaces which this interface inherits from,
1020            * recursively
1021            */
1022           UTL_ScopedName *n = 0;
1023           ACE_NEW_RETURN (n,
1024                           UTL_ScopedName ($1, 0),
1025                           1);
1026           ACE_NEW_RETURN ($$,
1027                           FE_InterfaceHeader (n,
1028                                               $2,
1029                                               false,
1030                                               false,
1031                                               true),
1032                           1);
1034           if (0 != $2)
1035             {
1036               $2->destroy ();
1037               delete $2;
1038               $2 = 0;
1039             }
1040         }
1041         |
1042         IDL_LOCAL interface_decl inheritance_spec
1043         {
1044           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1046           /*
1047            * Create an AST representation of the information in the header
1048            * part of an interface - this representation contains a computed
1049            * list of all interfaces which this interface inherits from,
1050            * recursively
1051            */
1052           UTL_ScopedName *n = 0;
1053           ACE_NEW_RETURN (n,
1054                           UTL_ScopedName ($2, 0),
1055                           1);
1056           ACE_NEW_RETURN ($$,
1057                           FE_InterfaceHeader (n,
1058                                               $3,
1059                                               true,
1060                                               false,
1061                                               true),
1062                           1);
1064           if (0 != $3)
1065             {
1066               $3->destroy ();
1067               delete $3;
1068               $3 = 0;
1069             }
1070         }
1071         |
1072         IDL_ABSTRACT interface_decl inheritance_spec
1073         {
1074           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1076           /*
1077            * Create an AST representation of the information in the header
1078            * part of an interface - this representation contains a computed
1079            * list of all interfaces which this interface inherits from,
1080            * recursively
1081            */
1082           UTL_ScopedName *n = 0;
1083           ACE_NEW_RETURN (n,
1084                           UTL_ScopedName ($2, 0),
1085                           1);
1086           ACE_NEW_RETURN ($$,
1087                           FE_InterfaceHeader (n,
1088                                               $3,
1089                                               false,
1090                                               true,
1091                                               true),
1092                           1);
1094           if (0 != $3)
1095             {
1096               $3->destroy ();
1097               delete $3;
1098               $3 = 0;
1099             }
1100         }
1101         ;
1103 inheritance_spec
1104         : ':' opt_truncatable
1105         {
1106           idl_global->set_parse_state (IDL_GlobalData::PS_InheritColonSeen);
1107         }
1108           at_least_one_scoped_name
1109         {
1110           $4->truncatable ($2);
1111           $$ = $4;
1112         }
1113         | %empty
1114         {
1115           $$ = 0;
1116         }
1117         ;
1119 value_def
1120         : valuetype
1121         | value_abs_decl
1122         | value_forward_decl
1123         | value_box_decl
1124         ;
1126 valuetype
1127         : IDL_CUSTOM value_concrete_decl
1128         {
1129           idl_global->err ()->unsupported_error ("custom is not supported");
1130           $<dcval>$ = $2;
1131         }
1132         | value_concrete_decl
1133         ;
1135 value_concrete_decl :
1136         value_header
1137         {
1138           FE_OBVHeader *&valuetype_header = $1;
1139           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
1140           AST_ValueType *valuetype = 0;
1142           if (scope && valuetype_header)
1143             {
1144               valuetype = idl_global->gen ()->create_valuetype (
1145                 valuetype_header->name (),
1146                 valuetype_header->inherits (),
1147                 valuetype_header->n_inherits (),
1148                 valuetype_header->inherits_concrete (),
1149                 valuetype_header->inherits_flat (),
1150                 valuetype_header->n_inherits_flat (),
1151                 valuetype_header->supports (),
1152                 valuetype_header->n_supports (),
1153                 valuetype_header->supports_concrete (),
1154                 false,
1155                 valuetype_header->truncatable (),
1156                 false);
1158               AST_Interface *valuetype_as_interface =
1159                 dynamic_cast<AST_Interface *> (valuetype);
1160               AST_Interface::fwd_redefinition_helper (
1161                 valuetype_as_interface, scope);
1162               valuetype = dynamic_cast<AST_ValueType *> (
1163                 valuetype_as_interface);
1165               /*
1166                * Add the valuetype to its definition scope
1167                */
1168               scope->fe_add_valuetype (valuetype);
1170               // FE_OBVHeader is not automatically destroyed in the AST
1171               valuetype_header->destroy ();
1172               delete valuetype_header;
1173               valuetype_header = 0;
1174             }
1176           /*
1177            * Push it on the scope stack
1178            */
1179           idl_global->scopes ().push (valuetype);
1181           $<dcval>$ = valuetype;
1182         }
1183         '{'
1184         {
1185           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeSqSeen);
1186         }
1187         value_elements
1188         {
1189           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeBodySeen);
1190         }
1191         '}'
1192         {
1193           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeQsSeen);
1195           AST_ValueType *vt =
1196             dynamic_cast<AST_ValueType*> (
1197                 idl_global->scopes ().top_non_null ()
1198               );
1200           if (vt != 0 && vt->will_have_factory ())
1201             {
1202               idl_global->valuefactory_seen_ = true;
1203             }
1205           /*
1206            * Done with this value type - pop it off the scopes stack
1207            */
1208           idl_global->scopes ().pop ();
1210           $$ = $<dcval>2;
1211         }
1212         ;
1214 value_abs_decl :
1215         IDL_ABSTRACT
1216         value_header
1217         {
1218           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1219           AST_ValueType *v = 0;
1220           AST_Interface *i = 0;
1222           if (s != 0 && $2 != 0)
1223             {
1224               v =
1225                 idl_global->gen ()->create_valuetype (
1226                     $2->name (),
1227                     $2->inherits (),
1228                     $2->n_inherits (),
1229                     $2->inherits_concrete (),
1230                     $2->inherits_flat (),
1231                     $2->n_inherits_flat (),
1232                     $2->supports (),
1233                     $2->n_supports (),
1234                     $2->supports_concrete (),
1235                     true,
1236                     false,
1237                     false
1238                   );
1239               i = dynamic_cast<AST_Interface*> (v);
1240               AST_Interface::fwd_redefinition_helper (i,
1241                                                       s);
1242               /*
1243                * Add the valuetype to its definition scope
1244                */
1245               v = dynamic_cast<AST_ValueType*> (i);
1246               (void) s->fe_add_valuetype (v);
1248               // FE_OBVHeader is not automatically destroyed in the AST
1249               $2->destroy ();
1250               delete $2;
1251               $2 = 0;
1252             }
1254           /*
1255            * Push it on the scope stack.
1256            */
1257           idl_global->scopes ().push (v);
1258         }
1259         '{'
1260         {
1261           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeSqSeen);
1262         }
1263         exports
1264         {
1265           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeBodySeen);
1266         }
1267         '}'
1268         {
1269           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeQsSeen);
1271           /*
1272            * Done with this valuetype - pop it off the scopes stack.
1273            */
1274           idl_global->scopes ().pop ();
1276           $$ = 0;
1277         }
1278         ;
1280 value_header :
1281         value_decl
1282         inheritance_spec
1283         {
1284           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1285         }
1286         supports_spec
1287         {
1288           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
1290           UTL_ScopedName *sn = 0;
1291           ACE_NEW_RETURN (sn,
1292                           UTL_ScopedName ($1, 0),
1293                           1);
1294           ACE_NEW_RETURN ($$,
1295                           FE_OBVHeader (sn,
1296                                         $2,
1297                                         $4,
1298                                         ($2 != 0
1299                                            ? $2->truncatable ()
1300                                            : false)),
1301                           1);
1303           if (0 != $4)
1304             {
1305               $4->destroy ();
1306               delete $4;
1307               $4 = 0;
1308             }
1310           if (0 != $2)
1311             {
1312               $2->destroy ();
1313               delete $2;
1314               $2 = 0;
1315             }
1316         }
1317         ;
1319 value_decl
1320         : IDL_VALUETYPE
1321         {
1322            idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeSeen);
1323         }
1324         defining_id
1325         {
1326           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeIDSeen);
1327           $$ = $3;
1328         }
1329         ;
1331 opt_truncatable :
1332         IDL_TRUNCATABLE
1333         {
1334           $$ = true;
1335         }
1336         | %empty
1337         {
1338           $$ = false;
1339         }
1340         ;
1342 supports_spec :
1343         IDL_SUPPORTS
1344         at_least_one_scoped_name
1345         {
1346           $$ = $2;
1347         }
1348         | %empty
1349         {
1350           $$ = 0;
1351         }
1352         ;
1354 value_forward_decl :
1355         IDL_ABSTRACT
1356         value_decl
1357         {
1358           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1359           UTL_ScopedName n ($2,
1360                             0);
1361           AST_ValueTypeFwd *f = 0;
1362           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeForwardSeen);
1364           /*
1365            * Create a node representing a forward declaration of an
1366            * valuetype. Store it in the enclosing scope
1367            */
1368           if (s != 0)
1369             {
1370               f = idl_global->gen ()->create_valuetype_fwd (&n,
1371                                                             true);
1372               (void) s->fe_add_valuetype_fwd (f);
1373             }
1375           $2->destroy ();
1376           delete $2;
1377           $2 = 0;
1378         }
1379         |
1380         value_decl
1381         {
1382           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1383           UTL_ScopedName n ($1,
1384                             0);
1385           AST_ValueTypeFwd *f = 0;
1386           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeForwardSeen);
1388           /*
1389            * Create a node representing a forward declaration of an
1390            * valuetype. Store it in the enclosing scope
1391            */
1392           if (s != 0)
1393             {
1394               f = idl_global->gen ()->create_valuetype_fwd (&n,
1395                                                             false);
1396               (void) s->fe_add_valuetype_fwd (f);
1397             }
1399           $1->destroy ();
1400           delete $1;
1401           $1 = 0;
1403           $$ = 0;
1404         }
1405         ;
1407 value_box_decl
1408         : value_decl type_spec /* in this order %!?*/
1409         {
1410           idl_global->set_parse_state (IDL_GlobalData::PS_ValueBoxDeclSeen);
1412           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1413           UTL_ScopedName n ($1,
1414                             0);
1416           if (s != 0 && $2 != 0)
1417             {
1418               /*
1419               * Get the type_spec associated with the valuebox
1420               */
1421               AST_Type *tp = 0;
1422               AST_Typedef *td
1423                 = dynamic_cast<AST_Typedef*> ($2);
1425               if (td == 0)
1426                 {
1427                   tp = dynamic_cast<AST_Type*> ($2);
1428                 }
1429               else
1430                 {
1431                   tp = td->primitive_base_type ();
1432                 }
1434               if (tp == 0)
1435                 {
1436                   // The <type_spec> given is a valid type
1437                   idl_global->err ()->not_a_type ($2);
1438                 }
1439               else
1440                 {
1441                   AST_Decl::NodeType nt = tp->node_type ();
1443                   if (nt == AST_Decl::NT_valuetype
1444                       || nt == AST_Decl::NT_eventtype)
1445                     {
1446                       // valuetype is not allowed as <type_spec>
1447                       // for boxed value
1448                       idl_global->err ()->error0 (
1449                           UTL_Error::EIDL_ILLEGAL_BOXED_TYPE
1450                         );
1451                     }
1452                   else
1453                     {
1454                       /*
1455                       * Add the valuebox to its definition scope
1456                       */
1457                       AST_ValueBox *vb =
1458                         idl_global->gen ()->create_valuebox (&n,
1459                                                              tp);
1460                       (void) s->fe_add_valuebox (vb);
1461                     }
1462                 }
1463             }
1465           $1->destroy ();
1466           delete $1;
1467           $1 = 0;
1469           $$ = 0;
1470         }
1471         ;
1473 value_elements
1474         : value_elements at_least_one_annotation value_element
1475         {
1476           AST_Annotation_Appls *&annotations = $2;
1477           AST_Decls *&decls = $3;
1478           if (decls)
1479             {
1480               for (size_t i = 0; i < decls->size (); i++)
1481                 {
1482                   (*decls)[i]->annotation_appls (*annotations);
1483                 }
1484             }
1485           else
1486             {
1487               idl_global->err ()-> unsupported_warning (
1488                 "Annotating this is not supported");
1489             }
1490           delete annotations;
1491           delete decls;
1492         }
1493         | value_elements value_element
1494         {
1495           delete $2;
1496         }
1497         | %empty
1498         ;
1500 value_element
1501         : state_member
1502         | export
1503         {
1504           AST_Decl *&node = $1;
1505           AST_Decls *value = 0;
1506           if (node)
1507             {
1508               value = new AST_Decls;
1509               value->push_back (node);
1510             }
1511           $$ = value;
1512         }
1513         | init_decl
1514         {
1515           AST_Decl *&node = $1;
1516           AST_Decls *value = 0;
1517           if (node)
1518             {
1519               value = new AST_Decls;
1520               value->push_back (node);
1521             }
1522           $<decls_val>$ = value;
1523         }
1524         ';'
1525         {
1526           $$ = $<decls_val>2;
1527         }
1528         ;
1530 visibility
1531         : IDL_PUBLIC
1532         {
1533           $$ = AST_Field::vis_PUBLIC;
1534         }
1535         | IDL_PRIVATE
1536         {
1537           $$ = AST_Field::vis_PRIVATE;
1538         }
1539         ;
1541 state_member
1542         : visibility member_i
1543         {
1544           AST_Field::Visibility &visibility = $1;
1545           AST_Decls *&decls_ptr = $2;
1546           if (decls_ptr)
1547             {
1548               AST_Decls &decls = *decls_ptr;
1549               for (size_t i = 0; i < decls.size (); i++)
1550                 {
1551                   AST_Field *field = dynamic_cast<AST_Field *> (decls[i]);
1552                   if (field)
1553                     {
1554                       field->visibility (visibility);
1555                     }
1556                 }
1557             }
1558           $$ = decls_ptr;
1559         }
1560         ;
1562 exports
1563         : at_least_one_export
1564         | %empty
1565         ;
1567 at_least_one_export
1568         : exports at_least_one_annotation export
1569         {
1570           AST_Annotation_Appls *annotations = $2;
1571           AST_Decl *d = $3;
1572           if (d)
1573             {
1574               d->annotation_appls (*annotations);
1575             }
1576           else
1577             {
1578               idl_global->err ()-> unsupported_warning (
1579                 "Annotating this is not supported");
1580             }
1581           delete annotations;
1582         }
1583         | exports export
1584         ;
1586 export
1587         : type_dcl
1588         {
1589           idl_global->set_parse_state (IDL_GlobalData::PS_TypeDeclSeen);
1590         }
1591         ';'
1592         {
1593           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1594         }
1595         | typeid_dcl
1596         {
1597           idl_global->set_parse_state (IDL_GlobalData::PS_TypeIdDeclSeen);
1598         }
1599         ';'
1600         {
1601           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1602         }
1603         | typeprefix_dcl
1604         {
1605           idl_global->set_parse_state (IDL_GlobalData::PS_TypePrefixDeclSeen);
1606         }
1607         ';'
1608         {
1609           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1610         }
1611         | const_dcl
1612         {
1613           idl_global->set_parse_state (IDL_GlobalData::PS_ConstDeclSeen);
1614         }
1615         ';'
1616         {
1617           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1618         }
1619         | exception
1620         {
1621           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptDeclSeen);
1622         }
1623         ';'
1624         {
1625           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1626         }
1627         | attribute
1628         {
1629           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
1630         }
1631         ';'
1632         {
1633           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1634         }
1635         | operation
1636         {
1637           idl_global->set_parse_state (IDL_GlobalData::PS_OpDeclSeen);
1638         }
1639         ';'
1640         {
1641           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1642         }
1643         | error
1644         {
1645           idl_global->err ()->syntax_error (idl_global->parse_state ());
1646         }
1647         ';'
1648         {
1649           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1650           yyerrok;
1651           $$ = 0;
1652         }
1653         ;
1655 at_least_one_scoped_name :
1656         scoped_name scoped_names
1657         {
1658           ACE_NEW_RETURN ($<nlval>$,
1659                           UTL_NameList ($1,
1660                                         $2),
1661                           1);
1662         }
1663         ;
1665 scoped_names
1666         : scoped_names
1667           ','
1668         {
1669           idl_global->set_parse_state (IDL_GlobalData::PS_SNListCommaSeen);
1670         }
1671         scoped_name
1672         {
1673           idl_global->set_parse_state (IDL_GlobalData::PS_ScopedNameSeen);
1675           UTL_NameList *nl = 0;
1676           ACE_NEW_RETURN (nl,
1677                           UTL_NameList ($4,
1678                                         0),
1679                           1);
1681           if ($1 == 0)
1682             {
1683               $<nlval>$ = nl;
1684             }
1685           else
1686             {
1687               $1->nconc (nl);
1688               $<nlval>$ = $1;
1689             }
1690         }
1691         | %empty
1692         {
1693           $<nlval>$ = 0;
1694         }
1695         ;
1697 scoped_name
1698         : id
1699         {
1700           idl_global->set_parse_state (IDL_GlobalData::PS_SN_IDSeen);
1702           ACE_NEW_RETURN ($$,
1703                           UTL_IdList ($1,
1704                                       0),
1705                           1);
1706         }
1707         | IDL_SCOPE_DELIMITOR
1708         {
1709           idl_global->set_parse_state (IDL_GlobalData::PS_ScopeDelimSeen);
1710         }
1711         id
1712         {
1713           idl_global->set_parse_state (IDL_GlobalData::PS_SN_IDSeen);
1715           Identifier *id = 0;
1716           ACE_NEW_RETURN (id,
1717                           Identifier ($1),
1718                           1);
1719           ACE::strdelete ($1);
1720           $1 = 0;
1721           UTL_IdList *sn = 0;
1722           ACE_NEW_RETURN (sn,
1723                           UTL_IdList ($3,
1724                                       0),
1725                           1);
1726           ACE_NEW_RETURN ($<idlist>$,
1727                           UTL_IdList (id,
1728                                       sn),
1729                           1);
1730         }
1731         | scoped_name
1732           IDL_SCOPE_DELIMITOR
1733         {
1734           idl_global->set_parse_state (IDL_GlobalData::PS_ScopeDelimSeen);
1736           // This cleans up all the non-global "::"s in scoped names.
1737           // If there is a global one, it gets put into the UTL_IdList,
1738           // so we clean it up in the case above.
1739           ACE::strdelete ($2);
1740           $2 = 0;
1741         }
1742         id
1743         {
1744           idl_global->set_parse_state (IDL_GlobalData::PS_SN_IDSeen);
1746           UTL_IdList *sn = 0;
1747           ACE_NEW_RETURN (sn,
1748                           UTL_IdList ($4,
1749                                       0),
1750                           1);
1751           $1->nconc (sn);
1752           $<idlist>$ = $1;
1753         }
1754         ;
1756 id : IDENTIFIER
1757         {
1758           ACE_NEW_RETURN ($$,
1759                           Identifier ($1),
1760                           1);
1761           ACE::strdelete ($1);
1762           $1 = 0;
1763         }
1764         ;
1766 defining_id : IDENTIFIER
1767         {
1768           /* defining_id is a defining identifier
1769              whereas id is usually a reference to a defining identifier */
1770           ACE_NEW_RETURN ($$, Identifier ($1), 1);
1771           ACE::strdelete ($1);
1772           $1 = 0;
1773         }
1774         ;
1776 interface_forward :
1777         interface_decl
1778         {
1779           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1780           UTL_ScopedName n ($1, 0);
1782           if (ACE_OS::strcmp ($1->get_string (),
1783                               "TypeCode") == 0
1784               && !idl_global->in_main_file ())
1785             {
1786               AST_PredefinedType *pdt =
1787                 idl_global->gen ()->create_predefined_type (
1788                                         AST_PredefinedType::PT_pseudo,
1789                                         &n
1790                                       );
1792               s->add_to_scope (pdt);
1794               $1->destroy ();
1795               delete $1;
1796               $1 = 0;
1798               break;
1799             }
1801           AST_InterfaceFwd *f = 0;
1802           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceForwardSeen);
1804           /*
1805            * Create a node representing a forward declaration of an
1806            * interface. Store it in the enclosing scope
1807            */
1808           if (s != 0)
1809             {
1810               f = idl_global->gen ()->create_interface_fwd (&n,
1811                                                             0,
1812                                                             0);
1813               (void) s->fe_add_interface_fwd (f);
1814             }
1816           $1->destroy ();
1817           delete $1;
1818           $1 = 0;
1819         }
1820         |
1821         IDL_LOCAL interface_decl
1822         {
1823           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1824           UTL_ScopedName n ($2,
1825                             0);
1826           AST_InterfaceFwd *f = 0;
1827           idl_global->set_parse_state (
1828                           IDL_GlobalData::PS_InterfaceForwardSeen
1829                         );
1831           /*
1832            * Create a node representing a forward declaration of an
1833            * interface. Store it in the enclosing scope
1834            */
1835           if (s != 0)
1836             {
1837               f = idl_global->gen ()->create_interface_fwd (&n,
1838                                                             1,
1839                                                             0);
1840               (void) s->fe_add_interface_fwd (f);
1841             }
1843           $2->destroy ();
1844           delete $2;
1845           $2 = 0;
1846         }
1847         |
1848         IDL_ABSTRACT interface_decl
1849         {
1850           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1851           UTL_ScopedName n ($2,
1852                             0);
1853           AST_InterfaceFwd *f = 0;
1854           idl_global->set_parse_state (
1855                           IDL_GlobalData::PS_InterfaceForwardSeen
1856                         );
1858           /*
1859            * Create a node representing a forward declaration of an
1860            * interface. Store it in the enclosing scope
1861            */
1862           if (s != 0)
1863             {
1864               f = idl_global->gen ()->create_interface_fwd (&n,
1865                                                             0,
1866                                                             1);
1867               (void) s->fe_add_interface_fwd (f);
1868             }
1870           $2->destroy ();
1871           delete $2;
1872           $2 = 0;
1874           $$ = dynamic_cast<AST_Decl *> (f);
1875         }
1876         ;
1878 const_dcl :
1879         IDL_CONST
1880         {
1881           idl_global->set_parse_state (IDL_GlobalData::PS_ConstSeen);
1882         }
1883         const_type
1884         {
1885           idl_global->set_parse_state (IDL_GlobalData::PS_ConstTypeSeen);
1886         }
1887         defining_id
1888         {
1889           idl_global->set_parse_state (IDL_GlobalData::PS_ConstIDSeen);
1890         }
1891         '='
1892         {
1893           idl_global->set_parse_state (IDL_GlobalData::PS_ConstAssignSeen);
1894         }
1895         expression
1896         {
1897           $$ = 0;
1898           UTL_ScopedName n ($5, 0);
1900           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1901           AST_Constant *c = 0;
1902           idl_global->set_parse_state (IDL_GlobalData::PS_ConstExprSeen);
1904           /*
1905            * Create a node representing a constant declaration. Store
1906            * it in the enclosing scope.
1907            */
1908           if ($9 != 0 && s != 0)
1909             {
1910               AST_Param_Holder *param_holder = $9->param_holder ();
1912               AST_Expression::AST_ExprValue *result =
1913                 $9->check_and_coerce ($3, tao_enum_constant_decl);
1914               tao_enum_constant_decl = 0;
1916               // If the expression is a template parameter place
1917               // holder, 'result' will be 0, but it's ok.
1918               if (result == 0 && param_holder == 0)
1919                 {
1920                   idl_global->err ()->coercion_error ($9, $3);
1921                   $9->destroy ();
1922                   delete $9;
1923                   $9 = 0;
1924                 }
1925               else
1926                 {
1927                   AST_Expression::ExprType et = $3;
1929                   if (param_holder != 0
1930                       && et != param_holder->info ()->const_type_)
1931                     {
1932                       idl_global->err ()->mismatched_template_param (
1933                         param_holder->info ()->name_.c_str ());
1934                     }
1935                   else
1936                     {
1937                       c = idl_global->gen ()->create_constant ($3, $9, &n);
1938                       (void) s->fe_add_constant (c);
1939                       $$ = c;
1940                     }
1941                 }
1943               delete result;
1944               result = 0;
1945             }
1947           $5->destroy ();
1948           delete $5;
1949           $5 = 0;
1950         }
1951         ;
1953 const_type
1954         : integer_type
1955         | char_type
1956         | octet_type
1957         | boolean_type
1958         | floating_pt_type
1959         | fixed_type
1960         | string_type_spec
1961         {
1962           $$ = AST_Expression::EV_string;
1963         }
1964         | wstring_type_spec
1965         {
1966           $$ = AST_Expression::EV_wstring;
1967         }
1968         | scoped_name
1969         {
1970           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1971           AST_PredefinedType *c = 0;
1972           AST_Typedef *t = 0;
1973           UTL_ScopedName *sn = $1;
1975           /*
1976            * If the constant's type is a scoped name, it must resolve
1977            * to a scalar constant type
1978            */
1979           AST_Decl *d =
1980             s->lookup_by_name (sn);
1982           if (s != 0 && d != 0)
1983             {
1984               /*
1985                * Look through typedefs.
1986                */
1987               while (d->node_type () == AST_Decl::NT_typedef)
1988                 {
1989                   t = dynamic_cast<AST_Typedef*> (d);
1991                   if (t == 0)
1992                     {
1993                       break;
1994                     }
1996                   d = t->base_type ();
1997                 }
1999               if (d->node_type () == AST_Decl::NT_pre_defined)
2000                 {
2001                   c = dynamic_cast<AST_PredefinedType*> (d);
2003                   $$ = FE_Utils::PredefinedTypeToExprType (c->pt ());
2004                 }
2005               else if (d->node_type () == AST_Decl::NT_string)
2006                 {
2007                   $$ = AST_Expression::EV_string;
2008                 }
2009               else if (d->node_type () == AST_Decl::NT_wstring)
2010                 {
2011                   $$ = AST_Expression::EV_wstring;
2012                 }
2013               else if (d->node_type () == AST_Decl::NT_enum)
2014                 {
2015                   $$ = AST_Expression::EV_enum;
2016                   tao_enum_constant_decl =
2017                     dynamic_cast<AST_Enum*> (d);
2018                 }
2019               else
2020                 {
2021                   idl_global->err ()->constant_expected (sn, d);
2022                 }
2023             }
2024           else
2025             {
2026               idl_global->err ()->lookup_error (sn);
2027             }
2029           sn->destroy ();
2030           delete sn;
2031           sn = 0;
2032           $1 = 0;
2033         }
2034         ;
2036 expression : const_expr ;
2038 const_expr : or_expr ;
2040 or_expr : xor_expr
2041         | or_expr '|' xor_expr
2042         {
2043           $$ =
2044             idl_global->gen ()->create_expr (
2045                                     AST_Expression::EC_or,
2046                                     $1,
2047                                     $3
2048                                   );
2049         }
2050         ;
2052 xor_expr
2053         : and_expr
2054         | xor_expr '^' and_expr
2055         {
2056           $$ =
2057             idl_global->gen ()->create_expr (
2058                                     AST_Expression::EC_xor,
2059                                     $1,
2060                                     $3
2061                                   );
2062         }
2063         ;
2065 and_expr
2066         : shift_expr
2067         | and_expr '&' shift_expr
2068         {
2069           $$ =
2070             idl_global->gen ()->create_expr (
2071                                     AST_Expression::EC_and,
2072                                     $1,
2073                                     $3
2074                                   );
2075         }
2076         ;
2078 shift_expr
2079         : add_expr
2080         | shift_expr IDL_LEFT_SHIFT add_expr
2081         {
2082           $$ =
2083             idl_global->gen ()->create_expr (
2084                                     AST_Expression::EC_left,
2085                                     $1,
2086                                     $3
2087                                   );
2088         }
2089         | shift_expr IDL_RIGHT_SHIFT add_expr
2090         {
2091           $$ =
2092             idl_global->gen ()->create_expr (
2093                                     AST_Expression::EC_right,
2094                                     $1,
2095                                     $3
2096                                   );
2097         }
2098         ;
2100 add_expr
2101         : mult_expr
2102         | add_expr '+' mult_expr
2103         {
2104           $$ =
2105             idl_global->gen ()->create_expr (
2106                                     AST_Expression::EC_add,
2107                                     $1,
2108                                     $3
2109                                   );
2110         }
2111         | add_expr '-' mult_expr
2112         {
2113           $$ =
2114             idl_global->gen ()->create_expr (
2115                                     AST_Expression::EC_minus,
2116                                     $1,
2117                                     $3
2118                                   );
2119         }
2120         ;
2122 mult_expr
2123         : unary_expr
2124         | mult_expr '*' unary_expr
2125         {
2126           $$ =
2127             idl_global->gen ()->create_expr (
2128                                     AST_Expression::EC_mul,
2129                                     $1,
2130                                     $3
2131                                   );
2132         }
2133         | mult_expr '/' unary_expr
2134         {
2135           $$ =
2136             idl_global->gen ()->create_expr (
2137                                     AST_Expression::EC_div,
2138                                     $1,
2139                                     $3
2140                                   );
2141         }
2142         | mult_expr '%' unary_expr
2143         {
2144           $$ =
2145             idl_global->gen ()->create_expr (
2146                                     AST_Expression::EC_mod,
2147                                     $1,
2148                                     $3
2149                                   );
2150         }
2151         ;
2153 unary_expr
2154         : primary_expr
2155         | '+' primary_expr
2156         {
2157           $$ =
2158             idl_global->gen ()->create_expr (
2159                                     AST_Expression::EC_u_plus,
2160                                     $2,
2161                                     0
2162                                   );
2163         }
2164         | '-' primary_expr
2165         {
2166           $$ =
2167             idl_global->gen ()->create_expr (
2168                                    AST_Expression::EC_u_minus,
2169                                    $2,
2170                                    0
2171                                  );
2172         }
2173         | '~' primary_expr
2174         {
2175           $$ =
2176             idl_global->gen ()->create_expr (
2177                                    AST_Expression::EC_bit_neg,
2178                                    $2,
2179                                    0
2180                                  );
2181         }
2182         ;
2184 primary_expr
2185         : scoped_name
2186         {
2187           UTL_ScopedName *name = $1;
2189           /*
2190            * An expression which is a scoped name is not resolved now,
2191            * but only when it is evaluated (such as when it is assigned
2192            * as a constant value).
2193            */
2194           AST_Expression *expr = 0;
2196           AST_Decl *node = stack_based_lookup_for_primary_expr ?
2197             idl_global->scopes ().lookup_by_name (name) :
2198             idl_global->scopes ().top_non_null ()->lookup_by_name (name);
2199           if (!node)
2200             {
2201               if (!idl_global->ignore_lookup_errors_)
2202                 {
2203                   idl_global->err ()->lookup_error (name);
2204                   return 1;
2205                 }
2206             }
2207           else if (node->node_type () == AST_Decl::NT_const)
2208             {
2209               /*
2210                * If the scoped name is an IDL constant, it
2211                * may be used in an array dim, a string
2212                * bound, or a sequence bound. If so, it
2213                * must be unsigned and > 0. We assign the
2214                * constant's value and type to the
2215                * expression created here so we can check
2216                * them later.
2217                */
2218               AST_Constant *c = dynamic_cast<AST_Constant *> (node);
2219               expr = idl_global->gen ()->create_expr (
2220                   c->constant_value (),
2221                   c->et ());
2222             }
2223           else
2224             {
2225               // An AST_Expression owns the scoped name
2226               // passed in this constructor, so we copy it
2227               // and destroy it below no matter which case
2228               // is followed.
2229               expr = idl_global->gen ()->create_expr (name->copy ());
2230               if (node->node_type () == AST_Decl::NT_enum_val)
2231                 {
2232                   expr->enum_parent (
2233                     dynamic_cast<AST_EnumVal *> (node)->enum_parent ());
2234                 }
2235             }
2237           $<exval>$ = expr;
2238           name->destroy ();
2239           delete name;
2240           $1 = name = 0;
2241         }
2242         | literal
2243         | '(' const_expr ')'
2244         {
2245           $$ = $2;
2246         }
2247         ;
2249 literal
2250         : IDL_INTEGER_LITERAL
2251         {
2252           $$ = idl_global->gen ()->create_expr ($1);
2253         }
2254         | IDL_UINTEGER_LITERAL
2255         {
2256           $$ =
2257             idl_global->gen ()->create_expr ($1);
2258         }
2259         | IDL_STRING_LITERAL
2260         {
2261           $$ = idl_global->gen ()->create_expr ($1);
2262           $1->destroy ();
2263           delete $1;
2264           $1 = 0;
2265         }
2266         | IDL_WSTRING_LITERAL
2267         {
2268           char *wide_string = $1;
2269           $$ = idl_global->gen ()->create_expr (wide_string);
2270           ACE_OS::free (wide_string);
2271           $1 = 0;
2272         }
2273         | IDL_CHARACTER_LITERAL
2274         {
2275           $$ = idl_global->gen ()->create_expr ($1);
2276         }
2277         | IDL_WCHAR_LITERAL
2278         {
2279           ACE_OutputCDR::from_wchar wc ($1);
2280           $$ = idl_global->gen ()->create_expr (wc);
2281         }
2282         | IDL_FIXED_PT_LITERAL
2283         {
2284           $$ = idl_global->gen ()->create_expr ($1);
2285         }
2286         | IDL_FLOATING_PT_LITERAL
2287         {
2288           $$ = idl_global->gen ()->create_expr ($1);
2289         }
2290         | IDL_TRUETOK
2291         {
2292           $$ = idl_global->gen ()->create_expr (true);
2293         }
2294         | IDL_FALSETOK
2295         {
2296           $$ = idl_global->gen ()->create_expr (false);
2297         }
2298         ;
2300 positive_int_expr :
2301         const_expr
2302         {
2303           int good_expression = 1;
2304           $1->evaluate (AST_Expression::EK_positive_int);
2305           AST_Expression::AST_ExprValue *ev = $1->ev ();
2307           /*
2308            * If const_expr is an enum value (AST_EnumVal inherits from
2309            * AST_Constant), the AST_ExprValue will probably not be set,
2310            * but there's no need to check anyway
2311            */
2312           if (ev != 0)
2313             {
2314               switch (ev->et)
2315               {
2316                 case AST_Expression::EV_ushort:
2317                   if (ev->u.usval == 0)
2318                     {
2319                       good_expression = 0;
2320                     }
2322                   break;
2323                 case AST_Expression::EV_ulong:
2324                   if (ev->u.ulval == 0)
2325                     {
2326                       good_expression = 0;
2327                     }
2329                   break;
2330                 case AST_Expression::EV_ulonglong:
2331                   if (ev->u.ullval == 0)
2332                     {
2333                       good_expression = 0;
2334                     }
2336                   break;
2337                 case AST_Expression::EV_octet:
2338                   if (ev->u.oval == 0)
2339                     {
2340                       good_expression = 0;
2341                     }
2343                   break;
2344                 case AST_Expression::EV_bool:
2345                   if (ev->u.bval == 0)
2346                     {
2347                       good_expression = 0;
2348                     }
2350                   break;
2351                 default:
2352                   good_expression = 0;
2353                   break;
2354               }
2355             }
2357           if (good_expression)
2358             {
2359               $$ = $1;
2360             }
2361           else
2362             {
2363               idl_global->err ()->syntax_error (idl_global->parse_state ());
2364             }
2365         }
2366         ;
2368 annotation_dcl
2369         : IDL_ANNOTATION_DECL defining_id '{'
2370         {
2371           if (idl_global->idl_version_ < IDL_VERSION_4)
2372             idl_global->err ()->idl_version_error (
2373               "Annotations are not allowed in IDL versions before 4");
2375           Identifier *id = $2;
2376           UTL_ScopedName name (id, 0);
2377           AST_Annotation_Decl::escape_name (&name);
2378           AST_Annotation_Decl *annotation_decl = idl_global->gen ()->
2379             create_annotation_decl (&name);
2380           idl_global->scopes ().top_non_null ()->
2381             fe_add_annotation_decl (annotation_decl);
2382           idl_global->scopes ().push (annotation_decl);
2383         }
2384         annotation_body '}'
2385         {
2386           Identifier *id = $2;
2387           idl_global->scopes ().pop ();
2388           id->destroy ();
2389           delete id;
2391           $$ = 0;
2392         }
2393         ;
2395 annotation_body
2396         : annotation_body annotation_statement
2397         | %empty
2398         ;
2400 annotation_statement
2401         : annotation_member
2402         | const_dcl ';'
2403         | enum_type ';'
2404         | IDL_TYPEDEF
2405         {
2406           idl_global->set_parse_state (IDL_GlobalData::PS_TypedefSeen);
2407           idl_global->in_typedef (true);
2408         }
2409         type_declarator ';'
2410         ;
2412 annotation_member_type
2413         : const_type
2414         | any_type
2415         ;
2417 annotation_member
2418         : annotation_member_type defining_id annotation_member_default ';'
2419         {
2420           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
2421           UTL_Scope *root = idl_global->scopes ().bottom ();
2423           AST_Expression::ExprType type = $1;
2424           Identifier *name = $2;
2425           // Annotation member names can't clash with C++ keywords
2426           FE_Utils::original_local_name (name);
2427           UTL_ScopedName *scoped_name = new UTL_ScopedName (name, 0);
2428           AST_Expression *default_value = $3;
2430           AST_Decl * type_obj;
2431           switch (type)
2432             {
2433             case AST_Expression::EV_string:
2434             case AST_Expression::EV_wstring:
2435               type_obj = tao_string_decl;
2436               break;
2437             case AST_Expression::EV_enum:
2438               type_obj = tao_enum_constant_decl;
2439               break;
2440             default:
2441               type_obj = root->lookup_primitive_type (type);
2442             }
2444           FE_Declarator *declarator = new FE_Declarator (
2445             scoped_name, FE_Declarator::FD_simple, 0);
2446           AST_Annotation_Member *member = idl_global->gen ()->
2447             create_annotation_member (
2448               type, declarator->compose (type_obj), declarator->name ());
2449           scope->fe_add_annotation_member (member);
2451           declarator->destroy ();
2452           delete declarator;
2454           if (default_value)
2455             {
2456               // Check if types are compatible, else report error
2457               AST_Expression::AST_ExprValue *result =
2458                 default_value->check_and_coerce (type, tao_enum_constant_decl);
2459               tao_enum_constant_decl = 0;
2460               if (result)
2461                 {
2462                   member->value (default_value);
2463                 }
2464               else
2465                 {
2466                   idl_global->err ()->coercion_error (default_value, type);
2467                 }
2468               delete result;
2469             }
2470         }
2471         ;
2473 annotation_member_default
2474         : IDL_DEFAULT const_expr
2475         {
2476           $$ = $2;
2477         }
2478         | %empty
2479         {
2480           $$ = 0;
2481         }
2482         ;
2484 at_least_one_annotation
2485         : annotations_maybe annotation_appl
2486         {
2487           AST_Annotation_Appls *annotations = $1;
2488           AST_Annotation_Appl *annotation = $2;
2489           if (annotation)
2490             {
2491               annotations->add (annotation);
2492             }
2493           $$ = annotations;
2494         }
2495         ;
2497 annotations_maybe
2498         : annotations_maybe annotation_appl
2499         {
2500           AST_Annotation_Appls *annotations = $1;
2501           AST_Annotation_Appl *annotation = $2;
2502           if (annotation)
2503             {
2504               annotations->add (annotation);
2505             }
2506           $$ = annotations;
2507         }
2508         | %empty
2509         {
2510           $$ = new AST_Annotation_Appls ();
2511         }
2512         ;
2514 annotation_appl
2515         : IDL_ANNOTATION_SYMBOL scoped_name
2516         {
2517           if (idl_global->idl_version_ < IDL_VERSION_4)
2518             idl_global->err ()->idl_version_error (
2519               "Annotations are not allowed in IDL versions before 4");
2521           AST_Annotation_Decl *decl = 0;
2522           UTL_ScopedName *name = $2;
2523           AST_Annotation_Decl::escape_name (name);
2525           // Check for Matching Annotation Declaration
2526           AST_Decl *d = idl_global->scopes ().top_non_null ()->
2527             lookup_by_name (name);
2528           if (d)
2529             {
2530               decl = dynamic_cast<AST_Annotation_Decl*> (d);
2531               if (decl)
2532                 {
2533                   idl_global->scopes ().push (decl);
2534                 }
2535             }
2536           else
2537             {
2538               Identifier &id = *name->last_component ();
2539               switch (idl_global->unknown_annotations_)
2540                 {
2541                 default:
2542                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ONCE:
2543                   if (idl_global->unknown_annotations_seen_.insert (id) == 1)
2544                     {
2545                       break;
2546                     }
2547                   idl_global->err ()->lookup_warning (name);
2548                   break;
2549                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ALL:
2550                   idl_global->err ()->lookup_warning (name);
2551                   break;
2552                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_ERROR:
2553                   idl_global->err ()->lookup_error (name);
2554                   break;
2555                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_IGNORE:
2556                   break;
2557                 }
2559               /*
2560                * Ignore lookup errors for parameter values that might depend on
2561                * constants or enums from the missing annotation declaration.
2562                */
2563               idl_global->ignore_lookup_errors_ = true;
2564             }
2566           stack_based_lookup_for_primary_expr = true;
2568           $<annotation_decl_val>$ = decl;
2569         }
2570         annotation_appl_params_maybe
2571         {
2572           idl_global->ignore_lookup_errors_ = false;
2573           stack_based_lookup_for_primary_expr = false;
2574           AST_Annotation_Appl *appl = 0;
2575           UTL_ScopedName *name = $2;
2576           AST_Annotation_Decl *decl = $<annotation_decl_val>3;
2577           AST_Annotation_Appl::Params *params = $4;
2579           if (decl)
2580             {
2581               appl = idl_global->gen ()->create_annotation_appl (name, params);
2582               appl->apply_from (decl);
2583               idl_global->scopes ().pop ();
2584             }
2585           else
2586             {
2587               AST_Annotation_Appl::delete_params (params);
2588             }
2590           if (name)
2591             {
2592               name->destroy ();
2593               delete name;
2594             }
2596           $$ = appl;
2597         }
2598         ;
2600 annotation_appl_params_maybe
2601         : '(' annotation_appl_params ')'
2602         {
2603           $$ = $2;
2604         }
2605         | %empty
2606         {
2607           $$ = 0;
2608         }
2609         ;
2611 annotation_appl_params
2612         : const_expr
2613         {
2614           AST_Annotation_Appl::Params *params = new AST_Annotation_Appl::Params;
2615           AST_Annotation_Appl::Param *param = new AST_Annotation_Appl::Param;
2616           param->id = 0;
2617           param->expr = $1;
2618           params->push (param);
2619           $$ = params;
2620         }
2621         | named_annotation_appl_params
2622         {
2623           $$ = $1;
2624         }
2625         | %empty
2626         {
2627           $$ = 0;
2628         }
2629         ;
2631 named_annotation_appl_params
2632         : named_annotation_appl_param more_named_annotation_appl_params
2633         {
2634           AST_Annotation_Appl::Params *params = $2;
2635           params->push ($1);
2636           $$ = params;
2637         }
2639 more_named_annotation_appl_params
2640         : ',' named_annotation_appl_param more_named_annotation_appl_params
2641         {
2642           AST_Annotation_Appl::Params *params = $3;
2643           params->push ($2);
2644           $$ = params;
2645         }
2646         | %empty
2647         {
2648           $$ = new AST_Annotation_Appl::Params;
2649         }
2650         ;
2652 named_annotation_appl_param
2653         : id '=' const_expr
2654         {
2655           AST_Annotation_Appl::Param *param = new AST_Annotation_Appl::Param;
2656           param->id = $1;
2657           // Annotation Member Names Can't Clash with C++ keywords
2658           FE_Utils::original_local_name (param->id);
2659           param->expr = $3;
2660           $$ = param;
2661         }
2662         ;
2664 type_dcl
2665         : IDL_TYPEDEF
2666         {
2667           idl_global->set_parse_state (IDL_GlobalData::PS_TypedefSeen);
2668           idl_global->in_typedef (true);
2669         }
2670         type_declarator
2671         {
2672           $$ = $3;
2673         }
2674         | struct_type
2675         {
2676           $$ = $1;
2677         }
2678         | union_type
2679         {
2680           $$ = $1;
2681         }
2682         | enum_type
2683         {
2684           $$ = $1;
2685         }
2686         | IDL_NATIVE simple_declarator
2687         {
2688           UTL_Scope *s = idl_global->scopes ().top_non_null ();
2689           AST_Native *node = 0;
2690           idl_global->set_parse_state (IDL_GlobalData::PS_NativeSeen);
2692           /*
2693            * Create a node representing a Native and add it to its
2694            * enclosing scope
2695            */
2696           if (s != 0)
2697             {
2698               node =
2699                 idl_global->gen ()->create_native (
2700                                         $2->name ()
2701                                       );
2702               /*
2703                * Add it to its defining scope
2704                */
2705               (void) s->fe_add_native (node);
2706             }
2708           $2->destroy ();
2709           delete $2;
2710           $2 = 0;
2712           $$ = 0;
2713         }
2714         | constructed_forward_type_spec
2715         {
2716           $$ = 0;
2717         }
2718         ;
2720 type_declarator :
2721         type_spec
2722         {
2723           idl_global->set_parse_state (IDL_GlobalData::PS_TypeSpecSeen);
2724         }
2725         at_least_one_declarator
2726         {
2727           AST_Decl *type_spec = $1;
2728           UTL_DeclList *decls = $3;
2730           UTL_Scope *s = idl_global->scopes ().top_non_null ();
2731           FE_Declarator *d = 0;
2732           AST_Typedef *t = 0;
2733           unsigned long index = 0UL;
2734           idl_global->set_parse_state (IDL_GlobalData::PS_DeclaratorsSeen);
2736           /*
2737            * Create a list of type renamings. Add them to the
2738            * enclosing scope
2739            */
2740           if (s && type_spec && decls)
2741             {
2742               for (UTL_DecllistActiveIterator l (decls); !l.is_done (); l.next ())
2743                 {
2744                   d = l.item ();
2745                   if (d == 0)
2746                     {
2747                       continue;
2748                     }
2750                   AST_Type *tp = d->compose (type_spec);
2751                   if (tp == 0)
2752                     {
2753                       continue;
2754                     }
2756                   if (AST_Decl::NT_except == tp->node_type ())
2757                     {
2758                       idl_global->err ()->not_a_type (tp);
2759                       continue;
2760                     }
2762                   t = idl_global->gen ()->create_typedef (tp,
2763                                                           d->name (),
2764                                                           s->is_local (),
2765                                                           s->is_abstract ());
2767                   // If the base type is a sequence or array, the typedef
2768                   // constructor sets owns_base_type_ to true. But if
2769                   // there is a comma-separated list of such typedefs,
2770                   // the base type can be destroyed only once. In all
2771                   // other cases, the line below has no effect.
2772                   if (index++ > 0)
2773                     {
2774                       t->owns_base_type (false);
2775                     }
2777                   (void) s->fe_add_typedef (t);
2778                   idl_global->in_typedef (false);
2779                 }
2781               // This FE_Declarator class isn't destroyed with the AST.
2782               decls->destroy ();
2783               delete decls;
2784               $3 = decls = 0;
2785             }
2787           $$ = t;
2788         }
2789         ;
2791 type_spec
2792         : simple_type_spec
2793         | constructed_type_spec
2794         ;
2796 simple_type_spec
2797         : base_type_spec
2798         {
2799           $$ =
2800             idl_global->scopes ().bottom ()->lookup_primitive_type (
2801                                                  $1
2802                                                );
2803         }
2804         | template_type_spec
2805         | scoped_name
2806         {
2807           UTL_Scope *s = idl_global->scopes ().top_non_null ();
2808           AST_Decl *d = 0;
2810           if (s != 0)
2811             {
2812               d =
2813                 s->lookup_by_name ($1);
2814             }
2816           if (d == 0)
2817             {
2818               idl_global->err ()->lookup_error ($1);
2819             }
2820           else
2821             {
2822               d->last_referenced_as ($1);
2823             }
2826           $$ = d;
2827         }
2828         ;
2830 base_type_spec
2831         : integer_type
2832         | floating_pt_type
2833         | char_type
2834         | boolean_type
2835         | octet_type
2836         | fixed_type
2837         | any_type
2838         | object_type
2839         ;
2841 template_type_spec
2842         : sequence_type_spec
2843         | string_type_spec
2844         | wstring_type_spec
2845         | fixed_type_spec
2846         | map_type_spec
2847         ;
2849 constructed_type_spec
2850         : struct_type
2851         | union_type
2852         | enum_type
2853         ;
2855 constructed_forward_type_spec
2856         : struct_forward_type
2857         | union_forward_type
2858         ;
2860 at_least_one_declarator :
2861         declarator declarators
2862         {
2863           ACE_NEW_RETURN ($$,
2864                           UTL_DeclList ($1,
2865                                         $2),
2866                           1);
2867         }
2868         ;
2870 declarators
2871         : declarators
2872           ','
2873         {
2874           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsCommaSeen);
2875         }
2876         declarator
2877         {
2878           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsDeclSeen);
2880           UTL_DeclList *dl = 0;
2881           ACE_NEW_RETURN (dl,
2882                           UTL_DeclList ($4,
2883                                         0),
2884                           1);
2886           if ($1 == 0)
2887             {
2888               $<dlval>$ = dl;
2889             }
2890           else
2891             {
2892               $1->nconc (dl);
2893               $<dlval>$ = $1;
2894             }
2895         }
2896         | %empty
2897         {
2898           $<dlval>$ = 0;
2899         }
2900         ;
2902 declarator
2903         : simple_declarator
2904         | complex_declarator
2905         ;
2907 at_least_one_simple_declarator :
2908         simple_declarator simple_declarators
2909         {
2910           ACE_NEW_RETURN ($<dlval>$,
2911                           UTL_DeclList ($1,
2912                                         $2),
2913                           1);
2914         }
2915         ;
2917 simple_declarators
2918         : simple_declarators
2919           ','
2920         {
2921           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsCommaSeen);
2922         }
2923         simple_declarator
2924         {
2925           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsDeclSeen);
2927           UTL_DeclList *dl = 0;
2928           ACE_NEW_RETURN (dl,
2929                           UTL_DeclList ($4,
2930                                         0),
2931                           1);
2933           if ($1 == 0)
2934             {
2935               $<dlval>$ = dl;
2936             }
2937           else
2938             {
2939               $1->nconc (dl);
2940               $<dlval>$ = $1;
2941             }
2942         }
2943         | %empty
2944         {
2945           $<dlval>$ = 0;
2946         }
2947         ;
2949 simple_declarator :
2950         defining_id
2951         {
2952           UTL_ScopedName *sn = 0;
2953           ACE_NEW_RETURN (sn,
2954                           UTL_ScopedName ($1,
2955                                           0),
2956                           1);
2957           ACE_NEW_RETURN ($<deval>$,
2958                           FE_Declarator (sn,
2959                                          FE_Declarator::FD_simple,
2960                                          0),
2961                           1);
2962         }
2963         ;
2965 complex_declarator :
2966         array_declarator
2967         {
2968           UTL_ScopedName *sn = 0;
2969           ACE_NEW_RETURN (sn,
2970                           UTL_ScopedName (
2971                               $1->local_name ()->copy (),
2972                               0
2973                             ),
2974                           1);
2975           ACE_NEW_RETURN ($<deval>$,
2976                           FE_Declarator (sn,
2977                                          FE_Declarator::FD_complex,
2978                                          $1),
2979                           1);
2980         }
2981         ;
2983 integer_type
2984         : signed_int
2985         | unsigned_int
2986         ;
2988 signed_int
2989         : IDL_LONG
2990         {
2991           $$ = AST_Expression::EV_long;
2992         }
2993         | IDL_LONG IDL_LONG
2994         {
2995           $$ = AST_Expression::EV_longlong;
2996         }
2997         | IDL_SHORT
2998         {
2999           $$ = AST_Expression::EV_short;
3000         }
3001         | IDL_INT8
3002         {
3003           $$ = AST_Expression::EV_int8;
3004         }
3005         | IDL_INT16
3006         {
3007           $$ = AST_Expression::EV_short;
3008         }
3009         | IDL_INT32
3010         {
3011           $$ = AST_Expression::EV_long;
3012         }
3013         | IDL_INT64
3014         {
3015           $$ = AST_Expression::EV_longlong;
3016         }
3017         ;
3019 unsigned_int
3020         : IDL_UNSIGNED IDL_LONG
3021         {
3022           $$ = AST_Expression::EV_ulong;
3023         }
3024         | IDL_UNSIGNED IDL_LONG IDL_LONG
3025         {
3026           $$ = AST_Expression::EV_ulonglong;
3027         }
3028         | IDL_UNSIGNED IDL_SHORT
3029         {
3030           $$ = AST_Expression::EV_ushort;
3031         }
3032         | IDL_UINT8
3033         {
3034           $$ = AST_Expression::EV_uint8;
3035         }
3036         | IDL_UINT16
3037         {
3038           $$ = AST_Expression::EV_ushort;
3039         }
3040         | IDL_UINT32
3041         {
3042           $$ = AST_Expression::EV_ulong;
3043         }
3044         | IDL_UINT64
3045         {
3046           $$ = AST_Expression::EV_ulonglong;
3047         }
3048         ;
3050 floating_pt_type
3051         : IDL_DOUBLE
3052         {
3053           $$ = AST_Expression::EV_double;
3054         }
3055         | IDL_FLOAT
3056         {
3057           $$ = AST_Expression::EV_float;
3058         }
3059         | IDL_LONG IDL_DOUBLE
3060         {
3061           $$ = AST_Expression::EV_longdouble;
3062         }
3063         ;
3065 fixed_type
3066         : IDL_FIXED
3067         {
3068           $$ = AST_Expression::EV_fixed;
3069         }
3070         ;
3072 char_type
3073         : IDL_CHAR
3074         {
3075           $$ = AST_Expression::EV_char;
3076         }
3077         | IDL_WCHAR
3078         {
3079           $$ = AST_Expression::EV_wchar;
3080         }
3081         ;
3083 octet_type
3084         : IDL_OCTET
3085         {
3086           $$ = AST_Expression::EV_octet;
3087         }
3088         ;
3090 boolean_type
3091         : IDL_BOOLEAN
3092         {
3093           $$ = AST_Expression::EV_bool;
3094         }
3095         ;
3097 any_type
3098         : IDL_ANY
3099         {
3100           $$ = AST_Expression::EV_any;
3101         }
3102         ;
3104 object_type
3105         : IDL_OBJECT
3106         {
3107           $$ = AST_Expression::EV_object;
3108         }
3109         ;
3111 struct_decl :
3112         IDL_STRUCT
3113         {
3114           idl_global->set_parse_state (IDL_GlobalData::PS_StructSeen);
3115         }
3116         defining_id
3117         {
3118           idl_global->set_parse_state (IDL_GlobalData::PS_StructIDSeen);
3119           $$ = $3;
3120         }
3121         ;
3124 struct_type
3125         : struct_decl
3126         {
3127           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3128           UTL_ScopedName n ($1, 0);
3129           AST_Structure *d = 0;
3131           /*
3132            * Create a node representing a struct declaration. Add it
3133            * to the enclosing scope
3134            */
3135           if (s != 0)
3136             {
3137               d =
3138                 idl_global->gen ()->create_structure (
3139                                         &n,
3140                                         s->is_local (),
3141                                         s->is_abstract ()
3142                                       );
3143               AST_Structure::fwd_redefinition_helper (d, s);
3144               (void) s->fe_add_structure (d);
3145             }
3147           /*
3148            * Push the scope of the struct on the scopes stack.
3149            */
3150           idl_global->scopes ().push (d);
3152           $1->destroy ();
3153           delete $1;
3154           $1 = 0;
3155         }
3156         '{'
3157         {
3158           idl_global->set_parse_state (IDL_GlobalData::PS_StructSqSeen);
3159         }
3160         struct_body
3161         {
3162           /*
3163            * Done with this struct. Pop its scope off the scopes stack.
3164            */
3165           $$ = dynamic_cast<AST_Structure*> (
3166                    idl_global->scopes ().top_non_null ()
3167                  );
3168           idl_global->scopes ().pop ();
3169         }
3170         ;
3172 struct_body
3173         : '}'
3174         {
3175           if (idl_global->idl_version_ < IDL_VERSION_4)
3176             idl_global->err ()->idl_version_error (
3177               "Empty structs are not allowed in IDL versions before 4");
3179           idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen);
3180         }
3181         | struct_body_with_members
3182         ;
3184 struct_body_with_members
3185         : member members
3186         {
3187           idl_global->set_parse_state (IDL_GlobalData::PS_StructBodySeen);
3188         }
3189         '}'
3190         {
3191           idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen);
3192         }
3193         ;
3195 members
3196         : members member
3197         | %empty
3198         ;
3200 member
3201         : annotations_maybe member_i
3202         {
3203           AST_Annotation_Appls *annotations = $1;
3204           AST_Decls *members = $2;
3205           if (annotations && members)
3206             {
3207               for (size_t i = 0; i < members->size (); i++)
3208                 {
3209                   (*members)[i]->annotation_appls (*annotations);
3210                 }
3211             }
3212           delete annotations;
3213           delete members;
3214         }
3215         ;
3217 member_i :
3218         type_spec
3219         {
3220           idl_global->set_parse_state (IDL_GlobalData::PS_MemberTypeSeen);
3221         }
3222         at_least_one_declarator
3223         {
3224           idl_global->set_parse_state (IDL_GlobalData::PS_MemberDeclsSeen);
3225         }
3226         ';'
3227         {
3228           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3229           FE_Declarator *d = 0;
3230           AST_Field *f = 0;
3231           idl_global->set_parse_state (IDL_GlobalData::PS_MemberDeclsCompleted);
3232           AST_Decls *members = 0;
3234           /*
3235            * Check for illegal recursive use of type.
3236            */
3237           if ($1 != 0
3238               && AST_illegal_recursive_type ($1))
3239             {
3240               idl_global->err ()->error1 (UTL_Error::EIDL_RECURSIVE_TYPE,
3241                                           $1);
3242             }
3243           /*
3244            * Create a node representing a struct or exception member
3245            * Add it to the enclosing scope.
3246            */
3247           else if (s && $1 && $3)
3248             {
3249               members = new AST_Decls;
3250               for (UTL_DecllistActiveIterator l ($3);
3251                    !l.is_done ();
3252                    l.next ())
3253                 {
3254                   d = l.item ();
3256                   if (d == 0)
3257                     {
3258                       continue;
3259                     }
3261                   AST_Type *tp = d->compose ($1);
3263                   if (tp == 0)
3264                     {
3265                       continue;
3266                     }
3268                   f = idl_global->gen ()->create_field (tp, d->name ());
3269                   members->push_back (f);
3270                   (void) s->fe_add_field (f);
3271                 }
3272             }
3274           $3->destroy ();
3275           delete $3;
3276           $3 = 0;
3278           $$ = members;
3279         }
3280         | error
3281         {
3282           idl_global->err ()->syntax_error (idl_global->parse_state ());
3283         }
3284         ';'
3285         {
3286           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
3287           yyerrok;
3288         }
3289         ;
3291 union_decl :
3292         IDL_UNION
3293         {
3294           idl_global->set_parse_state (IDL_GlobalData::PS_UnionSeen);
3295         }
3296         defining_id
3297         {
3298           idl_global->set_parse_state (IDL_GlobalData::PS_UnionIDSeen);
3299           $$ = $3;
3300         }
3301         ;
3303 union_type
3304         : union_decl IDL_SWITCH
3305         {
3306           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchSeen);
3307         }
3308         '('
3309         {
3310           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3311           UTL_ScopedName n ($1, 0);
3312           AST_Union *u = 0;
3313           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchOpenParSeen);
3315           /*
3316            * Create a node representing an empty union. Add it to its enclosing
3317            * scope.
3318            */
3319           if (s != 0)
3320             {
3321               u = idl_global->gen ()->create_union (0,
3322                                                     &n,
3323                                                     s->is_local (),
3324                                                     s->is_abstract ());
3326               AST_Structure *st = dynamic_cast<AST_Structure*> (u);
3327               AST_Structure::fwd_redefinition_helper (st, s);
3328               u = dynamic_cast<AST_Union*> (st);
3329               (void) s->fe_add_union (u);
3330             }
3332           /*
3333            * Push the scope of the union on the scopes stack
3334            */
3335           idl_global->scopes ().push (u);
3337           /*
3338            * Don't delete $1 yet; we'll need it a bit later.
3339            */
3340         }
3341         annotations_maybe switch_type_spec
3342         {
3343           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchTypeSeen);
3344         }
3345         ')'
3346         {
3347           /*
3348            * The top of the scopes must be an empty union we added after we
3349            * encountered 'union <id> switch ('. Now we are ready to add a
3350            * correct one. Temporarily remove the top so that we setup the
3351            * correct union in a right scope.
3352            */
3353           UTL_Scope *top = idl_global->scopes ().top_non_null ();
3354           idl_global->scopes ().pop ();
3355           AST_Annotation_Appls *disc_annotations = $6;
3357           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3358           UTL_ScopedName n ($1, 0);
3359           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchCloseParSeen);
3361           /*
3362            * Create a node representing a union.
3363            */
3364           if ($7 != 0 && s != 0)
3365             {
3366               AST_ConcreteType *tp =
3367                 dynamic_cast<AST_ConcreteType*> ($7);
3369               if (tp == 0)
3370                 {
3371                   idl_global->err ()->not_a_type ($7);
3372                 }
3373               else
3374                 {
3375                   /* Create a union with a correct discriminator. */
3376                   AST_Union *u = 0;
3377                   u = idl_global->gen ()->create_union (tp,
3378                                                         &n,
3379                                                         s->is_local (),
3380                                                         s->is_abstract ());
3382                   /* Narrow the enclosing scope. */
3383                   AST_Union *e = dynamic_cast<AST_Union*> (top);
3385                   e->redefine (u);
3386                   e->disc_annotations (*disc_annotations); // Set Discriminator Annotations
3388                   u->destroy ();
3389                   delete u;
3390                 }
3391             }
3393           /*
3394            * Restore the top.
3395            */
3396           idl_global->scopes ().push (top);
3398           $1->destroy ();
3399           delete $1;
3400           $1 = 0;
3402           delete disc_annotations;
3403         }
3404         '{'
3405         {
3406           idl_global->set_parse_state (IDL_GlobalData::PS_UnionSqSeen);
3407         }
3408         at_least_one_case_branch
3409         {
3410           idl_global->set_parse_state (IDL_GlobalData::PS_UnionBodySeen);
3411         }
3412         '}'
3413         {
3414           idl_global->set_parse_state (IDL_GlobalData::PS_UnionQsSeen);
3416           /*
3417            * Done with this union. Pop its scope from the scopes stack.
3418            */
3419           $$ = dynamic_cast<AST_Union*> (
3420                    idl_global->scopes ().top_non_null ()
3421                  );
3423           if ($$ != 0)
3424             {
3425               idl_global->scopes ().pop ();
3426             }
3427         }
3428         ;
3430 switch_type_spec :
3431         integer_type
3432         {
3433           $$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
3434         }
3435         | char_type
3436         {
3437           if ($1 == AST_Expression::EV_wchar && idl_global->idl_version_ < IDL_VERSION_4)
3438             idl_global->err ()->idl_version_error (
3439               "Using wchar as a union discriminator isn't allowed in IDL versions before 4");
3441           $$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
3442         }
3443         | octet_type
3444         {
3445           if (idl_global->idl_version_ < IDL_VERSION_4)
3446             idl_global->err ()->idl_version_error (
3447               "Using octet as a union discriminator isn't allowed in IDL versions before 4");
3449           $$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
3450         }
3451         | boolean_type
3452         {
3453           $$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
3454         }
3455         | enum_type
3456         | scoped_name
3457         {
3458           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3459           AST_Decl *d = 0;
3460           AST_PredefinedType *p = 0;
3461           AST_Typedef *t = 0;
3462           bool found = false;
3464           /*
3465            * The discriminator is a scoped name. Try to resolve to
3466            * one of the scalar types or to an enum. Thread through
3467            * typedef's to arrive at the base type at the end of the
3468            * chain.
3469            */
3470           d = s->lookup_by_name ($1);
3472           if (s != 0 && d != 0)
3473             {
3474               while (!found)
3475                 {
3476                   switch (d->node_type ())
3477                   {
3478                     case AST_Decl::NT_enum:
3479                       $$ = d;
3480                       found = true;
3481                       break;
3482                     case AST_Decl::NT_pre_defined:
3483                       p = dynamic_cast<AST_PredefinedType*> (d);
3485                       if (p != 0)
3486                         {
3487                           switch (p->pt ())
3488                           {
3489                             case AST_PredefinedType::PT_long:
3490                             case AST_PredefinedType::PT_ulong:
3491                             case AST_PredefinedType::PT_longlong:
3492                             case AST_PredefinedType::PT_ulonglong:
3493                             case AST_PredefinedType::PT_short:
3494                             case AST_PredefinedType::PT_ushort:
3495                             case AST_PredefinedType::PT_int8:
3496                             case AST_PredefinedType::PT_uint8:
3497                             case AST_PredefinedType::PT_char:
3498                             case AST_PredefinedType::PT_boolean:
3499                               $$ = p;
3500                               found = true;
3501                               break;
3502                             case AST_PredefinedType::PT_wchar:
3503                             case AST_PredefinedType::PT_octet:
3504                               if (idl_global->idl_version_ < IDL_VERSION_4)
3505                                 idl_global->err ()->idl_version_error (
3506                                   "Using octet or wchar as a union discriminator isn't allowed in IDL versions before 4");
3507                               $$ = p;
3508                               found = true;
3509                               break;
3510                             default:
3511                               $$ = 0;
3512                               found = true;
3513                               break;
3514                           }
3515                         }
3516                       else
3517                         {
3518                           $$ = 0;
3519                           found = true;
3520                         }
3522                       break;
3523                     case AST_Decl::NT_typedef:
3524                       t = dynamic_cast<AST_Typedef*> (d);
3526                       if (t != 0)
3527                         {
3528                           d = t->base_type ();
3529                         }
3531                       break;
3532                     default:
3533                       $$ = 0;
3534                       found = true;
3535                       break;
3536                   }
3537                 }
3538             }
3539           else
3540             {
3541               $$ = 0;
3542             }
3544           if ($$ == 0)
3545             {
3546               idl_global->err ()->lookup_error ($1);
3548               $1->destroy ();
3549               delete $1;
3550               $1 = 0;
3552               /* If we don't return here, we'll crash later.*/
3553               if (!idl_global->ignore_lookup_errors_)
3554                 {
3555                   return 1;
3556                 }
3557             }
3559           $1->destroy ();
3560           delete $1;
3561           $1 = 0;
3562         }
3563         ;
3565 at_least_one_case_branch : case_branch case_branches ;
3567 case_branches
3568         : case_branches case_branch
3569         | %empty
3570         ;
3572 case_branch :
3573         at_least_one_case_label
3574         {
3575           idl_global->set_parse_state (IDL_GlobalData::PS_UnionLabelSeen);
3576         }
3577         annotations_maybe element_spec
3578         {
3579           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemSeen);
3580         }
3581         ';'
3582         {
3583           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3584           AST_UnionBranch *b = 0;
3585           AST_Annotation_Appls *annotations = $3;
3586           AST_Field *f = $4;
3587           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemCompleted);
3589           /*
3590            * Create several nodes representing branches of a union.
3591            * Add them to the enclosing scope (the union scope)
3592            */
3593           if (s != 0 && $1 != 0 && $4 != 0)
3594             {
3595               b =
3596                 idl_global->gen ()->create_union_branch (
3597                                         $1,
3598                                         f->field_type (),
3599                                         f->name ()
3600                                       );
3601               b->annotation_appls (*annotations);
3602               (void) s->fe_add_union_branch (b);
3604               // f has passed its field type to the union branch,
3605               // but the rest still needs to be cleaned up.
3606               f->AST_Decl::destroy ();
3607               delete f;
3608               f = 0;
3609             }
3611           delete annotations;
3612         }
3613         | error
3614         {
3615           idl_global->err ()->syntax_error (idl_global->parse_state ());
3616         }
3617         ';'
3618         {
3619           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
3620           yyerrok;
3621         }
3622         ;
3624 at_least_one_case_label :
3625         case_label case_labels
3626         {
3627           ACE_NEW_RETURN ($<llval>$,
3628                           UTL_LabelList ($1,
3629                                          $2),
3630                           1);
3631         }
3632         ;
3634 case_labels
3635         : case_labels case_label
3636         {
3637           UTL_LabelList *ll = 0;
3638           ACE_NEW_RETURN (ll,
3639                           UTL_LabelList ($2,
3640                                          0),
3641                           1);
3643           if ($1 == 0)
3644             {
3645               $<llval>$ = ll;
3646             }
3647           else
3648             {
3649               $1->nconc (ll);
3650               $<llval>$ = $1;
3651             }
3652         }
3653         | %empty
3654         {
3655           $<llval>$ = 0;
3656         }
3657         ;
3659 case_label
3660         : IDL_DEFAULT
3661         {
3662           idl_global->set_parse_state (IDL_GlobalData::PS_DefaultSeen);
3663         }
3664           ':'
3665         {
3666           idl_global->set_parse_state (IDL_GlobalData::PS_LabelColonSeen);
3668           $$ = idl_global->gen ()->create_union_label (
3669                                        AST_UnionLabel::UL_default,
3670                                        0
3671                                      );
3672         }
3673         | IDL_CASE
3674         {
3675           idl_global->set_parse_state (IDL_GlobalData::PS_CaseSeen);
3676         }
3677           const_expr
3678         {
3679           idl_global->set_parse_state (IDL_GlobalData::PS_LabelExprSeen);
3680         }
3681           ':'
3682         {
3683           idl_global->set_parse_state (IDL_GlobalData::PS_LabelColonSeen);
3685           $$ = idl_global->gen ()->create_union_label (
3686                                       AST_UnionLabel::UL_label,
3687                                       $3
3688                                     );
3689         }
3690         ;
3692 element_spec :
3693         type_spec
3694         {
3695           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemTypeSeen);
3696         }
3697         declarator
3698         {
3699           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemDeclSeen);
3701           /*
3702            * Check for illegal recursive use of type
3703            */
3704           if ($1 != 0
3705               && AST_illegal_recursive_type ($1))
3706             {
3707               idl_global->err ()->error1 (UTL_Error::EIDL_RECURSIVE_TYPE, $1);
3709               $$ = 0;
3710             }
3711           /*
3712            * Create a field in a union branch
3713            */
3714           else if ($1 == 0
3715                    || $3 == 0)
3716             {
3717               $$ = 0;
3718             }
3719           else
3720             {
3721               AST_Type *tp = $3->compose ($1);
3723               if (tp == 0)
3724                 {
3725                   $$ = 0;
3726                 }
3727               else
3728                 {
3729                   $$ = idl_global->gen ()->create_field (
3730                                                tp,
3731                                                $3->name ()
3732                                              );
3733                 }
3735               $3->destroy ();
3736               delete $3;
3737               $3 = 0;
3738             }
3739         }
3740         ;
3742 struct_forward_type
3743         : struct_decl
3744         {
3745           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3746           UTL_ScopedName n ($1,
3747                             0);
3748           AST_StructureFwd *d = 0;
3750           /*
3751            * Create a node representing a forward declaration of a struct.
3752            */
3753           if (s != 0)
3754             {
3755               d = idl_global->gen ()->create_structure_fwd (&n);
3756               (void) s->fe_add_structure_fwd (d);
3757             }
3759           $1->destroy ();
3760           delete $1;
3761           $1 = 0;
3763           $$ = d;
3764         }
3765         ;
3767 union_forward_type
3768         : union_decl
3769         {
3770           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3771           UTL_ScopedName n ($1,
3772                             0);
3773           AST_UnionFwd *u = 0;
3775           /*
3776            * Create a node representing a forward declaration of a union.
3777            */
3778           if (s != 0)
3779             {
3780               u = idl_global->gen ()->create_union_fwd (&n);
3781               (void) s->fe_add_union_fwd (u);
3782             }
3784           $1->destroy ();
3785           delete $1;
3786           $1 = 0;
3787         }
3788         ;
3790 enum_type :
3791         IDL_ENUM
3792         {
3793           idl_global->set_parse_state (IDL_GlobalData::PS_EnumSeen);
3794         }
3795         defining_id
3796         {
3797           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3798           UTL_ScopedName n ($3, 0);
3799           AST_Enum *e = 0;
3800           idl_global->set_parse_state (IDL_GlobalData::PS_EnumIDSeen);
3802           /*
3803            * Create a node representing an enum and add it to its
3804            * enclosing scope.
3805            */
3806           if (s != 0)
3807             {
3808               e = idl_global->gen ()->create_enum (&n,
3809                                                    s->is_local (),
3810                                                    s->is_abstract ());
3811               /*
3812                * Add it to its defining scope
3813                */
3814               (void) s->fe_add_enum (e);
3815             }
3817           /*
3818            * Push the enum scope on the scopes stack.
3819            */
3820           idl_global->scopes ().push (e);
3822           $3->destroy ();
3823           delete $3;
3824           $3 = 0;
3825         }
3826         '{'
3827         {
3828           idl_global->set_parse_state (IDL_GlobalData::PS_EnumSqSeen);
3829         }
3830         at_least_one_enumerator
3831         {
3832           idl_global->set_parse_state (IDL_GlobalData::PS_EnumBodySeen);
3833         }
3834         '}'
3835         {
3836           idl_global->set_parse_state (IDL_GlobalData::PS_EnumQsSeen);
3838           /*
3839            * Done with this enum. Pop its scope from the scopes stack.
3840            */
3841           if (idl_global->scopes ().top () == 0)
3842             {
3843               $$ = 0;
3844             }
3845           else
3846             {
3847               $$ = dynamic_cast<AST_Enum*> (
3848                        idl_global->scopes ().top_non_null ()
3849                      );
3850               idl_global->scopes ().pop ();
3851             }
3852         }
3853         ;
3855 at_least_one_enumerator : enumerator enumerators ;
3857 enumerators
3858         : enumerators
3859           ','
3860         {
3861           idl_global->set_parse_state (IDL_GlobalData::PS_EnumCommaSeen);
3862         }
3863           enumerator
3864         | %empty
3865         ;
3867 enumerator :
3868         annotations_maybe IDENTIFIER
3869         {
3870           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3871           AST_Annotation_Appls *annotations = $1;
3872           Identifier id ($2);
3873           ACE::strdelete ($2);
3874           $2 = 0;
3875           UTL_ScopedName n (&id, 0);
3876           AST_EnumVal *e = 0;
3877           AST_Enum *c = 0;
3879           /*
3880            * Create a node representing one enumerator in an enum
3881            * Add it to the enclosing scope (the enum scope)
3882            */
3883           if (s != 0
3884               && s->scope_node_type () == AST_Decl::NT_enum)
3885             {
3886               c = dynamic_cast<AST_Enum*> (s);
3888               if (c != 0)
3889                 {
3890                   e = idl_global->gen ()->create_enum_val (
3891                                               c->next_enum_val (),
3892                                               &n
3893                                             );
3894                   e->enum_parent (c);
3895                   e->annotation_appls (*annotations);
3896                 }
3898               (void) s->fe_add_enum_val (e);
3899             }
3901           delete annotations;
3902         }
3903         ;
3905 map_type_spec
3906         : map_head
3907         '>'
3908         {
3909           AST_Map *map = 0;
3910           Decl_Annotations_Pair_Pair* type_pair = $1;
3911           Decl_Annotations_Pair *key_type = type_pair->first;
3912           Decl_Annotations_Pair *val_type = type_pair->second;
3914           /*
3915            * Remove map marker from scopes stack.
3916            */
3917           if (idl_global->scopes ().top () == 0)
3918             {
3919              idl_global->scopes ().pop ();
3920             }
3922           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3924           /*
3925            * Create a node representing a map.
3926            */
3927           if (key_type && val_type)
3928             {
3929               AST_Type *ktp = dynamic_cast<AST_Type*> (key_type->decl);
3930               AST_Type *vtp = dynamic_cast<AST_Type*> (val_type->decl);
3932               if (ktp == 0 || vtp == 0)
3933                 {
3934                   ; // Error will be caught in FE_Declarator.
3935                 }
3936               else
3937                 {
3938                   Identifier id ("map");
3939                   UTL_ScopedName sn (&id, 0);
3940                   ACE_CDR::ULong bound = 0UL;
3942                   map =
3943                     idl_global->gen ()->create_map (
3944                         idl_global->gen ()->create_expr (
3945                                                 bound,
3946                                                 AST_Expression::EV_ulong
3947                                               ),
3948                         ktp,
3949                         vtp,
3950                         &sn,
3951                         s->is_local (),
3952                         s->is_abstract ()
3953                       );
3954                   map->key_type_annotations (*key_type->annotations);
3955                   map->value_type_annotations (*val_type->annotations);
3957                   idl_global->err ()->anonymous_type_diagnostic ();
3958                 }
3959             }
3961           delete key_type->annotations;
3962           delete val_type->annotations;
3963           delete type_pair;
3964           $$ = map;
3965         }
3966         ;
3968 map_head :
3969         IDL_MAP
3970         {
3971           idl_global->set_parse_state (IDL_GlobalData::PS_MapSeen);
3973           /*
3974            * Push a map marker on scopes stack.
3975            */
3976           idl_global->scopes ().push (0);
3977         }
3978         '<'
3979         annotations_maybe simple_type_spec
3980         {
3981           idl_global->set_parse_state(IDL_GlobalData::PS_MapKeyTypeSeen);
3982         }
3983         ','
3984         annotations_maybe simple_type_spec
3985         {
3986           idl_global->set_parse_state(IDL_GlobalData::PS_MapValueTypeSeen);
3987           Decl_Annotations_Pair *key = new Decl_Annotations_Pair;
3988           key->decl = $5;
3989           key->annotations = $4;
3991           Decl_Annotations_Pair *value = new Decl_Annotations_Pair;
3992           value->decl = $9;
3993           value->annotations = $8;
3995           Decl_Annotations_Pair_Pair* pairs = new Decl_Annotations_Pair_Pair;
3996           pairs->first = key;
3997           pairs->second = value;
3998           $$ = pairs;
3999         }
4000         ;
4002 sequence_type_spec
4003         : seq_head
4004           ','
4005         {
4006           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceCommaSeen);
4007         }
4008         positive_int_expr
4009         {
4010           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceExprSeen);
4011         }
4012           '>'
4013         {
4014           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceQsSeen);
4016           AST_Sequence *seq = 0;
4017           Decl_Annotations_Pair *seq_head = $1;
4018           AST_Decl *type = 0;
4019           AST_Annotation_Appls *type_annotations = 0;
4020           if (seq_head)
4021             {
4022               type = seq_head->decl;
4023               type_annotations = seq_head->annotations;
4024             }
4025           delete seq_head;
4027           /*
4028            * Remove sequence marker from scopes stack.
4029            */
4030           if (idl_global->scopes ().top () == 0)
4031             {
4032               idl_global->scopes ().pop ();
4033             }
4035           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4037           /*
4038            * Create a node representing a sequence
4039            */
4040           AST_Expression::AST_ExprValue *ev = 0;
4041           AST_Param_Holder *param_holder = 0;
4043           if ($4 != 0)
4044             {
4045               param_holder =
4046                 $4->param_holder ();
4048               ev = $4->coerce (AST_Expression::EV_ulong);
4049             }
4051           // If the expression corresponds to a template parameter,
4052           // it's ok for the coercion to fail at this point. We check
4053           // for a type mismatch below.
4054           if (0 == $4
4055               || (0 == ev && 0 == param_holder))
4056             {
4057               idl_global->err ()->coercion_error ($4,
4058                                                   AST_Expression::EV_ulong);
4059             }
4060           else if (type)
4061             {
4062               AST_Type *tp = dynamic_cast<AST_Type*> (type);
4064               if (0 == tp)
4065                 {
4066                   ; // Error will be caught in FE_Declarator.
4067                 }
4068               else
4069                 {
4070                   Identifier id ("sequence");
4071                   UTL_ScopedName sn (&id,
4072                                      0);
4074                   seq =
4075                     idl_global->gen ()->create_sequence (
4076                                             $4,
4077                                             tp,
4078                                             &sn,
4079                                             s->is_local (),
4080                                             s->is_abstract ()
4081                                           );
4082                   seq->base_type_annotations (*type_annotations);
4084                   idl_global->err ()->anonymous_type_diagnostic ();
4085                 }
4086             }
4088           delete type_annotations;
4089           delete ev;
4090           ev = 0;
4091           $$ = seq;
4092         }
4093         | seq_head
4094           '>'
4095         {
4096           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceQsSeen);
4098           AST_Sequence *seq = 0;
4099           Decl_Annotations_Pair *seq_head = $1;
4100           AST_Decl *type = 0;
4101           AST_Annotation_Appls *type_annotations = 0;
4102           if (seq_head)
4103             {
4104               type = seq_head->decl;
4105               type_annotations = seq_head->annotations;
4106             }
4107           delete seq_head;
4109           /*
4110            * Remove sequence marker from scopes stack.
4111            */
4112           if (idl_global->scopes ().top () == 0)
4113             {
4114              idl_global->scopes ().pop ();
4115             }
4117           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4119           /*
4120            * Create a node representing a sequence.
4121            */
4122           if (type)
4123             {
4124               AST_Type *tp = dynamic_cast<AST_Type*> (type);
4126               if (tp == 0)
4127                 {
4128                   ; // Error will be caught in FE_Declarator.
4129                 }
4130               else
4131                 {
4132                   Identifier id ("sequence");
4133                   UTL_ScopedName sn (&id, 0);
4134                   ACE_CDR::ULong bound = 0UL;
4136                   seq =
4137                     idl_global->gen ()->create_sequence (
4138                         idl_global->gen ()->create_expr (
4139                                                 bound,
4140                                                 AST_Expression::EV_ulong
4141                                               ),
4142                         tp,
4143                         &sn,
4144                         s->is_local (),
4145                         s->is_abstract ()
4146                       );
4147                   seq->base_type_annotations (*type_annotations);
4149                   idl_global->err ()->anonymous_type_diagnostic ();
4150                 }
4151             }
4153           delete type_annotations;
4154           $$ = seq;
4155         }
4156         ;
4158 seq_head :
4159         IDL_SEQUENCE
4160         {
4161           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceSeen);
4163           /*
4164            * Push a sequence marker on scopes stack.
4165            */
4166           idl_global->scopes ().push (0);
4167         }
4168         '<'
4169         {
4170           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceSqSeen);
4171         }
4172         annotations_maybe simple_type_spec
4173         {
4174           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceTypeSeen);
4175           Decl_Annotations_Pair *seq_head = new Decl_Annotations_Pair;
4176           seq_head->decl = $6;
4177           seq_head->annotations = $5;
4178           $$ = seq_head;
4179         }
4180         ;
4182 fixed_type_spec
4183         : IDL_FIXED '<' positive_int_expr ',' const_expr '>'
4184         {
4185           $5->evaluate (AST_Expression::EK_positive_int);
4186           $$ = idl_global->gen ()->create_fixed ($3, $5);
4187         }
4188         ;
4190 string_type_spec
4191         : string_head
4192           '<'
4193         {
4194           idl_global->set_parse_state (IDL_GlobalData::PS_StringSqSeen);
4195         }
4196         positive_int_expr
4197         {
4198            idl_global->set_parse_state (IDL_GlobalData::PS_StringExprSeen);
4199         }
4200         '>'
4201         {
4202           idl_global->set_parse_state (IDL_GlobalData::PS_StringQsSeen);
4204           /*
4205            * Create a node representing a string.
4206            */
4207           AST_Expression::AST_ExprValue *ev = 0;
4209           if ($4 != 0)
4210             {
4211               ev = $4->coerce (AST_Expression::EV_ulong);
4212             }
4214           if (0 == $4 || 0 == ev)
4215             {
4216               idl_global->err ()->coercion_error ($4,
4217                                                   AST_Expression::EV_ulong);
4218               $$ = 0;
4219             }
4220           else
4221             {
4222               tao_string_decl = idl_global->gen ()->create_string ($4);
4224               /*
4225                * Add this AST_String to the types defined in the global scope.
4226                */
4227               idl_global->root ()->fe_add_string (
4228                 dynamic_cast<AST_String*> (
4229                   tao_string_decl));
4231               idl_global->err ()->anonymous_type_diagnostic ();
4233               $$ = tao_string_decl;
4234             }
4236           delete ev;
4237           ev = 0;
4238         }
4239         | string_head
4240         {
4241           idl_global->set_parse_state (IDL_GlobalData::PS_StringCompleted);
4243           /*
4244            * Create a node representing a string.
4245            */
4246           ACE_CDR::ULong bound = 0UL;
4247           tao_string_decl =
4248             idl_global->gen ()->create_string (
4249                 idl_global->gen ()->create_expr (bound,
4250                                                  AST_Expression::EV_ulong)
4251               );
4253           /*
4254            * Add this AST_String to the types defined in the global scope.
4255            */
4256           idl_global->root ()->fe_add_string (
4257             dynamic_cast<AST_String*> (
4258               tao_string_decl));
4260           $$ = tao_string_decl;
4261         }
4262         ;
4264 string_head :
4265         IDL_STRING
4266         {
4267           idl_global->set_parse_state (IDL_GlobalData::PS_StringSeen);
4268         }
4269         ;
4271 wstring_type_spec
4272         : wstring_head
4273           '<'
4274         {
4275           idl_global->set_parse_state (IDL_GlobalData::PS_StringSqSeen);
4276         }
4277         positive_int_expr
4278         {
4279            idl_global->set_parse_state (IDL_GlobalData::PS_StringExprSeen);
4280         }
4281         '>'
4282         {
4283           idl_global->set_parse_state (IDL_GlobalData::PS_StringQsSeen);
4285           /*
4286            * Create a node representing a string.
4287            */
4288           AST_Expression::AST_ExprValue *ev = 0;
4290           if ($4 != 0)
4291             {
4292               ev = $4->coerce (AST_Expression::EV_ulong);
4293             }
4295           if (0 == $4 || 0 == ev)
4296             {
4297               idl_global->err ()->coercion_error ($4,
4298                                                   AST_Expression::EV_ulong);
4299               $$ = 0;
4300             }
4301           else
4302             {
4303               AST_String *string = idl_global->gen ()->create_wstring ($4);
4305               /*
4306                * Add this AST_String to the types defined in the global scope.
4307                */
4308               idl_global->root ()->fe_add_string (
4309                 dynamic_cast<AST_String*> (
4310                   string));
4312               idl_global->err ()->anonymous_type_diagnostic ();
4314               $$ = string;
4315             }
4317           delete ev;
4318           ev = 0;
4319         }
4320         | wstring_head
4321         {
4322           idl_global->set_parse_state (IDL_GlobalData::PS_StringCompleted);
4324           /*
4325            * Create a node representing a wstring.
4326            */
4327           ACE_CDR::ULong bound = 0UL;
4328           AST_String *string =
4329             idl_global->gen ()->create_wstring (
4330                 idl_global->gen ()->create_expr (bound,
4331                                                  AST_Expression::EV_ulong)
4332               );
4334           /*
4335            * Add this AST_String to the types defined in the global scope.
4336            */
4337           idl_global->root ()->fe_add_string (
4338             dynamic_cast<AST_String*> (
4339               string));
4341           $$ = string;
4342         }
4343         ;
4345 wstring_head :
4346         IDL_WSTRING
4347         {
4348           idl_global->set_parse_state (IDL_GlobalData::PS_StringSeen);
4349         }
4350         ;
4352 array_declarator :
4353         defining_id
4354         {
4355           idl_global->set_parse_state (IDL_GlobalData::PS_ArrayIDSeen);
4356         }
4357         annotations_maybe at_least_one_array_dim
4358         {
4359           idl_global->set_parse_state (IDL_GlobalData::PS_ArrayCompleted);
4361           AST_Array *array = 0;
4362           AST_Annotation_Appls *base_type_annotations = $3;
4363           UTL_ExprList *array_dims = $4;
4365           /*
4366            * Create a node representing an array.
4367            */
4368           if (array_dims)
4369             {
4370               UTL_ScopedName sn ($1,
4371                                  0);
4372               array =
4373                 idl_global->gen ()->create_array (
4374                                         &sn,
4375                                         array_dims->length (),
4376                                         array_dims,
4377                                         0,
4378                                         0
4379                                       );
4380               array->base_type_annotations (*base_type_annotations);
4381               sn.destroy ();
4383               idl_global->err ()->anonymous_type_diagnostic ();
4384             }
4386           array_dims->destroy ();
4387           delete array_dims;
4389           delete base_type_annotations;
4391           $$ = array;
4392         }
4393         ;
4395 at_least_one_array_dim :
4396         array_dim array_dims
4397         {
4398           ACE_NEW_RETURN ($$,
4399                           UTL_ExprList ($1,
4400                                         $2),
4401                           1);
4402         }
4403         ;
4405 array_dims
4406         : array_dims array_dim
4407         {
4408           UTL_ExprList *el = 0;
4409           ACE_NEW_RETURN (el,
4410                           UTL_ExprList ($2,
4411                                         0),
4412                           1);
4414           if ($1 == 0)
4415             {
4416               $$ = el;
4417             }
4418           else
4419             {
4420               $1->nconc (el);
4421               $$ = $1;
4422             }
4423         }
4424         | %empty
4425         {
4426           $$ = 0;
4427         }
4428         ;
4430 array_dim :
4431         '['
4432         {
4433           idl_global->set_parse_state (IDL_GlobalData::PS_DimSqSeen);
4434         }
4435         positive_int_expr
4436         {
4437           idl_global->set_parse_state (IDL_GlobalData::PS_DimExprSeen);
4438         }
4439         ']'
4440         {
4441           idl_global->set_parse_state (IDL_GlobalData::PS_DimQsSeen);
4443           /*
4444            * Array dimensions are expressions which must be coerced to
4445            * positive integers.
4446            */
4447           AST_Expression::AST_ExprValue *ev = 0;
4448           AST_Param_Holder *param_holder = 0;
4450           if ($3 != 0)
4451             {
4452               param_holder =
4453                 $3->param_holder ();
4455               ev =
4456                 $3->coerce (AST_Expression::EV_ulong);
4457             }
4459           if (0 == $3
4460               || (ev == 0 && param_holder == 0))
4461             {
4462               idl_global->err ()->coercion_error ($3,
4463                                                   AST_Expression::EV_ulong);
4464               $$ = 0;
4465             }
4466           else
4467             {
4468               if (param_holder != 0)
4469                 {
4470                   AST_Expression::ExprType et =
4471                     param_holder->info ()->const_type_;
4473                   // If the bound expression represents a
4474                   // template parameter, it must be a const
4475                   // and of type unsigned long.
4476                   if (et != AST_Expression::EV_ulong)
4477                     {
4478                       idl_global->err ()->mismatched_template_param (
4479                         param_holder->info ()->name_.c_str ());
4481                       delete ev;
4482                       ev = 0;
4483                       return 1;
4484                     }
4485                 }
4487               $$ = $3;
4488             }
4490           delete ev;
4491           ev = 0;
4492         }
4493         ;
4495 attribute
4496         : attribute_readonly
4497         | attribute_readwrite
4498         ;
4500 attribute_readonly :
4501         IDL_READONLY
4502         {
4503           idl_global->set_parse_state (IDL_GlobalData::PS_AttrROSeen);
4504         }
4505         IDL_ATTRIBUTE
4506         {
4507           idl_global->set_parse_state (IDL_GlobalData::PS_AttrSeen);
4508         }
4509         param_type_spec
4510         {
4511           idl_global->set_parse_state (IDL_GlobalData::PS_AttrTypeSeen);
4512         }
4513         at_least_one_simple_declarator
4514         {
4515           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclsSeen);
4516         }
4517         opt_raises
4518         {
4519           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4520           AST_Attribute *a = 0;
4521           FE_Declarator *d = 0;
4523           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
4525           /*
4526            * Create nodes representing attributes and add them to the
4527            * enclosing scope.
4528            */
4529           if (s != 0 && $5 != 0 && $7 != 0)
4530             {
4531               for (UTL_DecllistActiveIterator l ($7); !l.is_done (); l.next ())
4532                 {
4533                   d = l.item ();
4535                   if (d == 0)
4536                     {
4537                       continue;
4538                     }
4540                   AST_Type *tp = d->compose ($5);
4542                   if (tp == 0)
4543                     {
4544                       continue;
4545                     }
4547                   a = idl_global->gen ()->create_attribute (
4548                     true, tp, d->name (), s->is_local (), s->is_abstract ());
4550                   if ($9 != 0)
4551                     {
4552                       (void) a->fe_add_get_exceptions ($9);
4554                       $9->destroy ();
4555                       delete $9;
4556                       $9 = 0;
4557                     }
4559                   (void) s->fe_add_attribute (a);
4560                 }
4561             }
4563           $7->destroy ();
4564           delete $7;
4565           $7 = 0;
4567           $$ = a;
4568         }
4569         ;
4571 attribute_readwrite :
4572         IDL_ATTRIBUTE
4573         {
4574           idl_global->set_parse_state (IDL_GlobalData::PS_AttrSeen);
4575         }
4576         param_type_spec
4577         {
4578           idl_global->set_parse_state (IDL_GlobalData::PS_AttrTypeSeen);
4579         }
4580         at_least_one_simple_declarator
4581         {
4582           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclsSeen);
4583         }
4584         opt_getraises
4585         {
4586           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseCompleted);
4587         }
4588         opt_setraises
4589         {
4590           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4591           AST_Attribute *a = 0;
4592           FE_Declarator *d = 0;
4594           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseCompleted);
4596           /*
4597            * Create nodes representing attributes and add them to the
4598            * enclosing scope.
4599            */
4600           if (s != 0 && $3 != 0 && $5 != 0)
4601             {
4602               for (UTL_DecllistActiveIterator l ($5); !l.is_done (); l.next ())
4603                 {
4604                   d = l.item ();
4606                   if (d == 0)
4607                     {
4608                       continue;
4609                     }
4611                   AST_Type *tp = d->compose ($3);
4613                   if (tp == 0)
4614                     {
4615                       continue;
4616                     }
4618                   a = idl_global->gen ()->create_attribute (
4619                    false, tp, d->name (), s->is_local (), s->is_abstract ());
4621                   if ($7 != 0)
4622                     {
4623                       (void) a->fe_add_get_exceptions ($7);
4625                       $7->destroy ();
4626                       delete $7;
4627                       $7 = 0;
4628                     }
4630                   if ($9 != 0)
4631                     {
4632                       (void) a->fe_add_set_exceptions ($9);
4634                       $9->destroy ();
4635                       delete $9;
4636                       $9 = 0;
4637                     }
4639                   (void) s->fe_add_attribute (a);
4640                 }
4641             }
4643           $5->destroy ();
4644           delete $5;
4645           $5 = 0;
4647           $$ = a;
4648         }
4649         ;
4651 exception :
4652         IDL_EXCEPTION
4653         {
4654           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptSeen);
4655         }
4656         defining_id
4657         {
4658           Identifier *&id = $3;
4659           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
4660           UTL_ScopedName scoped_name (id, 0);
4661           AST_Exception *exception = 0;
4662           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptIDSeen);
4664           /*
4665            * Create a node representing an exception and add it to
4666            * the enclosing scope.
4667            */
4668           if (scope)
4669             {
4670               exception = idl_global->gen ()->create_exception (
4671                 &scoped_name,
4672                 scope->is_local (),
4673                 scope->is_abstract ());
4674               scope->fe_add_exception (exception);
4675             }
4677           /*
4678            * Push the exception scope on the scope stack.
4679            */
4680           idl_global->scopes ().push (exception);
4682           id->destroy ();
4683           delete id;
4684           id = 0;
4686           $<dcval>$ = exception;
4687         }
4688         '{'
4689         {
4690           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptSqSeen);
4691         }
4692         members
4693         {
4694           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptBodySeen);
4695         }
4696         '}'
4697         {
4698           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptQsSeen);
4699           /*
4700            * Done with this exception. Pop its scope from the scope stack.
4701            */
4702           idl_global->scopes ().pop ();
4704           $$ = $<dcval>4;
4705         }
4706         ;
4708 operation
4709         : opt_op_attribute op_type_spec
4710         {
4711           idl_global->set_parse_state (IDL_GlobalData::PS_OpTypeSeen);
4712         }
4713         IDENTIFIER
4714         {
4715           AST_Operation *op = 0;
4716           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
4718           AST_Operation::Flags op_flags = $1;
4719           AST_Decl *type_node = $2;
4720           $2 = 0;
4721           Identifier id ($4);
4722           ACE::strdelete ($4);
4723           $4 = 0;
4725           UTL_ScopedName name (&id, 0);
4726           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
4728           /*
4729            * Create a node representing an operation on an interface
4730            * and add it to its enclosing scope.
4731            */
4732           if (scope != 0 && type_node != 0)
4733             {
4734               AST_Type *type = dynamic_cast<AST_Type*> (type_node);
4736               if (type == 0)
4737                 {
4738                   idl_global->err ()->not_a_type (type_node);
4739                 }
4740               else if (type->node_type () == AST_Decl::NT_except)
4741                 {
4742                   idl_global->err ()->not_a_type (type_node);
4743                 }
4744               else
4745                 {
4746                   AST_Decl *d = ScopeAsDecl (scope);
4747                   AST_Decl::NodeType nt = d->node_type ();
4748                   const bool local = scope->is_local ()
4749                     || nt == AST_Decl::NT_valuetype
4750                     || nt == AST_Decl::NT_eventtype;
4752                   op = idl_global->gen ()->create_operation (
4753                     type, op_flags, &name, local, scope->is_abstract ());
4755                   if (!local && type->is_local ())
4756                     {
4757                       idl_global->err ()->local_remote_mismatch (type, op);
4758                       op->destroy ();
4759                       delete op;
4760                       op = 0;
4761                     }
4762                   else
4763                     {
4764                       scope->fe_add_operation (op);
4765                     }
4766                 }
4767             }
4769           /*
4770            * Push the operation scope onto the scopes stack.
4771            */
4772           idl_global->scopes ().push (op);
4773         }
4774         parameter_list
4775         {
4776           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
4777         }
4778         opt_raises
4779         {
4780           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
4781         }
4782         opt_context
4783         {
4784           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4785           AST_Operation *o = 0;
4786           idl_global->set_parse_state (IDL_GlobalData::PS_OpCompleted);
4788           /*
4789            * Add exceptions and context to the operation.
4790            */
4791           if (s != 0 && s->scope_node_type () == AST_Decl::NT_op)
4792             {
4793               o = dynamic_cast<AST_Operation*> (s);
4795               if ($8 != 0 && o != 0)
4796                 {
4797                   (void) o->fe_add_exceptions ($8);
4798                 }
4800               if ($10 != 0)
4801                 {
4802                   (void) o->fe_add_context ($10);
4803                 }
4804             }
4806           /*
4807            * Done with this operation. Pop its scope from the scopes stack.
4808            */
4809           idl_global->scopes ().pop ();
4811           $$ = o;
4812         }
4813         ;
4815 opt_op_attribute
4816         : IDL_ONEWAY
4817         {
4818           idl_global->set_parse_state (IDL_GlobalData::PS_OpAttrSeen);
4819           $$ = AST_Operation::OP_oneway;
4820         }
4821         | IDL_IDEMPOTENT
4822         {
4823           idl_global->set_parse_state (IDL_GlobalData::PS_OpAttrSeen);
4824           $$ = AST_Operation::OP_idempotent;
4825         }
4826         | %empty
4827         {
4828           $$ = AST_Operation::OP_noflags;
4829         }
4830         ;
4832 op_type_spec
4833         : param_type_spec
4834         | IDL_VOID
4835         {
4836           $$ =
4837             idl_global->scopes ().bottom ()->lookup_primitive_type (
4838                                                   AST_Expression::EV_void
4839                                                 );
4840         }
4841         ;
4843 init_decl
4844         : IDL_FACTORY
4845         {
4846           //@@ PS_FactorySeen?
4847           idl_global->set_parse_state (IDL_GlobalData::PS_OpTypeSeen);
4848         }
4849         IDENTIFIER
4850         {
4851           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4853           if (s->is_abstract ())
4854             {
4855               //@@ Fire error
4856               ACE_ERROR ((LM_ERROR,
4857                           ACE_TEXT ("error in %C line %d:\n")
4858                           ACE_TEXT ("Abstract valuetype can't have a ")
4859                           ACE_TEXT ("factory construct.\n"),
4860                           idl_global->filename ()->get_string (),
4861                           idl_global->lineno ()));
4863               idl_global->set_err_count (idl_global->err_count () + 1);
4864             }
4866           Identifier id ($3);
4867           ACE::strdelete ($3);
4868           $3 = 0;
4870           UTL_ScopedName n (&id,
4871                             0);
4872           AST_Factory *factory = 0;
4873           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
4875           /*
4876            * Create a node representing an factory construct
4877            * and add it to its enclosing scope
4878            */
4879           if (s != 0)
4880             {
4881               factory = idl_global->gen ()->create_factory (&n);
4882               (void) s->fe_add_factory (factory);
4883             }
4885           /*
4886            * Push the operation scope onto the scopes stack.
4887            */
4888           idl_global->scopes ().push (factory);
4890           $<dcval>$ = factory;
4891         }
4892         init_parameter_list
4893         {
4894           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
4895         }
4896         opt_raises
4897         {
4898           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
4900           if ($7)
4901             {
4902               UTL_Scope *s = idl_global->scopes ().top_non_null ();
4903               AST_Factory *f = dynamic_cast<AST_Factory*> (s);
4904               (void) f->fe_add_exceptions ($7);
4905             }
4907           idl_global->scopes ().pop ();
4909           $$ = $<dcval>4;
4910         }
4911         ;
4913 init_parameter_list
4914         : '('
4915         {
4916           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4917         }
4918         ')'
4919         {
4920           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4921         }
4922         | '('
4923         {
4924           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4925         }
4926         at_least_one_in_parameter
4927         ')'
4928         {
4929           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4930         }
4931         ;
4933 at_least_one_in_parameter : in_parameter in_parameters ;
4935 in_parameters
4936         : in_parameters
4937           ','
4938         {
4939           idl_global->set_parse_state (IDL_GlobalData::PS_OpParCommaSeen);
4940         }
4941         in_parameter
4942         | %empty
4943         ;
4945 in_parameter :
4946         IDL_IN
4947         {
4948           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDirSeen);
4949         }
4950         param_type_spec
4951         {
4952           idl_global->set_parse_state (IDL_GlobalData::PS_OpParTypeSeen);
4953         }
4954         declarator
4955         {
4956           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4957           AST_Argument *a = 0;
4958           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDeclSeen);
4960           /*
4961            * Create a node representing an argument to an operation
4962            * Add it to the enclosing scope (the operation scope).
4963            */
4964           if ($3 != 0
4965               && $5 != 0 &&
4966               s != 0)
4967             {
4968               AST_Type *tp = $5->compose ($3);
4970               if (tp != 0)
4971                 {
4972                   a = idl_global->gen ()->create_argument (
4973                           AST_Argument::dir_IN,
4974                           tp,
4975                           $5->name ()
4976                         );
4978                   (void) s->fe_add_argument (a);
4979                 }
4980             }
4982           $5->destroy ();
4983           delete $5;
4984           $5 = 0;
4985         }
4986         ;
4988 parameter_list
4989         : '('
4990         {
4991           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4992         }
4993         ')'
4994         {
4995           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4996         }
4997         | '('
4998         {
4999           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
5000         }
5001         at_least_one_parameter
5002         ')'
5003         {
5004           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
5005         }
5006         ;
5008 at_least_one_parameter : parameter parameters ;
5010 parameters
5011         : parameters
5012           ','
5013         {
5014           idl_global->set_parse_state (IDL_GlobalData::PS_OpParCommaSeen);
5015         }
5016         parameter
5017         | %empty
5018         ;
5020 parameter :
5021         direction
5022         {
5023           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDirSeen);
5024         }
5025         param_type_spec
5026         {
5027           idl_global->set_parse_state (IDL_GlobalData::PS_OpParTypeSeen);
5028         }
5029         declarator
5030         {
5031           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5032           AST_Argument *a = 0;
5033           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDeclSeen);
5035           /*
5036            * Create a node representing an argument to an operation
5037            * Add it to the enclosing scope (the operation scope).
5038            */
5039           if ($3 != 0
5040               && $5 != 0
5041               && s != 0)
5042             {
5043               AST_Type *tp = $5->compose ($3);
5045               if (tp != 0)
5046                 {
5047                   if (!s->is_local () && tp->is_local ())
5048                     {
5049                       idl_global->err ()->local_remote_mismatch (tp, s);
5050                     }
5051                   else
5052                     {
5053                       a =
5054                         idl_global->gen ()->create_argument (
5055                             $1,
5056                             tp,
5057                             $5->name ()
5058                           );
5059                       (void) s->fe_add_argument (a);
5060                     }
5061                 }
5062             }
5064           $5->destroy ();
5065           delete $5;
5066           $5 = 0;
5067         }
5068         ;
5070 param_type_spec
5071         : base_type_spec
5072         {
5073           $$ =
5074             idl_global->scopes ().bottom ()->lookup_primitive_type (
5075                                                  $1
5076                                                );
5077         }
5078         | string_type_spec
5079         | wstring_type_spec
5080         | scoped_name
5081         {
5082           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5083           AST_Decl *d = 0;
5084           UTL_ScopedName *n = $1;
5086           if (s != 0)
5087             {
5088               d = s->lookup_by_name (n, false, false);
5089             }
5091           if (d == 0)
5092             {
5093               idl_global->err ()->lookup_error (n);
5094               $1->destroy ();
5095               $1 = 0;
5097               /* If we don't return here, we'll crash later.*/
5098               return 1;
5099             }
5100           else
5101             {
5102               d->last_referenced_as ($1);
5103               AST_Decl::NodeType nt = d->node_type ();
5104               AST_Type *t = dynamic_cast<AST_Type*> (d);
5105               AST_Typedef *td = 0;
5106               bool can_be_undefined = false;
5108               if (nt == AST_Decl::NT_typedef)
5109                 {
5110                   // This code block ensures that a sequence of
5111                   // as-yet-undefined struct or union isn't used
5112                   // as a return type or argument.
5113                   td = dynamic_cast<AST_Typedef*> (d);
5114                   AST_Type *pbt = td->primitive_base_type ();
5116                   if (pbt->node_type () == AST_Decl::NT_sequence)
5117                     {
5118                       t = pbt;
5119                       AST_Sequence *seq_type =
5120                         dynamic_cast<AST_Sequence*> (pbt);
5121                       AST_Type *elem_type =
5122                         seq_type->base_type ();
5123                       AST_Decl::NodeType elem_nt =
5124                         elem_type->node_type ();
5126                       if (elem_nt == AST_Decl::NT_typedef)
5127                         {
5128                           AST_Typedef *elem_td =
5129                             dynamic_cast<AST_Typedef*> (elem_type);
5130                           elem_type = elem_td->primitive_base_type ();
5131                           elem_nt = elem_type->node_type ();
5132                         }
5134                       if (elem_nt == AST_Decl::NT_interface
5135                           || elem_nt == AST_Decl::NT_interface_fwd
5136                           || elem_nt == AST_Decl::NT_valuetype
5137                           || elem_nt == AST_Decl::NT_valuetype_fwd
5138                           || elem_nt == AST_Decl::NT_component
5139                           || elem_nt == AST_Decl::NT_component_fwd)
5140                         {
5141                           can_be_undefined = true;
5142                         }
5143                     }
5145                   if (pbt->node_type() == AST_Decl::NT_map)
5146                     {
5147                       t = pbt;
5148                       AST_Map *map_type =
5149                         dynamic_cast<AST_Map*> (pbt);
5150                       AST_Type *key_type =
5151                         map_type->key_type ();
5152                       AST_Type *val_type =
5153                         map_type->value_type ();
5155                       AST_Decl::NodeType key_nt =
5156                         key_type->node_type ();
5157                       AST_Decl::NodeType val_nt =
5158                         val_type->node_type ();
5160                       if (key_nt == AST_Decl::NT_typedef)
5161                         {
5162                           AST_Typedef *key_td =
5163                             dynamic_cast<AST_Typedef*> (key_type);
5164                           key_type = key_td->primitive_base_type ();
5165                           key_nt = key_type->node_type ();
5166                         }
5168                       if (val_nt == AST_Decl::NT_typedef)
5169                         {
5170                           AST_Typedef *val_td =
5171                             dynamic_cast<AST_Typedef*> (val_type);
5172                           val_type = val_td->primitive_base_type ();
5173                           val_nt = val_type->node_type ();
5174                         }
5176                       if (key_nt == AST_Decl::NT_interface
5177                           || key_nt == AST_Decl::NT_interface_fwd
5178                           || key_nt == AST_Decl::NT_valuetype
5179                           || key_nt == AST_Decl::NT_valuetype_fwd
5180                           || key_nt == AST_Decl::NT_component
5181                           || key_nt == AST_Decl::NT_component_fwd
5182                           || val_nt == AST_Decl::NT_interface
5183                           || val_nt == AST_Decl::NT_interface_fwd
5184                           || val_nt == AST_Decl::NT_valuetype
5185                           || val_nt == AST_Decl::NT_valuetype_fwd
5186                           || val_nt == AST_Decl::NT_component
5187                           || val_nt == AST_Decl::NT_component_fwd)
5188                         {
5189                           can_be_undefined = true;
5190                         }
5191                     }
5193                   if (! t->is_defined () && ! can_be_undefined)
5194                     {
5195                       idl_global->err ()->error1 (
5196                         UTL_Error::EIDL_ILLEGAL_ADD,
5197                         (nt == AST_Decl::NT_typedef ? td : t));
5199                       /* If we don't return here, we'll crash later.*/
5200                       return 1;
5201                     }
5202                 }
5203               else
5204                 {
5205                   // For forward declared structs and unions, we
5206                   // want the full definition, but we need to
5207                   // check that it's been fully defined.
5208                   AST_StructureFwd *fwd =
5209                     dynamic_cast<AST_StructureFwd*> (d);
5211                   if (fwd != 0)
5212                     {
5213                       t = fwd->full_definition ();
5215                       if (! t->is_defined ())
5216                         {
5217                           idl_global->err ()->error1 (
5218                             UTL_Error::EIDL_ILLEGAL_ADD,
5219                             t);
5221                           /* If we don't return here, we'll crash later.*/
5222                           return 1;
5223                         }
5225                       d = t;
5226                     }
5227                 }
5228             }
5230           $$ = d;
5231         }
5232         ;
5234 direction
5235         : IDL_IN
5236         {
5237           $$ = AST_Argument::dir_IN;
5238         }
5239         | IDL_OUT
5240         {
5241           $$ = AST_Argument::dir_OUT;
5242         }
5243         | IDL_INOUT
5244         {
5245           $$ = AST_Argument::dir_INOUT;
5246         }
5247         ;
5249 opt_raises
5250         : IDL_RAISES
5251         {
5252           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseSeen);
5253         }
5254           '('
5255         {
5256           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseSqSeen);
5257         }
5258           at_least_one_scoped_name
5259           ')'
5260         {
5261           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseQsSeen);
5262           $$ = $5;
5263         }
5264         | %empty
5265         {
5266           $$ = 0;
5267         }
5268         ;
5270 opt_getraises
5271         : IDL_GETRAISES
5272         {
5273           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseSeen);
5274         }
5275           '('
5276         {
5277           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseSqSeen);
5278         }
5279           at_least_one_scoped_name
5280           ')'
5281         {
5282           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseQsSeen);
5283           $$ = $5;
5284         }
5285         | %empty
5286         {
5287           $$ = 0;
5288         }
5289         ;
5291 opt_setraises
5292         : IDL_SETRAISES
5293         {
5294           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseSeen);
5295         }
5296           '('
5297         {
5298           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseSqSeen);
5299         }
5300           at_least_one_scoped_name
5301           ')'
5302         {
5303           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseQsSeen);
5304           $$ = $5;
5305         }
5306         | %empty
5307         {
5308           $$ = 0;
5309         }
5310         ;
5312 opt_context
5313         : IDL_CONTEXT
5314         {
5315           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextSeen);
5316         }
5317         '('
5318         {
5319           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextSqSeen);
5320         }
5321         at_least_one_string_literal
5322         ')'
5323         {
5324           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextQsSeen);
5325           $$ = $5;
5326         }
5327         | %empty
5328         {
5329           $$ = 0;
5330         }
5331         ;
5333 at_least_one_string_literal :
5334         IDL_STRING_LITERAL string_literals
5335         {
5336           ACE_NEW_RETURN ($<slval>$,
5337                           UTL_StrList ($1,
5338                                        $2),
5339                           1);
5340         }
5341         ;
5343 string_literals
5344         : string_literals
5345           ','
5346         {
5347           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextCommaSeen);
5348         }
5349         IDL_STRING_LITERAL
5350         {
5351           UTL_StrList *sl = 0;
5352           ACE_NEW_RETURN (sl,
5353                           UTL_StrList ($4,
5354                                        0),
5355                           1);
5357           if ($1 == 0)
5358             {
5359               $<slval>$ = sl;
5360             }
5361           else
5362             {
5363               $1->nconc (sl);
5364               $<slval>$ = $1;
5365             }
5366         }
5367         | %empty
5368         {
5369           $$ = 0;
5370         }
5371         ;
5373 typeid_dcl
5374         : IDL_TYPEID scoped_name IDL_STRING_LITERAL
5375         {
5376           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5377           AST_Decl *d =
5378             s->lookup_by_name ($2);
5380           if (d == 0)
5381             {
5382               idl_global->err ()->lookup_error ($2);
5383             }
5384           else
5385             {
5386               d->set_id_with_typeid (
5387                      $3->get_string ()
5388                    );
5389             }
5391           $2->destroy ();
5392           delete $2;
5393           $2 = 0;
5395           $3->destroy ();
5396           delete $3;
5397           $3 = 0;
5399           $$ = 0;
5400         }
5401         ;
5403 typeprefix_dcl
5404         : IDL_TYPEPREFIX scoped_name IDL_STRING_LITERAL
5405         {
5406           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5407           AST_Decl *d = ScopeAsDecl (s);
5409           // If we are in a module, we want to avoid a lookup unless the
5410           // typeprefix is to be applied to some other scope, since we
5411           // might get a previous opening of the module, and the prefix
5412           // of this opening would never get checked or set.
5413           if (d->name ()->compare ($2) != 0)
5414             {
5415               d =
5416                 s->lookup_by_name ($2);
5417             }
5419           if (d == 0)
5420             {
5421               idl_global->err ()->lookup_error ($2);
5422             }
5423           else
5424             {
5425               d->set_prefix_with_typeprefix (
5426                      $3->get_string ()
5427                    );
5428             }
5430           $2->destroy ();
5431           delete $2;
5432           $2 = 0;
5434           $3->destroy ();
5435           delete $3;
5436           $3 = 0;
5438           $$ = 0;
5439         }
5440         ;
5442 component
5443         : component_decl
5444         | component_forward_decl
5445         ;
5447 component_forward_decl :
5448         IDL_COMPONENT
5449         defining_id
5450         {
5451           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5452           UTL_ScopedName n ($2,
5453                             0);
5454           AST_ComponentFwd *f = 0;
5455           idl_global->set_parse_state (
5456                           IDL_GlobalData::PS_ComponentForwardSeen
5457                         );
5459           /*
5460            * Create a node representing a forward declaration of a
5461            * component. Store it in the enclosing scope.
5462            */
5463           if (s != 0)
5464             {
5465               f = idl_global->gen ()->create_component_fwd (&n);
5466               (void) s->fe_add_component_fwd (f);
5467             }
5469           $2->destroy ();
5470           delete $2;
5471           $2 = 0;
5473           $$ = 0;
5474         }
5475         ;
5477 component_decl :
5478         component_header
5479         {
5480           FE_ComponentHeader *&component_header = $1;
5481           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
5482           AST_Component *component = 0;
5484           /*
5485            * Make a new component node and add it to the enclosing scope.
5486            */
5487           if (scope && component_header)
5488             {
5489               component = idl_global->gen ()->create_component (
5490                 component_header->name (),
5491                 component_header->base_component (),
5492                 component_header->supports (),
5493                 component_header->n_supports (),
5494                 component_header->supports_flat (),
5495                 component_header->n_supports_flat ());
5496               AST_Interface *component_as_interface =
5497                 dynamic_cast<AST_Interface *> (component);
5498               AST_Interface::fwd_redefinition_helper (
5499                 component_as_interface, scope);
5500               component = dynamic_cast<AST_Component *> (component_as_interface);
5502               /*
5503                * Add the component to its definition scope.
5504                */
5505               scope->fe_add_component (component);
5507               // This FE_ComponentHeader class isn't destroyed with the AST.
5508               component_header->destroy ();
5509               delete component_header;
5510               component_header = 0;
5511             }
5513           /*
5514            * Push it on the scope stack.
5515            */
5516           idl_global->scopes ().push (component);
5518           $<dcval>$ = component;
5519         }
5520         '{'
5521         {
5522           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentSqSeen);
5523         }
5524         component_exports
5525         {
5526           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentBodySeen);
5527         }
5528         '}'
5529         {
5530           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentQsSeen);
5532           /*
5533            * Done with this component - pop it off the scopes stack.
5534            */
5535           idl_global->scopes ().pop ();
5537           $$ = $<dcval>2;
5538         }
5539         ;
5541 component_header :
5542         IDL_COMPONENT
5543         defining_id
5544         {
5545           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentIDSeen);
5546         }
5547         component_inheritance_spec
5548         {
5549           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
5550         }
5551         supports_spec
5552         {
5553           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
5555           /*
5556            * Create an AST representation of the information in the header
5557            * part of a component.
5558            */
5559           UTL_ScopedName *n = 0;
5560           ACE_NEW_RETURN (n,
5561                           UTL_ScopedName ($2,
5562                                           0),
5563                           1);
5564           ACE_NEW_RETURN ($<chval>$,
5565                           FE_ComponentHeader (n,
5566                                               $4,
5567                                               $6,
5568                                               false),
5569                           1);
5571           if (0 != $6)
5572             {
5573               $6->destroy ();
5574               delete $6;
5575               $6 = 0;
5576             }
5578           if (0 != $4)
5579             {
5580               $4->destroy ();
5581               delete $4;
5582               $4 = 0;
5583             }
5584         }
5585         ;
5587 component_inheritance_spec
5588         : ':'
5589         {
5590           idl_global->set_parse_state (IDL_GlobalData::PS_InheritColonSeen);
5591         }
5592         scoped_name
5593         {
5594           $<idlist>$ = $3;
5595         }
5596         | %empty
5597         {
5598           $$ = 0;
5599         }
5600         ;
5602 component_exports
5603         : component_exports at_least_one_annotation component_export
5604         {
5605           AST_Annotation_Appls *&annotations = $2;
5606           AST_Decl *&node = $3;
5607           if (node)
5608             {
5609               node->annotation_appls (*annotations);
5610             }
5611           else
5612             {
5613               idl_global->err ()-> unsupported_warning (
5614                 "Annotating this is not supported");
5615             }
5616           delete annotations;
5617         }
5618         | component_exports component_export
5619         | %empty
5620         ;
5622 component_export
5623         : provides_decl
5624         {
5625           idl_global->set_parse_state (IDL_GlobalData::PS_ProvidesDeclSeen);
5626         }
5627         ';'
5628         {
5629           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5630           $$ = $1;
5631         }
5632         | uses_decl
5633         {
5634           idl_global->set_parse_state (IDL_GlobalData::PS_UsesDeclSeen);
5635         }
5636         ';'
5637         {
5638           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5639           $$ = $1;
5640         }
5641         | emits_decl
5642         {
5643           idl_global->set_parse_state (IDL_GlobalData::PS_EmitsDeclSeen);
5644         }
5645         ';'
5646         {
5647           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5648           $$ = $1;
5649         }
5650         | publishes_decl
5651         {
5652           idl_global->set_parse_state (IDL_GlobalData::PS_PublishesDeclSeen);
5653         }
5654         ';'
5655         {
5656           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5657           $$ = $1;
5658         }
5659         | consumes_decl
5660         {
5661           idl_global->set_parse_state (IDL_GlobalData::PS_ConsumesDeclSeen);
5662         }
5663         ';'
5664         {
5665           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5666           $$ = $1;
5667         }
5668         | attribute
5669         {
5670           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
5671         }
5672         ';'
5673         {
5674           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5675           $$ = $1;
5676         }
5677         | extended_port_decl
5678         {
5679           idl_global->set_parse_state (IDL_GlobalData::PS_ExtendedPortDeclSeen);
5680         }
5681         ';'
5682         {
5683           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5684           $$ = $1;
5685         }
5686         ;
5688 provides_decl : IDL_PROVIDES interface_type id
5689         {
5690           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5691           bool so_far_so_good = true;
5692           AST_Decl::NodeType nt = AST_Decl::NT_type;
5693           AST_Param_Holder *ph = 0;
5695           AST_Decl *d =
5696             s->lookup_by_name ($2, true, false);
5698           if (d == 0)
5699             {
5700               idl_global->err ()->lookup_error ($2);
5701               so_far_so_good = false;
5702             }
5703           else
5704             {
5705               int compare = 0;
5706               nt = d->node_type ();
5708               switch (nt)
5709                 {
5710                   case AST_Decl::NT_interface:
5711                     break;
5712                   case AST_Decl::NT_param_holder:
5713                     ph = dynamic_cast<AST_Param_Holder*> (d);
5714                     nt = ph->info ()->type_;
5716                     if (nt != AST_Decl::NT_type
5717                        && nt != AST_Decl::NT_interface)
5718                       {
5719                         idl_global->err ()->mismatched_template_param (
5720                           ph->info ()->name_.c_str ());
5722                         so_far_so_good = false;
5723                       }
5725                     break;
5726                   case AST_Decl::NT_pre_defined:
5727                     // Nothing else but CORBA::Object can have
5728                     // this identifier.
5729                     compare =
5730                       ACE_OS::strcmp (d->local_name ()->get_string (),
5731                                       "Object");
5733                     // Simple provides port must use IDL interface
5734                     // or CORBA::Object.
5735                     if (compare != 0)
5736                       {
5737                         idl_global->err ()->interface_expected (d);
5738                         so_far_so_good = false;
5739                       }
5741                     break;
5742                   default:
5743                     idl_global->err ()->interface_expected (d);
5744                     so_far_so_good = false;
5745                     break;
5746                 }
5747             }
5749           AST_Provides *provides = 0;
5751           if (so_far_so_good)
5752             {
5753               AST_Type *port_interface_type =
5754                 dynamic_cast<AST_Type*> (d);
5756               // Strip off _cxx_, if any, for port name.
5757               FE_Utils::original_local_name ($3);
5759               UTL_ScopedName sn ($3,
5760                                  0);
5762               provides = idl_global->gen ()->create_provides (
5763                 &sn, port_interface_type);
5765               (void) s->fe_add_provides (provides);
5766             }
5768           $2->destroy ();
5769           delete $2;
5770           $2 = 0;
5772           $3->destroy ();
5773           delete $3;
5774           $3 = 0;
5776           $$ = dynamic_cast<AST_Decl *> (provides);
5777         }
5778         ;
5780 interface_type
5781         : scoped_name
5782         {
5783           // Lookups and checking are done where the 'interface_type'
5784           // token is used, in 'provides_decl' and 'uses_decl'.
5785           $$ = $1;
5786         }
5787         | IDL_OBJECT
5788         {
5789           Identifier *corba_id = 0;
5791           ACE_NEW_RETURN (corba_id,
5792                           Identifier ("Object"),
5793                           1);
5795           UTL_IdList *conc_name = 0;
5796           ACE_NEW_RETURN (conc_name,
5797                           UTL_IdList (corba_id,
5798                                       0),
5799                           1);
5801           ACE_NEW_RETURN (corba_id,
5802                           Identifier ("CORBA"),
5803                           1);
5805           ACE_NEW_RETURN ($<idlist>$,
5806                           UTL_IdList (corba_id,
5807                                       conc_name),
5808                           1);
5809         }
5810         ;
5812 uses_decl : uses_opt_multiple interface_type id
5813         {
5814           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5815           bool so_far_so_good = true;
5816           AST_Decl::NodeType nt = AST_Decl::NT_type;
5817           AST_Param_Holder *ph = 0;
5819           AST_Decl *d =
5820             s->lookup_by_name ($2, true, false);
5822           if (d == 0)
5823             {
5824               idl_global->err ()->lookup_error ($2);
5825               so_far_so_good = false;
5826             }
5827           else
5828             {
5829               int compare = 0;
5830               nt = d->node_type ();
5832               switch (nt)
5833                 {
5834                   case AST_Decl::NT_interface:
5835                     break;
5836                   case AST_Decl::NT_param_holder:
5837                     ph = dynamic_cast<AST_Param_Holder*> (d);
5838                     nt = ph->info ()->type_;
5840                     if (nt != AST_Decl::NT_type
5841                        && nt != AST_Decl::NT_interface)
5842                       {
5843                         idl_global->err ()->mismatched_template_param (
5844                           ph->info ()->name_.c_str ());
5846                         so_far_so_good = false;
5847                       }
5849                     break;
5850                   case AST_Decl::NT_pre_defined:
5851                     // Nothing else but CORBA::Object can have
5852                     // this identifier.
5853                     compare =
5854                       ACE_OS::strcmp (d->local_name ()->get_string (),
5855                                       "Object");
5857                     // Simple provides port must use IDL interface
5858                     // or CORBA::Object.
5859                     if (compare != 0)
5860                       {
5861                         idl_global->err ()->interface_expected (d);
5862                         so_far_so_good = false;
5863                       }
5865                     break;
5866                   default:
5867                     idl_global->err ()->interface_expected (d);
5868                     so_far_so_good = false;
5869                     break;
5870                 }
5871             }
5873           AST_Uses *uses = 0;
5875           if (so_far_so_good)
5876             {
5877               AST_Type *port_interface_type =
5878                 dynamic_cast<AST_Type*> (d);
5880               // Strip off _cxx_, if any, for port name.
5881               FE_Utils::original_local_name ($3);
5883               UTL_ScopedName sn ($3,
5884                                  0);
5886               uses = idl_global->gen ()->create_uses (
5887                 &sn, port_interface_type, $1);
5888               s->fe_add_uses (uses);
5890               AST_Component *c =
5891                 dynamic_cast<AST_Component*> (s);
5893               if (c != 0
5894                   && uses->is_multiple ()
5895                   && !idl_global->using_ifr_backend ()
5896                   && !idl_global->ignore_idl3 ()
5897                   && nt != AST_Decl::NT_param_holder)
5898                 {
5899                   // These datatypes must be created in the
5900                   // front end so they can be looked up
5901                   // when compiling the generated executor IDL.
5902                   FE_Utils::create_uses_multiple_stuff (c, uses);
5903                 }
5904             }
5906           $2->destroy ();
5907           delete $2;
5908           $2 = 0;
5910           $3->destroy ();
5911           delete $3;
5912           $3 = 0;
5914           $$ = uses;
5915         }
5916         ;
5918 uses_opt_multiple
5919         : IDL_USES opt_multiple
5920         {
5921           // We use this extra rule here to use in both uses_decl and
5922           // extended_uses_decl, so the LALR(1) parser can avoid conflicts.
5923           $$ = $2;
5924         }
5925         ;
5927 opt_multiple
5928         : IDL_MULTIPLE
5929         {
5930           $$ = true;
5931         }
5932         | %empty
5933         {
5934           $$ = false;
5935         }
5936         ;
5938 emits_decl
5939         : IDL_EMITS scoped_name id
5940         {
5941           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5942           bool so_far_so_good = true;
5943           AST_Decl::NodeType nt = AST_Decl::NT_type;
5944           AST_Param_Holder *ph = 0;
5946           AST_Decl *d =
5947             s->lookup_by_name ($2, true, false);
5949           if (0 == d)
5950             {
5951               idl_global->err ()->lookup_error ($2);
5952               so_far_so_good = false;
5953             }
5954           else
5955             {
5956               nt = d->node_type ();
5958               switch (nt)
5959                 {
5960                   case AST_Decl::NT_eventtype:
5961                     break;
5962                   case AST_Decl::NT_param_holder:
5963                     ph = dynamic_cast<AST_Param_Holder*> (d);
5964                     nt = ph->info ()->type_;
5966                     if (nt != AST_Decl::NT_type
5967                        && nt != AST_Decl::NT_eventtype)
5968                       {
5969                         idl_global->err ()->mismatched_template_param (
5970                           ph->info ()->name_.c_str ());
5972                         so_far_so_good = false;
5973                       }
5975                     break;
5976                   default:
5977                     idl_global->err ()->eventtype_expected (d);
5978                     so_far_so_good = false;
5979                     break;
5980                 }
5981             }
5983           AST_Emits *e = 0;
5985           if (so_far_so_good)
5986             {
5987               AST_Type *event_type =
5988                 dynamic_cast<AST_Type*> (d);
5990               // Strip off _cxx_, if any, for port name.
5991               FE_Utils::original_local_name ($3);
5993               UTL_ScopedName sn ($3,
5994                                  0);
5996               e = idl_global->gen ()->create_emits (&sn, event_type);
5998               (void) s->fe_add_emits (e);
5999             }
6001           $2->destroy ();
6002           delete $2;
6003           $2 = 0;
6005           $3->destroy ();
6006           delete $3;
6007           $3 = 0;
6009           $$ = e;
6010         }
6011         ;
6013 publishes_decl
6014         : IDL_PUBLISHES scoped_name id
6015         {
6016           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6017           bool so_far_so_good = true;
6018           AST_Decl::NodeType nt = AST_Decl::NT_type;
6019           AST_Param_Holder *ph = 0;
6021           AST_Decl *d =
6022             s->lookup_by_name ($2, true, false);
6024           if (0 == d)
6025             {
6026               idl_global->err ()->lookup_error ($2);
6027               so_far_so_good = false;
6028             }
6029           else
6030             {
6031               nt = d->node_type ();
6033               switch (nt)
6034                 {
6035                   case AST_Decl::NT_eventtype:
6036                     break;
6037                   case AST_Decl::NT_param_holder:
6038                     ph = dynamic_cast<AST_Param_Holder*> (d);
6039                     nt = ph->info ()->type_;
6041                     if (nt != AST_Decl::NT_type
6042                        && nt != AST_Decl::NT_eventtype)
6043                       {
6044                         idl_global->err ()->mismatched_template_param (
6045                           ph->info ()->name_.c_str ());
6047                         so_far_so_good = false;
6048                       }
6050                     break;
6051                   default:
6052                     idl_global->err ()->eventtype_expected (d);
6053                     so_far_so_good = false;
6054                     break;
6055                 }
6056             }
6058           AST_Publishes *p = 0;
6060           if (so_far_so_good)
6061             {
6062               AST_Type *event_type =
6063                 dynamic_cast<AST_Type*> (d);
6065               // Strip off _cxx_, if any, for port name.
6066               FE_Utils::original_local_name ($3);
6068               UTL_ScopedName sn ($3, 0);
6069               p = idl_global->gen ()->create_publishes (&sn, event_type);
6070               s->fe_add_publishes (p);
6071             }
6073           $2->destroy ();
6074           delete $2;
6075           $2 = 0;
6077           $3->destroy ();
6078           delete $3;
6079           $3 = 0;
6081           $$ = p;
6082         }
6083         ;
6085 consumes_decl
6086         : IDL_CONSUMES scoped_name id
6087         {
6088           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6089           bool so_far_so_good = true;
6090           AST_Decl::NodeType nt = AST_Decl::NT_type;
6091           AST_Param_Holder *ph = 0;
6093           AST_Decl *d =
6094             s->lookup_by_name ($2, true, false);
6096           if (0 == d)
6097             {
6098               idl_global->err ()->lookup_error ($2);
6099               so_far_so_good = false;
6100             }
6101           else
6102             {
6103               nt = d->node_type ();
6105               switch (nt)
6106                 {
6107                   case AST_Decl::NT_eventtype:
6108                     break;
6109                   case AST_Decl::NT_param_holder:
6110                     ph = dynamic_cast<AST_Param_Holder*> (d);
6111                     nt = ph->info ()->type_;
6113                     if (nt != AST_Decl::NT_type
6114                        && nt != AST_Decl::NT_eventtype)
6115                       {
6116                         idl_global->err ()->mismatched_template_param (
6117                           ph->info ()->name_.c_str ());
6119                         so_far_so_good = false;
6120                       }
6122                     break;
6123                   default:
6124                     idl_global->err ()->eventtype_expected (d);
6125                     so_far_so_good = false;
6126                     break;
6127                 }
6128             }
6130           AST_Consumes *c = 0;
6132           if (so_far_so_good)
6133             {
6134               AST_Type *event_type =
6135                 dynamic_cast<AST_Type*> (d);
6137               // Strip off _cxx_, if any, for port name.
6138               FE_Utils::original_local_name ($3);
6140               UTL_ScopedName sn ($3,
6141                                  0);
6143               c = idl_global->gen ()->create_consumes (&sn, event_type);
6145               (void) s->fe_add_consumes (c);
6146             }
6148           $2->destroy ();
6149           delete $2;
6150           $2 = 0;
6152           $3->destroy ();
6153           delete $3;
6154           $3 = 0;
6156           $$ = c;
6157        }
6158        ;
6160 home_decl
6161         : home_header
6162         {
6163           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6164           AST_Home *h = 0;
6166           /*
6167            * Make a new home node and add it to the enclosing scope.
6168            */
6169           if (s != 0 && $1 != 0)
6170             {
6171               h =
6172                 idl_global->gen ()->create_home (
6173                                         $1->name (),
6174                                         $1->base_home (),
6175                                         $1->managed_component (),
6176                                         $1->primary_key (),
6177                                         $1->supports (),
6178                                         $1->n_supports (),
6179                                         $1->supports_flat (),
6180                                         $1->n_supports_flat ()
6181                                       );
6182               /*
6183                * Add the home to its definition scope.
6184                */
6185               (void) s->fe_add_home (h);
6187               // This FE_HomeHeader class isn't destroyed with the AST.
6188               $1->destroy ();
6189               delete $1;
6190               $1 = 0;
6191             }
6193           /*
6194            * Push it on the scope stack.
6195            */
6196           idl_global->scopes ().push (h);
6197         }
6198         home_body
6199         {
6200           /*
6201            * Done with this component - pop it off the scopes stack.
6202            */
6203           idl_global->scopes ().pop ();
6205           $$ = 0;
6206         }
6207         ;
6209 home_header
6210         : IDL_HOME
6211         {
6212           idl_global->set_parse_state (IDL_GlobalData::PS_HomeSeen);
6213         }
6214         defining_id
6215         {
6216           idl_global->set_parse_state (IDL_GlobalData::PS_HomeIDSeen);
6217         }
6218         home_inheritance_spec
6219         {
6220           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
6221         }
6222         supports_spec
6223         {
6224           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
6225         }
6226         IDL_MANAGES
6227         {
6228           idl_global->set_parse_state (IDL_GlobalData::PS_ManagesSeen);
6229         }
6230         scoped_name
6231         {
6232           idl_global->set_parse_state (IDL_GlobalData::PS_ManagesIDSeen);
6233         }
6234         primary_key_spec
6235         {
6236           idl_global->set_parse_state (IDL_GlobalData::PS_PrimaryKeySpecSeen);
6238           /*
6239            * Create an AST representation of the information in the header
6240            * part of a component home.
6241            */
6242           UTL_ScopedName *n = 0;
6243           ACE_NEW_RETURN (n,
6244                           UTL_ScopedName ($3, 0),
6245                           1);
6247           ACE_NEW_RETURN ($<hhval>$,
6248                           FE_HomeHeader (n,
6249                                          $5,
6250                                          $7,
6251                                          $11,
6252                                          $13),
6253                           1);
6255           $11->destroy ();
6256           delete $11;
6257           $11 = 0;
6259           if (0 != $5)
6260             {
6261               $5->destroy ();
6262               delete $5;
6263               $5 = 0;
6264             }
6266           if (0 != $13)
6267             {
6268               $13->destroy ();
6269               delete $13;
6270               $13 = 0;
6271             }
6273           if (0 != $7)
6274             {
6275               $7->destroy ();
6276               delete $7;
6277               $7 = 0;
6278             }
6279         }
6280         ;
6282 home_inheritance_spec
6283         : ':'
6284         {
6285           idl_global->set_parse_state (IDL_GlobalData::PS_InheritColonSeen);
6286         }
6287           scoped_name
6288         {
6289           $<idlist>$ = $3;
6290         }
6291         | %empty
6292         {
6293           $$ = 0;
6294         }
6295         ;
6297 primary_key_spec
6298         : IDL_PRIMARYKEY
6299           scoped_name
6300         {
6301           $$ = $2;
6302         }
6303         | %empty
6304         {
6305           $$ = 0;
6306         }
6307         ;
6309 home_body :
6310         '{'
6311         {
6312           idl_global->set_parse_state (IDL_GlobalData::PS_HomeSqSeen);
6313         }
6314         home_exports
6315         {
6316           idl_global->set_parse_state (IDL_GlobalData::PS_HomeBodySeen);
6317         }
6318         '}'
6319         {
6320           idl_global->set_parse_state (IDL_GlobalData::PS_HomeQsSeen);
6321         }
6322         ;
6324 home_exports
6325         : home_exports home_export
6326         | %empty
6327         ;
6329 home_export
6330         : export
6331         | factory_decl
6332         {
6333           idl_global->set_parse_state (IDL_GlobalData::PS_FactoryDeclSeen);
6334         }
6335         ';'
6336         {
6337           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
6338         }
6339         | finder_decl
6340         {
6341           idl_global->set_parse_state (IDL_GlobalData::PS_FinderDeclSeen);
6342         }
6343         ';'
6344         {
6345           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
6346         }
6347         ;
6349 factory_decl :
6350         IDL_FACTORY
6351         defining_id
6352         {
6353           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6354           UTL_ScopedName n ($2,
6355                             0);
6356           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
6358           /*
6359            * Create a node representing a factory operation
6360            * and add it to the enclosing scope.
6361            */
6362           AST_Factory *f = idl_global->gen ()->create_factory (&n);
6363           (void) s->fe_add_factory (f);
6365           $2->destroy ();
6366           delete $2;
6367           $2 = 0;
6369           /*
6370            * Push the factory scope onto the scopes stack.
6371            */
6372           idl_global->scopes ().push (f);
6373         }
6374         init_parameter_list
6375         {
6376           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
6377         }
6378         opt_raises
6379         {
6380           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6381           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
6383           /*
6384            * Add exceptions and context to the factory.
6385            */
6386           if ($6 != 0)
6387             {
6388               (void) s->fe_add_exceptions ($6);
6389             }
6391           /*
6392            * Done with this factory. Pop its scope from the scopes stack.
6393            */
6394           idl_global->scopes ().pop ();
6395         }
6396         ;
6398 finder_decl :
6399         IDL_FINDER
6400         defining_id
6401         {
6402           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6403           UTL_ScopedName n ($2,
6404                             0);
6406           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
6408           /*
6409            * Create a node representing a home finder
6410            * and add it to the enclosing scope.
6411            */
6412           AST_Finder *f =
6413             idl_global->gen ()->create_finder (&n);
6415           (void) s->fe_add_finder (f);
6418           $2->destroy ();
6419           delete $2;
6420           $2 = 0;
6422           /*
6423            * Push the operation scope onto the scopes stack.
6424            */
6425           idl_global->scopes ().push (f);
6426         }
6427         init_parameter_list
6428         {
6429           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
6430         }
6431         opt_raises
6432         {
6433           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6434           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
6436           /*
6437            * Add exceptions and context to the finder.
6438            */
6439           if ($6 != 0)
6440             {
6441               (void) s->fe_add_exceptions ($6);
6442             }
6444           /*
6445            * Done with this operation. Pop its scope from the scopes stack.
6446            */
6447           idl_global->scopes ().pop ();
6448         }
6449         ;
6451 event
6452         : event_decl
6453         | event_abs_decl
6454         | event_forward_decl
6455         ;
6457 event_forward_decl
6458         : event_abs_forward_decl
6459         | event_concrete_forward_decl
6460         ;
6462 event_concrete_forward_decl :
6463         IDL_EVENTTYPE
6464         defining_id
6465         {
6466           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6467           UTL_ScopedName n ($2,
6468                             0);
6469           AST_EventTypeFwd *f = 0;
6470           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeForwardSeen);
6472           /*
6473            * Create a node representing a forward declaration of an
6474            * eventtype. Store it in the enclosing scope
6475            */
6476           if (s != 0)
6477             {
6478               f = idl_global->gen ()->create_eventtype_fwd (&n,
6479                                                             false);
6480               (void) s->fe_add_valuetype_fwd (f);
6481             }
6483           $2->destroy ();
6484           delete $2;
6485           $2 = 0;
6487           $$ = 0;
6488         }
6489         ;
6491 event_abs_forward_decl :
6492         IDL_ABSTRACT
6493         IDL_EVENTTYPE
6494         defining_id
6495         {
6496           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6497           UTL_ScopedName n ($3,
6498                             0);
6499           AST_EventTypeFwd *f = 0;
6500           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeForwardSeen);
6502           /*
6503            * Create a node representing a forward declaration of an
6504            * eventtype. Store it in the enclosing scope
6505            */
6506           if (s != 0)
6507             {
6508               f = idl_global->gen ()->create_eventtype_fwd (&n,
6509                                                             true);
6510               (void) s->fe_add_valuetype_fwd (f);
6511             }
6513           $3->destroy ();
6514           delete $3;
6515           $3 = 0;
6517           $$ = 0;
6518         }
6519         ;
6521 event_abs_decl :
6522         event_abs_header
6523         event_rest_of_header
6524         {
6525           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6526           AST_EventType *e = 0;
6527           AST_Interface *i = 0;
6529           if (s != 0 && $1 != 0)
6530             {
6531               UTL_ScopedName sn ($1,
6532                                  0);
6533               e =
6534                 idl_global->gen ()->create_eventtype (
6535                     &sn,
6536                     $2->inherits (),
6537                     $2->n_inherits (),
6538                     $2->inherits_concrete (),
6539                     $2->inherits_flat (),
6540                     $2->n_inherits_flat (),
6541                     $2->supports (),
6542                     $2->n_supports (),
6543                     $2->supports_concrete (),
6544                     true,
6545                     false,
6546                     false
6547                   );
6548               i = dynamic_cast<AST_Interface*> (e);
6549               AST_Interface::fwd_redefinition_helper (i,
6550                                                       s);
6551               /*
6552                * Add the eventetype to its definition scope
6553                */
6554               e = dynamic_cast<AST_EventType*> (i);
6555               (void) s->fe_add_eventtype (e);
6556             }
6558           /*
6559            * Push it on the scope stack.
6560            */
6561           idl_global->scopes ().push (e);
6563           $1->destroy ();
6564           delete $1;
6565           $1 = 0;
6566         }
6567         '{'
6568         {
6569           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeSqSeen);
6570         }
6571         exports
6572         {
6573           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeBodySeen);
6574         }
6575         '}'
6576         {
6577           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeQsSeen);
6579           /*
6580            * Done with this eventtype - pop it off the scopes stack.
6581            */
6582           idl_global->scopes ().pop ();
6584           $$ = 0;
6585         }
6586         ;
6588 event_abs_header :
6589         IDL_ABSTRACT
6590         IDL_EVENTTYPE
6591         defining_id
6592         {
6593           $$ = $3;
6594         }
6595         ;
6597 event_custom_header :
6598         IDL_CUSTOM
6599         IDL_EVENTTYPE
6600         defining_id
6601         {
6602           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeIDSeen);
6604           ACE_DEBUG ((LM_DEBUG,
6605                       ACE_TEXT ("error in %C line %d\n"),
6606                       idl_global->filename ()->get_string (),
6607                       idl_global->lineno ()));
6608           ACE_DEBUG ((LM_DEBUG,
6609                       ACE_TEXT ("Sorry, I (TAO_IDL) can't handle")
6610                       ACE_TEXT (" custom yet\n")));
6611           $$ = 0;
6612         }
6613         ;
6615 event_plain_header :
6616         IDL_EVENTTYPE
6617         defining_id
6618         {
6619           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeIDSeen);
6621           $$ = $2;
6622         }
6623         ;
6625 event_rest_of_header :
6626         inheritance_spec
6627         {
6628           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
6629         }
6630         supports_spec
6631         {
6632           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
6634           ACE_NEW_RETURN ($<vhval>$,
6635                           FE_OBVHeader (
6636                             0,
6637                             $1,
6638                             $3,
6639                             $1
6640                               ? $1->truncatable ()
6641                               : false,
6642                             true),
6643                           1);
6645           if (0 != $3)
6646             {
6647               $3->destroy ();
6648               delete $3;
6649               $3 = 0;
6650             }
6652           if (0 != $1)
6653             {
6654               $1->destroy ();
6655               delete $1;
6656               $1 = 0;
6657             }
6658         }
6659         ;
6661 event_decl :
6662         event_header
6663         event_rest_of_header
6664         {
6665           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
6666           Identifier *&event_id = $1;
6667           FE_OBVHeader *&event_header = $2;
6668           AST_EventType *eventtype = 0;
6670           if (scope && event_header)
6671             {
6672               // We create the scoped name here instead of with the
6673               // FE_OBVHeader because there is a token for it only here.
6674               UTL_ScopedName sn (event_id, 0);
6675               eventtype = idl_global->gen ()->create_eventtype (
6676                 &sn,
6677                 event_header->inherits (),
6678                 event_header->n_inherits (),
6679                 event_header->inherits_concrete (),
6680                 event_header->inherits_flat (),
6681                 event_header->n_inherits_flat (),
6682                 event_header->supports (),
6683                 event_header->n_supports (),
6684                 event_header->supports_concrete (),
6685                 false,
6686                 event_header->truncatable (),
6687                 false);
6688               AST_Interface *eventtype_as_interface =
6689                 dynamic_cast<AST_Interface *> (eventtype);
6690               AST_Interface::fwd_redefinition_helper (
6691                 eventtype_as_interface, scope);
6692               eventtype = dynamic_cast<AST_EventType *> (eventtype_as_interface);
6694               /*
6695                * Add the eventetype to its definition scope
6696                */
6697               scope->fe_add_eventtype (eventtype);
6699               // FE_OBVHeader is not automatically destroyed in the AST
6700               event_header->destroy ();
6701               delete event_header;
6702               event_header = 0;
6704               sn.destroy ();
6705             }
6707           /*
6708            * Push it on the scope stack.
6709            */
6710           idl_global->scopes ().push (eventtype);
6712           $<dcval>$ = eventtype;
6713         }
6714         '{'
6715         {
6716           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeSqSeen);
6717         }
6718         value_elements
6719         {
6720           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeBodySeen);
6721         }
6722         '}'
6723         {
6724           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeQsSeen);
6726           /*
6727            * Done with this eventtype - pop it off the scopes stack.
6728            */
6729           idl_global->scopes ().pop ();
6731           $$ = $<dcval>3;
6732         }
6733         ;
6735 event_header
6736         : event_custom_header
6737         {
6738           $$ = $1;
6739         }
6740         | event_plain_header
6741         {
6742           $$ = $1;
6743         }
6744         ;
6746 formal_parameter_type
6747         : IDL_TYPENAME
6748         {
6749           $<ntval>$ = AST_Decl::NT_type;
6750         }
6751         | IDL_STRUCT
6752         {
6753           $<ntval>$ = AST_Decl::NT_struct;
6754         }
6755         | IDL_UNION
6756         {
6757           $<ntval>$ = AST_Decl::NT_union;
6758         }
6759         | IDL_EVENTTYPE
6760         {
6761           $<ntval>$ = AST_Decl::NT_eventtype;
6762         }
6763         | IDL_SEQUENCE
6764         {
6765           $<ntval>$ = AST_Decl::NT_sequence;
6766         }
6767         | IDL_MAP
6768         {
6769           $<ntval>$ = AST_Decl::NT_map;
6770         }
6771         | IDL_INTERFACE
6772         {
6773           $<ntval>$ = AST_Decl::NT_interface;
6774         }
6775         | IDL_VALUETYPE
6776         {
6777           $<ntval>$ = AST_Decl::NT_valuetype;
6778         }
6779         | IDL_ENUM
6780         {
6781           $<ntval>$ = AST_Decl::NT_enum;
6782         }
6783         | IDL_EXCEPTION
6784         {
6785           $<ntval>$ = AST_Decl::NT_except;
6786         }
6787         | IDL_CONST const_type
6788         {
6789           $<ntval>$ = AST_Decl::NT_const;
6790           t_param_const_type = $2;
6791         }
6792         ;
6794 at_least_one_formal_parameter
6795         : formal_parameter formal_parameters
6796         {
6797           if ($2 == 0)
6798             {
6799               ACE_NEW_RETURN ($2, FE_Utils::T_PARAMLIST_INFO, 1);
6800             }
6802           $2->enqueue_head (*$1);
6803           delete $1;
6804           $1 = 0;
6806           // The param added above is always the last one parsed,
6807           // so we check for matches between sequence<T> & T here.
6808           ACE_CString bad_id =
6809             FE_Utils::check_for_seq_of_param (
6810               $2);
6812           if (!bad_id.empty ())
6813             {
6814               delete $2;
6815               $2 = 0;
6817               idl_global->err ()->mismatch_seq_of_param (bad_id.c_str ());
6818               return 1;
6819             }
6821           $$ = $2;
6822         }
6823         ;
6825 formal_parameters
6826         : formal_parameters ',' formal_parameter
6827         {
6828           if ($1 == 0)
6829             {
6830               ACE_NEW_RETURN ($1, FE_Utils::T_PARAMLIST_INFO, 1);
6831             }
6833           $1->enqueue_tail (*$3);
6834           $$ = $1;
6836           delete $3;
6837           $3 = 0;
6838         }
6839         | %empty
6840         {
6841           $$ = 0;
6842         }
6843         ;
6845 formal_parameter
6846         : formal_parameter_type IDENTIFIER
6847         {
6849           ACE_NEW_RETURN ($$,
6850                           FE_Utils::T_Param_Info,
6851                           1);
6853           AST_Decl::NodeType nt = $1;
6855           $$->type_ = nt;
6856           $$->name_ = $2;
6857           ACE::strdelete ($2);
6858           $2 = 0;
6860           if (nt == AST_Decl::NT_const)
6861             {
6862               $$->const_type_ = t_param_const_type;
6863               $$->enum_const_type_decl_ =
6864                 tao_enum_constant_decl;
6866               // Reset these values.
6867               t_param_const_type = AST_Expression::EV_none;
6868               tao_enum_constant_decl = 0;
6869             }
6870         }
6871         | IDL_SEQUENCE '<' IDENTIFIER '>' IDENTIFIER
6872         {
6873           ACE_NEW_RETURN ($$,
6874                           FE_Utils::T_Param_Info,
6875                           1);
6877           $$->type_ = AST_Decl::NT_sequence;
6878           $$->seq_param_ref_  = $3;
6879           $$->name_ += $5;
6881           ACE::strdelete ($3);
6882           $3 = 0;
6883           ACE::strdelete ($5);
6884           $5 = 0;
6885         }
6886         ;
6888 at_least_one_formal_parameter_name
6889         : formal_parameter_name formal_parameter_names
6890         {
6891           ACE_NEW_RETURN ($$, UTL_StrList ($1, $2), 1);
6892         }
6893         ;
6895 formal_parameter_names
6896         : formal_parameter_names ',' formal_parameter_name
6897         {
6898           UTL_StrList *sl = 0;
6899           ACE_NEW_RETURN (sl, UTL_StrList ($3, 0), 1);
6901           if ($1 == 0)
6902             {
6903               $$ = sl;
6904             }
6905           else
6906             {
6907               $1->nconc (sl);
6908               $$ = $1;
6909             }
6910         }
6911         | %empty
6912         {
6913           $$ = 0;
6914         }
6915         ;
6917 formal_parameter_name
6918         : IDENTIFIER
6919         {
6920           ACE_NEW_RETURN ($$,
6921                           UTL_String ($1, true),
6922                           1);
6923         }
6924         ;
6926 porttype_decl
6927         : IDL_PORTTYPE
6928         {
6929           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeSeen);
6930         }
6931         IDENTIFIER
6932         {
6933           char *&id_value = $3;
6934           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeIDSeen);
6935           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
6937           Identifier id (id_value);
6938           ACE::strdelete (id_value);
6939           id_value = 0;
6941           UTL_ScopedName scoped_name (&id, 0);
6942           AST_PortType *porttype = idl_global->gen ()->create_porttype (
6943             &scoped_name);
6944           scope->fe_add_porttype (porttype);
6945           $<dcval>$ = porttype;
6947           // Push it on the scopes stack.
6948           idl_global->scopes ().push (porttype);
6949         }
6950         '{'
6951         {
6952           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeSqSeen);
6953         }
6954         /**
6955          * NOTE: IDL4.2 spec has a different definition of what can go inside a
6956          * portype.
6957          */
6958         at_least_one_port_export
6959         {
6960           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeBodySeen);
6961         }
6962         '}'
6963         {
6964           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeQsSeen);
6966           // Done with this port type - pop it off the scopes stack.
6967           idl_global->scopes ().pop ();
6969           $$ = $<dcval>4;
6970         }
6971         ;
6973 at_least_one_port_export
6974         : port_exports at_least_one_annotation port_export
6975         {
6976           AST_Annotation_Appls *&annotations = $2;
6977           AST_Decl *&node = $3;
6978           if (node)
6979             {
6980               node->annotation_appls (*annotations);
6981             }
6982           else
6983             {
6984               idl_global->err ()-> unsupported_warning (
6985                 "Annotating this is not supported");
6986             }
6987           delete annotations;
6988         }
6989         | port_exports port_export
6990         ;
6992 port_exports
6993         : at_least_one_port_export
6994         | %empty
6995         ;
6997 port_export
6998         : provides_decl ';'
6999         | uses_decl ';'
7000         | attribute
7001         {
7002           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
7003         }
7004         ';'
7005         {
7006           $$ = $1;
7007         }
7008         ;
7010 extended_port_decl
7011         : IDL_PORT scoped_name IDENTIFIER
7012         {
7013           idl_global->set_parse_state (IDL_GlobalData::PS_ExtendedPortDeclSeen);
7014           UTL_Scope *s = idl_global->scopes ().top_non_null ();
7015           AST_Decl *d =
7016             s->lookup_by_name ($2);
7017           AST_PortType *pt = 0;
7018           bool so_far_so_good = true;
7020           if (d == 0)
7021             {
7022               idl_global->err ()->lookup_error ($2);
7023               so_far_so_good = false;
7024             }
7025           else
7026             {
7027               pt = dynamic_cast<AST_PortType*> (d);
7029               if (pt == 0)
7030                 {
7031                   idl_global->err ()->error1 (UTL_Error::EIDL_PORTTYPE_EXPECTED,
7032                                               d);
7033                   so_far_so_good = false;
7034                 }
7035             }
7037           AST_Extended_Port *ep = 0;
7039           if (so_far_so_good)
7040             {
7041               Identifier id ($3);
7042               ACE::strdelete ($3);
7043               $3 = 0;
7045               UTL_ScopedName sn (&id, 0);
7046               ep = idl_global->gen ()->create_extended_port (&sn, pt);
7047               s->fe_add_extended_port (ep);
7049               // Create (in the AST) the struct(s) and sequence(s)
7050               // needed for multiplex uses ports, if any.
7051               for (UTL_ScopeActiveIterator i (pt, UTL_Scope::IK_decls);
7052                    !i.is_done ();
7053                    i.next ())
7054                 {
7055                   d = i.item ();
7057                   AST_Uses *u = dynamic_cast<AST_Uses*> (d);
7059                   if (u != 0 && u->is_multiple ())
7060                     {
7061                       AST_Component *c =
7062                         dynamic_cast<AST_Component*> (s);
7064                       FE_Utils::create_uses_multiple_stuff (
7065                         c,
7066                         u,
7067                         id.get_string ());
7068                     }
7069                 }
7070             }
7072           $2->destroy ();
7073           delete $2;
7074           $2 = 0;
7076           $$ = ep;
7077         }
7078         | IDL_MIRRORPORT scoped_name IDENTIFIER
7079         {
7080           idl_global->set_parse_state (IDL_GlobalData::PS_MirrorPortDeclSeen);
7081           UTL_Scope *s = idl_global->scopes ().top_non_null ();
7082           AST_Decl *d =
7083             s->lookup_by_name ($2);
7084           AST_PortType *pt = 0;
7085           bool so_far_so_good = true;
7087           if (d == 0)
7088             {
7089               idl_global->err ()->lookup_error ($2);
7090               so_far_so_good = false;
7091             }
7092            else
7093              {
7094                pt = dynamic_cast<AST_PortType*> (d);
7096                if (pt == 0)
7097                  {
7098                    idl_global->err ()->error1 (UTL_Error::EIDL_PORTTYPE_EXPECTED,
7099                                                d);
7100                    so_far_so_good = false;
7101                  }
7102              }
7104           AST_Mirror_Port *mp = 0;
7106           if (so_far_so_good)
7107             {
7108               Identifier id ($3);
7109               ACE::strdelete ($3);
7110               $3 = 0;
7112               UTL_ScopedName sn (&id, 0);
7113               mp = idl_global->gen ()->create_mirror_port (&sn, pt);
7114               s->fe_add_mirror_port (mp);
7115             }
7117           $2->destroy ();
7118           delete $2;
7119           $2 = 0;
7121           $$ = mp;
7122         }
7123         ;
7125 at_least_one_actual_parameter
7126         : annotations_maybe actual_parameter actual_parameters
7127         {
7128           if ($3 == 0)
7129             {
7130               ACE_NEW_RETURN ($3,
7131                               FE_Utils::T_ARGLIST,
7132                               1);
7133             }
7135           delete $1;
7136           $3->enqueue_head ($2);
7137           $<alval>$ = $3;
7138         }
7139         ;
7141 actual_parameters
7142         : actual_parameters ',' annotations_maybe actual_parameter
7143         {
7144           if ($1 == 0)
7145             {
7146               ACE_NEW_RETURN ($1,
7147                               FE_Utils::T_ARGLIST,
7148                               1);
7149             }
7151           delete $3;
7152           $1->enqueue_tail ($4);
7153           $<alval>$ = $1;
7154         }
7155         | %empty
7156         {
7157           $<alval>$ = 0;
7158         }
7159         ;
7161 actual_parameter
7162         : expression
7163         {
7164           // To avoid grammar conflicts with this LALR(1) parser,
7165           // we take advantage of the fact that an expression can
7166           // be a scoped name. At that lower level, we create an
7167           // expression containing the scoped name, and at a
7168           // higher lever, deduce that it's not supposed to be
7169           // a constant and look up the type to add to the template
7170           // arg list.
7171           AST_Expression *ex = $1;
7172           UTL_ScopedName *sn = ex->n ();
7173           AST_Decl *d = 0;
7174           UTL_Scope *s = idl_global->scopes ().top_non_null ();
7176           if (sn != 0)
7177             {
7178               d = s->lookup_by_name (sn);
7180               if (d == 0)
7181                 {
7182                   idl_global->err ()->lookup_error (sn);
7183                   return 1;
7184                 }
7185               else
7186                 {
7187                   AST_Decl::NodeType nt = d->node_type ();
7189                   if (nt == AST_Decl::NT_enum_val)
7190                     {
7191                       $1->evaluate (
7192                         AST_Expression::EK_const);
7194                       $<dcval>$ =
7195                         idl_global->gen ()->create_constant (
7196                           $1->ev ()->et,
7197                           $1,
7198                           sn);
7199                     }
7200                   else
7201                     {
7202                       $<dcval>$ = d;
7203                     }
7204                 }
7205             }
7206           else
7207             {
7208               $1->evaluate (
7209                 AST_Expression::EK_const);
7211               $<dcval>$ =
7212                 idl_global->gen ()->create_constant (
7213                   $1->ev ()->et,
7214                   $1,
7215                   0);
7216             }
7217         }
7218         ;
7220 connector_decl
7221         : connector_header connector_body
7222         {
7223           $$ = 0;
7224         }
7225         ;
7227 connector_header
7228         : IDL_CONNECTOR
7229         {
7230           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorSeen);
7231         }
7232         annotations_maybe IDENTIFIER
7233         {
7234           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorIDSeen);
7235         }
7236         component_inheritance_spec
7237         {
7238           UTL_Scope *s = idl_global->scopes ().top_non_null ();
7239           AST_Connector *parent = 0;
7240           bool so_far_so_good = true;
7242           Identifier id ($4);
7243           ACE::strdelete ($4);
7244           $4 = 0;
7246           UTL_ScopedName sn (&id, 0);
7248           if ($6 != 0)
7249             {
7250               AST_Decl *d =
7251                 s->lookup_by_name ($6);
7253               if (d == 0)
7254                 {
7255                   idl_global->err ()->lookup_error ($6);
7256                   so_far_so_good = false;
7257                 }
7259               parent =
7260                 dynamic_cast<AST_Connector*> (d);
7262               if (parent == 0)
7263                 {
7264                   idl_global->err ()->error1 (
7265                     UTL_Error::EIDL_CONNECTOR_EXPECTED,
7266                     d);
7268                   so_far_so_good = false;
7269                 }
7271               $6->destroy ();
7272               delete $6;
7273               $6 = 0;
7274             }
7276           if (so_far_so_good)
7277             {
7278               AST_Connector *c =
7279                 idl_global->gen ()->create_connector (&sn,
7280                                                       parent);
7282               (void) s->fe_add_connector (c);
7284               // Push it on the scopes stack.
7285               idl_global->scopes ().push (c);
7286            }
7288           delete $3;
7289         }
7290         ;
7292 connector_body
7293         : '{'
7294         {
7295           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorSqSeen);
7296         }
7297         connector_exports
7298         {
7299           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorBodySeen);
7300         }
7301         '}'
7302         {
7303           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorQsSeen);
7305           // Done with this connector - pop it off the scope stack.
7306           idl_global->scopes ().pop ();
7307         }
7308         ;
7310 connector_exports
7311         : connector_exports connector_export
7312         | %empty
7313         ;
7315 connector_export
7316         : provides_decl
7317         {
7318           idl_global->set_parse_state (IDL_GlobalData::PS_ProvidesDeclSeen);
7319         }
7320         ';'
7321         {
7322           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7323         }
7324         | uses_decl
7325         {
7326           idl_global->set_parse_state (IDL_GlobalData::PS_UsesDeclSeen);
7327         }
7328         ';'
7329         {
7330           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7331         }
7332         | attribute
7333         {
7334           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
7335         }
7336         ';'
7337         {
7338           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7339         }
7340         | extended_port_decl
7341         {
7342           idl_global->set_parse_state (IDL_GlobalData::PS_ExtendedPortDeclSeen);
7343         }
7344         ';'
7345         {
7346           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7347         }
7348         ;
7351 /* programs */
7354  * ???
7355  */
7357 tao_yywrap (void)
7359   return 1;
7363  * Report an error situation discovered in a production
7364  */
7365 void
7366 tao_yyerror (const char *msg)
7368   ACE_ERROR ((LM_ERROR, "%C\n", msg));