Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / TAO_IDL / fe / idl.ypp
blobc4fd51e4d99eed68a4a189b5e091473faef3914b
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>
135 #include <fe_declarator.h>
136 #include <fe_interface_header.h>
137 #include <fe_obv_header.h>
138 #include <fe_component_header.h>
139 #include <fe_home_header.h>
140 #include <fe_utils.h>
142 void tao_yyerror (const char *);
143 int tao_yylex (void);
144 extern "C" int tao_yywrap (void);
146 extern char tao_yytext[];
147 extern int tao_yyleng;
149 AST_Enum *tao_enum_constant_decl = 0;
150 AST_String *tao_string_decl = 0;
151 AST_Expression::ExprType t_param_const_type = AST_Expression::EV_none;
152 bool stack_based_lookup_for_primary_expr = false;
154 #define TAO_YYDEBUG_LEXER_TEXT (tao_yytext[tao_yyleng] = '\0', tao_yytext)
155 // Compile Optional Tracing Output for Parser, can be enabled with --bison-trace
156 #define YYDEBUG 1
160  * Declare the type of values in the grammar
161  */
163 %union {
164   AST_Decl                      *dcval;         /* Decl value           */
165   UTL_StrList                   *slval;         /* String list          */
166   UTL_NameList                  *nlval;         /* Name list            */
167   UTL_ExprList                  *elval;         /* Expression list      */
168   UTL_LabelList                 *llval;         /* Label list           */
169   UTL_DeclList                  *dlval;         /* Declaration list     */
170   FE_InterfaceHeader            *ihval;         /* Interface header     */
171   FE_OBVHeader                  *vhval;         /* Valuetype header     */
172   FE_ComponentHeader            *chval;         /* Component header     */
173   FE_HomeHeader                 *hhval;         /* Home header          */
174   AST_Expression                *exval;         /* Expression value     */
175   AST_UnionLabel                *ulval;         /* Union label          */
176   AST_Field                     *ffval;         /* Field value          */
177   AST_Field::Visibility         vival;          /* N/A, pub or priv     */
178   AST_Expression::ExprType      etval;          /* Expression type      */
179   AST_Argument::Direction       dival;          /* Argument direction   */
180   AST_Operation::Flags          ofval;          /* Operation flags      */
181   FE_Declarator                 *deval;         /* Declarator value     */
182   ACE_CDR::Boolean              bval;           /* Boolean value        */
183   ACE_CDR::LongLong             ival;           /* Long Long value      */
184   ACE_CDR::ULongLong            uival;          /* Unsigned long long   */
185   ACE_CDR::Double               dval;           /* Double value         */
186   ACE_CDR::Float                fval;           /* Float value          */
187   ACE_CDR::Char                 cval;           /* Char value           */
188   ACE_CDR::WChar                wcval;          /* WChar value          */
189   ACE_CDR::Fixed                fixval;         /* Fixed point value    */
190   UTL_String                    *sval;          /* String value         */
191   char                          *wsval;         /* WString value        */
192   char                          *strval;        /* char * value         */
193   Identifier                    *idval;         /* Identifier           */
194   UTL_IdList                    *idlist;        /* Identifier list      */
195   AST_Decl::NodeType            ntval;          /* Node type value      */
196   FE_Utils::T_Param_Info        *pival;         /* Template interface param */
197   FE_Utils::T_PARAMLIST_INFO    *plval;         /* List of template params */
198   FE_Utils::T_ARGLIST           *alval;         /* List of template args */
199   AST_Annotation_Appl *annotation_val;
200   AST_Annotation_Appls *annotations_val;
201   AST_Annotation_Appl::Param *annotation_param_val;
202   AST_Annotation_Appl::Params *annotation_params_val;
203   AST_Annotation_Decl *annotation_decl_val;
204   AST_Decls *decls_val;
205   Decl_Annotations_Pair *decl_annotations_pair_val;
209  * Token types: These are returned by the lexer
210  */
212 %token <strval> IDENTIFIER
214 %token          IDL_CONST
215 %token          IDL_MODULE
216 %token          IDL_INTERFACE
217 %token          IDL_TYPEDEF
218 %token          IDL_LONG
219 %token          IDL_SHORT
220 %token          IDL_UNSIGNED
221 %token          IDL_DOUBLE
222 %token          IDL_FLOAT
223 %token          IDL_CHAR
224 %token          IDL_WCHAR
225 %token          IDL_OCTET
226 %token          IDL_BOOLEAN
227 %token          IDL_FIXED
228 %token          IDL_ANY
229 %token          IDL_OBJECT
230 %token          IDL_STRUCT
231 %token          IDL_UNION
232 %token          IDL_SWITCH
233 %token          IDL_ENUM
234 %token          IDL_SEQUENCE
235 %token          IDL_STRING
236 %token          IDL_WSTRING
237 %token          IDL_EXCEPTION
238 %token          IDL_CASE
239 %token          IDL_DEFAULT
240 %token          IDL_READONLY
241 %token          IDL_ATTRIBUTE
242 %token          IDL_ONEWAY
243 %token          IDL_IDEMPOTENT
244 %token          IDL_VOID
245 %token          IDL_IN
246 %token          IDL_OUT
247 %token          IDL_INOUT
248 %token          IDL_RAISES
249 %token          IDL_CONTEXT
250 %token          IDL_NATIVE
251 %token          IDL_LOCAL
252                 /* OBV tokens */
253 %token          IDL_ABSTRACT
254 %token          IDL_CUSTOM
255 %token          IDL_FACTORY
256 %token          IDL_PRIVATE
257 %token          IDL_PUBLIC
258 %token          IDL_SUPPORTS
259 %token          IDL_TRUNCATABLE
260 %token          IDL_VALUETYPE
261                 /* Component tokens */
262 %token          IDL_COMPONENT
263 %token          IDL_CONSUMES
264 %token          IDL_EMITS
265 %token          IDL_EVENTTYPE
266 %token          IDL_FINDER
267 %token          IDL_GETRAISES
268 %token          IDL_HOME
269 %token          IDL_IMPORT
270 %token          IDL_MULTIPLE
271 %token          IDL_PRIMARYKEY
272 %token          IDL_PROVIDES
273 %token          IDL_PUBLISHES
274 %token          IDL_SETRAISES
275 %token          IDL_TYPEID
276 %token          IDL_TYPEPREFIX
277 %token          IDL_USES
278 %token          IDL_MANAGES
279                 /* Extended ports tokens  */
280 %token          IDL_TYPENAME
281 %token          IDL_PORT
282 %token          IDL_MIRRORPORT
283 %token          IDL_PORTTYPE
284 %token          IDL_CONNECTOR
285 %token          IDL_ALIAS
287 %token <ival>   IDL_INTEGER_LITERAL
288 %token <uival>  IDL_UINTEGER_LITERAL
289 %token <sval>   IDL_STRING_LITERAL
290 %token <cval>   IDL_CHARACTER_LITERAL
291 %token <dval>   IDL_FLOATING_PT_LITERAL
292 %token <fixval> IDL_FIXED_PT_LITERAL
293 %token          IDL_TRUETOK
294 %token          IDL_FALSETOK
296 %token <strval> IDL_SCOPE_DELIMITOR
297 %token          IDL_LEFT_SHIFT
298 %token          IDL_RIGHT_SHIFT
299 %token <wcval>  IDL_WCHAR_LITERAL
300 %token <wsval>  IDL_WSTRING_LITERAL
302 %token IDL_ANNOTATION_DECL
303 %token IDL_ANNOTATION_SYMBOL
306  * These are production names:
307  */
309 %type <dcval>   type_spec simple_type_spec constructed_type_spec
310 %type <dcval>   template_type_spec sequence_type_spec string_type_spec
311 %type <dcval>   struct_type enum_type switch_type_spec union_type
312 %type <dcval>   array_declarator op_type_spec wstring_type_spec
313 %type <dcval>   param_type_spec type_dcl type_declarator actual_parameter
314 %type <dcval>   fixed_type_spec
315 %type <dcval>   definition fixed_definition module const_dcl struct_forward_type
316 %type <dcval>   interface_def interface interface_forward
317 %type <dcval>   export operation attribute attribute_readonly attribute_readwrite
318 %type <dcval>   template_module template_module_inst annotation_dcl typeid_dcl
319 %type <dcval>   typeprefix_dcl exception component home_decl
320 %type <dcval>   event_decl event_abs_decl event_forward_decl
321 %type <dcval>   event_abs_forward_decl event_concrete_forward_decl
322 %type <dcval>   porttype_decl connector_decl value_def
323 %type <dcval>   valuetype value_abs_decl value_forward_decl value_box_decl
324 %type <dcval>   value_concrete_decl component_forward_decl component_decl
325 %type <dcval>   init_decl provides_decl uses_decl port_export
326 %type <dcval>   component_export emits_decl publishes_decl consumes_decl
327 %type <dcval>   extended_port_decl
329 %type <idlist>  scoped_name interface_type component_inheritance_spec
330 %type <idlist>  home_inheritance_spec primary_key_spec module_header
331 %type <idlist>  template_module_header
333 %type <slval>   opt_context at_least_one_string_literal
334 %type <slval>   string_literals formal_parameter_names
335 %type <slval>   at_least_one_formal_parameter_name
337 %type <nlval>   at_least_one_scoped_name scoped_names inheritance_spec
338 %type <nlval>   opt_raises opt_getraises opt_setraises supports_spec
340 %type <elval>   at_least_one_array_dim array_dims
342 %type <llval>   at_least_one_case_label case_labels
344 %type <dlval>   at_least_one_declarator declarators
345 %type <dlval>   at_least_one_simple_declarator simple_declarators
347 %type <ihval>   interface_header
349 %type <vhval>   value_header event_rest_of_header
351 %type <chval>   component_header
353 %type <hhval>   home_header
355 %type <exval>   expression const_expr or_expr xor_expr and_expr shift_expr
356 %type <exval>   add_expr mult_expr unary_expr primary_expr literal
357 %type <exval>   positive_int_expr array_dim annotation_member_default
359 %type <ulval>   case_label
361 %type <ffval>   element_spec
363 %type <etval>   const_type integer_type char_type boolean_type
364 %type <etval>   floating_pt_type fixed_type any_type signed_int
365 %type <etval>   unsigned_int base_type_spec octet_type object_type
366 %type <etval>   annotation_member_type
368 %type <dival>   direction
370 %type <ofval>   opt_op_attribute
372 %type <deval>   declarator simple_declarator complex_declarator
374 %type <bval>    opt_truncatable opt_multiple uses_opt_multiple
376 %type <idval>   interface_decl value_decl union_decl struct_decl id
377 %type <idval>   defining_id
378 %type <idval>   event_header event_plain_header event_custom_header
379 %type <idval>   event_abs_header
381 %type <ntval>   formal_parameter_type
383 %type <pival>   formal_parameter
384 %type <plval>   formal_parameters at_least_one_formal_parameter
386 %type <sval>    formal_parameter_name
388 %type <alval>   actual_parameters at_least_one_actual_parameter
390 %type <annotations_val> at_least_one_annotation annotations_maybe
391 %type <annotation_val> annotation_appl
392 %type <annotation_params_val> annotation_appl_params_maybe annotation_appl_params
393 %type <annotation_params_val> named_annotation_appl_params more_named_annotation_appl_params
394 %type <annotation_param_val> named_annotation_appl_param
395 %type <decl_annotations_pair_val> seq_head
397 %type <decls_val> member_i state_member value_element
398 %type <vival> visibility
402  * Production starts here.
403  */
404 start : definitions ;
406 definitions
407         : at_least_one_definition
408         | %empty
409         ;
411 at_least_one_definition
412         /*
413          * This is broken up into 2 rules to avoid a grammer ambiguity which
414          * manifests as bison complaining about shift/reduce conflicts.
415          */
416         : definitions at_least_one_annotation definition
417         {
418           AST_Annotation_Appls *&annotations = $2;
419           AST_Decl *&node = $3;
420           if (node)
421             {
422               node->annotation_appls (*annotations);
423             }
424           else
425             {
426               idl_global->err ()-> unsupported_warning (
427                 "Annotating this is not supported");
428             }
429           delete annotations;
430         }
431         | definitions definition
432         ;
434 definition
435         : fixed_definition
436         | template_module ';'
437         | template_module_inst ';'
438         ;
440 fixed_definition
441         : annotation_dcl
442         {
443           idl_global->set_parse_state (IDL_GlobalData::PS_AnnotationDeclSeen);
444         }
445         ';'
446         {
447           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
448         }
449         | type_dcl
450         {
451           idl_global->set_parse_state (IDL_GlobalData::PS_TypeDeclSeen);
452         }
453         ';'
454         {
455           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
456         }
457         | typeid_dcl
458         {
459           idl_global->set_parse_state (IDL_GlobalData::PS_TypeIdDeclSeen);
460         }
461         ';'
462         {
463           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
464         }
465         | typeprefix_dcl
466         {
467           idl_global->set_parse_state (IDL_GlobalData::PS_TypePrefixDeclSeen);
468         }
469         ';'
470         {
471           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
472         }
473         | const_dcl
474         {
475           idl_global->set_parse_state (IDL_GlobalData::PS_ConstDeclSeen);
476         }
477         ';'
478         {
479           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
480         }
481         | exception
482         {
483           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptDeclSeen);
484         }
485         ';'
486         {
487           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
488         }
489         | interface_def
490         {
491           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceDeclSeen);
492         }
493         ';'
494         {
495           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
496         }
497         | module
498         {
499           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleDeclSeen);
500         }
501         ';'
502         {
503           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
504         }
505         | value_def
506         {
507           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeDeclSeen);
508         }
509         ';'
510         {
511           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
512         }
513         | component
514         {
515           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentDeclSeen);
516         }
517         ';'
518         {
519           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
520         }
521         | home_decl
522         {
523           idl_global->set_parse_state (IDL_GlobalData::PS_HomeDeclSeen);
524         }
525         ';'
526         {
527           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
528         }
529         | event
530         {
531           idl_global->set_parse_state (IDL_GlobalData::PS_EventDeclSeen);
532         }
533         ';'
534         {
535           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
536         }
537         | porttype_decl
538         {
539           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeDeclSeen);
540         }
541         ';'
542         {
543           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
544         }
545         | connector_decl
546         {
547           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorDeclSeen);
548         }
549         ';'
550         {
551           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
552         }
553         | error
554         {
555           idl_global->err ()->syntax_error (idl_global->parse_state ());
556         }
557         ';'
558         {
559           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
560           yyerrok;
561           $$ = 0;
562         }
563         ;
565 module_header
566         : IDL_MODULE
567         {
568           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleSeen);
569         }
570         scoped_name
571         {
572           $<idlist>$ = $3;
573         }
574         ;
576 module
577         : module_header
578         {
579           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleIDSeen);
581           // The module_header rule is common to template module, fixed
582           // module and instantiated template module. In the last
583           // case, a fully scoped name is allowed, but here we
584           // allow only an identifier (a scoped name of length
585           // 1). If not satisfied, we output a parse error with
586           // the appropriate message.
587           if ($1->length () != 1)
588             {
589               idl_global->err ()->syntax_error (
590                 IDL_GlobalData::PS_ModuleIDSeen);
591             }
593           AST_Module *m = 0;
594           UTL_Scope *s = idl_global->scopes ().top_non_null ();
596           /*
597            * Make a new module and add it to the enclosing scope
598            */
599           if (s != 0)
600             {
601               m = idl_global->gen ()->create_module (s, $1);
602               (void) s->fe_add_module (m);
603             }
605           $1->destroy ();
606           delete $1;
607           $1 = 0;
609           /*
610            * Push it on the stack
611            */
612           idl_global->scopes ().push (m);
614           $<dcval>$ = m;
615         }
616         '{'
617         {
618           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleSqSeen);
619         }
620         at_least_one_definition
621         {
622           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleBodySeen);
623         }
624         '}'
625         {
626           idl_global->set_parse_state (IDL_GlobalData::PS_ModuleQsSeen);
627           /*
628            * Finished with this module - pop it from the scope stack.
629            */
631           idl_global->scopes ().pop ();
632           $$ = $<dcval>2;
633         }
634         ;
636 template_module_header
637         : module_header '<'
638         {
639           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleIDSeen);
640         }
641         ;
643 template_module
644         : template_module_header
645         {
646           // The module_header rule is common to template module, fixed
647           // module and instantiated template module. In the last
648           // case, a fully scoped name is allowed, but here we
649           // allow only an identifier (a scoped name of length
650           // 1). If not satisfied, we output a syntax error with
651           // the appropriate message.
652           if ($1->length () != 1)
653             {
654               idl_global->err ()->syntax_error (
655                 IDL_GlobalData::PS_ModuleIDSeen);
656             }
657         }
658         at_least_one_formal_parameter
659         {
660           if (FE_Utils::duplicate_param_id ($3))
661             {
662               idl_global->err ()->duplicate_param_id (
663                 $1);
665               return 1;
666             }
667         }
668         '>'
669         {
670           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleParamsSeen);
672           AST_Template_Module *tm =
673             idl_global->gen ()->create_template_module ($1,
674                                                         $3);
676           UTL_Scope *s = idl_global->scopes ().top_non_null ();
677           AST_Module *m = s->fe_add_module (tm);
679           // We've probably tried to reopen a template module,
680           // going further will cause a crash.
681           if (m == 0)
682             {
683               return 1;
684             }
686           /*
687            * Push it on the stack
688            */
689           idl_global->scopes ().push (tm);
691           // Contained items not part of an alias will get flag set.
692           idl_global->in_tmpl_mod_no_alias (true);
694           // Store these for reference as we parse the scope
695           // of the template module.
696           idl_global->current_params ($3);
697         }
698         '{'
699         {
700           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleSqSeen);
701         }
702         at_least_one_tpl_definition
703         {
704           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleBodySeen);
705         }
706         '}'
707         {
708           idl_global->set_parse_state (IDL_GlobalData::PS_TmplModuleQsSeen);
710           /*
711            * Finished with this module - pop it from the scope stack.
712            */
713           idl_global->scopes ().pop ();
715           // Unset the flag, the no_alias version because any scope
716           // traversal triggered by an alias would have ended by now.
717           idl_global->in_tmpl_mod_no_alias (false);
719           // Clear the pointer so scoped name lookup will know
720           // that we are no longer in a template module scope.
721           idl_global->current_params (0);
723           $$ = 0;
724         }
725         ;
727 at_least_one_tpl_definition
728         : tpl_definition tpl_definitions
729         ;
731 tpl_definitions
732         : tpl_definitions tpl_definition
733         | %empty
734         ;
736 tpl_definition
737         : fixed_definition
738         | template_module_ref ';'
739         ;
741 template_module_ref
742         : IDL_ALIAS scoped_name
743         {
744           idl_global->set_parse_state (
745             IDL_GlobalData::PS_ModuleRefSeen);
746         }
747         '<' at_least_one_formal_parameter_name '>'
748         {
749           idl_global->set_parse_state (
750             IDL_GlobalData::PS_ModuleRefParamsSeen);
751         }
752         defining_id
753         {
754           idl_global->set_parse_state (
755             IDL_GlobalData::PS_ModuleRefIDSeen);
757           UTL_Scope *s = idl_global->scopes ().top_non_null ();
758           AST_Decl *d =
759             s->lookup_by_name ($2);
761           if (d == 0)
762             {
763               idl_global->err ()->lookup_error ($2);
764               return 1;
765             }
767           AST_Template_Module *ref =
768             dynamic_cast<AST_Template_Module*> (d);
770           if (ref == 0)
771             {
772               idl_global->err ()->template_module_expected (d);
773               return 1;
774             }
776           bool refs_match =
777             ref->match_param_refs ($5,
778                                    s);
780           if (! refs_match)
781             {
782               // Error message is already output.
783               return 1;
784             }
786           UTL_ScopedName sn ($8, 0);
788           AST_Template_Module_Ref *tmr =
789             idl_global->gen ()->create_template_module_ref (
790               &sn,
791               ref,
792               $5);
794           (void) s->fe_add_template_module_ref (tmr);
796           sn.destroy ();
797           $2->destroy ();
798           delete $2;
799           $2 = 0;
801           // Save the current flag value to be restored below.
802           bool itmna_flag = idl_global->in_tmpl_mod_no_alias ();
803           idl_global->in_tmpl_mod_no_alias (false);
804           idl_global->in_tmpl_mod_alias (true);
806           ast_visitor_context ctx;
807           ctx.template_params (ref->template_params ());
808           ast_visitor_tmpl_module_ref v (&ctx);
810           // The implied IDL resulting from this reference is
811           // created here, in the template module scope. Upon
812           // instantiation of the enclosing template module, the
813           // visitor copies this implied IDL to the instantiated
814           // module scope. The extra copy is less than ideal, but
815           // otherwise we have ugly lookup issues when the
816           // referenced template module's contents are referenced
817           // using the aliased scoped name.
818           if (v.visit_template_module_ref (tmr) != 0)
819             {
820               ACE_ERROR ((LM_ERROR,
821                           ACE_TEXT ("visit_template_module_ref")
822                           ACE_TEXT (" failed\n")));
824               idl_global->set_err_count (idl_global->err_count () + 1);
825             }
827           idl_global->in_tmpl_mod_no_alias (itmna_flag);
828           idl_global->in_tmpl_mod_alias (false);
829         }
830         ;
832 template_module_inst
833         : template_module_header
834         {
835           idl_global->set_parse_state (
836             IDL_GlobalData::PS_InstModuleSeen);
837         }
838         at_least_one_actual_parameter '>'
839         {
840           idl_global->set_parse_state (
841             IDL_GlobalData::PS_InstModuleArgsSeen);
842         }
843         defining_id
844         {
845           idl_global->set_parse_state (
846             IDL_GlobalData::PS_InstModuleIDSeen);
848           UTL_Scope *s = idl_global->scopes ().top_non_null ();
849           UTL_ScopedName *sn = $1;
850           AST_Template_Module *ref = 0;
851           AST_Decl *d = s->lookup_by_name (sn);
853           if (d == 0)
854             {
855               idl_global->err ()->lookup_error (sn);
856               return 1;
857             }
858           else
859             {
860               ref = dynamic_cast<AST_Template_Module*> (d);
862               if (ref == 0)
863                 {
864                   idl_global->err ()->template_module_expected (d);
865                   return 1;
866                 }
867             }
869           sn->destroy ();
870           delete sn;
871           sn = 0;
872           $1 = 0;
874           if (! ref->match_arg_names ($3))
875             {
876               return 1;
877             }
879           ACE_NEW_RETURN (sn,
880                           UTL_ScopedName ($6,
881                                            0),
882                           1);
884           AST_Template_Module_Inst *tmi =
885             idl_global->gen ()->create_template_module_inst (
886               sn,
887               ref,
888               $3);
890           (void) s->fe_add_template_module_inst (tmi);
892           ast_visitor_context ctx;
893           ctx.template_args ($3);
894           ast_visitor_tmpl_module_inst v (&ctx);
896           if (v.visit_template_module_inst (tmi) != 0)
897             {
898               ACE_ERROR ((LM_ERROR,
899                           ACE_TEXT ("visit_template_module_inst")
900                           ACE_TEXT (" failed\n")));
902               idl_global->set_err_count (idl_global->err_count () + 1);
903             }
905           $$ = 0;
906         }
907         ;
909 interface_def
910         : interface
911         | interface_forward
912         ;
914 interface
915         : interface_header
916         {
917           UTL_Scope *s = idl_global->scopes ().top_non_null ();
918           AST_Interface *i = 0;
920           FE_InterfaceHeader *header = $1;
921           $1 = 0;
923           /*
924            * Make a new interface node and add it to its enclosing scope.
925            */
926           if (s && header)
927             {
928               i = idl_global->gen ()->create_interface (
929                 header->name (),
930                 header->inherits (),
931                 header->n_inherits (),
932                 header->inherits_flat (),
933                 header->n_inherits_flat (),
934                 header->is_local (),
935                 header->is_abstract ()
936               );
937               AST_Interface::fwd_redefinition_helper (i, s);
938               /*
939                * Add the interface to its definition scope.
940                */
941               s->fe_add_interface (i);
943               // This FE_InterfaceHeader class isn't destroyed with the AST.
944               header->destroy ();
945               delete header;
946             }
948           /*
949            * Push it on the scope stack.
950            */
951           idl_global->scopes ().push (i);
952         }
953         '{'
954         {
955           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceSqSeen);
956         }
957         exports
958         {
959           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceBodySeen);
960         }
961         '}'
962         {
963           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceQsSeen);
965           $$ = dynamic_cast<AST_Decl *> (idl_global->scopes ().top_non_null ());
966           /*
967            * Done with this interface - pop it off the scopes stack
968            */
969           idl_global->scopes ().pop ();
970         }
971         ;
973 interface_decl:
974          IDL_INTERFACE
975          {
976            idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceSeen);
977          }
978          defining_id
979          {
980            idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceIDSeen);
981            $$ = $3;
982          }
983         ;
985 interface_header :
986         interface_decl inheritance_spec
987         {
988           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
990           if ($2 != 0 && $2->truncatable ())
991             {
992               idl_global->err ()->syntax_error (
993                                       IDL_GlobalData::PS_InheritColonSeen
994                                     );
995             }
997           /*
998            * Create an AST representation of the information in the header
999            * part of an interface - this representation contains a computed
1000            * list of all interfaces which this interface inherits from,
1001            * recursively
1002            */
1003           UTL_ScopedName *n = 0;
1004           ACE_NEW_RETURN (n,
1005                           UTL_ScopedName ($1, 0),
1006                           1);
1007           ACE_NEW_RETURN ($$,
1008                           FE_InterfaceHeader (n,
1009                                               $2,
1010                                               false,
1011                                               false,
1012                                               true),
1013                           1);
1015           if (0 != $2)
1016             {
1017               $2->destroy ();
1018               delete $2;
1019               $2 = 0;
1020             }
1021         }
1022         |
1023         IDL_LOCAL interface_decl inheritance_spec
1024         {
1025           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1027           /*
1028            * Create an AST representation of the information in the header
1029            * part of an interface - this representation contains a computed
1030            * list of all interfaces which this interface inherits from,
1031            * recursively
1032            */
1033           UTL_ScopedName *n = 0;
1034           ACE_NEW_RETURN (n,
1035                           UTL_ScopedName ($2, 0),
1036                           1);
1037           ACE_NEW_RETURN ($$,
1038                           FE_InterfaceHeader (n,
1039                                               $3,
1040                                               true,
1041                                               false,
1042                                               true),
1043                           1);
1045           if (0 != $3)
1046             {
1047               $3->destroy ();
1048               delete $3;
1049               $3 = 0;
1050             }
1051         }
1052         |
1053         IDL_ABSTRACT interface_decl inheritance_spec
1054         {
1055           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1057           /*
1058            * Create an AST representation of the information in the header
1059            * part of an interface - this representation contains a computed
1060            * list of all interfaces which this interface inherits from,
1061            * recursively
1062            */
1063           UTL_ScopedName *n = 0;
1064           ACE_NEW_RETURN (n,
1065                           UTL_ScopedName ($2, 0),
1066                           1);
1067           ACE_NEW_RETURN ($$,
1068                           FE_InterfaceHeader (n,
1069                                               $3,
1070                                               false,
1071                                               true,
1072                                               true),
1073                           1);
1075           if (0 != $3)
1076             {
1077               $3->destroy ();
1078               delete $3;
1079               $3 = 0;
1080             }
1081         }
1082         ;
1084 inheritance_spec
1085         : ':' opt_truncatable
1086         {
1087           idl_global->set_parse_state (IDL_GlobalData::PS_InheritColonSeen);
1088         }
1089           at_least_one_scoped_name
1090         {
1091           $4->truncatable ($2);
1092           $$ = $4;
1093         }
1094         | %empty
1095         {
1096           $$ = 0;
1097         }
1098         ;
1100 value_def
1101         : valuetype
1102         | value_abs_decl
1103         | value_forward_decl
1104         | value_box_decl
1105         ;
1107 valuetype
1108         : IDL_CUSTOM value_concrete_decl
1109         {
1110           idl_global->err ()->unsupported_error ("custom is not supported");
1111           $<dcval>$ = $2;
1112         }
1113         | value_concrete_decl
1114         ;
1116 value_concrete_decl :
1117         value_header
1118         {
1119           FE_OBVHeader *&valuetype_header = $1;
1120           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
1121           AST_ValueType *valuetype = 0;
1123           if (scope && valuetype_header)
1124             {
1125               valuetype = idl_global->gen ()->create_valuetype (
1126                 valuetype_header->name (),
1127                 valuetype_header->inherits (),
1128                 valuetype_header->n_inherits (),
1129                 valuetype_header->inherits_concrete (),
1130                 valuetype_header->inherits_flat (),
1131                 valuetype_header->n_inherits_flat (),
1132                 valuetype_header->supports (),
1133                 valuetype_header->n_supports (),
1134                 valuetype_header->supports_concrete (),
1135                 false,
1136                 valuetype_header->truncatable (),
1137                 false);
1139               AST_Interface *valuetype_as_interface =
1140                 dynamic_cast<AST_Interface *> (valuetype);
1141               AST_Interface::fwd_redefinition_helper (
1142                 valuetype_as_interface, scope);
1143               valuetype = dynamic_cast<AST_ValueType *> (
1144                 valuetype_as_interface);
1146               /*
1147                * Add the valuetype to its definition scope
1148                */
1149               scope->fe_add_valuetype (valuetype);
1151               // FE_OBVHeader is not automatically destroyed in the AST
1152               valuetype_header->destroy ();
1153               delete valuetype_header;
1154               valuetype_header = 0;
1155             }
1157           /*
1158            * Push it on the scope stack
1159            */
1160           idl_global->scopes ().push (valuetype);
1162           $<dcval>$ = valuetype;
1163         }
1164         '{'
1165         {
1166           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeSqSeen);
1167         }
1168         value_elements
1169         {
1170           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeBodySeen);
1171         }
1172         '}'
1173         {
1174           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeQsSeen);
1176           AST_ValueType *vt =
1177             dynamic_cast<AST_ValueType*> (
1178                 idl_global->scopes ().top_non_null ()
1179               );
1181           if (vt != 0 && vt->will_have_factory ())
1182             {
1183               idl_global->valuefactory_seen_ = true;
1184             }
1186           /*
1187            * Done with this value type - pop it off the scopes stack
1188            */
1189           idl_global->scopes ().pop ();
1191           $$ = $<dcval>2;
1192         }
1193         ;
1195 value_abs_decl :
1196         IDL_ABSTRACT
1197         value_header
1198         {
1199           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1200           AST_ValueType *v = 0;
1201           AST_Interface *i = 0;
1203           if (s != 0 && $2 != 0)
1204             {
1205               v =
1206                 idl_global->gen ()->create_valuetype (
1207                     $2->name (),
1208                     $2->inherits (),
1209                     $2->n_inherits (),
1210                     $2->inherits_concrete (),
1211                     $2->inherits_flat (),
1212                     $2->n_inherits_flat (),
1213                     $2->supports (),
1214                     $2->n_supports (),
1215                     $2->supports_concrete (),
1216                     true,
1217                     false,
1218                     false
1219                   );
1220               i = dynamic_cast<AST_Interface*> (v);
1221               AST_Interface::fwd_redefinition_helper (i,
1222                                                       s);
1223               /*
1224                * Add the valuetype to its definition scope
1225                */
1226               v = dynamic_cast<AST_ValueType*> (i);
1227               (void) s->fe_add_valuetype (v);
1229               // FE_OBVHeader is not automatically destroyed in the AST
1230               $2->destroy ();
1231               delete $2;
1232               $2 = 0;
1233             }
1235           /*
1236            * Push it on the scope stack.
1237            */
1238           idl_global->scopes ().push (v);
1239         }
1240         '{'
1241         {
1242           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeSqSeen);
1243         }
1244         exports
1245         {
1246           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeBodySeen);
1247         }
1248         '}'
1249         {
1250           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeQsSeen);
1252           /*
1253            * Done with this valuetype - pop it off the scopes stack.
1254            */
1255           idl_global->scopes ().pop ();
1257           $$ = 0;
1258         }
1259         ;
1261 value_header :
1262         value_decl
1263         inheritance_spec
1264         {
1265           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
1266         }
1267         supports_spec
1268         {
1269           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
1271           UTL_ScopedName *sn = 0;
1272           ACE_NEW_RETURN (sn,
1273                           UTL_ScopedName ($1, 0),
1274                           1);
1275           ACE_NEW_RETURN ($$,
1276                           FE_OBVHeader (sn,
1277                                         $2,
1278                                         $4,
1279                                         ($2 != 0
1280                                            ? $2->truncatable ()
1281                                            : false)),
1282                           1);
1284           if (0 != $4)
1285             {
1286               $4->destroy ();
1287               delete $4;
1288               $4 = 0;
1289             }
1291           if (0 != $2)
1292             {
1293               $2->destroy ();
1294               delete $2;
1295               $2 = 0;
1296             }
1297         }
1298         ;
1300 value_decl
1301         : IDL_VALUETYPE
1302         {
1303            idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeSeen);
1304         }
1305         defining_id
1306         {
1307           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeIDSeen);
1308           $$ = $3;
1309         }
1310         ;
1312 opt_truncatable :
1313         IDL_TRUNCATABLE
1314         {
1315           $$ = true;
1316         }
1317         | %empty
1318         {
1319           $$ = false;
1320         }
1321         ;
1323 supports_spec :
1324         IDL_SUPPORTS
1325         at_least_one_scoped_name
1326         {
1327           $$ = $2;
1328         }
1329         | %empty
1330         {
1331           $$ = 0;
1332         }
1333         ;
1335 value_forward_decl :
1336         IDL_ABSTRACT
1337         value_decl
1338         {
1339           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1340           UTL_ScopedName n ($2,
1341                             0);
1342           AST_ValueTypeFwd *f = 0;
1343           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeForwardSeen);
1345           /*
1346            * Create a node representing a forward declaration of an
1347            * valuetype. Store it in the enclosing scope
1348            */
1349           if (s != 0)
1350             {
1351               f = idl_global->gen ()->create_valuetype_fwd (&n,
1352                                                             true);
1353               (void) s->fe_add_valuetype_fwd (f);
1354             }
1356           $2->destroy ();
1357           delete $2;
1358           $2 = 0;
1359         }
1360         |
1361         value_decl
1362         {
1363           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1364           UTL_ScopedName n ($1,
1365                             0);
1366           AST_ValueTypeFwd *f = 0;
1367           idl_global->set_parse_state (IDL_GlobalData::PS_ValueTypeForwardSeen);
1369           /*
1370            * Create a node representing a forward declaration of an
1371            * valuetype. Store it in the enclosing scope
1372            */
1373           if (s != 0)
1374             {
1375               f = idl_global->gen ()->create_valuetype_fwd (&n,
1376                                                             false);
1377               (void) s->fe_add_valuetype_fwd (f);
1378             }
1380           $1->destroy ();
1381           delete $1;
1382           $1 = 0;
1384           $$ = 0;
1385         }
1386         ;
1388 value_box_decl
1389         : value_decl type_spec /* in this order %!?*/
1390         {
1391           idl_global->set_parse_state (IDL_GlobalData::PS_ValueBoxDeclSeen);
1393           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1394           UTL_ScopedName n ($1,
1395                             0);
1397           if (s != 0 && $2 != 0)
1398             {
1399               /*
1400               * Get the type_spec associated with the valuebox
1401               */
1402               AST_Type *tp = 0;
1403               AST_Typedef *td
1404                 = dynamic_cast<AST_Typedef*> ($2);
1406               if (td == 0)
1407                 {
1408                   tp = dynamic_cast<AST_Type*> ($2);
1409                 }
1410               else
1411                 {
1412                   tp = td->primitive_base_type ();
1413                 }
1415               if (tp == 0)
1416                 {
1417                   // The <type_spec> given is a valid type
1418                   idl_global->err ()->not_a_type ($2);
1419                 }
1420               else
1421                 {
1422                   AST_Decl::NodeType nt = tp->node_type ();
1424                   if (nt == AST_Decl::NT_valuetype
1425                       || nt == AST_Decl::NT_eventtype)
1426                     {
1427                       // valuetype is not allowed as <type_spec>
1428                       // for boxed value
1429                       idl_global->err ()->error0 (
1430                           UTL_Error::EIDL_ILLEGAL_BOXED_TYPE
1431                         );
1432                     }
1433                   else
1434                     {
1435                       /*
1436                       * Add the valuebox to its definition scope
1437                       */
1438                       AST_ValueBox *vb =
1439                         idl_global->gen ()->create_valuebox (&n,
1440                                                              tp);
1441                       (void) s->fe_add_valuebox (vb);
1442                     }
1443                 }
1444             }
1446           $1->destroy ();
1447           delete $1;
1448           $1 = 0;
1450           $$ = 0;
1451         }
1452         ;
1454 value_elements
1455         : value_elements at_least_one_annotation value_element
1456         {
1457           AST_Annotation_Appls *&annotations = $2;
1458           AST_Decls *&decls = $3;
1459           if (decls)
1460             {
1461               for (size_t i = 0; i < decls->size (); i++)
1462                 {
1463                   (*decls)[i]->annotation_appls (*annotations);
1464                 }
1465             }
1466           else
1467             {
1468               idl_global->err ()-> unsupported_warning (
1469                 "Annotating this is not supported");
1470             }
1471           delete annotations;
1472           delete decls;
1473         }
1474         | value_elements value_element
1475         {
1476           delete $2;
1477         }
1478         | %empty
1479         ;
1481 value_element
1482         : state_member
1483         | export
1484         {
1485           AST_Decl *&node = $1;
1486           AST_Decls *value = 0;
1487           if (node)
1488             {
1489               value = new AST_Decls;
1490               value->push_back (node);
1491             }
1492           $$ = value;
1493         }
1494         | init_decl
1495         {
1496           AST_Decl *&node = $1;
1497           AST_Decls *value = 0;
1498           if (node)
1499             {
1500               value = new AST_Decls;
1501               value->push_back (node);
1502             }
1503           $<decls_val>$ = value;
1504         }
1505         ';'
1506         {
1507           $$ = $<decls_val>2;
1508         }
1509         ;
1511 visibility
1512         : IDL_PUBLIC
1513         {
1514           $$ = AST_Field::vis_PUBLIC;
1515         }
1516         | IDL_PRIVATE
1517         {
1518           $$ = AST_Field::vis_PRIVATE;
1519         }
1520         ;
1522 state_member
1523         : visibility member_i
1524         {
1525           AST_Field::Visibility &visibility = $1;
1526           AST_Decls *&decls_ptr = $2;
1527           if (decls_ptr)
1528             {
1529               AST_Decls &decls = *decls_ptr;
1530               for (size_t i = 0; i < decls.size (); i++)
1531                 {
1532                   AST_Field *field = dynamic_cast<AST_Field *> (decls[i]);
1533                   if (field)
1534                     {
1535                       field->visibility (visibility);
1536                     }
1537                 }
1538             }
1539           $$ = decls_ptr;
1540         }
1541         ;
1543 exports
1544         : at_least_one_export
1545         | %empty
1546         ;
1548 at_least_one_export
1549         : exports at_least_one_annotation export
1550         {
1551           AST_Annotation_Appls *annotations = $2;
1552           AST_Decl *d = $3;
1553           if (d)
1554             {
1555               d->annotation_appls (*annotations);
1556             }
1557           else
1558             {
1559               idl_global->err ()-> unsupported_warning (
1560                 "Annotating this is not supported");
1561             }
1562           delete annotations;
1563         }
1564         | exports export
1565         ;
1567 export
1568         : type_dcl
1569         {
1570           idl_global->set_parse_state (IDL_GlobalData::PS_TypeDeclSeen);
1571         }
1572         ';'
1573         {
1574           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1575         }
1576         | typeid_dcl
1577         {
1578           idl_global->set_parse_state (IDL_GlobalData::PS_TypeIdDeclSeen);
1579         }
1580         ';'
1581         {
1582           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1583         }
1584         | typeprefix_dcl
1585         {
1586           idl_global->set_parse_state (IDL_GlobalData::PS_TypePrefixDeclSeen);
1587         }
1588         ';'
1589         {
1590           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1591         }
1592         | const_dcl
1593         {
1594           idl_global->set_parse_state (IDL_GlobalData::PS_ConstDeclSeen);
1595         }
1596         ';'
1597         {
1598           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1599         }
1600         | exception
1601         {
1602           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptDeclSeen);
1603         }
1604         ';'
1605         {
1606           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1607         }
1608         | attribute
1609         {
1610           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
1611         }
1612         ';'
1613         {
1614           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1615         }
1616         | operation
1617         {
1618           idl_global->set_parse_state (IDL_GlobalData::PS_OpDeclSeen);
1619         }
1620         ';'
1621         {
1622           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1623         }
1624         | error
1625         {
1626           idl_global->err ()->syntax_error (idl_global->parse_state ());
1627         }
1628         ';'
1629         {
1630           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
1631           yyerrok;
1632           $$ = 0;
1633         }
1634         ;
1636 at_least_one_scoped_name :
1637         scoped_name scoped_names
1638         {
1639           ACE_NEW_RETURN ($<nlval>$,
1640                           UTL_NameList ($1,
1641                                         $2),
1642                           1);
1643         }
1644         ;
1646 scoped_names
1647         : scoped_names
1648           ','
1649         {
1650           idl_global->set_parse_state (IDL_GlobalData::PS_SNListCommaSeen);
1651         }
1652         scoped_name
1653         {
1654           idl_global->set_parse_state (IDL_GlobalData::PS_ScopedNameSeen);
1656           UTL_NameList *nl = 0;
1657           ACE_NEW_RETURN (nl,
1658                           UTL_NameList ($4,
1659                                         0),
1660                           1);
1662           if ($1 == 0)
1663             {
1664               $<nlval>$ = nl;
1665             }
1666           else
1667             {
1668               $1->nconc (nl);
1669               $<nlval>$ = $1;
1670             }
1671         }
1672         | %empty
1673         {
1674           $<nlval>$ = 0;
1675         }
1676         ;
1678 scoped_name
1679         : id
1680         {
1681           idl_global->set_parse_state (IDL_GlobalData::PS_SN_IDSeen);
1683           ACE_NEW_RETURN ($$,
1684                           UTL_IdList ($1,
1685                                       0),
1686                           1);
1687         }
1688         | IDL_SCOPE_DELIMITOR
1689         {
1690           idl_global->set_parse_state (IDL_GlobalData::PS_ScopeDelimSeen);
1691         }
1692         id
1693         {
1694           idl_global->set_parse_state (IDL_GlobalData::PS_SN_IDSeen);
1696           Identifier *id = 0;
1697           ACE_NEW_RETURN (id,
1698                           Identifier ($1),
1699                           1);
1700           ACE::strdelete ($1);
1701           $1 = 0;
1702           UTL_IdList *sn = 0;
1703           ACE_NEW_RETURN (sn,
1704                           UTL_IdList ($3,
1705                                       0),
1706                           1);
1707           ACE_NEW_RETURN ($<idlist>$,
1708                           UTL_IdList (id,
1709                                       sn),
1710                           1);
1711         }
1712         | scoped_name
1713           IDL_SCOPE_DELIMITOR
1714         {
1715           idl_global->set_parse_state (IDL_GlobalData::PS_ScopeDelimSeen);
1717           // This cleans up all the non-global "::"s in scoped names.
1718           // If there is a global one, it gets put into the UTL_IdList,
1719           // so we clean it up in the case above.
1720           ACE::strdelete ($2);
1721           $2 = 0;
1722         }
1723         id
1724         {
1725           idl_global->set_parse_state (IDL_GlobalData::PS_SN_IDSeen);
1727           UTL_IdList *sn = 0;
1728           ACE_NEW_RETURN (sn,
1729                           UTL_IdList ($4,
1730                                       0),
1731                           1);
1732           $1->nconc (sn);
1733           $<idlist>$ = $1;
1734         }
1735         ;
1737 id : IDENTIFIER
1738         {
1739           ACE_NEW_RETURN ($$,
1740                           Identifier ($1),
1741                           1);
1742           ACE::strdelete ($1);
1743           $1 = 0;
1744         }
1745         ;
1747 defining_id : IDENTIFIER
1748         {
1749           /* defining_id is a defining identifier
1750              whereas id is usually a reference to a defining identifier */
1751           ACE_NEW_RETURN ($$, Identifier ($1), 1);
1752           ACE::strdelete ($1);
1753           $1 = 0;
1754         }
1755         ;
1757 interface_forward :
1758         interface_decl
1759         {
1760           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1761           UTL_ScopedName n ($1, 0);
1763           if (ACE_OS::strcmp ($1->get_string (),
1764                               "TypeCode") == 0
1765               && !idl_global->in_main_file ())
1766             {
1767               AST_PredefinedType *pdt =
1768                 idl_global->gen ()->create_predefined_type (
1769                                         AST_PredefinedType::PT_pseudo,
1770                                         &n
1771                                       );
1773               s->add_to_scope (pdt);
1775               $1->destroy ();
1776               delete $1;
1777               $1 = 0;
1779               break;
1780             }
1782           AST_InterfaceFwd *f = 0;
1783           idl_global->set_parse_state (IDL_GlobalData::PS_InterfaceForwardSeen);
1785           /*
1786            * Create a node representing a forward declaration of an
1787            * interface. Store it in the enclosing scope
1788            */
1789           if (s != 0)
1790             {
1791               f = idl_global->gen ()->create_interface_fwd (&n,
1792                                                             0,
1793                                                             0);
1794               (void) s->fe_add_interface_fwd (f);
1795             }
1797           $1->destroy ();
1798           delete $1;
1799           $1 = 0;
1800         }
1801         |
1802         IDL_LOCAL interface_decl
1803         {
1804           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1805           UTL_ScopedName n ($2,
1806                             0);
1807           AST_InterfaceFwd *f = 0;
1808           idl_global->set_parse_state (
1809                           IDL_GlobalData::PS_InterfaceForwardSeen
1810                         );
1812           /*
1813            * Create a node representing a forward declaration of an
1814            * interface. Store it in the enclosing scope
1815            */
1816           if (s != 0)
1817             {
1818               f = idl_global->gen ()->create_interface_fwd (&n,
1819                                                             1,
1820                                                             0);
1821               (void) s->fe_add_interface_fwd (f);
1822             }
1824           $2->destroy ();
1825           delete $2;
1826           $2 = 0;
1827         }
1828         |
1829         IDL_ABSTRACT interface_decl
1830         {
1831           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1832           UTL_ScopedName n ($2,
1833                             0);
1834           AST_InterfaceFwd *f = 0;
1835           idl_global->set_parse_state (
1836                           IDL_GlobalData::PS_InterfaceForwardSeen
1837                         );
1839           /*
1840            * Create a node representing a forward declaration of an
1841            * interface. Store it in the enclosing scope
1842            */
1843           if (s != 0)
1844             {
1845               f = idl_global->gen ()->create_interface_fwd (&n,
1846                                                             0,
1847                                                             1);
1848               (void) s->fe_add_interface_fwd (f);
1849             }
1851           $2->destroy ();
1852           delete $2;
1853           $2 = 0;
1855           $$ = dynamic_cast<AST_Decl *> (f);
1856         }
1857         ;
1859 const_dcl :
1860         IDL_CONST
1861         {
1862           idl_global->set_parse_state (IDL_GlobalData::PS_ConstSeen);
1863         }
1864         const_type
1865         {
1866           idl_global->set_parse_state (IDL_GlobalData::PS_ConstTypeSeen);
1867         }
1868         defining_id
1869         {
1870           idl_global->set_parse_state (IDL_GlobalData::PS_ConstIDSeen);
1871         }
1872         '='
1873         {
1874           idl_global->set_parse_state (IDL_GlobalData::PS_ConstAssignSeen);
1875         }
1876         expression
1877         {
1878           $$ = 0;
1879           UTL_ScopedName n ($5, 0);
1881           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1882           AST_Constant *c = 0;
1883           idl_global->set_parse_state (IDL_GlobalData::PS_ConstExprSeen);
1885           /*
1886            * Create a node representing a constant declaration. Store
1887            * it in the enclosing scope.
1888            */
1889           if ($9 != 0 && s != 0)
1890             {
1891               AST_Param_Holder *param_holder = $9->param_holder ();
1893               AST_Expression::AST_ExprValue *result =
1894                 $9->check_and_coerce ($3, tao_enum_constant_decl);
1895               tao_enum_constant_decl = 0;
1897               // If the expression is a template parameter place
1898               // holder, 'result' will be 0, but it's ok.
1899               if (result == 0 && param_holder == 0)
1900                 {
1901                   idl_global->err ()->coercion_error ($9, $3);
1902                   $9->destroy ();
1903                   delete $9;
1904                   $9 = 0;
1905                 }
1906               else
1907                 {
1908                   AST_Expression::ExprType et = $3;
1910                   if (param_holder != 0
1911                       && et != param_holder->info ()->const_type_)
1912                     {
1913                       idl_global->err ()->mismatched_template_param (
1914                         param_holder->info ()->name_.c_str ());
1915                     }
1916                   else
1917                     {
1918                       c = idl_global->gen ()->create_constant ($3, $9, &n);
1919                       (void) s->fe_add_constant (c);
1920                       $$ = c;
1921                     }
1922                 }
1924               delete result;
1925               result = 0;
1926             }
1928           $5->destroy ();
1929           delete $5;
1930           $5 = 0;
1931         }
1932         ;
1934 const_type
1935         : integer_type
1936         | char_type
1937         | octet_type
1938         | boolean_type
1939         | floating_pt_type
1940         | fixed_type
1941         | string_type_spec
1942         {
1943           $$ = AST_Expression::EV_string;
1944         }
1945         | wstring_type_spec
1946         {
1947           $$ = AST_Expression::EV_wstring;
1948         }
1949         | scoped_name
1950         {
1951           UTL_Scope *s = idl_global->scopes ().top_non_null ();
1952           AST_PredefinedType *c = 0;
1953           AST_Typedef *t = 0;
1954           UTL_ScopedName *sn = $1;
1956           /*
1957            * If the constant's type is a scoped name, it must resolve
1958            * to a scalar constant type
1959            */
1960           AST_Decl *d =
1961             s->lookup_by_name (sn);
1963           if (s != 0 && d != 0)
1964             {
1965               /*
1966                * Look through typedefs.
1967                */
1968               while (d->node_type () == AST_Decl::NT_typedef)
1969                 {
1970                   t = dynamic_cast<AST_Typedef*> (d);
1972                   if (t == 0)
1973                     {
1974                       break;
1975                     }
1977                   d = t->base_type ();
1978                 }
1980               if (d->node_type () == AST_Decl::NT_pre_defined)
1981                 {
1982                   c = dynamic_cast<AST_PredefinedType*> (d);
1984                   $$ = FE_Utils::PredefinedTypeToExprType (c->pt ());
1985                 }
1986               else if (d->node_type () == AST_Decl::NT_string)
1987                 {
1988                   $$ = AST_Expression::EV_string;
1989                 }
1990               else if (d->node_type () == AST_Decl::NT_wstring)
1991                 {
1992                   $$ = AST_Expression::EV_wstring;
1993                 }
1994               else if (d->node_type () == AST_Decl::NT_enum)
1995                 {
1996                   $$ = AST_Expression::EV_enum;
1997                   tao_enum_constant_decl =
1998                     dynamic_cast<AST_Enum*> (d);
1999                 }
2000               else
2001                 {
2002                   idl_global->err ()->constant_expected (sn, d);
2003                 }
2004             }
2005           else
2006             {
2007               idl_global->err ()->lookup_error (sn);
2008             }
2010           sn->destroy ();
2011           delete sn;
2012           sn = 0;
2013           $1 = 0;
2014         }
2015         ;
2017 expression : const_expr ;
2019 const_expr : or_expr ;
2021 or_expr : xor_expr
2022         | or_expr '|' xor_expr
2023         {
2024           $$ =
2025             idl_global->gen ()->create_expr (
2026                                     AST_Expression::EC_or,
2027                                     $1,
2028                                     $3
2029                                   );
2030         }
2031         ;
2033 xor_expr
2034         : and_expr
2035         | xor_expr '^' and_expr
2036         {
2037           $$ =
2038             idl_global->gen ()->create_expr (
2039                                     AST_Expression::EC_xor,
2040                                     $1,
2041                                     $3
2042                                   );
2043         }
2044         ;
2046 and_expr
2047         : shift_expr
2048         | and_expr '&' shift_expr
2049         {
2050           $$ =
2051             idl_global->gen ()->create_expr (
2052                                     AST_Expression::EC_and,
2053                                     $1,
2054                                     $3
2055                                   );
2056         }
2057         ;
2059 shift_expr
2060         : add_expr
2061         | shift_expr IDL_LEFT_SHIFT add_expr
2062         {
2063           $$ =
2064             idl_global->gen ()->create_expr (
2065                                     AST_Expression::EC_left,
2066                                     $1,
2067                                     $3
2068                                   );
2069         }
2070         | shift_expr IDL_RIGHT_SHIFT add_expr
2071         {
2072           $$ =
2073             idl_global->gen ()->create_expr (
2074                                     AST_Expression::EC_right,
2075                                     $1,
2076                                     $3
2077                                   );
2078         }
2079         ;
2081 add_expr
2082         : mult_expr
2083         | add_expr '+' mult_expr
2084         {
2085           $$ =
2086             idl_global->gen ()->create_expr (
2087                                     AST_Expression::EC_add,
2088                                     $1,
2089                                     $3
2090                                   );
2091         }
2092         | add_expr '-' mult_expr
2093         {
2094           $$ =
2095             idl_global->gen ()->create_expr (
2096                                     AST_Expression::EC_minus,
2097                                     $1,
2098                                     $3
2099                                   );
2100         }
2101         ;
2103 mult_expr
2104         : unary_expr
2105         | mult_expr '*' unary_expr
2106         {
2107           $$ =
2108             idl_global->gen ()->create_expr (
2109                                     AST_Expression::EC_mul,
2110                                     $1,
2111                                     $3
2112                                   );
2113         }
2114         | mult_expr '/' unary_expr
2115         {
2116           $$ =
2117             idl_global->gen ()->create_expr (
2118                                     AST_Expression::EC_div,
2119                                     $1,
2120                                     $3
2121                                   );
2122         }
2123         | mult_expr '%' unary_expr
2124         {
2125           $$ =
2126             idl_global->gen ()->create_expr (
2127                                     AST_Expression::EC_mod,
2128                                     $1,
2129                                     $3
2130                                   );
2131         }
2132         ;
2134 unary_expr
2135         : primary_expr
2136         | '+' primary_expr
2137         {
2138           $$ =
2139             idl_global->gen ()->create_expr (
2140                                     AST_Expression::EC_u_plus,
2141                                     $2,
2142                                     0
2143                                   );
2144         }
2145         | '-' primary_expr
2146         {
2147           $$ =
2148             idl_global->gen ()->create_expr (
2149                                    AST_Expression::EC_u_minus,
2150                                    $2,
2151                                    0
2152                                  );
2153         }
2154         | '~' primary_expr
2155         {
2156           $$ =
2157             idl_global->gen ()->create_expr (
2158                                    AST_Expression::EC_bit_neg,
2159                                    $2,
2160                                    0
2161                                  );
2162         }
2163         ;
2165 primary_expr
2166         : scoped_name
2167         {
2168           UTL_ScopedName *name = $1;
2170           /*
2171            * An expression which is a scoped name is not resolved now,
2172            * but only when it is evaluated (such as when it is assigned
2173            * as a constant value).
2174            */
2175           AST_Expression *expr = 0;
2177           AST_Decl *node = stack_based_lookup_for_primary_expr ?
2178             idl_global->scopes ().lookup_by_name (name) :
2179             idl_global->scopes ().top_non_null ()->lookup_by_name (name);
2180           if (!node)
2181             {
2182               if (!idl_global->ignore_lookup_errors_)
2183                 {
2184                   idl_global->err ()->lookup_error (name);
2185                   return 1;
2186                 }
2187             }
2188           else if (node->node_type () == AST_Decl::NT_const)
2189             {
2190               /*
2191                * If the scoped name is an IDL constant, it
2192                * may be used in an array dim, a string
2193                * bound, or a sequence bound. If so, it
2194                * must be unsigned and > 0. We assign the
2195                * constant's value and type to the
2196                * expression created here so we can check
2197                * them later.
2198                */
2199               AST_Constant *c = dynamic_cast<AST_Constant *> (node);
2200               expr = idl_global->gen ()->create_expr (
2201                   c->constant_value (),
2202                   c->et ());
2203             }
2204           else
2205             {
2206               // An AST_Expression owns the scoped name
2207               // passed in this constructor, so we copy it
2208               // and destroy it below no matter which case
2209               // is followed.
2210               expr = idl_global->gen ()->create_expr (name->copy ());
2211               if (node->node_type () == AST_Decl::NT_enum_val)
2212                 {
2213                   expr->enum_parent (
2214                     dynamic_cast<AST_EnumVal *> (node)->enum_parent ());
2215                 }
2216             }
2218           $<exval>$ = expr;
2219           name->destroy ();
2220           delete name;
2221           $1 = name = 0;
2222         }
2223         | literal
2224         | '(' const_expr ')'
2225         {
2226           $$ = $2;
2227         }
2228         ;
2230 literal
2231         : IDL_INTEGER_LITERAL
2232         {
2233           $$ = idl_global->gen ()->create_expr ($1);
2234         }
2235         | IDL_UINTEGER_LITERAL
2236         {
2237           $$ =
2238             idl_global->gen ()->create_expr ($1);
2239         }
2240         | IDL_STRING_LITERAL
2241         {
2242           $$ = idl_global->gen ()->create_expr ($1);
2243           $1->destroy ();
2244           delete $1;
2245           $1 = 0;
2246         }
2247         | IDL_WSTRING_LITERAL
2248         {
2249           char *wide_string = $1;
2250           $$ = idl_global->gen ()->create_expr (wide_string);
2251           ACE_OS::free (wide_string);
2252           $1 = 0;
2253         }
2254         | IDL_CHARACTER_LITERAL
2255         {
2256           $$ = idl_global->gen ()->create_expr ($1);
2257         }
2258         | IDL_WCHAR_LITERAL
2259         {
2260           ACE_OutputCDR::from_wchar wc ($1);
2261           $$ = idl_global->gen ()->create_expr (wc);
2262         }
2263         | IDL_FIXED_PT_LITERAL
2264         {
2265           $$ = idl_global->gen ()->create_expr ($1);
2266         }
2267         | IDL_FLOATING_PT_LITERAL
2268         {
2269           $$ = idl_global->gen ()->create_expr ($1);
2270         }
2271         | IDL_TRUETOK
2272         {
2273           $$ = idl_global->gen ()->create_expr (true);
2274         }
2275         | IDL_FALSETOK
2276         {
2277           $$ = idl_global->gen ()->create_expr (false);
2278         }
2279         ;
2281 positive_int_expr :
2282         const_expr
2283         {
2284           int good_expression = 1;
2285           $1->evaluate (AST_Expression::EK_positive_int);
2286           AST_Expression::AST_ExprValue *ev = $1->ev ();
2288           /*
2289            * If const_expr is an enum value (AST_EnumVal inherits from
2290            * AST_Constant), the AST_ExprValue will probably not be set,
2291            * but there's no need to check anyway
2292            */
2293           if (ev != 0)
2294             {
2295               switch (ev->et)
2296               {
2297                 case AST_Expression::EV_ushort:
2298                   if (ev->u.usval == 0)
2299                     {
2300                       good_expression = 0;
2301                     }
2303                   break;
2304                 case AST_Expression::EV_ulong:
2305                   if (ev->u.ulval == 0)
2306                     {
2307                       good_expression = 0;
2308                     }
2310                   break;
2311                 case AST_Expression::EV_ulonglong:
2312                   if (ev->u.ullval == 0)
2313                     {
2314                       good_expression = 0;
2315                     }
2317                   break;
2318                 case AST_Expression::EV_octet:
2319                   if (ev->u.oval == 0)
2320                     {
2321                       good_expression = 0;
2322                     }
2324                   break;
2325                 case AST_Expression::EV_bool:
2326                   if (ev->u.bval == 0)
2327                     {
2328                       good_expression = 0;
2329                     }
2331                   break;
2332                 default:
2333                   good_expression = 0;
2334                   break;
2335               }
2336             }
2338           if (good_expression)
2339             {
2340               $$ = $1;
2341             }
2342           else
2343             {
2344               idl_global->err ()->syntax_error (idl_global->parse_state ());
2345             }
2346         }
2347         ;
2349 annotation_dcl
2350         : IDL_ANNOTATION_DECL defining_id '{'
2351         {
2352           if (idl_global->idl_version_ < IDL_VERSION_4)
2353             {
2354               idl_global->err ()->idl_version_error (
2355                 "Annotations are an IDL4 feature");
2356             }
2358           Identifier *id = $2;
2359           UTL_ScopedName name (id, 0);
2360           AST_Annotation_Decl::escape_name (&name);
2361           AST_Annotation_Decl *annotation_decl = idl_global->gen ()->
2362             create_annotation_decl (&name);
2363           idl_global->scopes ().top_non_null ()->
2364             fe_add_annotation_decl (annotation_decl);
2365           idl_global->scopes ().push (annotation_decl);
2366         }
2367         annotation_body '}'
2368         {
2369           Identifier *id = $2;
2370           idl_global->scopes ().pop ();
2371           id->destroy ();
2372           delete id;
2374           $$ = 0;
2375         }
2376         ;
2378 annotation_body
2379         : annotation_body annotation_statement
2380         | %empty
2381         ;
2383 annotation_statement
2384         : annotation_member
2385         | const_dcl ';'
2386         | enum_type ';'
2387         | IDL_TYPEDEF
2388         {
2389           idl_global->set_parse_state (IDL_GlobalData::PS_TypedefSeen);
2390           idl_global->in_typedef (true);
2391         }
2392         type_declarator ';'
2393         ;
2395 annotation_member_type
2396         : const_type
2397         | any_type
2398         ;
2400 annotation_member
2401         : annotation_member_type defining_id annotation_member_default ';'
2402         {
2403           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
2404           UTL_Scope *root = idl_global->scopes ().bottom ();
2406           AST_Expression::ExprType type = $1;
2407           Identifier *name = $2;
2408           // Annotation member names can't clash with C++ keywords
2409           FE_Utils::original_local_name (name);
2410           UTL_ScopedName *scoped_name = new UTL_ScopedName (name, 0);
2411           AST_Expression *default_value = $3;
2413           AST_Decl * type_obj;
2414           switch (type)
2415             {
2416             case AST_Expression::EV_string:
2417             case AST_Expression::EV_wstring:
2418               type_obj = tao_string_decl;
2419               break;
2420             case AST_Expression::EV_enum:
2421               type_obj = tao_enum_constant_decl;
2422               break;
2423             default:
2424               type_obj = root->lookup_primitive_type (type);
2425             }
2427           FE_Declarator *declarator = new FE_Declarator (
2428             scoped_name, FE_Declarator::FD_simple, 0);
2429           AST_Annotation_Member *member = idl_global->gen ()->
2430             create_annotation_member (
2431               type, declarator->compose (type_obj), declarator->name ());
2432           scope->fe_add_annotation_member (member);
2434           declarator->destroy ();
2435           delete declarator;
2437           if (default_value)
2438             {
2439               // Check if types are compatible, else report error
2440               AST_Expression::AST_ExprValue *result =
2441                 default_value->check_and_coerce (type, tao_enum_constant_decl);
2442               tao_enum_constant_decl = 0;
2443               if (result)
2444                 {
2445                   member->value (default_value);
2446                 }
2447               else
2448                 {
2449                   idl_global->err ()->coercion_error (default_value, type);
2450                 }
2451               delete result;
2452             }
2453         }
2454         ;
2456 annotation_member_default
2457         : IDL_DEFAULT const_expr
2458         {
2459           $$ = $2;
2460         }
2461         | %empty
2462         {
2463           $$ = 0;
2464         }
2465         ;
2467 at_least_one_annotation
2468         : annotations_maybe annotation_appl
2469         {
2470           AST_Annotation_Appls *annotations = $1;
2471           AST_Annotation_Appl *annotation = $2;
2472           if (annotation)
2473             {
2474               annotations->add (annotation);
2475             }
2476           $$ = annotations;
2477         }
2478         ;
2480 annotations_maybe
2481         : annotations_maybe annotation_appl
2482         {
2483           AST_Annotation_Appls *annotations = $1;
2484           AST_Annotation_Appl *annotation = $2;
2485           if (annotation)
2486             {
2487               annotations->add (annotation);
2488             }
2489           $$ = annotations;
2490         }
2491         | %empty
2492         {
2493           $$ = new AST_Annotation_Appls ();
2494         }
2495         ;
2497 annotation_appl
2498         : IDL_ANNOTATION_SYMBOL scoped_name
2499         {
2500           if (idl_global->idl_version_ < IDL_VERSION_4)
2501             {
2502               idl_global->err ()->idl_version_error (
2503                 "Annotations are an IDL4 feature");
2504             }
2506           AST_Annotation_Decl *decl = 0;
2507           UTL_ScopedName *name = $2;
2508           AST_Annotation_Decl::escape_name (name);
2510           // Check for Matching Annotation Declaration
2511           AST_Decl *d = idl_global->scopes ().top_non_null ()->
2512             lookup_by_name (name);
2513           if (d)
2514             {
2515               decl = dynamic_cast<AST_Annotation_Decl*> (d);
2516               if (decl)
2517                 {
2518                   idl_global->scopes ().push (decl);
2519                 }
2520             }
2521           else
2522             {
2523               Identifier &id = *name->last_component ();
2524               switch (idl_global->unknown_annotations_)
2525                 {
2526                 default:
2527                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ONCE:
2528                   if (idl_global->unknown_annotations_seen_.insert (id) == 1)
2529                     {
2530                       break;
2531                     }
2532                   idl_global->err ()->lookup_warning (name);
2533                   break;
2534                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ALL:
2535                   idl_global->err ()->lookup_warning (name);
2536                   break;
2537                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_ERROR:
2538                   idl_global->err ()->lookup_error (name);
2539                   break;
2540                 case IDL_GlobalData::UNKNOWN_ANNOTATIONS_IGNORE:
2541                   break;
2542                 }
2544               /*
2545                * Ignore lookup errors for parameter values that might depend on
2546                * constants or enums from the missing annotation declaration.
2547                */
2548               idl_global->ignore_lookup_errors_ = true;
2549             }
2551           stack_based_lookup_for_primary_expr = true;
2553           $<annotation_decl_val>$ = decl;
2554         }
2555         annotation_appl_params_maybe
2556         {
2557           idl_global->ignore_lookup_errors_ = false;
2558           stack_based_lookup_for_primary_expr = false;
2559           AST_Annotation_Appl *appl = 0;
2560           UTL_ScopedName *name = $2;
2561           AST_Annotation_Decl *decl = $<annotation_decl_val>3;
2562           AST_Annotation_Appl::Params *params = $4;
2564           if (decl)
2565             {
2566               appl = idl_global->gen ()->create_annotation_appl (name, params);
2567               appl->apply_from (decl);
2568               idl_global->scopes ().pop ();
2569             }
2570           else
2571             {
2572               AST_Annotation_Appl::delete_params (params);
2573             }
2575           if (name)
2576             {
2577               name->destroy ();
2578               delete name;
2579             }
2581           $$ = appl;
2582         }
2583         ;
2585 annotation_appl_params_maybe
2586         : '(' annotation_appl_params ')'
2587         {
2588           $$ = $2;
2589         }
2590         | %empty
2591         {
2592           $$ = 0;
2593         }
2594         ;
2596 annotation_appl_params
2597         : const_expr
2598         {
2599           AST_Annotation_Appl::Params *params = new AST_Annotation_Appl::Params;
2600           AST_Annotation_Appl::Param *param = new AST_Annotation_Appl::Param;
2601           param->id = 0;
2602           param->expr = $1;
2603           params->push (param);
2604           $$ = params;
2605         }
2606         | named_annotation_appl_params
2607         {
2608           $$ = $1;
2609         }
2610         ;
2612 named_annotation_appl_params
2613         : named_annotation_appl_param more_named_annotation_appl_params
2614         {
2615           AST_Annotation_Appl::Params *params = $2;
2616           params->push ($1);
2617           $$ = params;
2618         }
2620 more_named_annotation_appl_params
2621         : ',' named_annotation_appl_param more_named_annotation_appl_params
2622         {
2623           AST_Annotation_Appl::Params *params = $3;
2624           params->push ($2);
2625           $$ = params;
2626         }
2627         | %empty
2628         {
2629           $$ = new AST_Annotation_Appl::Params;
2630         }
2631         ;
2633 named_annotation_appl_param
2634         : id '=' const_expr
2635         {
2636           AST_Annotation_Appl::Param *param = new AST_Annotation_Appl::Param;
2637           param->id = $1;
2638           // Annotation Member Names Can't Clash with C++ keywords
2639           FE_Utils::original_local_name (param->id);
2640           param->expr = $3;
2641           $$ = param;
2642         }
2643         ;
2645 type_dcl
2646         : IDL_TYPEDEF
2647         {
2648           idl_global->set_parse_state (IDL_GlobalData::PS_TypedefSeen);
2649           idl_global->in_typedef (true);
2650         }
2651         type_declarator
2652         {
2653           $$ = $3;
2654         }
2655         | struct_type
2656         {
2657           $$ = $1;
2658         }
2659         | union_type
2660         {
2661           $$ = $1;
2662         }
2663         | enum_type
2664         {
2665           $$ = $1;
2666         }
2667         | IDL_NATIVE simple_declarator
2668         {
2669           UTL_Scope *s = idl_global->scopes ().top_non_null ();
2670           AST_Native *node = 0;
2671           idl_global->set_parse_state (IDL_GlobalData::PS_NativeSeen);
2673           /*
2674            * Create a node representing a Native and add it to its
2675            * enclosing scope
2676            */
2677           if (s != 0)
2678             {
2679               node =
2680                 idl_global->gen ()->create_native (
2681                                         $2->name ()
2682                                       );
2683               /*
2684                * Add it to its defining scope
2685                */
2686               (void) s->fe_add_native (node);
2687             }
2689           $2->destroy ();
2690           delete $2;
2691           $2 = 0;
2693           $$ = 0;
2694         }
2695         | constructed_forward_type_spec
2696         {
2697           $$ = 0;
2698         }
2699         ;
2701 type_declarator :
2702         type_spec
2703         {
2704           idl_global->set_parse_state (IDL_GlobalData::PS_TypeSpecSeen);
2705         }
2706         at_least_one_declarator
2707         {
2708           AST_Decl *type_spec = $1;
2709           UTL_DeclList *decls = $3;
2711           UTL_Scope *s = idl_global->scopes ().top_non_null ();
2712           FE_Declarator *d = 0;
2713           AST_Typedef *t = 0;
2714           unsigned long index = 0UL;
2715           idl_global->set_parse_state (IDL_GlobalData::PS_DeclaratorsSeen);
2717           /*
2718            * Create a list of type renamings. Add them to the
2719            * enclosing scope
2720            */
2721           if (s && type_spec && decls)
2722             {
2723               for (UTL_DecllistActiveIterator l (decls); !l.is_done (); l.next ())
2724                 {
2725                   d = l.item ();
2726                   if (d == 0)
2727                     {
2728                       continue;
2729                     }
2731                   AST_Type *tp = d->compose (type_spec);
2732                   if (tp == 0)
2733                     {
2734                       continue;
2735                     }
2737                   if (AST_Decl::NT_except == tp->node_type ())
2738                     {
2739                       idl_global->err ()->not_a_type (tp);
2740                       continue;
2741                     }
2743                   t = idl_global->gen ()->create_typedef (tp,
2744                                                           d->name (),
2745                                                           s->is_local (),
2746                                                           s->is_abstract ());
2748                   // If the base type is a sequence or array, the typedef
2749                   // constructor sets owns_base_type_ to true. But if
2750                   // there is a comma-separated list of such typedefs,
2751                   // the base type can be destroyed only once. In all
2752                   // other cases, the line below has no effect.
2753                   if (index++ > 0)
2754                     {
2755                       t->owns_base_type (false);
2756                     }
2758                   (void) s->fe_add_typedef (t);
2759                   idl_global->in_typedef (false);
2760                 }
2762               // This FE_Declarator class isn't destroyed with the AST.
2763               decls->destroy ();
2764               delete decls;
2765               $3 = decls = 0;
2766             }
2768           $$ = t;
2769         }
2770         ;
2772 type_spec
2773         : simple_type_spec
2774         | constructed_type_spec
2775         ;
2777 simple_type_spec
2778         : base_type_spec
2779         {
2780           $$ =
2781             idl_global->scopes ().bottom ()->lookup_primitive_type (
2782                                                  $1
2783                                                );
2784         }
2785         | template_type_spec
2786         | scoped_name
2787         {
2788           UTL_Scope *s = idl_global->scopes ().top_non_null ();
2789           AST_Decl *d = 0;
2791           if (s != 0)
2792             {
2793               d =
2794                 s->lookup_by_name ($1);
2795             }
2797           if (d == 0)
2798             {
2799               idl_global->err ()->lookup_error ($1);
2800             }
2801           else
2802             {
2803               d->last_referenced_as ($1);
2804             }
2807           $$ = d;
2808         }
2809         ;
2811 base_type_spec
2812         : integer_type
2813         | floating_pt_type
2814         | char_type
2815         | boolean_type
2816         | octet_type
2817         | fixed_type
2818         | any_type
2819         | object_type
2820         ;
2822 template_type_spec
2823         : sequence_type_spec
2824         | string_type_spec
2825         | wstring_type_spec
2826         | fixed_type_spec
2827         ;
2829 constructed_type_spec
2830         : struct_type
2831         | union_type
2832         | enum_type
2833         ;
2835 constructed_forward_type_spec
2836         : struct_forward_type
2837         | union_forward_type
2838         ;
2840 at_least_one_declarator :
2841         declarator declarators
2842         {
2843           ACE_NEW_RETURN ($$,
2844                           UTL_DeclList ($1,
2845                                         $2),
2846                           1);
2847         }
2848         ;
2850 declarators
2851         : declarators
2852           ','
2853         {
2854           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsCommaSeen);
2855         }
2856         declarator
2857         {
2858           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsDeclSeen);
2860           UTL_DeclList *dl = 0;
2861           ACE_NEW_RETURN (dl,
2862                           UTL_DeclList ($4,
2863                                         0),
2864                           1);
2866           if ($1 == 0)
2867             {
2868               $<dlval>$ = dl;
2869             }
2870           else
2871             {
2872               $1->nconc (dl);
2873               $<dlval>$ = $1;
2874             }
2875         }
2876         | %empty
2877         {
2878           $<dlval>$ = 0;
2879         }
2880         ;
2882 declarator
2883         : simple_declarator
2884         | complex_declarator
2885         ;
2887 at_least_one_simple_declarator :
2888         simple_declarator simple_declarators
2889         {
2890           ACE_NEW_RETURN ($<dlval>$,
2891                           UTL_DeclList ($1,
2892                                         $2),
2893                           1);
2894         }
2895         ;
2897 simple_declarators
2898         : simple_declarators
2899           ','
2900         {
2901           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsCommaSeen);
2902         }
2903         simple_declarator
2904         {
2905           idl_global->set_parse_state (IDL_GlobalData::PS_DeclsDeclSeen);
2907           UTL_DeclList *dl = 0;
2908           ACE_NEW_RETURN (dl,
2909                           UTL_DeclList ($4,
2910                                         0),
2911                           1);
2913           if ($1 == 0)
2914             {
2915               $<dlval>$ = dl;
2916             }
2917           else
2918             {
2919               $1->nconc (dl);
2920               $<dlval>$ = $1;
2921             }
2922         }
2923         | %empty
2924         {
2925           $<dlval>$ = 0;
2926         }
2927         ;
2929 simple_declarator :
2930         defining_id
2931         {
2932           UTL_ScopedName *sn = 0;
2933           ACE_NEW_RETURN (sn,
2934                           UTL_ScopedName ($1,
2935                                           0),
2936                           1);
2937           ACE_NEW_RETURN ($<deval>$,
2938                           FE_Declarator (sn,
2939                                          FE_Declarator::FD_simple,
2940                                          0),
2941                           1);
2942         }
2943         ;
2945 complex_declarator :
2946         array_declarator
2947         {
2948           UTL_ScopedName *sn = 0;
2949           ACE_NEW_RETURN (sn,
2950                           UTL_ScopedName (
2951                               $1->local_name ()->copy (),
2952                               0
2953                             ),
2954                           1);
2955           ACE_NEW_RETURN ($<deval>$,
2956                           FE_Declarator (sn,
2957                                          FE_Declarator::FD_complex,
2958                                          $1),
2959                           1);
2960         }
2961         ;
2963 integer_type
2964         : signed_int
2965         | unsigned_int
2966         ;
2968 signed_int
2969         : IDL_LONG
2970         {
2971           $$ = AST_Expression::EV_long;
2972         }
2973         | IDL_LONG IDL_LONG
2974         {
2975           $$ = AST_Expression::EV_longlong;
2976         }
2977         | IDL_SHORT
2978         {
2979           $$ = AST_Expression::EV_short;
2980         }
2981         ;
2983 unsigned_int
2984         : IDL_UNSIGNED IDL_LONG
2985         {
2986           $$ = AST_Expression::EV_ulong;
2987         }
2988         | IDL_UNSIGNED IDL_LONG IDL_LONG
2989         {
2990           $$ = AST_Expression::EV_ulonglong;
2991         }
2992         | IDL_UNSIGNED IDL_SHORT
2993         {
2994           $$ = AST_Expression::EV_ushort;
2995         }
2996         ;
2998 floating_pt_type
2999         : IDL_DOUBLE
3000         {
3001           $$ = AST_Expression::EV_double;
3002         }
3003         | IDL_FLOAT
3004         {
3005           $$ = AST_Expression::EV_float;
3006         }
3007         | IDL_LONG IDL_DOUBLE
3008         {
3009           $$ = AST_Expression::EV_longdouble;
3010         }
3011         ;
3013 fixed_type
3014         : IDL_FIXED
3015         {
3016           $$ = AST_Expression::EV_fixed;
3017         }
3018         ;
3020 char_type
3021         : IDL_CHAR
3022         {
3023           $$ = AST_Expression::EV_char;
3024         }
3025         | IDL_WCHAR
3026         {
3027           $$ = AST_Expression::EV_wchar;
3028         }
3029         ;
3031 octet_type
3032         : IDL_OCTET
3033         {
3034           $$ = AST_Expression::EV_octet;
3035         }
3036         ;
3038 boolean_type
3039         : IDL_BOOLEAN
3040         {
3041           $$ = AST_Expression::EV_bool;
3042         }
3043         ;
3045 any_type
3046         : IDL_ANY
3047         {
3048           $$ = AST_Expression::EV_any;
3049         }
3050         ;
3052 object_type
3053         : IDL_OBJECT
3054         {
3055           $$ = AST_Expression::EV_object;
3056         }
3057         ;
3059 struct_decl :
3060         IDL_STRUCT
3061         {
3062           idl_global->set_parse_state (IDL_GlobalData::PS_StructSeen);
3063         }
3064         defining_id
3065         {
3066           idl_global->set_parse_state (IDL_GlobalData::PS_StructIDSeen);
3067           $$ = $3;
3068         }
3069         ;
3072 struct_type
3073         : struct_decl
3074         {
3075           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3076           UTL_ScopedName n ($1, 0);
3077           AST_Structure *d = 0;
3079           /*
3080            * Create a node representing a struct declaration. Add it
3081            * to the enclosing scope
3082            */
3083           if (s != 0)
3084             {
3085               d =
3086                 idl_global->gen ()->create_structure (
3087                                         &n,
3088                                         s->is_local (),
3089                                         s->is_abstract ()
3090                                       );
3091               AST_Structure::fwd_redefinition_helper (d, s);
3092               (void) s->fe_add_structure (d);
3093             }
3095           /*
3096            * Push the scope of the struct on the scopes stack.
3097            */
3098           idl_global->scopes ().push (d);
3100           $1->destroy ();
3101           delete $1;
3102           $1 = 0;
3103         }
3104         '{'
3105         {
3106           idl_global->set_parse_state (IDL_GlobalData::PS_StructSqSeen);
3107         }
3108         at_least_one_member
3109         {
3110           idl_global->set_parse_state (IDL_GlobalData::PS_StructBodySeen);
3111         }
3112         '}'
3113         {
3114           idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen);
3116           /*
3117            * Done with this struct. Pop its scope off the scopes stack.
3118            */
3119           $$ = dynamic_cast<AST_Structure*> (
3120                    idl_global->scopes ().top_non_null ()
3121                  );
3122           idl_global->scopes ().pop ();
3123         }
3124         ;
3126 at_least_one_member : member members ;
3128 members
3129         : members member
3130         | %empty
3131         ;
3133 member
3134         : annotations_maybe member_i
3135         {
3136           AST_Annotation_Appls *annotations = $1;
3137           AST_Decls *members = $2;
3138           if (annotations && members)
3139             {
3140               for (size_t i = 0; i < members->size (); i++)
3141                 {
3142                   (*members)[i]->annotation_appls (*annotations);
3143                 }
3144             }
3145           delete annotations;
3146           delete members;
3147         }
3148         ;
3150 member_i :
3151         type_spec
3152         {
3153           idl_global->set_parse_state (IDL_GlobalData::PS_MemberTypeSeen);
3154         }
3155         at_least_one_declarator
3156         {
3157           idl_global->set_parse_state (IDL_GlobalData::PS_MemberDeclsSeen);
3158         }
3159         ';'
3160         {
3161           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3162           FE_Declarator *d = 0;
3163           AST_Field *f = 0;
3164           idl_global->set_parse_state (IDL_GlobalData::PS_MemberDeclsCompleted);
3165           AST_Decls *members = 0;
3167           /*
3168            * Check for illegal recursive use of type.
3169            */
3170           if ($1 != 0
3171               && AST_illegal_recursive_type ($1))
3172             {
3173               idl_global->err ()->error1 (UTL_Error::EIDL_RECURSIVE_TYPE,
3174                                           $1);
3175             }
3176           /*
3177            * Create a node representing a struct or exception member
3178            * Add it to the enclosing scope.
3179            */
3180           else if (s && $1 && $3)
3181             {
3182               members = new AST_Decls;
3183               for (UTL_DecllistActiveIterator l ($3);
3184                    !l.is_done ();
3185                    l.next ())
3186                 {
3187                   d = l.item ();
3189                   if (d == 0)
3190                     {
3191                       continue;
3192                     }
3194                   AST_Type *tp = d->compose ($1);
3196                   if (tp == 0)
3197                     {
3198                       continue;
3199                     }
3201                   f = idl_global->gen ()->create_field (tp, d->name ());
3202                   members->push_back (f);
3203                   (void) s->fe_add_field (f);
3204                 }
3205             }
3207           $3->destroy ();
3208           delete $3;
3209           $3 = 0;
3211           $$ = members;
3212         }
3213         | error
3214         {
3215           idl_global->err ()->syntax_error (idl_global->parse_state ());
3216         }
3217         ';'
3218         {
3219           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
3220           yyerrok;
3221         }
3222         ;
3224 union_decl :
3225         IDL_UNION
3226         {
3227           idl_global->set_parse_state (IDL_GlobalData::PS_UnionSeen);
3228         }
3229         defining_id
3230         {
3231           idl_global->set_parse_state (IDL_GlobalData::PS_UnionIDSeen);
3232           $$ = $3;
3233         }
3234         ;
3236 union_type
3237         : union_decl IDL_SWITCH
3238         {
3239           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchSeen);
3240         }
3241         '('
3242         {
3243           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3244           UTL_ScopedName n ($1, 0);
3245           AST_Union *u = 0;
3246           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchOpenParSeen);
3248           /*
3249            * Create a node representing an empty union. Add it to its enclosing
3250            * scope.
3251            */
3252           if (s != 0)
3253             {
3254               u = idl_global->gen ()->create_union (0,
3255                                                     &n,
3256                                                     s->is_local (),
3257                                                     s->is_abstract ());
3259               AST_Structure *st = dynamic_cast<AST_Structure*> (u);
3260               AST_Structure::fwd_redefinition_helper (st, s);
3261               u = dynamic_cast<AST_Union*> (st);
3262               (void) s->fe_add_union (u);
3263             }
3265           /*
3266            * Push the scope of the union on the scopes stack
3267            */
3268           idl_global->scopes ().push (u);
3270           /*
3271            * Don't delete $1 yet; we'll need it a bit later.
3272            */
3273         }
3274         annotations_maybe switch_type_spec
3275         {
3276           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchTypeSeen);
3277         }
3278         ')'
3279         {
3280           /*
3281            * The top of the scopes must be an empty union we added after we
3282            * encountered 'union <id> switch ('. Now we are ready to add a
3283            * correct one. Temporarily remove the top so that we setup the
3284            * correct union in a right scope.
3285            */
3286           UTL_Scope *top = idl_global->scopes ().top_non_null ();
3287           idl_global->scopes ().pop ();
3288           AST_Annotation_Appls *disc_annotations = $6;
3290           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3291           UTL_ScopedName n ($1, 0);
3292           idl_global->set_parse_state (IDL_GlobalData::PS_SwitchCloseParSeen);
3294           /*
3295            * Create a node representing a union.
3296            */
3297           if ($7 != 0 && s != 0)
3298             {
3299               AST_ConcreteType *tp =
3300                 dynamic_cast<AST_ConcreteType*> ($7);
3302               if (tp == 0)
3303                 {
3304                   idl_global->err ()->not_a_type ($7);
3305                 }
3306               else
3307                 {
3308                   /* Create a union with a correct discriminator. */
3309                   AST_Union *u = 0;
3310                   u = idl_global->gen ()->create_union (tp,
3311                                                         &n,
3312                                                         s->is_local (),
3313                                                         s->is_abstract ());
3315                   /* Narrow the enclosing scope. */
3316                   AST_Union *e = dynamic_cast<AST_Union*> (top);
3318                   e->redefine (u);
3319                   e->disc_annotations (*disc_annotations); // Set Discriminator Annotations
3321                   u->destroy ();
3322                   delete u;
3323                 }
3324             }
3326           /*
3327            * Restore the top.
3328            */
3329           idl_global->scopes ().push (top);
3331           $1->destroy ();
3332           delete $1;
3333           $1 = 0;
3335           delete disc_annotations;
3336         }
3337         '{'
3338         {
3339           idl_global->set_parse_state (IDL_GlobalData::PS_UnionSqSeen);
3340         }
3341         at_least_one_case_branch
3342         {
3343           idl_global->set_parse_state (IDL_GlobalData::PS_UnionBodySeen);
3344         }
3345         '}'
3346         {
3347           idl_global->set_parse_state (IDL_GlobalData::PS_UnionQsSeen);
3349           /*
3350            * Done with this union. Pop its scope from the scopes stack.
3351            */
3352           $$ = dynamic_cast<AST_Union*> (
3353                    idl_global->scopes ().top_non_null ()
3354                  );
3356           if ($$ != 0)
3357             {
3358               idl_global->scopes ().pop ();
3359             }
3360         }
3361         ;
3363 switch_type_spec :
3364         integer_type
3365         {
3366           $$ =
3367             idl_global->scopes ().bottom ()->lookup_primitive_type (
3368                                                  $1
3369                                                );
3370         }
3371         | char_type
3372         {
3373           /* wchars are not allowed. */
3374           if ($1 == AST_Expression::EV_wchar)
3375             {
3376               idl_global->err ()->error0 (UTL_Error::EIDL_DISC_TYPE);
3377             }
3379           $$ =
3380             idl_global->scopes ().bottom ()->lookup_primitive_type (
3381                                                  $1
3382                                                );
3383         }
3384         | octet_type
3385         {
3386           /* octets are not allowed. */
3387           idl_global->err ()->error0 (UTL_Error::EIDL_DISC_TYPE);
3388           $$ =
3389             idl_global->scopes ().bottom ()->lookup_primitive_type (
3390                                                  $1
3391                                                );
3392         }
3393         | boolean_type
3394         {
3395           $$ =
3396             idl_global->scopes ().bottom ()->lookup_primitive_type (
3397                                                  $1
3398                                                );
3399         }
3400         | enum_type
3401         | scoped_name
3402         {
3403           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3404           AST_Decl *d = 0;
3405           AST_PredefinedType *p = 0;
3406           AST_Typedef *t = 0;
3407           bool found = false;
3409           /*
3410            * The discriminator is a scoped name. Try to resolve to
3411            * one of the scalar types or to an enum. Thread through
3412            * typedef's to arrive at the base type at the end of the
3413            * chain.
3414            */
3415           d =
3416             s->lookup_by_name ($1);
3418           if (s != 0 && d != 0)
3419             {
3420               while (!found)
3421                 {
3422                   switch (d->node_type ())
3423                   {
3424                     case AST_Decl::NT_enum:
3425                       $$ = d;
3426                       found = true;
3427                       break;
3428                     case AST_Decl::NT_pre_defined:
3429                       p = dynamic_cast<AST_PredefinedType*> (d);
3431                       if (p != 0)
3432                         {
3433                           switch (p->pt ())
3434                           {
3435                             case AST_PredefinedType::PT_long:
3436                             case AST_PredefinedType::PT_ulong:
3437                             case AST_PredefinedType::PT_longlong:
3438                             case AST_PredefinedType::PT_ulonglong:
3439                             case AST_PredefinedType::PT_short:
3440                             case AST_PredefinedType::PT_ushort:
3441                             case AST_PredefinedType::PT_char:
3442                             case AST_PredefinedType::PT_boolean:
3443                               $$ = p;
3444                               found = true;
3445                               break;
3446                             case AST_PredefinedType::PT_wchar:
3447                             case AST_PredefinedType::PT_octet:
3448                               /* octets and wchars are not allowed */
3449                               idl_global->err ()->error0 (
3450                                   UTL_Error::EIDL_DISC_TYPE
3451                                 );
3452                               $$ = 0;
3453                               found = true;
3454                               break;
3455                             default:
3456                               $$ = 0;
3457                               found = true;
3458                               break;
3459                           }
3460                         }
3461                       else
3462                         {
3463                           $$ = 0;
3464                           found = true;
3465                         }
3467                       break;
3468                     case AST_Decl::NT_typedef:
3469                       t = dynamic_cast<AST_Typedef*> (d);
3471                       if (t != 0)
3472                         {
3473                           d = t->base_type ();
3474                         }
3476                       break;
3477                     default:
3478                       $$ = 0;
3479                       found = true;
3480                       break;
3481                   }
3482                 }
3483             }
3484           else
3485             {
3486               $$ = 0;
3487             }
3489           if ($$ == 0)
3490             {
3491               idl_global->err ()->lookup_error ($1);
3493               $1->destroy ();
3494               delete $1;
3495               $1 = 0;
3497               /* If we don't return here, we'll crash later.*/
3498               if (!idl_global->ignore_lookup_errors_)
3499                 {
3500                   return 1;
3501                 }
3502             }
3504           $1->destroy ();
3505           delete $1;
3506           $1 = 0;
3507         }
3508         ;
3510 at_least_one_case_branch : case_branch case_branches ;
3512 case_branches
3513         : case_branches case_branch
3514         | %empty
3515         ;
3517 case_branch :
3518         at_least_one_case_label
3519         {
3520           idl_global->set_parse_state (IDL_GlobalData::PS_UnionLabelSeen);
3521         }
3522         annotations_maybe element_spec
3523         {
3524           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemSeen);
3525         }
3526         ';'
3527         {
3528           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3529           AST_UnionBranch *b = 0;
3530           AST_Annotation_Appls *annotations = $3;
3531           AST_Field *f = $4;
3532           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemCompleted);
3534           /*
3535            * Create several nodes representing branches of a union.
3536            * Add them to the enclosing scope (the union scope)
3537            */
3538           if (s != 0 && $1 != 0 && $4 != 0)
3539             {
3540               b =
3541                 idl_global->gen ()->create_union_branch (
3542                                         $1,
3543                                         f->field_type (),
3544                                         f->name ()
3545                                       );
3546               b->annotation_appls (*annotations);
3547               (void) s->fe_add_union_branch (b);
3549               // f has passed its field type to the union branch,
3550               // but the rest still needs to be cleaned up.
3551               f->AST_Decl::destroy ();
3552               delete f;
3553               f = 0;
3554             }
3556           delete annotations;
3557         }
3558         | error
3559         {
3560           idl_global->err ()->syntax_error (idl_global->parse_state ());
3561         }
3562         ';'
3563         {
3564           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
3565           yyerrok;
3566         }
3567         ;
3569 at_least_one_case_label :
3570         case_label case_labels
3571         {
3572           ACE_NEW_RETURN ($<llval>$,
3573                           UTL_LabelList ($1,
3574                                          $2),
3575                           1);
3576         }
3577         ;
3579 case_labels
3580         : case_labels case_label
3581         {
3582           UTL_LabelList *ll = 0;
3583           ACE_NEW_RETURN (ll,
3584                           UTL_LabelList ($2,
3585                                          0),
3586                           1);
3588           if ($1 == 0)
3589             {
3590               $<llval>$ = ll;
3591             }
3592           else
3593             {
3594               $1->nconc (ll);
3595               $<llval>$ = $1;
3596             }
3597         }
3598         | %empty
3599         {
3600           $<llval>$ = 0;
3601         }
3602         ;
3604 case_label
3605         : IDL_DEFAULT
3606         {
3607           idl_global->set_parse_state (IDL_GlobalData::PS_DefaultSeen);
3608         }
3609           ':'
3610         {
3611           idl_global->set_parse_state (IDL_GlobalData::PS_LabelColonSeen);
3613           $$ = idl_global->gen ()->create_union_label (
3614                                        AST_UnionLabel::UL_default,
3615                                        0
3616                                      );
3617         }
3618         | IDL_CASE
3619         {
3620           idl_global->set_parse_state (IDL_GlobalData::PS_CaseSeen);
3621         }
3622           const_expr
3623         {
3624           idl_global->set_parse_state (IDL_GlobalData::PS_LabelExprSeen);
3625         }
3626           ':'
3627         {
3628           idl_global->set_parse_state (IDL_GlobalData::PS_LabelColonSeen);
3630           $$ = idl_global->gen ()->create_union_label (
3631                                       AST_UnionLabel::UL_label,
3632                                       $3
3633                                     );
3634         }
3635         ;
3637 element_spec :
3638         type_spec
3639         {
3640           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemTypeSeen);
3641         }
3642         declarator
3643         {
3644           idl_global->set_parse_state (IDL_GlobalData::PS_UnionElemDeclSeen);
3646           /*
3647            * Check for illegal recursive use of type
3648            */
3649           if ($1 != 0
3650               && AST_illegal_recursive_type ($1))
3651             {
3652               idl_global->err ()->error1 (UTL_Error::EIDL_RECURSIVE_TYPE, $1);
3654               $$ = 0;
3655             }
3656           /*
3657            * Create a field in a union branch
3658            */
3659           else if ($1 == 0
3660                    || $3 == 0)
3661             {
3662               $$ = 0;
3663             }
3664           else
3665             {
3666               AST_Type *tp = $3->compose ($1);
3668               if (tp == 0)
3669                 {
3670                   $$ = 0;
3671                 }
3672               else
3673                 {
3674                   $$ = idl_global->gen ()->create_field (
3675                                                tp,
3676                                                $3->name ()
3677                                              );
3678                 }
3680               $3->destroy ();
3681               delete $3;
3682               $3 = 0;
3683             }
3684         }
3685         ;
3687 struct_forward_type
3688         : struct_decl
3689         {
3690           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3691           UTL_ScopedName n ($1,
3692                             0);
3693           AST_StructureFwd *d = 0;
3695           /*
3696            * Create a node representing a forward declaration of a struct.
3697            */
3698           if (s != 0)
3699             {
3700               d = idl_global->gen ()->create_structure_fwd (&n);
3701               (void) s->fe_add_structure_fwd (d);
3702             }
3704           $1->destroy ();
3705           delete $1;
3706           $1 = 0;
3708           $$ = d;
3709         }
3710         ;
3712 union_forward_type
3713         : union_decl
3714         {
3715           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3716           UTL_ScopedName n ($1,
3717                             0);
3718           AST_UnionFwd *u = 0;
3720           /*
3721            * Create a node representing a forward declaration of a union.
3722            */
3723           if (s != 0)
3724             {
3725               u = idl_global->gen ()->create_union_fwd (&n);
3726               (void) s->fe_add_union_fwd (u);
3727             }
3729           $1->destroy ();
3730           delete $1;
3731           $1 = 0;
3732         }
3733         ;
3735 enum_type :
3736         IDL_ENUM
3737         {
3738           idl_global->set_parse_state (IDL_GlobalData::PS_EnumSeen);
3739         }
3740         defining_id
3741         {
3742           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3743           UTL_ScopedName n ($3, 0);
3744           AST_Enum *e = 0;
3745           idl_global->set_parse_state (IDL_GlobalData::PS_EnumIDSeen);
3747           /*
3748            * Create a node representing an enum and add it to its
3749            * enclosing scope.
3750            */
3751           if (s != 0)
3752             {
3753               e = idl_global->gen ()->create_enum (&n,
3754                                                    s->is_local (),
3755                                                    s->is_abstract ());
3756               /*
3757                * Add it to its defining scope
3758                */
3759               (void) s->fe_add_enum (e);
3760             }
3762           /*
3763            * Push the enum scope on the scopes stack.
3764            */
3765           idl_global->scopes ().push (e);
3767           $3->destroy ();
3768           delete $3;
3769           $3 = 0;
3770         }
3771         '{'
3772         {
3773           idl_global->set_parse_state (IDL_GlobalData::PS_EnumSqSeen);
3774         }
3775         at_least_one_enumerator
3776         {
3777           idl_global->set_parse_state (IDL_GlobalData::PS_EnumBodySeen);
3778         }
3779         '}'
3780         {
3781           idl_global->set_parse_state (IDL_GlobalData::PS_EnumQsSeen);
3783           /*
3784            * Done with this enum. Pop its scope from the scopes stack.
3785            */
3786           if (idl_global->scopes ().top () == 0)
3787             {
3788               $$ = 0;
3789             }
3790           else
3791             {
3792               $$ = dynamic_cast<AST_Enum*> (
3793                        idl_global->scopes ().top_non_null ()
3794                      );
3795               idl_global->scopes ().pop ();
3796             }
3797         }
3798         ;
3800 at_least_one_enumerator : enumerator enumerators ;
3802 enumerators
3803         : enumerators
3804           ','
3805         {
3806           idl_global->set_parse_state (IDL_GlobalData::PS_EnumCommaSeen);
3807         }
3808           enumerator
3809         | %empty
3810         ;
3812 enumerator :
3813         annotations_maybe IDENTIFIER
3814         {
3815           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3816           AST_Annotation_Appls *annotations = $1;
3817           Identifier id ($2);
3818           ACE::strdelete ($2);
3819           $2 = 0;
3820           UTL_ScopedName n (&id, 0);
3821           AST_EnumVal *e = 0;
3822           AST_Enum *c = 0;
3824           /*
3825            * Create a node representing one enumerator in an enum
3826            * Add it to the enclosing scope (the enum scope)
3827            */
3828           if (s != 0
3829               && s->scope_node_type () == AST_Decl::NT_enum)
3830             {
3831               c = dynamic_cast<AST_Enum*> (s);
3833               if (c != 0)
3834                 {
3835                   e = idl_global->gen ()->create_enum_val (
3836                                               c->next_enum_val (),
3837                                               &n
3838                                             );
3839                   e->enum_parent (c);
3840                   e->annotation_appls (*annotations);
3841                 }
3843               (void) s->fe_add_enum_val (e);
3844             }
3846           delete annotations;
3847         }
3848         ;
3850 sequence_type_spec
3851         : seq_head
3852           ','
3853         {
3854           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceCommaSeen);
3855         }
3856         positive_int_expr
3857         {
3858           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceExprSeen);
3859         }
3860           '>'
3861         {
3862           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceQsSeen);
3864           AST_Sequence *seq = 0;
3865           Decl_Annotations_Pair *seq_head = $1;
3866           AST_Decl *type = 0;
3867           AST_Annotation_Appls *type_annotations = 0;
3868           if (seq_head)
3869             {
3870               type = seq_head->decl;
3871               type_annotations = seq_head->annotations;
3872             }
3873           delete seq_head;
3875           /*
3876            * Remove sequence marker from scopes stack.
3877            */
3878           if (idl_global->scopes ().top () == 0)
3879             {
3880               idl_global->scopes ().pop ();
3881             }
3883           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3885           /*
3886            * Create a node representing a sequence
3887            */
3888           AST_Expression::AST_ExprValue *ev = 0;
3889           AST_Param_Holder *param_holder = 0;
3891           if ($4 != 0)
3892             {
3893               param_holder =
3894                 $4->param_holder ();
3896               ev = $4->coerce (AST_Expression::EV_ulong);
3897             }
3899           // If the expression corresponds to a template parameter,
3900           // it's ok for the coercion to fail at this point. We check
3901           // for a type mismatch below.
3902           if (0 == $4
3903               || (0 == ev && 0 == param_holder))
3904             {
3905               idl_global->err ()->coercion_error ($4,
3906                                                   AST_Expression::EV_ulong);
3907             }
3908           else if (type)
3909             {
3910               AST_Type *tp = dynamic_cast<AST_Type*> (type);
3912               if (0 == tp)
3913                 {
3914                   ; // Error will be caught in FE_Declarator.
3915                 }
3916               else
3917                 {
3918                   Identifier id ("sequence");
3919                   UTL_ScopedName sn (&id,
3920                                      0);
3922                   seq =
3923                     idl_global->gen ()->create_sequence (
3924                                             $4,
3925                                             tp,
3926                                             &sn,
3927                                             s->is_local (),
3928                                             s->is_abstract ()
3929                                           );
3930                   seq->base_type_annotations (*type_annotations);
3932                   idl_global->err ()->anonymous_type_diagnostic ();
3933                 }
3934             }
3936           delete type_annotations;
3937           delete ev;
3938           ev = 0;
3939           $$ = seq;
3940         }
3941         | seq_head
3942           '>'
3943         {
3944           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceQsSeen);
3946           AST_Sequence *seq = 0;
3947           Decl_Annotations_Pair *seq_head = $1;
3948           AST_Decl *type = 0;
3949           AST_Annotation_Appls *type_annotations = 0;
3950           if (seq_head)
3951             {
3952               type = seq_head->decl;
3953               type_annotations = seq_head->annotations;
3954             }
3955           delete seq_head;
3957           /*
3958            * Remove sequence marker from scopes stack.
3959            */
3960           if (idl_global->scopes ().top () == 0)
3961             {
3962              idl_global->scopes ().pop ();
3963             }
3965           UTL_Scope *s = idl_global->scopes ().top_non_null ();
3967           /*
3968            * Create a node representing a sequence.
3969            */
3970           if (type)
3971             {
3972               AST_Type *tp = dynamic_cast<AST_Type*> (type);
3974               if (tp == 0)
3975                 {
3976                   ; // Error will be caught in FE_Declarator.
3977                 }
3978               else
3979                 {
3980                   Identifier id ("sequence");
3981                   UTL_ScopedName sn (&id, 0);
3982                   ACE_CDR::ULong bound = 0UL;
3984                   seq =
3985                     idl_global->gen ()->create_sequence (
3986                         idl_global->gen ()->create_expr (
3987                                                 bound,
3988                                                 AST_Expression::EV_ulong
3989                                               ),
3990                         tp,
3991                         &sn,
3992                         s->is_local (),
3993                         s->is_abstract ()
3994                       );
3995                   seq->base_type_annotations (*type_annotations);
3997                   idl_global->err ()->anonymous_type_diagnostic ();
3998                 }
3999             }
4001           delete type_annotations;
4002           $$ = seq;
4003         }
4004         ;
4006 seq_head :
4007         IDL_SEQUENCE
4008         {
4009           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceSeen);
4011           /*
4012            * Push a sequence marker on scopes stack.
4013            */
4014           idl_global->scopes ().push (0);
4015         }
4016         '<'
4017         {
4018           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceSqSeen);
4019         }
4020         annotations_maybe simple_type_spec
4021         {
4022           idl_global->set_parse_state (IDL_GlobalData::PS_SequenceTypeSeen);
4023           Decl_Annotations_Pair *seq_head = new Decl_Annotations_Pair;
4024           seq_head->decl = $6;
4025           seq_head->annotations = $5;
4026           $$ = seq_head;
4027         }
4028         ;
4030 fixed_type_spec
4031         : IDL_FIXED '<' positive_int_expr ',' const_expr '>'
4032         {
4033           $5->evaluate (AST_Expression::EK_positive_int);
4034           $$ = idl_global->gen ()->create_fixed ($3, $5);
4035         }
4036         ;
4038 string_type_spec
4039         : string_head
4040           '<'
4041         {
4042           idl_global->set_parse_state (IDL_GlobalData::PS_StringSqSeen);
4043         }
4044         positive_int_expr
4045         {
4046            idl_global->set_parse_state (IDL_GlobalData::PS_StringExprSeen);
4047         }
4048         '>'
4049         {
4050           idl_global->set_parse_state (IDL_GlobalData::PS_StringQsSeen);
4052           /*
4053            * Create a node representing a string.
4054            */
4055           AST_Expression::AST_ExprValue *ev = 0;
4057           if ($4 != 0)
4058             {
4059               ev = $4->coerce (AST_Expression::EV_ulong);
4060             }
4062           if (0 == $4 || 0 == ev)
4063             {
4064               idl_global->err ()->coercion_error ($4,
4065                                                   AST_Expression::EV_ulong);
4066               $$ = 0;
4067             }
4068           else
4069             {
4070               tao_string_decl = idl_global->gen ()->create_string ($4);
4072               /*
4073                * Add this AST_String to the types defined in the global scope.
4074                */
4075               idl_global->root ()->fe_add_string (
4076                 dynamic_cast<AST_String*> (
4077                   tao_string_decl));
4079               idl_global->err ()->anonymous_type_diagnostic ();
4081               $$ = tao_string_decl;
4082             }
4084           delete ev;
4085           ev = 0;
4086         }
4087         | string_head
4088         {
4089           idl_global->set_parse_state (IDL_GlobalData::PS_StringCompleted);
4091           /*
4092            * Create a node representing a string.
4093            */
4094           ACE_CDR::ULong bound = 0UL;
4095           tao_string_decl =
4096             idl_global->gen ()->create_string (
4097                 idl_global->gen ()->create_expr (bound,
4098                                                  AST_Expression::EV_ulong)
4099               );
4101           /*
4102            * Add this AST_String to the types defined in the global scope.
4103            */
4104           idl_global->root ()->fe_add_string (
4105             dynamic_cast<AST_String*> (
4106               tao_string_decl));
4108           $$ = tao_string_decl;
4109         }
4110         ;
4112 string_head :
4113         IDL_STRING
4114         {
4115           idl_global->set_parse_state (IDL_GlobalData::PS_StringSeen);
4116         }
4117         ;
4119 wstring_type_spec
4120         : wstring_head
4121           '<'
4122         {
4123           idl_global->set_parse_state (IDL_GlobalData::PS_StringSqSeen);
4124         }
4125         positive_int_expr
4126         {
4127            idl_global->set_parse_state (IDL_GlobalData::PS_StringExprSeen);
4128         }
4129         '>'
4130         {
4131           idl_global->set_parse_state (IDL_GlobalData::PS_StringQsSeen);
4133           /*
4134            * Create a node representing a string.
4135            */
4136           AST_Expression::AST_ExprValue *ev = 0;
4138           if ($4 != 0)
4139             {
4140               ev = $4->coerce (AST_Expression::EV_ulong);
4141             }
4143           if (0 == $4 || 0 == ev)
4144             {
4145               idl_global->err ()->coercion_error ($4,
4146                                                   AST_Expression::EV_ulong);
4147               $$ = 0;
4148             }
4149           else
4150             {
4151               AST_String *string = idl_global->gen ()->create_wstring ($4);
4153               /*
4154                * Add this AST_String to the types defined in the global scope.
4155                */
4156               idl_global->root ()->fe_add_string (
4157                 dynamic_cast<AST_String*> (
4158                   string));
4160               idl_global->err ()->anonymous_type_diagnostic ();
4162               $$ = string;
4163             }
4165           delete ev;
4166           ev = 0;
4167         }
4168         | wstring_head
4169         {
4170           idl_global->set_parse_state (IDL_GlobalData::PS_StringCompleted);
4172           /*
4173            * Create a node representing a wstring.
4174            */
4175           ACE_CDR::ULong bound = 0UL;
4176           AST_String *string =
4177             idl_global->gen ()->create_wstring (
4178                 idl_global->gen ()->create_expr (bound,
4179                                                  AST_Expression::EV_ulong)
4180               );
4182           /*
4183            * Add this AST_String to the types defined in the global scope.
4184            */
4185           idl_global->root ()->fe_add_string (
4186             dynamic_cast<AST_String*> (
4187               string));
4189           $$ = string;
4190         }
4191         ;
4193 wstring_head :
4194         IDL_WSTRING
4195         {
4196           idl_global->set_parse_state (IDL_GlobalData::PS_StringSeen);
4197         }
4198         ;
4200 array_declarator :
4201         defining_id
4202         {
4203           idl_global->set_parse_state (IDL_GlobalData::PS_ArrayIDSeen);
4204         }
4205         annotations_maybe at_least_one_array_dim
4206         {
4207           idl_global->set_parse_state (IDL_GlobalData::PS_ArrayCompleted);
4209           AST_Array *array = 0;
4210           AST_Annotation_Appls *base_type_annotations = $3;
4211           UTL_ExprList *array_dims = $4;
4213           /*
4214            * Create a node representing an array.
4215            */
4216           if (array_dims)
4217             {
4218               UTL_ScopedName sn ($1,
4219                                  0);
4220               array =
4221                 idl_global->gen ()->create_array (
4222                                         &sn,
4223                                         array_dims->length (),
4224                                         array_dims,
4225                                         0,
4226                                         0
4227                                       );
4228               array->base_type_annotations (*base_type_annotations);
4229               sn.destroy ();
4231               idl_global->err ()->anonymous_type_diagnostic ();
4232             }
4234           array_dims->destroy ();
4235           delete array_dims;
4237           delete base_type_annotations;
4239           $$ = array;
4240         }
4241         ;
4243 at_least_one_array_dim :
4244         array_dim array_dims
4245         {
4246           ACE_NEW_RETURN ($$,
4247                           UTL_ExprList ($1,
4248                                         $2),
4249                           1);
4250         }
4251         ;
4253 array_dims
4254         : array_dims array_dim
4255         {
4256           UTL_ExprList *el = 0;
4257           ACE_NEW_RETURN (el,
4258                           UTL_ExprList ($2,
4259                                         0),
4260                           1);
4262           if ($1 == 0)
4263             {
4264               $$ = el;
4265             }
4266           else
4267             {
4268               $1->nconc (el);
4269               $$ = $1;
4270             }
4271         }
4272         | %empty
4273         {
4274           $$ = 0;
4275         }
4276         ;
4278 array_dim :
4279         '['
4280         {
4281           idl_global->set_parse_state (IDL_GlobalData::PS_DimSqSeen);
4282         }
4283         positive_int_expr
4284         {
4285           idl_global->set_parse_state (IDL_GlobalData::PS_DimExprSeen);
4286         }
4287         ']'
4288         {
4289           idl_global->set_parse_state (IDL_GlobalData::PS_DimQsSeen);
4291           /*
4292            * Array dimensions are expressions which must be coerced to
4293            * positive integers.
4294            */
4295           AST_Expression::AST_ExprValue *ev = 0;
4296           AST_Param_Holder *param_holder = 0;
4298           if ($3 != 0)
4299             {
4300               param_holder =
4301                 $3->param_holder ();
4303               ev =
4304                 $3->coerce (AST_Expression::EV_ulong);
4305             }
4307           if (0 == $3
4308               || (ev == 0 && param_holder == 0))
4309             {
4310               idl_global->err ()->coercion_error ($3,
4311                                                   AST_Expression::EV_ulong);
4312               $$ = 0;
4313             }
4314           else
4315             {
4316               if (param_holder != 0)
4317                 {
4318                   AST_Expression::ExprType et =
4319                     param_holder->info ()->const_type_;
4321                   // If the bound expression represents a
4322                   // template parameter, it must be a const
4323                   // and of type unsigned long.
4324                   if (et != AST_Expression::EV_ulong)
4325                     {
4326                       idl_global->err ()->mismatched_template_param (
4327                         param_holder->info ()->name_.c_str ());
4329                       delete ev;
4330                       ev = 0;
4331                       return 1;
4332                     }
4333                 }
4335               $$ = $3;
4336             }
4338           delete ev;
4339           ev = 0;
4340         }
4341         ;
4343 attribute
4344         : attribute_readonly
4345         | attribute_readwrite
4346         ;
4348 attribute_readonly :
4349         IDL_READONLY
4350         {
4351           idl_global->set_parse_state (IDL_GlobalData::PS_AttrROSeen);
4352         }
4353         IDL_ATTRIBUTE
4354         {
4355           idl_global->set_parse_state (IDL_GlobalData::PS_AttrSeen);
4356         }
4357         param_type_spec
4358         {
4359           idl_global->set_parse_state (IDL_GlobalData::PS_AttrTypeSeen);
4360         }
4361         at_least_one_simple_declarator
4362         {
4363           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclsSeen);
4364         }
4365         opt_raises
4366         {
4367           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4368           AST_Attribute *a = 0;
4369           FE_Declarator *d = 0;
4371           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
4373           /*
4374            * Create nodes representing attributes and add them to the
4375            * enclosing scope.
4376            */
4377           if (s != 0 && $5 != 0 && $7 != 0)
4378             {
4379               for (UTL_DecllistActiveIterator l ($7); !l.is_done (); l.next ())
4380                 {
4381                   d = l.item ();
4383                   if (d == 0)
4384                     {
4385                       continue;
4386                     }
4388                   AST_Type *tp = d->compose ($5);
4390                   if (tp == 0)
4391                     {
4392                       continue;
4393                     }
4395                   a = idl_global->gen ()->create_attribute (
4396                     true, tp, d->name (), s->is_local (), s->is_abstract ());
4398                   if ($9 != 0)
4399                     {
4400                       (void) a->fe_add_get_exceptions ($9);
4402                       $9->destroy ();
4403                       delete $9;
4404                       $9 = 0;
4405                     }
4407                   (void) s->fe_add_attribute (a);
4408                 }
4409             }
4411           $7->destroy ();
4412           delete $7;
4413           $7 = 0;
4415           $$ = a;
4416         }
4417         ;
4419 attribute_readwrite :
4420         IDL_ATTRIBUTE
4421         {
4422           idl_global->set_parse_state (IDL_GlobalData::PS_AttrSeen);
4423         }
4424         param_type_spec
4425         {
4426           idl_global->set_parse_state (IDL_GlobalData::PS_AttrTypeSeen);
4427         }
4428         at_least_one_simple_declarator
4429         {
4430           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclsSeen);
4431         }
4432         opt_getraises
4433         {
4434           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseCompleted);
4435         }
4436         opt_setraises
4437         {
4438           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4439           AST_Attribute *a = 0;
4440           FE_Declarator *d = 0;
4442           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseCompleted);
4444           /*
4445            * Create nodes representing attributes and add them to the
4446            * enclosing scope.
4447            */
4448           if (s != 0 && $3 != 0 && $5 != 0)
4449             {
4450               for (UTL_DecllistActiveIterator l ($5); !l.is_done (); l.next ())
4451                 {
4452                   d = l.item ();
4454                   if (d == 0)
4455                     {
4456                       continue;
4457                     }
4459                   AST_Type *tp = d->compose ($3);
4461                   if (tp == 0)
4462                     {
4463                       continue;
4464                     }
4466                   a = idl_global->gen ()->create_attribute (
4467                    false, tp, d->name (), s->is_local (), s->is_abstract ());
4469                   if ($7 != 0)
4470                     {
4471                       (void) a->fe_add_get_exceptions ($7);
4473                       $7->destroy ();
4474                       delete $7;
4475                       $7 = 0;
4476                     }
4478                   if ($9 != 0)
4479                     {
4480                       (void) a->fe_add_set_exceptions ($9);
4482                       $9->destroy ();
4483                       delete $9;
4484                       $9 = 0;
4485                     }
4487                   (void) s->fe_add_attribute (a);
4488                 }
4489             }
4491           $5->destroy ();
4492           delete $5;
4493           $5 = 0;
4495           $$ = a;
4496         }
4497         ;
4499 exception :
4500         IDL_EXCEPTION
4501         {
4502           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptSeen);
4503         }
4504         defining_id
4505         {
4506           Identifier *&id = $3;
4507           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
4508           UTL_ScopedName scoped_name (id, 0);
4509           AST_Exception *exception = 0;
4510           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptIDSeen);
4512           /*
4513            * Create a node representing an exception and add it to
4514            * the enclosing scope.
4515            */
4516           if (scope)
4517             {
4518               exception = idl_global->gen ()->create_exception (
4519                 &scoped_name,
4520                 scope->is_local (),
4521                 scope->is_abstract ());
4522               scope->fe_add_exception (exception);
4523             }
4525           /*
4526            * Push the exception scope on the scope stack.
4527            */
4528           idl_global->scopes ().push (exception);
4530           id->destroy ();
4531           delete id;
4532           id = 0;
4534           $<dcval>$ = exception;
4535         }
4536         '{'
4537         {
4538           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptSqSeen);
4539         }
4540         members
4541         {
4542           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptBodySeen);
4543         }
4544         '}'
4545         {
4546           idl_global->set_parse_state (IDL_GlobalData::PS_ExceptQsSeen);
4547           /*
4548            * Done with this exception. Pop its scope from the scope stack.
4549            */
4550           idl_global->scopes ().pop ();
4552           $$ = $<dcval>4;
4553         }
4554         ;
4556 operation
4557         : opt_op_attribute op_type_spec
4558         {
4559           idl_global->set_parse_state (IDL_GlobalData::PS_OpTypeSeen);
4560         }
4561         IDENTIFIER
4562         {
4563           AST_Operation *op = 0;
4564           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
4566           AST_Operation::Flags op_flags = $1;
4567           AST_Decl *type_node = $2;
4568           $2 = 0;
4569           Identifier id ($4);
4570           ACE::strdelete ($4);
4571           $4 = 0;
4573           UTL_ScopedName name (&id, 0);
4574           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
4576           /*
4577            * Create a node representing an operation on an interface
4578            * and add it to its enclosing scope.
4579            */
4580           if (scope != 0 && type_node != 0)
4581             {
4582               AST_Type *type = dynamic_cast<AST_Type*> (type_node);
4584               if (type == 0)
4585                 {
4586                   idl_global->err ()->not_a_type (type_node);
4587                 }
4588               else if (type->node_type () == AST_Decl::NT_except)
4589                 {
4590                   idl_global->err ()->not_a_type (type_node);
4591                 }
4592               else
4593                 {
4594                   AST_Decl *d = ScopeAsDecl (scope);
4595                   AST_Decl::NodeType nt = d->node_type ();
4596                   const bool local = scope->is_local ()
4597                     || nt == AST_Decl::NT_valuetype
4598                     || nt == AST_Decl::NT_eventtype;
4600                   op = idl_global->gen ()->create_operation (
4601                     type, op_flags, &name, local, scope->is_abstract ());
4603                   if (!local && type->is_local ())
4604                     {
4605                       idl_global->err ()->local_remote_mismatch (type, op);
4606                       op->destroy ();
4607                       delete op;
4608                       op = 0;
4609                     }
4610                   else
4611                     {
4612                       scope->fe_add_operation (op);
4613                     }
4614                 }
4615             }
4617           /*
4618            * Push the operation scope onto the scopes stack.
4619            */
4620           idl_global->scopes ().push (op);
4621         }
4622         parameter_list
4623         {
4624           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
4625         }
4626         opt_raises
4627         {
4628           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
4629         }
4630         opt_context
4631         {
4632           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4633           AST_Operation *o = 0;
4634           idl_global->set_parse_state (IDL_GlobalData::PS_OpCompleted);
4636           /*
4637            * Add exceptions and context to the operation.
4638            */
4639           if (s != 0 && s->scope_node_type () == AST_Decl::NT_op)
4640             {
4641               o = dynamic_cast<AST_Operation*> (s);
4643               if ($8 != 0 && o != 0)
4644                 {
4645                   (void) o->fe_add_exceptions ($8);
4646                 }
4648               if ($10 != 0)
4649                 {
4650                   (void) o->fe_add_context ($10);
4651                 }
4652             }
4654           /*
4655            * Done with this operation. Pop its scope from the scopes stack.
4656            */
4657           idl_global->scopes ().pop ();
4659           $$ = o;
4660         }
4661         ;
4663 opt_op_attribute
4664         : IDL_ONEWAY
4665         {
4666           idl_global->set_parse_state (IDL_GlobalData::PS_OpAttrSeen);
4667           $$ = AST_Operation::OP_oneway;
4668         }
4669         | IDL_IDEMPOTENT
4670         {
4671           idl_global->set_parse_state (IDL_GlobalData::PS_OpAttrSeen);
4672           $$ = AST_Operation::OP_idempotent;
4673         }
4674         | %empty
4675         {
4676           $$ = AST_Operation::OP_noflags;
4677         }
4678         ;
4680 op_type_spec
4681         : param_type_spec
4682         | IDL_VOID
4683         {
4684           $$ =
4685             idl_global->scopes ().bottom ()->lookup_primitive_type (
4686                                                   AST_Expression::EV_void
4687                                                 );
4688         }
4689         ;
4691 init_decl
4692         : IDL_FACTORY
4693         {
4694           //@@ PS_FactorySeen?
4695           idl_global->set_parse_state (IDL_GlobalData::PS_OpTypeSeen);
4696         }
4697         IDENTIFIER
4698         {
4699           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4701           if (s->is_abstract ())
4702             {
4703               //@@ Fire error
4704               ACE_ERROR ((LM_ERROR,
4705                           ACE_TEXT ("error in %C line %d:\n")
4706                           ACE_TEXT ("Abstract valuetype can't have a ")
4707                           ACE_TEXT ("factory construct.\n"),
4708                           idl_global->filename ()->get_string (),
4709                           idl_global->lineno ()));
4711               idl_global->set_err_count (idl_global->err_count () + 1);
4712             }
4714           Identifier id ($3);
4715           ACE::strdelete ($3);
4716           $3 = 0;
4718           UTL_ScopedName n (&id,
4719                             0);
4720           AST_Factory *factory = 0;
4721           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
4723           /*
4724            * Create a node representing an factory construct
4725            * and add it to its enclosing scope
4726            */
4727           if (s != 0)
4728             {
4729               factory = idl_global->gen ()->create_factory (&n);
4730               (void) s->fe_add_factory (factory);
4731             }
4733           /*
4734            * Push the operation scope onto the scopes stack.
4735            */
4736           idl_global->scopes ().push (factory);
4738           $<dcval>$ = factory;
4739         }
4740         init_parameter_list
4741         {
4742           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
4743         }
4744         opt_raises
4745         {
4746           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
4748           if ($7)
4749             {
4750               UTL_Scope *s = idl_global->scopes ().top_non_null ();
4751               AST_Factory *f = dynamic_cast<AST_Factory*> (s);
4752               (void) f->fe_add_exceptions ($7);
4753             }
4755           idl_global->scopes ().pop ();
4757           $$ = $<dcval>4;
4758         }
4759         ;
4761 init_parameter_list
4762         : '('
4763         {
4764           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4765         }
4766         ')'
4767         {
4768           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4769         }
4770         | '('
4771         {
4772           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4773         }
4774         at_least_one_in_parameter
4775         ')'
4776         {
4777           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4778         }
4779         ;
4781 at_least_one_in_parameter : in_parameter in_parameters ;
4783 in_parameters
4784         : in_parameters
4785           ','
4786         {
4787           idl_global->set_parse_state (IDL_GlobalData::PS_OpParCommaSeen);
4788         }
4789         in_parameter
4790         | %empty
4791         ;
4793 in_parameter :
4794         IDL_IN
4795         {
4796           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDirSeen);
4797         }
4798         param_type_spec
4799         {
4800           idl_global->set_parse_state (IDL_GlobalData::PS_OpParTypeSeen);
4801         }
4802         declarator
4803         {
4804           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4805           AST_Argument *a = 0;
4806           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDeclSeen);
4808           /*
4809            * Create a node representing an argument to an operation
4810            * Add it to the enclosing scope (the operation scope).
4811            */
4812           if ($3 != 0
4813               && $5 != 0 &&
4814               s != 0)
4815             {
4816               AST_Type *tp = $5->compose ($3);
4818               if (tp != 0)
4819                 {
4820                   a = idl_global->gen ()->create_argument (
4821                           AST_Argument::dir_IN,
4822                           tp,
4823                           $5->name ()
4824                         );
4826                   (void) s->fe_add_argument (a);
4827                 }
4828             }
4830           $5->destroy ();
4831           delete $5;
4832           $5 = 0;
4833         }
4834         ;
4836 parameter_list
4837         : '('
4838         {
4839           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4840         }
4841         ')'
4842         {
4843           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4844         }
4845         | '('
4846         {
4847           idl_global->set_parse_state (IDL_GlobalData::PS_OpSqSeen);
4848         }
4849         at_least_one_parameter
4850         ')'
4851         {
4852           idl_global->set_parse_state (IDL_GlobalData::PS_OpQsSeen);
4853         }
4854         ;
4856 at_least_one_parameter : parameter parameters ;
4858 parameters
4859         : parameters
4860           ','
4861         {
4862           idl_global->set_parse_state (IDL_GlobalData::PS_OpParCommaSeen);
4863         }
4864         parameter
4865         | %empty
4866         ;
4868 parameter :
4869         direction
4870         {
4871           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDirSeen);
4872         }
4873         param_type_spec
4874         {
4875           idl_global->set_parse_state (IDL_GlobalData::PS_OpParTypeSeen);
4876         }
4877         declarator
4878         {
4879           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4880           AST_Argument *a = 0;
4881           idl_global->set_parse_state (IDL_GlobalData::PS_OpParDeclSeen);
4883           /*
4884            * Create a node representing an argument to an operation
4885            * Add it to the enclosing scope (the operation scope).
4886            */
4887           if ($3 != 0
4888               && $5 != 0
4889               && s != 0)
4890             {
4891               AST_Type *tp = $5->compose ($3);
4893               if (tp != 0)
4894                 {
4895                   if (!s->is_local () && tp->is_local ())
4896                     {
4897                       idl_global->err ()->local_remote_mismatch (tp, s);
4898                     }
4899                   else
4900                     {
4901                       a =
4902                         idl_global->gen ()->create_argument (
4903                             $1,
4904                             tp,
4905                             $5->name ()
4906                           );
4907                       (void) s->fe_add_argument (a);
4908                     }
4909                 }
4910             }
4912           $5->destroy ();
4913           delete $5;
4914           $5 = 0;
4915         }
4916         ;
4918 param_type_spec
4919         : base_type_spec
4920         {
4921           $$ =
4922             idl_global->scopes ().bottom ()->lookup_primitive_type (
4923                                                  $1
4924                                                );
4925         }
4926         | string_type_spec
4927         | wstring_type_spec
4928         | scoped_name
4929         {
4930           UTL_Scope *s = idl_global->scopes ().top_non_null ();
4931           AST_Decl *d = 0;
4932           UTL_ScopedName *n = $1;
4934           if (s != 0)
4935             {
4936               d = s->lookup_by_name (n, false, false);
4937             }
4939           if (d == 0)
4940             {
4941               idl_global->err ()->lookup_error (n);
4942               $1->destroy ();
4943               $1 = 0;
4945               /* If we don't return here, we'll crash later.*/
4946               return 1;
4947             }
4948           else
4949             {
4950               d->last_referenced_as ($1);
4951               AST_Decl::NodeType nt = d->node_type ();
4952               AST_Type *t = dynamic_cast<AST_Type*> (d);
4953               AST_Typedef *td = 0;
4954               bool can_be_undefined = false;
4956               if (nt == AST_Decl::NT_typedef)
4957                 {
4958                   // This code block ensures that a sequence of
4959                   // as-yet-undefined struct or union isn't used
4960                   // as a return type or argument.
4961                   td = dynamic_cast<AST_Typedef*> (d);
4962                   AST_Type *pbt = td->primitive_base_type ();
4964                   if (pbt->node_type () == AST_Decl::NT_sequence)
4965                     {
4966                       t = pbt;
4967                       AST_Sequence *seq_type =
4968                         dynamic_cast<AST_Sequence*> (pbt);
4969                       AST_Type *elem_type =
4970                         seq_type->base_type ();
4971                       AST_Decl::NodeType elem_nt =
4972                         elem_type->node_type ();
4974                       if (elem_nt == AST_Decl::NT_typedef)
4975                         {
4976                           AST_Typedef *elem_td =
4977                             dynamic_cast<AST_Typedef*> (elem_type);
4978                           elem_type = elem_td->primitive_base_type ();
4979                           elem_nt = elem_type->node_type ();
4980                         }
4982                       if (elem_nt == AST_Decl::NT_interface
4983                           || elem_nt == AST_Decl::NT_interface_fwd
4984                           || elem_nt == AST_Decl::NT_valuetype
4985                           || elem_nt == AST_Decl::NT_valuetype_fwd
4986                           || elem_nt == AST_Decl::NT_component
4987                           || elem_nt == AST_Decl::NT_component_fwd)
4988                         {
4989                           can_be_undefined = true;
4990                         }
4991                     }
4993                   if (! t->is_defined () && ! can_be_undefined)
4994                     {
4995                       idl_global->err ()->error1 (
4996                         UTL_Error::EIDL_ILLEGAL_ADD,
4997                         (nt == AST_Decl::NT_typedef ? td : t));
4999                       /* If we don't return here, we'll crash later.*/
5000                       return 1;
5001                     }
5002                 }
5003               else
5004                 {
5005                   // For forward declared structs and unions, we
5006                   // want the full definition, but we need to
5007                   // check that it's been fully defined.
5008                   AST_StructureFwd *fwd =
5009                     dynamic_cast<AST_StructureFwd*> (d);
5011                   if (fwd != 0)
5012                     {
5013                       t = fwd->full_definition ();
5015                       if (! t->is_defined ())
5016                         {
5017                           idl_global->err ()->error1 (
5018                             UTL_Error::EIDL_ILLEGAL_ADD,
5019                             t);
5021                           /* If we don't return here, we'll crash later.*/
5022                           return 1;
5023                         }
5025                       d = t;
5026                     }
5027                 }
5028             }
5030           $$ = d;
5031         }
5032         ;
5034 direction
5035         : IDL_IN
5036         {
5037           $$ = AST_Argument::dir_IN;
5038         }
5039         | IDL_OUT
5040         {
5041           $$ = AST_Argument::dir_OUT;
5042         }
5043         | IDL_INOUT
5044         {
5045           $$ = AST_Argument::dir_INOUT;
5046         }
5047         ;
5049 opt_raises
5050         : IDL_RAISES
5051         {
5052           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseSeen);
5053         }
5054           '('
5055         {
5056           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseSqSeen);
5057         }
5058           at_least_one_scoped_name
5059           ')'
5060         {
5061           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseQsSeen);
5062           $$ = $5;
5063         }
5064         | %empty
5065         {
5066           $$ = 0;
5067         }
5068         ;
5070 opt_getraises
5071         : IDL_GETRAISES
5072         {
5073           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseSeen);
5074         }
5075           '('
5076         {
5077           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseSqSeen);
5078         }
5079           at_least_one_scoped_name
5080           ')'
5081         {
5082           idl_global->set_parse_state (IDL_GlobalData::PS_OpGetRaiseQsSeen);
5083           $$ = $5;
5084         }
5085         | %empty
5086         {
5087           $$ = 0;
5088         }
5089         ;
5091 opt_setraises
5092         : IDL_SETRAISES
5093         {
5094           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseSeen);
5095         }
5096           '('
5097         {
5098           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseSqSeen);
5099         }
5100           at_least_one_scoped_name
5101           ')'
5102         {
5103           idl_global->set_parse_state (IDL_GlobalData::PS_OpSetRaiseQsSeen);
5104           $$ = $5;
5105         }
5106         | %empty
5107         {
5108           $$ = 0;
5109         }
5110         ;
5112 opt_context
5113         : IDL_CONTEXT
5114         {
5115           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextSeen);
5116         }
5117         '('
5118         {
5119           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextSqSeen);
5120         }
5121         at_least_one_string_literal
5122         ')'
5123         {
5124           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextQsSeen);
5125           $$ = $5;
5126         }
5127         | %empty
5128         {
5129           $$ = 0;
5130         }
5131         ;
5133 at_least_one_string_literal :
5134         IDL_STRING_LITERAL string_literals
5135         {
5136           ACE_NEW_RETURN ($<slval>$,
5137                           UTL_StrList ($1,
5138                                        $2),
5139                           1);
5140         }
5141         ;
5143 string_literals
5144         : string_literals
5145           ','
5146         {
5147           idl_global->set_parse_state (IDL_GlobalData::PS_OpContextCommaSeen);
5148         }
5149         IDL_STRING_LITERAL
5150         {
5151           UTL_StrList *sl = 0;
5152           ACE_NEW_RETURN (sl,
5153                           UTL_StrList ($4,
5154                                        0),
5155                           1);
5157           if ($1 == 0)
5158             {
5159               $<slval>$ = sl;
5160             }
5161           else
5162             {
5163               $1->nconc (sl);
5164               $<slval>$ = $1;
5165             }
5166         }
5167         | %empty
5168         {
5169           $$ = 0;
5170         }
5171         ;
5173 typeid_dcl
5174         : IDL_TYPEID scoped_name IDL_STRING_LITERAL
5175         {
5176           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5177           AST_Decl *d =
5178             s->lookup_by_name ($2);
5180           if (d == 0)
5181             {
5182               idl_global->err ()->lookup_error ($2);
5183             }
5184           else
5185             {
5186               d->set_id_with_typeid (
5187                      $3->get_string ()
5188                    );
5189             }
5191           $2->destroy ();
5192           delete $2;
5193           $2 = 0;
5195           $3->destroy ();
5196           delete $3;
5197           $3 = 0;
5199           $$ = 0;
5200         }
5201         ;
5203 typeprefix_dcl
5204         : IDL_TYPEPREFIX scoped_name IDL_STRING_LITERAL
5205         {
5206           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5207           AST_Decl *d = ScopeAsDecl (s);
5209           // If we are in a module, we want to avoid a lookup unless the
5210           // typeprefix is to be applied to some other scope, since we
5211           // might get a previous opening of the module, and the prefix
5212           // of this opening would never get checked or set.
5213           if (d->name ()->compare ($2) != 0)
5214             {
5215               d =
5216                 s->lookup_by_name ($2);
5217             }
5219           if (d == 0)
5220             {
5221               idl_global->err ()->lookup_error ($2);
5222             }
5223           else
5224             {
5225               d->set_prefix_with_typeprefix (
5226                      $3->get_string ()
5227                    );
5228             }
5230           $2->destroy ();
5231           delete $2;
5232           $2 = 0;
5234           $3->destroy ();
5235           delete $3;
5236           $3 = 0;
5238           $$ = 0;
5239         }
5240         ;
5242 component
5243         : component_decl
5244         | component_forward_decl
5245         ;
5247 component_forward_decl :
5248         IDL_COMPONENT
5249         defining_id
5250         {
5251           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5252           UTL_ScopedName n ($2,
5253                             0);
5254           AST_ComponentFwd *f = 0;
5255           idl_global->set_parse_state (
5256                           IDL_GlobalData::PS_ComponentForwardSeen
5257                         );
5259           /*
5260            * Create a node representing a forward declaration of a
5261            * component. Store it in the enclosing scope.
5262            */
5263           if (s != 0)
5264             {
5265               f = idl_global->gen ()->create_component_fwd (&n);
5266               (void) s->fe_add_component_fwd (f);
5267             }
5269           $2->destroy ();
5270           delete $2;
5271           $2 = 0;
5273           $$ = 0;
5274         }
5275         ;
5277 component_decl :
5278         component_header
5279         {
5280           FE_ComponentHeader *&component_header = $1;
5281           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
5282           AST_Component *component = 0;
5284           /*
5285            * Make a new component node and add it to the enclosing scope.
5286            */
5287           if (scope && component_header)
5288             {
5289               component = idl_global->gen ()->create_component (
5290                 component_header->name (),
5291                 component_header->base_component (),
5292                 component_header->supports (),
5293                 component_header->n_supports (),
5294                 component_header->supports_flat (),
5295                 component_header->n_supports_flat ());
5296               AST_Interface *component_as_interface =
5297                 dynamic_cast<AST_Interface *> (component);
5298               AST_Interface::fwd_redefinition_helper (
5299                 component_as_interface, scope);
5300               component = dynamic_cast<AST_Component *> (component_as_interface);
5302               /*
5303                * Add the component to its definition scope.
5304                */
5305               scope->fe_add_component (component);
5307               // This FE_ComponentHeader class isn't destroyed with the AST.
5308               component_header->destroy ();
5309               delete component_header;
5310               component_header = 0;
5311             }
5313           /*
5314            * Push it on the scope stack.
5315            */
5316           idl_global->scopes ().push (component);
5318           $<dcval>$ = component;
5319         }
5320         '{'
5321         {
5322           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentSqSeen);
5323         }
5324         component_exports
5325         {
5326           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentBodySeen);
5327         }
5328         '}'
5329         {
5330           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentQsSeen);
5332           /*
5333            * Done with this component - pop it off the scopes stack.
5334            */
5335           idl_global->scopes ().pop ();
5337           $$ = $<dcval>2;
5338         }
5339         ;
5341 component_header :
5342         IDL_COMPONENT
5343         defining_id
5344         {
5345           idl_global->set_parse_state (IDL_GlobalData::PS_ComponentIDSeen);
5346         }
5347         component_inheritance_spec
5348         {
5349           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
5350         }
5351         supports_spec
5352         {
5353           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
5355           /*
5356            * Create an AST representation of the information in the header
5357            * part of a component.
5358            */
5359           UTL_ScopedName *n = 0;
5360           ACE_NEW_RETURN (n,
5361                           UTL_ScopedName ($2,
5362                                           0),
5363                           1);
5364           ACE_NEW_RETURN ($<chval>$,
5365                           FE_ComponentHeader (n,
5366                                               $4,
5367                                               $6,
5368                                               false),
5369                           1);
5371           if (0 != $6)
5372             {
5373               $6->destroy ();
5374               delete $6;
5375               $6 = 0;
5376             }
5378           if (0 != $4)
5379             {
5380               $4->destroy ();
5381               delete $4;
5382               $4 = 0;
5383             }
5384         }
5385         ;
5387 component_inheritance_spec
5388         : ':'
5389         {
5390           idl_global->set_parse_state (IDL_GlobalData::PS_InheritColonSeen);
5391         }
5392         scoped_name
5393         {
5394           $<idlist>$ = $3;
5395         }
5396         | %empty
5397         {
5398           $$ = 0;
5399         }
5400         ;
5402 component_exports
5403         : component_exports at_least_one_annotation component_export
5404         {
5405           AST_Annotation_Appls *&annotations = $2;
5406           AST_Decl *&node = $3;
5407           if (node)
5408             {
5409               node->annotation_appls (*annotations);
5410             }
5411           else
5412             {
5413               idl_global->err ()-> unsupported_warning (
5414                 "Annotating this is not supported");
5415             }
5416           delete annotations;
5417         }
5418         | component_exports component_export
5419         | %empty
5420         ;
5422 component_export
5423         : provides_decl
5424         {
5425           idl_global->set_parse_state (IDL_GlobalData::PS_ProvidesDeclSeen);
5426         }
5427         ';'
5428         {
5429           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5430           $$ = $1;
5431         }
5432         | uses_decl
5433         {
5434           idl_global->set_parse_state (IDL_GlobalData::PS_UsesDeclSeen);
5435         }
5436         ';'
5437         {
5438           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5439           $$ = $1;
5440         }
5441         | emits_decl
5442         {
5443           idl_global->set_parse_state (IDL_GlobalData::PS_EmitsDeclSeen);
5444         }
5445         ';'
5446         {
5447           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5448           $$ = $1;
5449         }
5450         | publishes_decl
5451         {
5452           idl_global->set_parse_state (IDL_GlobalData::PS_PublishesDeclSeen);
5453         }
5454         ';'
5455         {
5456           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5457           $$ = $1;
5458         }
5459         | consumes_decl
5460         {
5461           idl_global->set_parse_state (IDL_GlobalData::PS_ConsumesDeclSeen);
5462         }
5463         ';'
5464         {
5465           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5466           $$ = $1;
5467         }
5468         | attribute
5469         {
5470           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
5471         }
5472         ';'
5473         {
5474           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5475           $$ = $1;
5476         }
5477         | extended_port_decl
5478         {
5479           idl_global->set_parse_state (IDL_GlobalData::PS_ExtendedPortDeclSeen);
5480         }
5481         ';'
5482         {
5483           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
5484           $$ = $1;
5485         }
5486         ;
5488 provides_decl : IDL_PROVIDES interface_type id
5489         {
5490           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5491           bool so_far_so_good = true;
5492           AST_Decl::NodeType nt = AST_Decl::NT_type;
5493           AST_Param_Holder *ph = 0;
5495           AST_Decl *d =
5496             s->lookup_by_name ($2, true, false);
5498           if (d == 0)
5499             {
5500               idl_global->err ()->lookup_error ($2);
5501               so_far_so_good = false;
5502             }
5503           else
5504             {
5505               int compare = 0;
5506               nt = d->node_type ();
5508               switch (nt)
5509                 {
5510                   case AST_Decl::NT_interface:
5511                     break;
5512                   case AST_Decl::NT_param_holder:
5513                     ph = dynamic_cast<AST_Param_Holder*> (d);
5514                     nt = ph->info ()->type_;
5516                     if (nt != AST_Decl::NT_type
5517                        && nt != AST_Decl::NT_interface)
5518                       {
5519                         idl_global->err ()->mismatched_template_param (
5520                           ph->info ()->name_.c_str ());
5522                         so_far_so_good = false;
5523                       }
5525                     break;
5526                   case AST_Decl::NT_pre_defined:
5527                     // Nothing else but CORBA::Object can have
5528                     // this identifier.
5529                     compare =
5530                       ACE_OS::strcmp (d->local_name ()->get_string (),
5531                                       "Object");
5533                     // Simple provides port must use IDL interface
5534                     // or CORBA::Object.
5535                     if (compare != 0)
5536                       {
5537                         idl_global->err ()->interface_expected (d);
5538                         so_far_so_good = false;
5539                       }
5541                     break;
5542                   default:
5543                     idl_global->err ()->interface_expected (d);
5544                     so_far_so_good = false;
5545                     break;
5546                 }
5547             }
5549           AST_Provides *provides = 0;
5551           if (so_far_so_good)
5552             {
5553               AST_Type *port_interface_type =
5554                 dynamic_cast<AST_Type*> (d);
5556               // Strip off _cxx_, if any, for port name.
5557               FE_Utils::original_local_name ($3);
5559               UTL_ScopedName sn ($3,
5560                                  0);
5562               provides = idl_global->gen ()->create_provides (
5563                 &sn, port_interface_type);
5565               (void) s->fe_add_provides (provides);
5566             }
5568           $2->destroy ();
5569           delete $2;
5570           $2 = 0;
5572           $3->destroy ();
5573           delete $3;
5574           $3 = 0;
5576           $$ = dynamic_cast<AST_Decl *> (provides);
5577         }
5578         ;
5580 interface_type
5581         : scoped_name
5582         {
5583           // Lookups and checking are done where the 'interface_type'
5584           // token is used, in 'provides_decl' and 'uses_decl'.
5585           $$ = $1;
5586         }
5587         | IDL_OBJECT
5588         {
5589           Identifier *corba_id = 0;
5591           ACE_NEW_RETURN (corba_id,
5592                           Identifier ("Object"),
5593                           1);
5595           UTL_IdList *conc_name = 0;
5596           ACE_NEW_RETURN (conc_name,
5597                           UTL_IdList (corba_id,
5598                                       0),
5599                           1);
5601           ACE_NEW_RETURN (corba_id,
5602                           Identifier ("CORBA"),
5603                           1);
5605           ACE_NEW_RETURN ($<idlist>$,
5606                           UTL_IdList (corba_id,
5607                                       conc_name),
5608                           1);
5609         }
5610         ;
5612 uses_decl : uses_opt_multiple interface_type id
5613         {
5614           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5615           bool so_far_so_good = true;
5616           AST_Decl::NodeType nt = AST_Decl::NT_type;
5617           AST_Param_Holder *ph = 0;
5619           AST_Decl *d =
5620             s->lookup_by_name ($2, true, false);
5622           if (d == 0)
5623             {
5624               idl_global->err ()->lookup_error ($2);
5625               so_far_so_good = false;
5626             }
5627           else
5628             {
5629               int compare = 0;
5630               nt = d->node_type ();
5632               switch (nt)
5633                 {
5634                   case AST_Decl::NT_interface:
5635                     break;
5636                   case AST_Decl::NT_param_holder:
5637                     ph = dynamic_cast<AST_Param_Holder*> (d);
5638                     nt = ph->info ()->type_;
5640                     if (nt != AST_Decl::NT_type
5641                        && nt != AST_Decl::NT_interface)
5642                       {
5643                         idl_global->err ()->mismatched_template_param (
5644                           ph->info ()->name_.c_str ());
5646                         so_far_so_good = false;
5647                       }
5649                     break;
5650                   case AST_Decl::NT_pre_defined:
5651                     // Nothing else but CORBA::Object can have
5652                     // this identifier.
5653                     compare =
5654                       ACE_OS::strcmp (d->local_name ()->get_string (),
5655                                       "Object");
5657                     // Simple provides port must use IDL interface
5658                     // or CORBA::Object.
5659                     if (compare != 0)
5660                       {
5661                         idl_global->err ()->interface_expected (d);
5662                         so_far_so_good = false;
5663                       }
5665                     break;
5666                   default:
5667                     idl_global->err ()->interface_expected (d);
5668                     so_far_so_good = false;
5669                     break;
5670                 }
5671             }
5673           AST_Uses *uses = 0;
5675           if (so_far_so_good)
5676             {
5677               AST_Type *port_interface_type =
5678                 dynamic_cast<AST_Type*> (d);
5680               // Strip off _cxx_, if any, for port name.
5681               FE_Utils::original_local_name ($3);
5683               UTL_ScopedName sn ($3,
5684                                  0);
5686               uses = idl_global->gen ()->create_uses (
5687                 &sn, port_interface_type, $1);
5688               s->fe_add_uses (uses);
5690               AST_Component *c =
5691                 dynamic_cast<AST_Component*> (s);
5693               if (c != 0
5694                   && uses->is_multiple ()
5695                   && !idl_global->using_ifr_backend ()
5696                   && !idl_global->ignore_idl3 ()
5697                   && nt != AST_Decl::NT_param_holder)
5698                 {
5699                   // These datatypes must be created in the
5700                   // front end so they can be looked up
5701                   // when compiling the generated executor IDL.
5702                   FE_Utils::create_uses_multiple_stuff (c, uses);
5703                 }
5704             }
5706           $2->destroy ();
5707           delete $2;
5708           $2 = 0;
5710           $3->destroy ();
5711           delete $3;
5712           $3 = 0;
5714           $$ = uses;
5715         }
5716         ;
5718 uses_opt_multiple
5719         : IDL_USES opt_multiple
5720         {
5721           // We use this extra rule here to use in both uses_decl and
5722           // extended_uses_decl, so the LALR(1) parser can avoid conflicts.
5723           $$ = $2;
5724         }
5725         ;
5727 opt_multiple
5728         : IDL_MULTIPLE
5729         {
5730           $$ = true;
5731         }
5732         | %empty
5733         {
5734           $$ = false;
5735         }
5736         ;
5738 emits_decl
5739         : IDL_EMITS scoped_name id
5740         {
5741           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5742           bool so_far_so_good = true;
5743           AST_Decl::NodeType nt = AST_Decl::NT_type;
5744           AST_Param_Holder *ph = 0;
5746           AST_Decl *d =
5747             s->lookup_by_name ($2, true, false);
5749           if (0 == d)
5750             {
5751               idl_global->err ()->lookup_error ($2);
5752               so_far_so_good = false;
5753             }
5754           else
5755             {
5756               nt = d->node_type ();
5758               switch (nt)
5759                 {
5760                   case AST_Decl::NT_eventtype:
5761                     break;
5762                   case AST_Decl::NT_param_holder:
5763                     ph = dynamic_cast<AST_Param_Holder*> (d);
5764                     nt = ph->info ()->type_;
5766                     if (nt != AST_Decl::NT_type
5767                        && nt != AST_Decl::NT_eventtype)
5768                       {
5769                         idl_global->err ()->mismatched_template_param (
5770                           ph->info ()->name_.c_str ());
5772                         so_far_so_good = false;
5773                       }
5775                     break;
5776                   default:
5777                     idl_global->err ()->eventtype_expected (d);
5778                     so_far_so_good = false;
5779                     break;
5780                 }
5781             }
5783           AST_Emits *e = 0;
5785           if (so_far_so_good)
5786             {
5787               AST_Type *event_type =
5788                 dynamic_cast<AST_Type*> (d);
5790               // Strip off _cxx_, if any, for port name.
5791               FE_Utils::original_local_name ($3);
5793               UTL_ScopedName sn ($3,
5794                                  0);
5796               e = idl_global->gen ()->create_emits (&sn, event_type);
5798               (void) s->fe_add_emits (e);
5799             }
5801           $2->destroy ();
5802           delete $2;
5803           $2 = 0;
5805           $3->destroy ();
5806           delete $3;
5807           $3 = 0;
5809           $$ = e;
5810         }
5811         ;
5813 publishes_decl
5814         : IDL_PUBLISHES scoped_name id
5815         {
5816           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5817           bool so_far_so_good = true;
5818           AST_Decl::NodeType nt = AST_Decl::NT_type;
5819           AST_Param_Holder *ph = 0;
5821           AST_Decl *d =
5822             s->lookup_by_name ($2, true, false);
5824           if (0 == d)
5825             {
5826               idl_global->err ()->lookup_error ($2);
5827               so_far_so_good = false;
5828             }
5829           else
5830             {
5831               nt = d->node_type ();
5833               switch (nt)
5834                 {
5835                   case AST_Decl::NT_eventtype:
5836                     break;
5837                   case AST_Decl::NT_param_holder:
5838                     ph = dynamic_cast<AST_Param_Holder*> (d);
5839                     nt = ph->info ()->type_;
5841                     if (nt != AST_Decl::NT_type
5842                        && nt != AST_Decl::NT_eventtype)
5843                       {
5844                         idl_global->err ()->mismatched_template_param (
5845                           ph->info ()->name_.c_str ());
5847                         so_far_so_good = false;
5848                       }
5850                     break;
5851                   default:
5852                     idl_global->err ()->eventtype_expected (d);
5853                     so_far_so_good = false;
5854                     break;
5855                 }
5856             }
5858           AST_Publishes *p = 0;
5860           if (so_far_so_good)
5861             {
5862               AST_Type *event_type =
5863                 dynamic_cast<AST_Type*> (d);
5865               // Strip off _cxx_, if any, for port name.
5866               FE_Utils::original_local_name ($3);
5868               UTL_ScopedName sn ($3, 0);
5869               p = idl_global->gen ()->create_publishes (&sn, event_type);
5870               s->fe_add_publishes (p);
5871             }
5873           $2->destroy ();
5874           delete $2;
5875           $2 = 0;
5877           $3->destroy ();
5878           delete $3;
5879           $3 = 0;
5881           $$ = p;
5882         }
5883         ;
5885 consumes_decl
5886         : IDL_CONSUMES scoped_name id
5887         {
5888           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5889           bool so_far_so_good = true;
5890           AST_Decl::NodeType nt = AST_Decl::NT_type;
5891           AST_Param_Holder *ph = 0;
5893           AST_Decl *d =
5894             s->lookup_by_name ($2, true, false);
5896           if (0 == d)
5897             {
5898               idl_global->err ()->lookup_error ($2);
5899               so_far_so_good = false;
5900             }
5901           else
5902             {
5903               nt = d->node_type ();
5905               switch (nt)
5906                 {
5907                   case AST_Decl::NT_eventtype:
5908                     break;
5909                   case AST_Decl::NT_param_holder:
5910                     ph = dynamic_cast<AST_Param_Holder*> (d);
5911                     nt = ph->info ()->type_;
5913                     if (nt != AST_Decl::NT_type
5914                        && nt != AST_Decl::NT_eventtype)
5915                       {
5916                         idl_global->err ()->mismatched_template_param (
5917                           ph->info ()->name_.c_str ());
5919                         so_far_so_good = false;
5920                       }
5922                     break;
5923                   default:
5924                     idl_global->err ()->eventtype_expected (d);
5925                     so_far_so_good = false;
5926                     break;
5927                 }
5928             }
5930           AST_Consumes *c = 0;
5932           if (so_far_so_good)
5933             {
5934               AST_Type *event_type =
5935                 dynamic_cast<AST_Type*> (d);
5937               // Strip off _cxx_, if any, for port name.
5938               FE_Utils::original_local_name ($3);
5940               UTL_ScopedName sn ($3,
5941                                  0);
5943               c = idl_global->gen ()->create_consumes (&sn, event_type);
5945               (void) s->fe_add_consumes (c);
5946             }
5948           $2->destroy ();
5949           delete $2;
5950           $2 = 0;
5952           $3->destroy ();
5953           delete $3;
5954           $3 = 0;
5956           $$ = c;
5957        }
5958        ;
5960 home_decl
5961         : home_header
5962         {
5963           UTL_Scope *s = idl_global->scopes ().top_non_null ();
5964           AST_Home *h = 0;
5966           /*
5967            * Make a new home node and add it to the enclosing scope.
5968            */
5969           if (s != 0 && $1 != 0)
5970             {
5971               h =
5972                 idl_global->gen ()->create_home (
5973                                         $1->name (),
5974                                         $1->base_home (),
5975                                         $1->managed_component (),
5976                                         $1->primary_key (),
5977                                         $1->supports (),
5978                                         $1->n_supports (),
5979                                         $1->supports_flat (),
5980                                         $1->n_supports_flat ()
5981                                       );
5982               /*
5983                * Add the home to its definition scope.
5984                */
5985               (void) s->fe_add_home (h);
5987               // This FE_HomeHeader class isn't destroyed with the AST.
5988               $1->destroy ();
5989               delete $1;
5990               $1 = 0;
5991             }
5993           /*
5994            * Push it on the scope stack.
5995            */
5996           idl_global->scopes ().push (h);
5997         }
5998         home_body
5999         {
6000           /*
6001            * Done with this component - pop it off the scopes stack.
6002            */
6003           idl_global->scopes ().pop ();
6005           $$ = 0;
6006         }
6007         ;
6009 home_header
6010         : IDL_HOME
6011         {
6012           idl_global->set_parse_state (IDL_GlobalData::PS_HomeSeen);
6013         }
6014         defining_id
6015         {
6016           idl_global->set_parse_state (IDL_GlobalData::PS_HomeIDSeen);
6017         }
6018         home_inheritance_spec
6019         {
6020           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
6021         }
6022         supports_spec
6023         {
6024           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
6025         }
6026         IDL_MANAGES
6027         {
6028           idl_global->set_parse_state (IDL_GlobalData::PS_ManagesSeen);
6029         }
6030         scoped_name
6031         {
6032           idl_global->set_parse_state (IDL_GlobalData::PS_ManagesIDSeen);
6033         }
6034         primary_key_spec
6035         {
6036           idl_global->set_parse_state (IDL_GlobalData::PS_PrimaryKeySpecSeen);
6038           /*
6039            * Create an AST representation of the information in the header
6040            * part of a component home.
6041            */
6042           UTL_ScopedName *n = 0;
6043           ACE_NEW_RETURN (n,
6044                           UTL_ScopedName ($3, 0),
6045                           1);
6047           ACE_NEW_RETURN ($<hhval>$,
6048                           FE_HomeHeader (n,
6049                                          $5,
6050                                          $7,
6051                                          $11,
6052                                          $13),
6053                           1);
6055           $11->destroy ();
6056           delete $11;
6057           $11 = 0;
6059           if (0 != $5)
6060             {
6061               $5->destroy ();
6062               delete $5;
6063               $5 = 0;
6064             }
6066           if (0 != $13)
6067             {
6068               $13->destroy ();
6069               delete $13;
6070               $13 = 0;
6071             }
6073           if (0 != $7)
6074             {
6075               $7->destroy ();
6076               delete $7;
6077               $7 = 0;
6078             }
6079         }
6080         ;
6082 home_inheritance_spec
6083         : ':'
6084         {
6085           idl_global->set_parse_state (IDL_GlobalData::PS_InheritColonSeen);
6086         }
6087           scoped_name
6088         {
6089           $<idlist>$ = $3;
6090         }
6091         | %empty
6092         {
6093           $$ = 0;
6094         }
6095         ;
6097 primary_key_spec
6098         : IDL_PRIMARYKEY
6099           scoped_name
6100         {
6101           $$ = $2;
6102         }
6103         | %empty
6104         {
6105           $$ = 0;
6106         }
6107         ;
6109 home_body :
6110         '{'
6111         {
6112           idl_global->set_parse_state (IDL_GlobalData::PS_HomeSqSeen);
6113         }
6114         home_exports
6115         {
6116           idl_global->set_parse_state (IDL_GlobalData::PS_HomeBodySeen);
6117         }
6118         '}'
6119         {
6120           idl_global->set_parse_state (IDL_GlobalData::PS_HomeQsSeen);
6121         }
6122         ;
6124 home_exports
6125         : home_exports home_export
6126         | %empty
6127         ;
6129 home_export
6130         : export
6131         | factory_decl
6132         {
6133           idl_global->set_parse_state (IDL_GlobalData::PS_FactoryDeclSeen);
6134         }
6135         ';'
6136         {
6137           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
6138         }
6139         | finder_decl
6140         {
6141           idl_global->set_parse_state (IDL_GlobalData::PS_FinderDeclSeen);
6142         }
6143         ';'
6144         {
6145           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
6146         }
6147         ;
6149 factory_decl :
6150         IDL_FACTORY
6151         defining_id
6152         {
6153           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6154           UTL_ScopedName n ($2,
6155                             0);
6156           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
6158           /*
6159            * Create a node representing a factory operation
6160            * and add it to the enclosing scope.
6161            */
6162           AST_Factory *f = idl_global->gen ()->create_factory (&n);
6163           (void) s->fe_add_factory (f);
6165           $2->destroy ();
6166           delete $2;
6167           $2 = 0;
6169           /*
6170            * Push the factory scope onto the scopes stack.
6171            */
6172           idl_global->scopes ().push (f);
6173         }
6174         init_parameter_list
6175         {
6176           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
6177         }
6178         opt_raises
6179         {
6180           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6181           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
6183           /*
6184            * Add exceptions and context to the factory.
6185            */
6186           if ($6 != 0)
6187             {
6188               (void) s->fe_add_exceptions ($6);
6189             }
6191           /*
6192            * Done with this factory. Pop its scope from the scopes stack.
6193            */
6194           idl_global->scopes ().pop ();
6195         }
6196         ;
6198 finder_decl :
6199         IDL_FINDER
6200         defining_id
6201         {
6202           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6203           UTL_ScopedName n ($2,
6204                             0);
6206           idl_global->set_parse_state (IDL_GlobalData::PS_OpIDSeen);
6208           /*
6209            * Create a node representing a home finder
6210            * and add it to the enclosing scope.
6211            */
6212           AST_Finder *f =
6213             idl_global->gen ()->create_finder (&n);
6215           (void) s->fe_add_finder (f);
6218           $2->destroy ();
6219           delete $2;
6220           $2 = 0;
6222           /*
6223            * Push the operation scope onto the scopes stack.
6224            */
6225           idl_global->scopes ().push (f);
6226         }
6227         init_parameter_list
6228         {
6229           idl_global->set_parse_state (IDL_GlobalData::PS_OpParsCompleted);
6230         }
6231         opt_raises
6232         {
6233           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6234           idl_global->set_parse_state (IDL_GlobalData::PS_OpRaiseCompleted);
6236           /*
6237            * Add exceptions and context to the finder.
6238            */
6239           if ($6 != 0)
6240             {
6241               (void) s->fe_add_exceptions ($6);
6242             }
6244           /*
6245            * Done with this operation. Pop its scope from the scopes stack.
6246            */
6247           idl_global->scopes ().pop ();
6248         }
6249         ;
6251 event
6252         : event_decl
6253         | event_abs_decl
6254         | event_forward_decl
6255         ;
6257 event_forward_decl
6258         : event_abs_forward_decl
6259         | event_concrete_forward_decl
6260         ;
6262 event_concrete_forward_decl :
6263         IDL_EVENTTYPE
6264         defining_id
6265         {
6266           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6267           UTL_ScopedName n ($2,
6268                             0);
6269           AST_EventTypeFwd *f = 0;
6270           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeForwardSeen);
6272           /*
6273            * Create a node representing a forward declaration of an
6274            * eventtype. Store it in the enclosing scope
6275            */
6276           if (s != 0)
6277             {
6278               f = idl_global->gen ()->create_eventtype_fwd (&n,
6279                                                             false);
6280               (void) s->fe_add_valuetype_fwd (f);
6281             }
6283           $2->destroy ();
6284           delete $2;
6285           $2 = 0;
6287           $$ = 0;
6288         }
6289         ;
6291 event_abs_forward_decl :
6292         IDL_ABSTRACT
6293         IDL_EVENTTYPE
6294         defining_id
6295         {
6296           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6297           UTL_ScopedName n ($3,
6298                             0);
6299           AST_EventTypeFwd *f = 0;
6300           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeForwardSeen);
6302           /*
6303            * Create a node representing a forward declaration of an
6304            * eventtype. Store it in the enclosing scope
6305            */
6306           if (s != 0)
6307             {
6308               f = idl_global->gen ()->create_eventtype_fwd (&n,
6309                                                             true);
6310               (void) s->fe_add_valuetype_fwd (f);
6311             }
6313           $3->destroy ();
6314           delete $3;
6315           $3 = 0;
6317           $$ = 0;
6318         }
6319         ;
6321 event_abs_decl :
6322         event_abs_header
6323         event_rest_of_header
6324         {
6325           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6326           AST_EventType *e = 0;
6327           AST_Interface *i = 0;
6329           if (s != 0 && $1 != 0)
6330             {
6331               UTL_ScopedName sn ($1,
6332                                  0);
6333               e =
6334                 idl_global->gen ()->create_eventtype (
6335                     &sn,
6336                     $2->inherits (),
6337                     $2->n_inherits (),
6338                     $2->inherits_concrete (),
6339                     $2->inherits_flat (),
6340                     $2->n_inherits_flat (),
6341                     $2->supports (),
6342                     $2->n_supports (),
6343                     $2->supports_concrete (),
6344                     true,
6345                     false,
6346                     false
6347                   );
6348               i = dynamic_cast<AST_Interface*> (e);
6349               AST_Interface::fwd_redefinition_helper (i,
6350                                                       s);
6351               /*
6352                * Add the eventetype to its definition scope
6353                */
6354               e = dynamic_cast<AST_EventType*> (i);
6355               (void) s->fe_add_eventtype (e);
6356             }
6358           /*
6359            * Push it on the scope stack.
6360            */
6361           idl_global->scopes ().push (e);
6363           $1->destroy ();
6364           delete $1;
6365           $1 = 0;
6366         }
6367         '{'
6368         {
6369           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeSqSeen);
6370         }
6371         exports
6372         {
6373           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeBodySeen);
6374         }
6375         '}'
6376         {
6377           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeQsSeen);
6379           /*
6380            * Done with this eventtype - pop it off the scopes stack.
6381            */
6382           idl_global->scopes ().pop ();
6384           $$ = 0;
6385         }
6386         ;
6388 event_abs_header :
6389         IDL_ABSTRACT
6390         IDL_EVENTTYPE
6391         defining_id
6392         {
6393           $$ = $3;
6394         }
6395         ;
6397 event_custom_header :
6398         IDL_CUSTOM
6399         IDL_EVENTTYPE
6400         defining_id
6401         {
6402           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeIDSeen);
6404           ACE_DEBUG ((LM_DEBUG,
6405                       ACE_TEXT ("error in %C line %d\n"),
6406                       idl_global->filename ()->get_string (),
6407                       idl_global->lineno ()));
6408           ACE_DEBUG ((LM_DEBUG,
6409                       ACE_TEXT ("Sorry, I (TAO_IDL) can't handle")
6410                       ACE_TEXT (" custom yet\n")));
6411           $$ = 0;
6412         }
6413         ;
6415 event_plain_header :
6416         IDL_EVENTTYPE
6417         defining_id
6418         {
6419           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeIDSeen);
6421           $$ = $2;
6422         }
6423         ;
6425 event_rest_of_header :
6426         inheritance_spec
6427         {
6428           idl_global->set_parse_state (IDL_GlobalData::PS_InheritSpecSeen);
6429         }
6430         supports_spec
6431         {
6432           idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen);
6434           ACE_NEW_RETURN ($<vhval>$,
6435                           FE_OBVHeader (
6436                             0,
6437                             $1,
6438                             $3,
6439                             $1
6440                               ? $1->truncatable ()
6441                               : false,
6442                             true),
6443                           1);
6445           if (0 != $3)
6446             {
6447               $3->destroy ();
6448               delete $3;
6449               $3 = 0;
6450             }
6452           if (0 != $1)
6453             {
6454               $1->destroy ();
6455               delete $1;
6456               $1 = 0;
6457             }
6458         }
6459         ;
6461 event_decl :
6462         event_header
6463         event_rest_of_header
6464         {
6465           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
6466           Identifier *&event_id = $1;
6467           FE_OBVHeader *&event_header = $2;
6468           AST_EventType *eventtype = 0;
6470           if (scope && event_header)
6471             {
6472               // We create the scoped name here instead of with the
6473               // FE_OBVHeader because there is a token for it only here.
6474               UTL_ScopedName sn (event_id, 0);
6475               eventtype = idl_global->gen ()->create_eventtype (
6476                 &sn,
6477                 event_header->inherits (),
6478                 event_header->n_inherits (),
6479                 event_header->inherits_concrete (),
6480                 event_header->inherits_flat (),
6481                 event_header->n_inherits_flat (),
6482                 event_header->supports (),
6483                 event_header->n_supports (),
6484                 event_header->supports_concrete (),
6485                 false,
6486                 event_header->truncatable (),
6487                 false);
6488               AST_Interface *eventtype_as_interface =
6489                 dynamic_cast<AST_Interface *> (eventtype);
6490               AST_Interface::fwd_redefinition_helper (
6491                 eventtype_as_interface, scope);
6492               eventtype = dynamic_cast<AST_EventType *> (eventtype_as_interface);
6494               /*
6495                * Add the eventetype to its definition scope
6496                */
6497               scope->fe_add_eventtype (eventtype);
6499               // FE_OBVHeader is not automatically destroyed in the AST
6500               event_header->destroy ();
6501               delete event_header;
6502               event_header = 0;
6504               sn.destroy ();
6505             }
6507           /*
6508            * Push it on the scope stack.
6509            */
6510           idl_global->scopes ().push (eventtype);
6512           $<dcval>$ = eventtype;
6513         }
6514         '{'
6515         {
6516           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeSqSeen);
6517         }
6518         value_elements
6519         {
6520           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeBodySeen);
6521         }
6522         '}'
6523         {
6524           idl_global->set_parse_state (IDL_GlobalData::PS_EventTypeQsSeen);
6526           /*
6527            * Done with this eventtype - pop it off the scopes stack.
6528            */
6529           idl_global->scopes ().pop ();
6531           $$ = $<dcval>3;
6532         }
6533         ;
6535 event_header
6536         : event_custom_header
6537         {
6538           $$ = $1;
6539         }
6540         | event_plain_header
6541         {
6542           $$ = $1;
6543         }
6544         ;
6546 formal_parameter_type
6547         : IDL_TYPENAME
6548         {
6549           $<ntval>$ = AST_Decl::NT_type;
6550         }
6551         | IDL_STRUCT
6552         {
6553           $<ntval>$ = AST_Decl::NT_struct;
6554         }
6555         | IDL_UNION
6556         {
6557           $<ntval>$ = AST_Decl::NT_union;
6558         }
6559         | IDL_EVENTTYPE
6560         {
6561           $<ntval>$ = AST_Decl::NT_eventtype;
6562         }
6563         | IDL_SEQUENCE
6564         {
6565           $<ntval>$ = AST_Decl::NT_sequence;
6566         }
6567         | IDL_INTERFACE
6568         {
6569           $<ntval>$ = AST_Decl::NT_interface;
6570         }
6571         | IDL_VALUETYPE
6572         {
6573           $<ntval>$ = AST_Decl::NT_valuetype;
6574         }
6575         | IDL_ENUM
6576         {
6577           $<ntval>$ = AST_Decl::NT_enum;
6578         }
6579         | IDL_EXCEPTION
6580         {
6581           $<ntval>$ = AST_Decl::NT_except;
6582         }
6583         | IDL_CONST const_type
6584         {
6585           $<ntval>$ = AST_Decl::NT_const;
6586           t_param_const_type = $2;
6587         }
6588         ;
6590 at_least_one_formal_parameter
6591         : formal_parameter formal_parameters
6592         {
6593           if ($2 == 0)
6594             {
6595               ACE_NEW_RETURN ($2, FE_Utils::T_PARAMLIST_INFO, 1);
6596             }
6598           $2->enqueue_head (*$1);
6599           delete $1;
6600           $1 = 0;
6602           // The param added above is always the last one parsed,
6603           // so we check for matches between sequence<T> & T here.
6604           ACE_CString bad_id =
6605             FE_Utils::check_for_seq_of_param (
6606               $2);
6608           if (!bad_id.empty ())
6609             {
6610               delete $2;
6611               $2 = 0;
6613               idl_global->err ()->mismatch_seq_of_param (bad_id.c_str ());
6614               return 1;
6615             }
6617           $$ = $2;
6618         }
6619         ;
6621 formal_parameters
6622         : formal_parameters ',' formal_parameter
6623         {
6624           if ($1 == 0)
6625             {
6626               ACE_NEW_RETURN ($1, FE_Utils::T_PARAMLIST_INFO, 1);
6627             }
6629           $1->enqueue_tail (*$3);
6630           $$ = $1;
6632           delete $3;
6633           $3 = 0;
6634         }
6635         | %empty
6636         {
6637           $$ = 0;
6638         }
6639         ;
6641 formal_parameter
6642         : formal_parameter_type IDENTIFIER
6643         {
6645           ACE_NEW_RETURN ($$,
6646                           FE_Utils::T_Param_Info,
6647                           1);
6649           AST_Decl::NodeType nt = $1;
6651           $$->type_ = nt;
6652           $$->name_ = $2;
6653           ACE::strdelete ($2);
6654           $2 = 0;
6656           if (nt == AST_Decl::NT_const)
6657             {
6658               $$->const_type_ = t_param_const_type;
6659               $$->enum_const_type_decl_ =
6660                 tao_enum_constant_decl;
6662               // Reset these values.
6663               t_param_const_type = AST_Expression::EV_none;
6664               tao_enum_constant_decl = 0;
6665             }
6666         }
6667         | IDL_SEQUENCE '<' IDENTIFIER '>' IDENTIFIER
6668         {
6669           ACE_NEW_RETURN ($$,
6670                           FE_Utils::T_Param_Info,
6671                           1);
6673           $$->type_ = AST_Decl::NT_sequence;
6674           $$->seq_param_ref_  = $3;
6675           $$->name_ += $5;
6677           ACE::strdelete ($3);
6678           $3 = 0;
6679           ACE::strdelete ($5);
6680           $5 = 0;
6681         }
6682         ;
6684 at_least_one_formal_parameter_name
6685         : formal_parameter_name formal_parameter_names
6686         {
6687           ACE_NEW_RETURN ($$, UTL_StrList ($1, $2), 1);
6688         }
6689         ;
6691 formal_parameter_names
6692         : formal_parameter_names ',' formal_parameter_name
6693         {
6694           UTL_StrList *sl = 0;
6695           ACE_NEW_RETURN (sl, UTL_StrList ($3, 0), 1);
6697           if ($1 == 0)
6698             {
6699               $$ = sl;
6700             }
6701           else
6702             {
6703               $1->nconc (sl);
6704               $$ = $1;
6705             }
6706         }
6707         | %empty
6708         {
6709           $$ = 0;
6710         }
6711         ;
6713 formal_parameter_name
6714         : IDENTIFIER
6715         {
6716           ACE_NEW_RETURN ($$,
6717                           UTL_String ($1, true),
6718                           1);
6719         }
6720         ;
6722 porttype_decl
6723         : IDL_PORTTYPE
6724         {
6725           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeSeen);
6726         }
6727         IDENTIFIER
6728         {
6729           char *&id_value = $3;
6730           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeIDSeen);
6731           UTL_Scope *scope = idl_global->scopes ().top_non_null ();
6733           Identifier id (id_value);
6734           ACE::strdelete (id_value);
6735           id_value = 0;
6737           UTL_ScopedName scoped_name (&id, 0);
6738           AST_PortType *porttype = idl_global->gen ()->create_porttype (
6739             &scoped_name);
6740           scope->fe_add_porttype (porttype);
6741           $<dcval>$ = porttype;
6743           // Push it on the scopes stack.
6744           idl_global->scopes ().push (porttype);
6745         }
6746         '{'
6747         {
6748           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeSqSeen);
6749         }
6750         /**
6751          * NOTE: IDL4.2 spec has a different definition of what can go inside a
6752          * portype.
6753          */
6754         at_least_one_port_export
6755         {
6756           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeBodySeen);
6757         }
6758         '}'
6759         {
6760           idl_global->set_parse_state (IDL_GlobalData::PS_PorttypeQsSeen);
6762           // Done with this port type - pop it off the scopes stack.
6763           idl_global->scopes ().pop ();
6765           $$ = $<dcval>4;
6766         }
6767         ;
6769 at_least_one_port_export
6770         : port_exports at_least_one_annotation port_export
6771         {
6772           AST_Annotation_Appls *&annotations = $2;
6773           AST_Decl *&node = $3;
6774           if (node)
6775             {
6776               node->annotation_appls (*annotations);
6777             }
6778           else
6779             {
6780               idl_global->err ()-> unsupported_warning (
6781                 "Annotating this is not supported");
6782             }
6783           delete annotations;
6784         }
6785         | port_exports port_export
6786         ;
6788 port_exports
6789         : at_least_one_port_export
6790         | %empty
6791         ;
6793 port_export
6794         : provides_decl ';'
6795         | uses_decl ';'
6796         | attribute
6797         {
6798           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
6799         }
6800         ';'
6801         {
6802           $$ = $1;
6803         }
6804         ;
6806 extended_port_decl
6807         : IDL_PORT scoped_name IDENTIFIER
6808         {
6809           idl_global->set_parse_state (IDL_GlobalData::PS_ExtendedPortDeclSeen);
6810           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6811           AST_Decl *d =
6812             s->lookup_by_name ($2);
6813           AST_PortType *pt = 0;
6814           bool so_far_so_good = true;
6816           if (d == 0)
6817             {
6818               idl_global->err ()->lookup_error ($2);
6819               so_far_so_good = false;
6820             }
6821           else
6822             {
6823               pt = dynamic_cast<AST_PortType*> (d);
6825               if (pt == 0)
6826                 {
6827                   idl_global->err ()->error1 (UTL_Error::EIDL_PORTTYPE_EXPECTED,
6828                                               d);
6829                   so_far_so_good = false;
6830                 }
6831             }
6833           AST_Extended_Port *ep = 0;
6835           if (so_far_so_good)
6836             {
6837               Identifier id ($3);
6838               ACE::strdelete ($3);
6839               $3 = 0;
6841               UTL_ScopedName sn (&id, 0);
6842               ep = idl_global->gen ()->create_extended_port (&sn, pt);
6843               s->fe_add_extended_port (ep);
6845               // Create (in the AST) the struct(s) and sequence(s)
6846               // needed for multiplex uses ports, if any.
6847               for (UTL_ScopeActiveIterator i (pt, UTL_Scope::IK_decls);
6848                    !i.is_done ();
6849                    i.next ())
6850                 {
6851                   d = i.item ();
6853                   AST_Uses *u = dynamic_cast<AST_Uses*> (d);
6855                   if (u != 0 && u->is_multiple ())
6856                     {
6857                       AST_Component *c =
6858                         dynamic_cast<AST_Component*> (s);
6860                       FE_Utils::create_uses_multiple_stuff (
6861                         c,
6862                         u,
6863                         id.get_string ());
6864                     }
6865                 }
6866             }
6868           $2->destroy ();
6869           delete $2;
6870           $2 = 0;
6872           $$ = ep;
6873         }
6874         | IDL_MIRRORPORT scoped_name IDENTIFIER
6875         {
6876           idl_global->set_parse_state (IDL_GlobalData::PS_MirrorPortDeclSeen);
6877           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6878           AST_Decl *d =
6879             s->lookup_by_name ($2);
6880           AST_PortType *pt = 0;
6881           bool so_far_so_good = true;
6883           if (d == 0)
6884             {
6885               idl_global->err ()->lookup_error ($2);
6886               so_far_so_good = false;
6887             }
6888            else
6889              {
6890                pt = dynamic_cast<AST_PortType*> (d);
6892                if (pt == 0)
6893                  {
6894                    idl_global->err ()->error1 (UTL_Error::EIDL_PORTTYPE_EXPECTED,
6895                                                d);
6896                    so_far_so_good = false;
6897                  }
6898              }
6900           AST_Mirror_Port *mp = 0;
6902           if (so_far_so_good)
6903             {
6904               Identifier id ($3);
6905               ACE::strdelete ($3);
6906               $3 = 0;
6908               UTL_ScopedName sn (&id, 0);
6909               mp = idl_global->gen ()->create_mirror_port (&sn, pt);
6910               s->fe_add_mirror_port (mp);
6911             }
6913           $2->destroy ();
6914           delete $2;
6915           $2 = 0;
6917           $$ = mp;
6918         }
6919         ;
6921 at_least_one_actual_parameter
6922         : annotations_maybe actual_parameter actual_parameters
6923         {
6924           if ($3 == 0)
6925             {
6926               ACE_NEW_RETURN ($3,
6927                               FE_Utils::T_ARGLIST,
6928                               1);
6929             }
6931           delete $1;
6932           $3->enqueue_head ($2);
6933           $<alval>$ = $3;
6934         }
6935         ;
6937 actual_parameters
6938         : actual_parameters ',' annotations_maybe actual_parameter
6939         {
6940           if ($1 == 0)
6941             {
6942               ACE_NEW_RETURN ($1,
6943                               FE_Utils::T_ARGLIST,
6944                               1);
6945             }
6947           delete $3;
6948           $1->enqueue_tail ($4);
6949           $<alval>$ = $1;
6950         }
6951         | %empty
6952         {
6953           $<alval>$ = 0;
6954         }
6955         ;
6957 actual_parameter
6958         : expression
6959         {
6960           // To avoid grammar conflicts with this LALR(1) parser,
6961           // we take advantage of the fact that an expression can
6962           // be a scoped name. At that lower level, we create an
6963           // expression containing the scoped name, and at a
6964           // higher lever, deduce that it's not supposed to be
6965           // a constant and look up the type to add to the template
6966           // arg list.
6967           AST_Expression *ex = $1;
6968           UTL_ScopedName *sn = ex->n ();
6969           AST_Decl *d = 0;
6970           UTL_Scope *s = idl_global->scopes ().top_non_null ();
6972           if (sn != 0)
6973             {
6974               d = s->lookup_by_name (sn);
6976               if (d == 0)
6977                 {
6978                   idl_global->err ()->lookup_error (sn);
6979                   return 1;
6980                 }
6981               else
6982                 {
6983                   AST_Decl::NodeType nt = d->node_type ();
6985                   if (nt == AST_Decl::NT_enum_val)
6986                     {
6987                       $1->evaluate (
6988                         AST_Expression::EK_const);
6990                       $<dcval>$ =
6991                         idl_global->gen ()->create_constant (
6992                           $1->ev ()->et,
6993                           $1,
6994                           sn);
6995                     }
6996                   else
6997                     {
6998                       $<dcval>$ = d;
6999                     }
7000                 }
7001             }
7002           else
7003             {
7004               $1->evaluate (
7005                 AST_Expression::EK_const);
7007               $<dcval>$ =
7008                 idl_global->gen ()->create_constant (
7009                   $1->ev ()->et,
7010                   $1,
7011                   0);
7012             }
7013         }
7014         ;
7016 connector_decl
7017         : connector_header connector_body
7018         {
7019           $$ = 0;
7020         }
7021         ;
7023 connector_header
7024         : IDL_CONNECTOR
7025         {
7026           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorSeen);
7027         }
7028         annotations_maybe IDENTIFIER
7029         {
7030           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorIDSeen);
7031         }
7032         component_inheritance_spec
7033         {
7034           UTL_Scope *s = idl_global->scopes ().top_non_null ();
7035           AST_Connector *parent = 0;
7036           bool so_far_so_good = true;
7038           Identifier id ($4);
7039           ACE::strdelete ($4);
7040           $4 = 0;
7042           UTL_ScopedName sn (&id, 0);
7044           if ($6 != 0)
7045             {
7046               AST_Decl *d =
7047                 s->lookup_by_name ($6);
7049               if (d == 0)
7050                 {
7051                   idl_global->err ()->lookup_error ($6);
7052                   so_far_so_good = false;
7053                 }
7055               parent =
7056                 dynamic_cast<AST_Connector*> (d);
7058               if (parent == 0)
7059                 {
7060                   idl_global->err ()->error1 (
7061                     UTL_Error::EIDL_CONNECTOR_EXPECTED,
7062                     d);
7064                   so_far_so_good = false;
7065                 }
7067               $6->destroy ();
7068               delete $6;
7069               $6 = 0;
7070             }
7072           if (so_far_so_good)
7073             {
7074               AST_Connector *c =
7075                 idl_global->gen ()->create_connector (&sn,
7076                                                       parent);
7078               (void) s->fe_add_connector (c);
7080               // Push it on the scopes stack.
7081               idl_global->scopes ().push (c);
7082            }
7084           delete $3;
7085         }
7086         ;
7088 connector_body
7089         : '{'
7090         {
7091           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorSqSeen);
7092         }
7093         connector_exports
7094         {
7095           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorBodySeen);
7096         }
7097         '}'
7098         {
7099           idl_global->set_parse_state (IDL_GlobalData::PS_ConnectorQsSeen);
7101           // Done with this connector - pop it off the scope stack.
7102           idl_global->scopes ().pop ();
7103         }
7104         ;
7106 connector_exports
7107         : connector_exports connector_export
7108         | %empty
7109         ;
7111 connector_export
7112         : provides_decl
7113         {
7114           idl_global->set_parse_state (IDL_GlobalData::PS_ProvidesDeclSeen);
7115         }
7116         ';'
7117         {
7118           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7119         }
7120         | uses_decl
7121         {
7122           idl_global->set_parse_state (IDL_GlobalData::PS_UsesDeclSeen);
7123         }
7124         ';'
7125         {
7126           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7127         }
7128         | attribute
7129         {
7130           idl_global->set_parse_state (IDL_GlobalData::PS_AttrDeclSeen);
7131         }
7132         ';'
7133         {
7134           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7135         }
7136         | extended_port_decl
7137         {
7138           idl_global->set_parse_state (IDL_GlobalData::PS_ExtendedPortDeclSeen);
7139         }
7140         ';'
7141         {
7142           idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
7143         }
7144         ;
7147 /* programs */
7150  * ???
7151  */
7153 tao_yywrap (void)
7155   return 1;
7159  * Report an error situation discovered in a production
7160  */
7161 void
7162 tao_yyerror (const char *msg)
7164   ACE_ERROR ((LM_ERROR, "%C\n", msg));