Merge pull request #1206 from iguessthislldo/igtd/no-return
[ACE_TAO.git] / TAO / TAO_IDL / util / utl_scope.cpp
blob347182d76f63715cecc7fa5a1ff23b812af87c67
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 which
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.
65 #include "utl_scope.h"
66 #include "utl_identifier.h"
67 #include "utl_err.h"
68 #include "utl_indenter.h"
69 #include "utl_string.h"
70 #include "utl_strlist.h"
71 #include "ast_valuebox.h"
72 #include "ast_valuetype.h"
73 #include "ast_valuetype_fwd.h"
74 #include "ast_eventtype.h"
75 #include "ast_eventtype_fwd.h"
76 #include "ast_component.h"
77 #include "ast_component_fwd.h"
78 #include "ast_home.h"
79 #include "ast_porttype.h"
80 #include "ast_template_module.h"
81 #include "ast_template_module_ref.h"
82 #include "ast_template_module_inst.h"
83 #include "ast_typedef.h"
84 #include "ast_type.h"
85 #include "ast_root.h"
86 #include "ast_array.h"
87 #include "ast_enum.h"
88 #include "ast_concrete_type.h"
89 #include "ast_sequence.h"
90 #include "ast_string.h"
91 #include "ast_structure_fwd.h"
92 #include "ast_exception.h"
93 #include "ast_constant.h"
94 #include "ast_attribute.h"
95 #include "ast_operation.h"
96 #include "ast_argument.h"
97 #include "ast_param_holder.h"
98 #include "ast_union.h"
99 #include "ast_union_fwd.h"
100 #include "ast_union_branch.h"
101 #include "ast_field.h"
102 #include "ast_enum_val.h"
103 #include "ast_native.h"
104 #include "ast_factory.h"
105 #include "ast_visitor.h"
106 #include "ast_generator.h"
107 #include "ast_extern.h"
109 #include "fe_extern.h"
110 #include "nr_extern.h"
111 #include "global_extern.h"
113 #include "ace/OS_NS_strings.h"
115 // FUZZ: disable check_for_streams_include
116 #include "ace/streams.h"
118 #undef INCREMENT
119 #define INCREMENT 64
121 // Constructors.
123 UTL_Scope::UTL_Scope (void)
124 : pd_scope_node_type (AST_Decl::NT_module),
125 pd_decls (0),
126 pd_decls_allocated (0),
127 pd_decls_used (0),
128 pd_local_types (0),
129 pd_locals_allocated (0),
130 pd_locals_used (0),
131 pd_referenced (0),
132 pd_referenced_allocated (0),
133 pd_referenced_used (0),
134 pd_name_referenced (0),
135 pd_name_referenced_allocated (0),
136 pd_name_referenced_used (0),
137 has_prefix_ (0),
138 which_pseudo_ (PSEUDO_ABSTRACTBASE)
142 UTL_Scope::UTL_Scope (AST_Decl::NodeType nt)
143 : pd_scope_node_type (nt),
144 pd_decls (0),
145 pd_decls_allocated (0),
146 pd_decls_used (0),
147 pd_local_types (0),
148 pd_locals_allocated (0),
149 pd_locals_used (0),
150 pd_referenced (0),
151 pd_referenced_allocated (0),
152 pd_referenced_used (0),
153 pd_name_referenced (0),
154 pd_name_referenced_allocated (0),
155 pd_name_referenced_used (0),
156 has_prefix_ (0),
157 which_pseudo_ (PSEUDO_ABSTRACTBASE)
161 // Destructor.
162 UTL_Scope::~UTL_Scope (void)
164 for (UTL_ScopeActiveIterator iter (this, IK_both);
165 !iter.is_done ();
166 iter.next ())
168 AST_Decl *d = iter.item ();
169 d->destroy ();
170 delete d;
173 delete [] this->pd_decls;
174 delete [] this->pd_local_types;
175 delete [] this->pd_referenced;
177 for (long i = this->pd_name_referenced_used; i--;) // NOTE test with i--
179 Identifier *id = this->pd_name_referenced[i];
180 id->destroy ();
181 delete id;
184 delete [] this->pd_name_referenced;
187 void
188 UTL_Scope::destroy (void)
190 for (UTL_ScopeActiveIterator iter (this, IK_both);
191 !iter.is_done ();
192 iter.next ())
194 AST_Decl *d = iter.item ();
195 d->destroy ();
196 delete d;
199 delete [] this->pd_decls;
200 this->pd_decls = 0;
201 this->pd_decls_allocated = 0;
202 this->pd_decls_used = 0;
204 delete [] this->pd_local_types;
205 this->pd_local_types = 0;
206 this->pd_locals_allocated = 0;
207 this->pd_locals_used = 0;
209 delete [] this->pd_referenced;
210 this->pd_referenced = 0;
211 this->pd_referenced_allocated = 0;
212 this->pd_referenced_used = 0;
214 for (long i = this->pd_name_referenced_used; i--;) // NOTE test with i--
216 Identifier *id = this->pd_name_referenced[i];
217 id->destroy ();
218 delete id;
221 delete [] this->pd_name_referenced;
222 this->pd_name_referenced = 0;
223 this->pd_name_referenced_allocated = 0;
224 this->pd_name_referenced_used = 0;
227 // Protected operations.
229 // Special version of lookup which only looks at the local name instead of
230 // the fully scoped name, when doing lookups. This version is intended to
231 // be used only by the frontend add_xxx functions.
232 AST_Decl *
233 UTL_Scope::lookup_for_add (AST_Decl *d)
235 if (!d)
237 return 0;
240 Identifier *id = d->local_name ();
241 if (this->idl_keyword_clash (id))
243 return 0;
246 return this->lookup_by_name_local (id, false);
250 UTL_Scope::idl_keyword_clash (Identifier *e)
252 if (e->escaped ())
254 return 0;
257 // Convert the identifier string into a
258 // canonical (uppercase) form as a ACE_CString
259 char *tmp = e->get_string ();
260 ACE_CString ext_id (tmp);
261 UTL_String::get_canonical_rep (ext_id);
263 if (!idl_global->idl_keywords ().find (ext_id))
265 if (idl_global->case_diff_error ())
267 idl_global->err ()->idl_keyword_error (tmp);
269 return -1;
272 idl_global->err ()->idl_keyword_warning (tmp);
275 return 0;
278 bool
279 UTL_Scope::redef_clash (AST_Decl::NodeType new_nt,
280 AST_Decl::NodeType scope_elem_nt)
282 switch (new_nt)
284 case AST_Decl::NT_module:
285 return scope_elem_nt != AST_Decl::NT_module;
287 case AST_Decl::NT_struct:
288 case AST_Decl::NT_struct_fwd:
289 return scope_elem_nt != AST_Decl::NT_struct_fwd;
291 case AST_Decl::NT_union:
292 case AST_Decl::NT_union_fwd:
293 return scope_elem_nt != AST_Decl::NT_union_fwd;
295 case AST_Decl::NT_interface:
296 return scope_elem_nt != AST_Decl::NT_interface_fwd;
298 case AST_Decl::NT_component:
299 return scope_elem_nt != AST_Decl::NT_component_fwd;
301 case AST_Decl::NT_interface_fwd:
302 return ( scope_elem_nt != AST_Decl::NT_interface_fwd
303 && scope_elem_nt != AST_Decl::NT_interface);
305 case AST_Decl::NT_component_fwd:
306 return ( scope_elem_nt != AST_Decl::NT_component_fwd
307 && scope_elem_nt != AST_Decl::NT_component);
309 case AST_Decl::NT_valuetype:
310 return scope_elem_nt != AST_Decl::NT_valuetype_fwd;
312 case AST_Decl::NT_eventtype:
313 return scope_elem_nt != AST_Decl::NT_eventtype_fwd;
315 case AST_Decl::NT_valuetype_fwd:
316 return ( scope_elem_nt != AST_Decl::NT_valuetype_fwd
317 && scope_elem_nt != AST_Decl::NT_valuetype);
319 case AST_Decl::NT_eventtype_fwd:
320 return ( scope_elem_nt != AST_Decl::NT_eventtype_fwd
321 && scope_elem_nt != AST_Decl::NT_eventtype);
323 default:
324 return true;
328 void
329 UTL_Scope::check_for_predef_seq (AST_Decl *d)
331 // Right now, we're interested only in predefined sequences
332 // referenced in the main IDL file. If we are processing
333 // multiple IDL files in one execution, the bits will
334 // stay set, and be accumulated as each file is parsed.
335 if (!idl_global->in_main_file ())
337 return;
340 AST_Type *bt = 0;
341 AST_Decl::NodeType nt = d->node_type ();
343 // We are interested only in members, arguments and typedefs.
344 switch (nt)
346 case AST_Decl::NT_field:
347 case AST_Decl::NT_union_branch:
348 case AST_Decl::NT_attr:
349 case AST_Decl::NT_argument:
350 bt = AST_Field::narrow_from_decl (d)->field_type ();
351 break;
353 case AST_Decl::NT_typedef:
354 bt = AST_Typedef::narrow_from_decl (d)->base_type ();
355 break;
357 default:
358 return;
361 // Check to eliminate more candidates.
362 if (!bt->imported () || bt->node_type () != AST_Decl::NT_typedef)
364 return;
367 bt = AST_Typedef::narrow_from_decl (bt)->base_type ();
368 nt = bt->node_type ();
370 // Must be a sequence with only one level of typedef.
371 if (nt != AST_Decl::NT_sequence)
373 return;
376 // Must be defined in the CORBA module.
377 AST_Decl *p = ScopeAsDecl (bt->defined_in ());
378 if (ACE_OS::strcmp (p->local_name ()->get_string (), "CORBA"))
380 return;
383 // We know this narrowing will be successful.
384 bt = AST_Sequence::narrow_from_decl (bt)->base_type ();
385 nt = bt->node_type ();
387 // First check for string or wstring base type.
388 if (nt == AST_Decl::NT_string)
390 idl_global->string_seq_seen_ = true;
391 return;
394 if (nt == AST_Decl::NT_wstring)
396 idl_global->wstring_seq_seen_ = true;
397 return;
400 // Now check for predefined base type.
401 AST_PredefinedType *pdt = AST_PredefinedType::narrow_from_decl (bt);
402 if (!pdt)
404 return;
407 switch (pdt->pt ())
409 case AST_PredefinedType::PT_long:
410 idl_global->long_seq_seen_ = true;
411 break;
413 case AST_PredefinedType::PT_ulong:
414 idl_global->ulong_seq_seen_ = true;
415 break;
417 case AST_PredefinedType::PT_longlong:
418 idl_global->longlong_seq_seen_ = true;
419 break;
421 case AST_PredefinedType::PT_ulonglong:
422 idl_global->ulonglong_seq_seen_ = true;
423 break;
425 case AST_PredefinedType::PT_short:
426 idl_global->short_seq_seen_ = true;
427 break;
429 case AST_PredefinedType::PT_ushort:
430 idl_global->ushort_seq_seen_ = true;
431 break;
433 case AST_PredefinedType::PT_float:
434 idl_global->float_seq_seen_ = true;
435 break;
437 case AST_PredefinedType::PT_double:
438 idl_global->double_seq_seen_ = true;
439 break;
441 case AST_PredefinedType::PT_longdouble:
442 idl_global->longdouble_seq_seen_ = true;
443 break;
445 case AST_PredefinedType::PT_char:
446 idl_global->char_seq_seen_ = true;
447 break;
449 case AST_PredefinedType::PT_wchar:
450 idl_global->wchar_seq_seen_ = true;
451 break;
453 case AST_PredefinedType::PT_boolean:
454 idl_global->boolean_seq_seen_ = true;
455 break;
457 case AST_PredefinedType::PT_octet:
458 idl_global->octet_seq_seen_ = true;
459 break;
461 case AST_PredefinedType::PT_any:
462 idl_global->any_seq_seen_ = true;
463 break;
465 default:
466 break;
470 // Protected Front End Scope Management Protocol.
472 // All members of the protocol defined in UTL_Scope simply return NULL
473 // and don't do a thing. This ensures that runtime errors will discover
474 // operations which should have been redefined to allow certain kinds of
475 // AST nodes to appear in a given context.
477 AST_Decl *
478 UTL_Scope::fe_add_decl (AST_Decl *t)
480 // Already defined and cannot be redefined? Or already used?
481 AST_Decl *d = this->lookup_for_add (t);
483 if (d != 0)
485 if (!FE_Utils::can_be_redefined (d, t))
487 idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
489 ScopeAsDecl (this),
491 return 0;
494 // For convenience, AST_Template_Module_Inst inherits
495 // from AST_Field, but has a node type of NT_module.
496 // Since we then can't add it using fe_add_module(), a
497 // check is needed here to avoid a redefinition error,
498 // if the instantiated module is meant to reopen a
499 // previous one.
501 AST_Decl::NodeType lnt = d->node_type ();
502 AST_Decl::NodeType ant = t->node_type ();
503 bool need_ref_check =
504 ( lnt != AST_Decl::NT_module
505 || ant != AST_Decl::NT_module);
507 if (need_ref_check && this->referenced (d, t->local_name ()))
509 idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
511 ScopeAsDecl (this),
513 return 0;
516 if (t->has_ancestor (d))
518 idl_global->err ()->redefinition_in_scope (t, d);
519 return 0;
522 else if (this->inherited_op_attr_clash (t))
524 return 0;
527 if (this->arg_specific_error (t))
529 return 0;
532 this->smart_local_add (t);
534 // Add it to set of locally referenced symbols, unless it is
535 // a home, in which case it will clash when the equivalent
536 // interface is created.
537 if (t->node_type () != AST_Decl::NT_home)
539 this->add_to_referenced (t,
540 false,
541 t->local_name ());
544 return t;
547 AST_Field *
548 UTL_Scope::fe_add_ref_decl (AST_Field *t)
550 AST_Decl *d = this->fe_add_decl (t);
551 if (d)
553 AST_Type *ft = t->field_type ();
554 UTL_ScopedName *mru = ft->last_referenced_as ();
555 if (mru)
557 this->add_to_referenced (ft,
558 false,
559 mru->first_component ());
563 // Catches struct/union/exception which all maintain a queue
564 // for fields as distinct from decls and enum values.
565 AST_Structure *s = AST_Structure::narrow_from_scope (this);
566 if (s)
568 s->fields ().enqueue_tail (t);
571 return AST_Field::narrow_from_decl (d);
574 AST_Structure *
575 UTL_Scope::fe_add_full_struct_type (AST_Structure *t)
577 AST_Decl *predef = this->lookup_for_add (t);
579 if (predef)
581 if (!FE_Utils::can_be_redefined (predef, t))
583 idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
585 ScopeAsDecl (this),
586 predef);
587 return 0;
590 if (referenced (predef, t->local_name ()) && !t->is_defined ())
592 idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
594 ScopeAsDecl (this),
595 predef);
596 return 0;
600 AST_Decl::NodeType nt = ScopeAsDecl (this)->node_type ();
602 // Decls inside a struct or union are also referenced by
603 // fields, and so must be handled differently.
604 if ( nt == AST_Decl::NT_struct
605 || nt == AST_Decl::NT_union
606 || nt == AST_Decl::NT_except)
608 this->add_to_local_types (t);
610 else
612 this->add_to_scope (t);
615 // Add it to set of locally referenced symbols.
616 this->add_to_referenced (t,
617 false,
618 t->local_name ());
619 return t;
622 AST_StructureFwd *
623 UTL_Scope::fe_add_fwd_struct_type (AST_StructureFwd *t)
625 // Already defined and cannot be redefined? Or already used?
626 AST_Decl *d = this->lookup_for_add (t);
627 if (d)
629 // There used to be another check here ANDed with the one below:
630 // d->defined_in () == this. But lookup_for_add() calls only
631 // lookup_by_name_local(), which does not bump up the scope,
632 // and look_in_prev_mods() for modules. If look_in_prev_mods()
633 // finds something, the scopes will NOT be the same pointer
634 // value, but the result is what we want.
635 if (d->node_type () == AST_Decl::NT_struct)
637 t->set_full_definition (AST_Structure::narrow_from_decl (d));
639 else if (!FE_Utils::can_be_redefined (d, t))
641 idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
643 ScopeAsDecl (this),
645 return 0;
647 else if (this->referenced (d, t->local_name ()))
649 idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
651 ScopeAsDecl (this),
653 return 0;
657 // Add it to scope
658 this->add_to_scope (t);
660 // Add it to set of locally referenced symbols
661 this->add_to_referenced (t,
662 false,
663 t->local_name ());
665 // Must check later that all struct and union forward declarations
666 // are defined in the same IDL file.
667 AST_record_fwd_decl (t);
668 return t;
671 AST_PredefinedType *
672 UTL_Scope::fe_add_predefined_type (AST_PredefinedType *)
674 return 0;
677 AST_Module *
678 UTL_Scope::fe_add_module (AST_Module *)
680 return 0;
683 AST_Template_Module_Inst *
684 UTL_Scope::fe_add_template_module_inst (AST_Template_Module_Inst *)
686 return 0;
689 AST_Template_Module_Ref *
690 UTL_Scope::fe_add_template_module_ref (AST_Template_Module_Ref *)
692 return 0;
695 AST_Interface *
696 UTL_Scope::fe_add_interface (AST_Interface *)
698 return 0;
701 AST_InterfaceFwd *
702 UTL_Scope::fe_add_interface_fwd (AST_InterfaceFwd *)
704 return 0;
707 AST_ValueBox *
708 UTL_Scope::fe_add_valuebox (AST_ValueBox *)
710 return 0;
713 AST_ValueType *
714 UTL_Scope::fe_add_valuetype (AST_ValueType *)
716 return 0;
719 AST_ValueTypeFwd *
720 UTL_Scope::fe_add_valuetype_fwd (AST_ValueTypeFwd *)
722 return 0;
725 AST_EventType *
726 UTL_Scope::fe_add_eventtype (AST_EventType *)
728 return 0;
731 AST_EventTypeFwd *
732 UTL_Scope::fe_add_eventtype_fwd (AST_EventTypeFwd *)
734 return 0;
737 AST_Component *
738 UTL_Scope::fe_add_component (AST_Component *)
740 return 0;
743 AST_ComponentFwd *
744 UTL_Scope::fe_add_component_fwd (AST_ComponentFwd *)
746 return 0;
749 AST_Home *
750 UTL_Scope::fe_add_home (AST_Home *)
752 return 0;
755 AST_Exception *
756 UTL_Scope::fe_add_exception (AST_Exception *)
758 return 0;
761 AST_Constant *
762 UTL_Scope::fe_add_constant (AST_Constant *)
764 return 0;
767 UTL_StrList *
768 UTL_Scope::fe_add_context (UTL_StrList *)
770 return 0;
773 UTL_NameList *
774 UTL_Scope::fe_add_exceptions (UTL_NameList *)
776 return 0;
779 AST_Attribute *
780 UTL_Scope::fe_add_attribute (AST_Attribute *)
782 return 0;
785 AST_Operation *
786 UTL_Scope::fe_add_operation (AST_Operation *)
788 return 0;
791 AST_Argument *
792 UTL_Scope::fe_add_argument (AST_Argument *)
794 return 0;
797 AST_Union *
798 UTL_Scope::fe_add_union (AST_Union *)
800 return 0;
803 AST_UnionFwd *
804 UTL_Scope::fe_add_union_fwd (AST_UnionFwd *)
806 return 0;
809 AST_UnionBranch *
810 UTL_Scope::fe_add_union_branch (AST_UnionBranch *)
812 return 0;
815 AST_Structure *
816 UTL_Scope::fe_add_structure (AST_Structure *)
818 return 0;
821 AST_StructureFwd *
822 UTL_Scope::fe_add_structure_fwd (AST_StructureFwd *)
824 return 0;
827 AST_Field *
828 UTL_Scope::fe_add_field (AST_Field *)
830 return 0;
833 AST_Enum *
834 UTL_Scope::fe_add_enum (AST_Enum *)
836 return 0;
839 AST_EnumVal *
840 UTL_Scope::fe_add_enum_val (AST_EnumVal *)
842 return 0;
845 AST_Typedef *
846 UTL_Scope::fe_add_typedef (AST_Typedef *)
848 return 0;
851 AST_Sequence *
852 UTL_Scope::fe_add_sequence (AST_Sequence *)
854 return 0;
857 AST_String *
858 UTL_Scope::fe_add_string (AST_String *)
860 return 0;
863 AST_Array *
864 UTL_Scope::fe_add_array (AST_Array *)
866 return 0;
869 AST_Native *
870 UTL_Scope::fe_add_native (AST_Native *)
872 return 0;
875 AST_Factory *
876 UTL_Scope::fe_add_factory (AST_Factory *)
878 return 0;
881 AST_Finder *
882 UTL_Scope::fe_add_finder (AST_Finder *)
884 return 0;
887 AST_PortType *
888 UTL_Scope::fe_add_porttype (AST_PortType *)
890 return 0;
893 AST_Provides *
894 UTL_Scope::fe_add_provides (AST_Provides *)
896 return 0;
899 AST_Uses *
900 UTL_Scope::fe_add_uses (AST_Uses *)
902 return 0;
905 AST_Publishes *
906 UTL_Scope::fe_add_publishes (AST_Publishes *)
908 return 0;
911 AST_Emits *
912 UTL_Scope::fe_add_emits (AST_Emits *)
914 return 0;
917 AST_Consumes *
918 UTL_Scope::fe_add_consumes (AST_Consumes *)
920 return 0;
923 AST_Extended_Port *
924 UTL_Scope::fe_add_extended_port (AST_Extended_Port *)
926 return 0;
929 AST_Mirror_Port *
930 UTL_Scope::fe_add_mirror_port (AST_Mirror_Port *)
932 return 0;
935 AST_Connector *
936 UTL_Scope::fe_add_connector (AST_Connector *)
938 return 0;
941 // Private lookup mechanism.
943 // For dealing with lookups of 'Object' and 'TypeCode'.
944 AST_Decl *
945 UTL_Scope::lookup_pseudo (Identifier *e)
947 if (e->escaped ())
949 return 0;
952 bool *seen = 0;
953 char *name_string = e->get_string ();
954 UTL_Scope *start_scope = idl_global->corba_module ();
956 if (ACE_OS::strcasecmp (name_string, "TypeCode") == 0
957 || ACE_OS::strcasecmp (name_string, "TCKind") == 0)
959 this->which_pseudo_ = PSEUDO_TYPECODE;
960 start_scope = this;
961 seen = &idl_global->typecode_seen_;
963 else if (ACE_OS::strcasecmp (name_string, "Object") == 0)
965 this->which_pseudo_ = PSEUDO_OBJECT;
966 seen = &idl_global->base_object_seen_;
968 else if (ACE_OS::strcasecmp (name_string, "ValueBase") == 0)
970 this->which_pseudo_ = PSEUDO_VALUEBASE;
971 seen = &idl_global->valuebase_seen_;
973 else if (ACE_OS::strcasecmp (name_string, "AbstractBase") == 0)
975 this->which_pseudo_ = PSEUDO_ABSTRACTBASE;
976 seen = &idl_global->abstractbase_seen_;
978 else
980 return 0;
983 for (UTL_ScopeActiveIterator i (start_scope, IK_decls);
984 !i.is_done ();
985 i.next ())
987 AST_Decl *d = i.item ();
989 if (e->case_compare (d->local_name ()))
991 // These have to be located here because we are just looking
992 // up a scoped name - skip for imported nodes.
993 if (idl_global->in_main_file ())
995 *seen = true;
998 return d;
1002 if (this->which_pseudo_ == PSEUDO_TYPECODE)
1004 AST_Decl *d = this->look_in_prev_mods_local (e);
1006 if (d != 0)
1008 // Generation of #includes for Typecode.h
1009 // checks this bit, so we set it for TCKind as well.
1010 *seen = true;
1011 return d;
1015 return 0;
1018 AST_Decl *
1019 UTL_Scope::look_in_prev_mods_local (Identifier *,
1020 bool /* ignore_fwd */)
1022 return 0;
1025 AST_Decl *
1026 UTL_Scope::special_lookup (UTL_ScopedName *,
1027 bool /* full_def_only */,
1028 AST_Decl *&/*final_parent_decl*/)
1030 return 0;
1033 // Lookup the node for a primitive (built-in) type.
1034 AST_Decl *
1035 UTL_Scope::lookup_primitive_type (AST_Expression::ExprType et)
1037 UTL_Scope *search = idl_global->corba_module ();
1039 AST_PredefinedType::PredefinedType pdt =
1040 FE_Utils::ExprTypeToPredefinedType (et);
1042 /// This return value means there was no PredefinedType match
1043 /// for the ExprType.
1044 if (pdt == AST_PredefinedType::PT_pseudo)
1046 return 0;
1049 /// The only 'predefined type' not in the CORBA module.
1050 if (pdt == AST_PredefinedType::PT_void)
1052 search = idl_global->root ();
1055 for (UTL_ScopeActiveIterator i (search, IK_decls);
1056 !i.is_done();
1057 i.next ())
1059 AST_Decl *as_decl = i.item ();
1061 if (as_decl->node_type () == AST_Decl::NT_pre_defined)
1063 AST_PredefinedType *t =
1064 AST_PredefinedType::narrow_from_decl (as_decl);
1066 if (t->pt () == pdt)
1068 if (idl_global->in_main_file ())
1070 switch (pdt)
1072 case AST_PredefinedType::PT_any:
1073 idl_global->any_seen_ = true;
1074 break;
1075 case AST_PredefinedType::PT_object:
1076 idl_global->base_object_seen_ = true;
1077 break;
1078 default:
1079 break;
1083 return t;
1088 return 0;
1091 // Look through inherited list. Overridden in AST_Interface.
1092 AST_Decl *
1093 UTL_Scope::look_in_inherited (UTL_ScopedName *,
1094 bool )
1096 return 0;
1099 // Look through supported interface list. Overridden where necessary.
1100 AST_Decl *
1101 UTL_Scope::look_in_supported (UTL_ScopedName *,
1102 bool)
1104 return 0;
1107 AST_Decl *
1108 UTL_Scope::lookup_by_name_local (Identifier *e,
1109 bool full_def_only)
1111 // Will catch Object, TypeCode, TCKind, ValueBase and
1112 // AbstractBase. A non-zero result of this lookup determines the
1113 // generation of some #includes and, whether successful or not,
1114 // incurs no extra overhead.
1115 AST_Decl *d = this->lookup_pseudo (e);
1116 if (d)
1118 return d;
1121 if (this->idl_keyword_clash (e))
1123 return 0;
1126 bool in_corba = (ACE_OS::strcmp (e->get_string (), "CORBA") == 0);
1128 // We search only the decls here, the local types are done
1129 // below as a last resort.
1130 for (UTL_ScopeActiveIterator i (this, IK_decls);
1131 !i.is_done ();
1132 i.next ())
1134 d = i.item ()->adjust_found (true, full_def_only);
1136 if (d != 0)
1138 Identifier *item_name = d->local_name ();
1140 if (item_name != 0
1141 // Right now we populate the global scope with all the CORBA basic
1142 // types, so something like 'ULong' in an IDL file will find a
1143 // match, unless we skip over these items. This is a workaround until
1144 // there's time to fix the code generation for CORBA basic types.
1145 && (in_corba
1146 || (ACE_OS::strcmp (d->name ()->head ()->get_string (), "CORBA") != 0))
1147 && e->case_compare (item_name))
1149 return d; // We have found the one and only one we are looking for.
1154 // Ok the name wasn't found in the current scope, if this
1155 // scope is a module, we can check it's previous openings!
1156 AST_Module *m = AST_Module::narrow_from_scope (this);
1157 if (m)
1159 d = m->look_in_prev_mods_local (e);
1160 if (d && (!full_def_only || d->is_defined ()))
1162 return d;
1165 else
1167 // Or if this scope is an interface, we can check if
1168 // it was inherited!
1169 AST_Interface *i = AST_Interface::narrow_from_scope (this);
1170 if (i)
1172 d = i->look_in_inherited_local (e);
1173 if (d)
1175 return d;
1180 // There are some cases where the iteration over IK_decls
1181 // above will fail because what we're searching for has been
1182 // added only to the local types. It's less complicated to
1183 // do the iteration below only as a last resort.
1184 for (UTL_ScopeActiveIterator i (this, IK_localtypes);
1185 !i.is_done ();
1186 i.next ())
1188 d = i.item ();
1189 if (e->case_compare (d->local_name ()))
1191 return d;
1195 return 0;
1198 AST_Decl *
1199 UTL_Scope::lookup_by_name (UTL_ScopedName *e,
1200 bool full_def_only,
1201 bool for_add)
1203 // Empty name? Exit immediately.
1204 if (!e)
1206 return 0;
1209 UTL_Scope *work = this;
1211 // If name starts with "::" or "" start lookup in global scope,
1212 // if we're not there already, short_circuiting the
1213 // scope-expanding iteration below.
1214 Identifier *name = e->head ();
1215 const bool global_scope_name = work->is_global_name (name);
1216 if (global_scope_name)
1218 // No tail, exit directly
1219 UTL_List* tail = e->tail ();
1220 if (!tail)
1222 return 0;
1224 // Remove the preceeding "::" or "" from the scopename
1225 e = static_cast<UTL_ScopedName *> (tail);
1226 name = e->head ();
1228 // Move directly to the root scope
1229 work = idl_global->root ();
1232 AST_Decl *first_found_final_parent_decl = 0;
1233 const bool searching_module_path = (e->length () != 1);
1234 AST_Decl *d = searching_module_path ?
1235 work->lookup_by_name_r (e, full_def_only, first_found_final_parent_decl) :
1236 work->lookup_by_name_r (e, full_def_only);
1237 if (d == 0)
1239 // If all else fails, look though each outer scope.
1240 for (UTL_Scope *outer = ScopeAsDecl (work)->defined_in ();
1241 outer;
1242 outer = ScopeAsDecl (outer)->defined_in ())
1244 AST_Decl *next_found_final_parent_decl= 0;
1245 d = outer->lookup_by_name_r (e, full_def_only, next_found_final_parent_decl);
1246 if (d != 0)
1248 work = outer;
1249 if (first_found_final_parent_decl)
1251 // Hidden scopes can't be used indirectly, therefore we didn't actually
1252 // find this one because the "first_found_final_parent_decl" was found and
1253 // this one just found is hidden by it.
1254 idl_global->err ()->scope_masking_error (d, first_found_final_parent_decl);
1255 d = 0; // Ignore this one; continue searching to report other ambiguous matches.
1257 else
1259 break; // Ok found it, stop searching.
1262 else if (searching_module_path && !first_found_final_parent_decl)
1264 first_found_final_parent_decl = next_found_final_parent_decl;
1269 if (for_add)
1271 /// Doesn't add if d == 0.
1272 work->add_to_referenced (d, false, name);
1275 return d;
1278 AST_Decl *
1279 UTL_Scope::lookup_by_name_r (UTL_ScopedName *e,
1280 bool full_def_only)
1282 AST_Decl *ignored= 0;
1283 return UTL_Scope::lookup_by_name_r (e, full_def_only, ignored);
1286 AST_Decl *
1287 UTL_Scope::lookup_by_name_r (UTL_ScopedName *e,
1288 bool full_def_only,
1289 AST_Decl *&final_parent_decl)
1291 bool work_another_level;
1292 UTL_Scope *work = this;
1293 final_parent_decl= (e->length () == 1) ? ScopeAsDecl (work) : 0;
1297 // Will catch Object, TypeCode, TCKind, ValueBase and
1298 // AbstractBase. A non-zero result of this lookup determines the
1299 // generation of some #includes and, whether successful or not,
1300 // incurs no extra overhead.
1301 AST_Decl *d = work->lookup_pseudo (e->head ());
1302 if (d)
1304 return d;
1307 if (work->idl_keyword_clash (e->head ()))
1309 return 0;
1312 // Before proceeding to normal lookup, check if the name
1313 // matches a template module parameter. If so, the return
1314 // value is created on the heap and is owned by the caller
1315 // of this lookup.
1316 if (final_parent_decl)
1318 // Since we are inside the scope of a template module, any
1319 // single-segment scoped name that matches a template
1320 // parameter name has to be a reference to that parameter,
1321 // so we return the created placeholder. If there's no
1322 // match, 0 is returned, and we proceed with the regular
1323 // lookup.
1324 AST_Param_Holder *param_holder =
1325 UTL_Scope::match_param (e);
1327 if (param_holder)
1329 return param_holder;
1333 work_another_level = false; // Until we find something.
1334 bool in_corba =
1335 (ACE_OS::strcmp (e->head ()->get_string (), "CORBA") == 0);
1337 for (UTL_ScopeActiveIterator i (work, IK_decls);
1338 !i.is_done ();
1339 i.next ())
1341 d = i.item ()->adjust_found (true, full_def_only);
1342 if (d
1343 // Right now we populate the global scope with all the CORBA basic
1344 // types, so something like 'ULong' in an IDL file will find a
1345 // match, unless we skip over these items. This is a workaround until
1346 // there's time to fix the code generation for CORBA basic types.
1347 && (in_corba ||
1348 ACE_OS::strcmp (d->name ()->head ()->get_string (), "CORBA"))
1349 && d->local_name ()->case_compare (e->head ()))
1351 // Ok we found a match, is there any more to find?
1352 if (final_parent_decl)
1354 return d; // Last scope name matched
1357 UTL_Scope *next = DeclAsScope (d); // The next scope to search
1359 if (next)
1361 work = next;
1362 work_another_level = true;
1363 e = static_cast<UTL_ScopedName *> (e->tail ());
1364 final_parent_decl= (e->length () == 1) ? d : 0;
1365 break;
1368 // Template weirdness, actual one we want should be
1369 // found next in this search, keep going.
1372 } while (work_another_level);
1374 // A rare enough case that it's worth it to separate it and
1375 // do it as a last resort. Catches anonymnous types, enums
1376 // and members with their types defined all in one statement.
1377 if (final_parent_decl)
1379 for (UTL_ScopeActiveIterator i (work, IK_localtypes);
1380 !i.is_done ();
1381 i.next ())
1383 AST_Decl *d = i.item ();
1385 if (d->local_name ()->case_compare (e->head ()))
1387 return d;
1392 // Last resort, check other module openings of working scope.
1393 return work->special_lookup (e, full_def_only, final_parent_decl);
1396 // Add a node to set of nodes referenced in this scope.
1397 void
1398 UTL_Scope::add_to_referenced (AST_Decl *e,
1399 bool recursive,
1400 Identifier *id,
1401 AST_Decl *ex)
1403 // Empty name? Exit immediately.
1404 if (!e)
1406 return;
1409 // Special case for forward declared interfaces in the
1410 // scope in which they're defined. Cannot add before full
1411 // definition is seen.
1412 AST_Decl::NodeType nt = e->node_type ();
1413 if ( nt == AST_Decl::NT_interface
1414 || nt == AST_Decl::NT_component)
1416 AST_Interface *itf = AST_Interface::narrow_from_decl (e);
1417 if (itf
1418 && itf->defined_in () == this
1419 && !itf->is_defined ())
1421 return;
1425 // Only insert if it is not there already.
1426 if (this->referenced (e, id))
1428 return;
1431 // Sets the appropriate *_seen_ flag for future use.
1432 this->check_for_predef_seq (e);
1434 // Make sure there's space for one more decl.
1435 if (this->pd_referenced_allocated == this->pd_referenced_used)
1437 long oreferenced_allocated = this->pd_referenced_allocated;
1438 this->pd_referenced_allocated += INCREMENT;
1440 AST_Decl **tmp = 0;
1441 ACE_NEW (tmp, AST_Decl *[this->pd_referenced_allocated]);
1443 for (long i = 0; i < oreferenced_allocated; ++i)
1445 tmp [i] = this->pd_referenced [i];
1448 delete [] this->pd_referenced;
1449 this->pd_referenced = tmp;
1452 // Insert new reference.
1453 if (!ex)
1455 this->pd_referenced [this->pd_referenced_used++] = e;
1457 else if (this->referenced (ex))
1459 long i;
1460 for (i = this->pd_referenced_used;
1461 0 < i && this->pd_referenced [i - 1] != ex;
1462 --i)
1464 this->pd_referenced [i] = this->pd_referenced [i - 1];
1466 this->pd_referenced [i] = e;
1467 ++this->pd_referenced_used;
1470 // Now, if recursive is specified and "this" is not a common ancestor
1471 // of the referencing scope and the scope of definition of "e" then
1472 // add "e" to the set of referenced nodes in the parent of "this".
1473 if (recursive && !(e->has_ancestor (ScopeAsDecl (this))))
1475 UTL_Scope *s = e->defined_in ();
1476 if (s)
1478 s->add_to_referenced (e, recursive, id);
1482 // Add the identifier arg, if non-null, to the identifier list.
1483 if (id)
1485 this->add_to_name_referenced (id);
1489 void
1490 UTL_Scope::add_to_name_referenced (Identifier *id)
1492 // Make sure we have enough space.
1493 if (this->pd_name_referenced_allocated == this->pd_name_referenced_used)
1495 long name_referenced_allocated = this->pd_name_referenced_allocated;
1496 this->pd_name_referenced_allocated += INCREMENT;
1498 Identifier **name_tmp = 0;
1499 ACE_NEW (name_tmp, Identifier *[this->pd_name_referenced_allocated]);
1501 for (long i = 0; i < name_referenced_allocated; ++i)
1503 name_tmp[i] = this->pd_name_referenced[i];
1506 delete [] this->pd_name_referenced;
1507 this->pd_name_referenced = name_tmp;
1510 // Insert new identifier.
1511 this->pd_name_referenced[this->pd_name_referenced_used++] = id->copy ();
1514 void
1515 UTL_Scope::replace_referenced (AST_Decl *old_decl,
1516 AST_Decl *new_decl)
1518 for (int i = 0; i < this->pd_referenced_used; ++i)
1520 if (this->pd_referenced[i] == old_decl)
1522 this->pd_referenced[i] = new_decl;
1523 break;
1528 void
1529 UTL_Scope::replace_scope (AST_Decl *old_decl,
1530 AST_Decl *new_decl)
1532 for (int i = 0; i < pd_decls_used; ++i)
1534 if (this->pd_decls[i] == old_decl)
1536 this->pd_decls[i] = new_decl;
1537 break;
1542 // Add a node to set of nodes declared in this scope.
1543 void
1544 UTL_Scope::add_to_scope (AST_Decl *e,
1545 AST_Decl *ex)
1547 if (!e)
1549 return;
1552 Identifier *decl_name = e->local_name ();
1553 char *decl_string = decl_name->get_string ();
1554 AST_Decl::NodeType new_nt = e->node_type ();
1556 // First, make sure there's no clash between e, that was
1557 // just declared, and some other identifier referenced
1558 // in this scope.
1559 AST_Decl **tmp = this->pd_decls;
1560 for (long i = this->pd_decls_used;
1561 i--; // NOTE i-- test
1562 ++tmp)
1564 // A local declaration doesn't use a scoped name.
1565 Identifier *ref_name = (*tmp)->local_name ();
1566 char *ref_string = ref_name->get_string ();
1568 // If the names compare exactly, it's a redefini8tion
1569 // error, unless they're both modules (which can be
1570 // reopened) or we have a belated definition of a
1571 // forward-declared interface.
1572 AST_Decl::NodeType scope_elem_nt = (*tmp)->node_type ();
1574 if (this->redef_clash (new_nt, scope_elem_nt)
1575 && decl_name->compare (ref_name))
1577 idl_global->err ()->redef_error (decl_string,
1578 ref_string);
1580 // if we try to continue from here, we risk a crash.
1581 throw Bailout ();
1583 // If the spellings differ only by case, it's also an error,
1584 // unless one, but not both of the identifiers were escaped.
1585 else if (!(decl_name->escaped () ^ ref_name->escaped ())
1586 && decl_name->case_compare_quiet (ref_name))
1588 if (idl_global->case_diff_error ())
1590 idl_global->err ()->name_case_error (decl_string,
1591 ref_string);
1593 // if we try to continue from here, we risk a crash.
1594 throw Bailout ();
1596 else
1598 idl_global->err ()->name_case_warning (decl_string,
1599 ref_string);
1604 // The name of any scope except the unnamed scope formed by an operation
1605 // may not be redefined immediately within (and the root scope has no name).
1606 // As well as OBV factory construct.
1607 AST_Decl *d = ScopeAsDecl (this);
1608 AST_Decl::NodeType nt = d->node_type ();
1609 if ( nt != AST_Decl::NT_root
1610 && nt != AST_Decl::NT_op
1611 && nt != AST_Decl::NT_factory)
1613 Identifier *parent_name = d->local_name ();
1614 if (decl_name->compare (parent_name))
1616 idl_global->err ()->redef_error (
1617 decl_name->get_string (),
1618 parent_name->get_string ()
1621 // if we try to continue from here, we risk a crash.
1622 throw Bailout ();
1624 else if (decl_name->case_compare_quiet (parent_name))
1626 if (idl_global->case_diff_error ())
1628 idl_global->err ()->name_case_error (
1629 decl_name->get_string (),
1630 parent_name->get_string ()
1633 // if we try to continue from here, we risk a crash.
1634 throw Bailout ();
1636 else
1638 idl_global->err ()->name_case_warning (
1639 decl_name->get_string (),
1640 parent_name->get_string ()
1646 // Now make sure there's space for one more.
1647 if (this->pd_decls_allocated == this->pd_decls_used)
1649 long odecls_allocated = this->pd_decls_allocated;
1650 this->pd_decls_allocated += INCREMENT;
1652 ACE_NEW (tmp, AST_Decl *[pd_decls_allocated]);
1653 for (long i = 0; i < odecls_allocated; ++i)
1655 tmp [i] = this->pd_decls [i];
1658 delete [] this->pd_decls;
1659 this->pd_decls = tmp;
1662 // Insert new decl.
1663 if (!ex)
1665 this->pd_decls [this->pd_decls_used++] = e;
1667 else
1669 long i;
1670 for (i = this->pd_decls_used;
1671 0 < i && this->pd_decls [i - 1] != ex;
1672 --i)
1674 this->pd_decls [i] = this->pd_decls [i - 1];
1676 this->pd_decls [i] = e;
1677 ++this->pd_decls_used;
1681 // Add a node to set of nodes representing manifest
1682 // types defined in this scope.
1683 void
1684 UTL_Scope::add_to_local_types (AST_Decl *e)
1686 if (!e)
1688 return;
1691 // Make sure there's space for one more.
1692 if (this->pd_locals_allocated == this->pd_locals_used)
1694 long olocals_allocated = this->pd_locals_allocated;
1695 this->pd_locals_allocated += INCREMENT;
1697 AST_Decl **tmp = 0;
1698 ACE_NEW (tmp, AST_Decl *[this->pd_locals_allocated]);
1699 for (long i = 0; i < olocals_allocated; ++i)
1701 tmp[i] = this->pd_local_types[i];
1704 delete [] this->pd_local_types;
1705 this->pd_local_types = tmp;
1708 // Insert new decl.
1709 this->pd_local_types[this->pd_locals_used++] = e;
1712 // Has this node been referenced here before?
1713 bool
1714 UTL_Scope::referenced (AST_Decl *e,
1715 Identifier *id)
1717 Identifier *test = e->local_name ();
1718 AST_Decl::NodeType nt = e->node_type ();
1720 AST_Decl **tmp = this->pd_referenced;
1721 for (long i = this->pd_referenced_used;
1722 i--; // NOTE test with i--
1723 ++tmp)
1725 // Same node?
1726 if (*tmp == e)
1728 return true;
1731 // Are we definging a forward declared struct, union, or interface,
1732 // or reopening a module?
1733 if (!this->redef_clash (nt, (*tmp)->node_type ())
1734 && (*tmp)->local_name ()->compare (test))
1736 return false;
1740 // pd_referenced is a list of decls, and so there's no
1741 // way of telling how much of its scoped name was used
1742 // when it was referenced in this scope. pd_name_referenced
1743 // is a list of Identifiers that store the identifier (or
1744 // the first segment of a scoped name) used in the reference,
1745 // so we can catch these name reolution clashes.
1746 if (id)
1748 Identifier **name_tmp = this->pd_name_referenced;
1749 for (long j = this->pd_name_referenced_used;
1750 j--; // NOTE test with j--
1751 ++name_tmp)
1753 // If we are a module, there is no clash, if we
1754 // are an interface, this is not the right place to
1755 // catch a clash, and if it wasn't defined in this
1756 // scope, then it's a type name for something else
1757 // that was, and it can appear any number of times
1758 // in this scope without a clash.
1759 AST_Decl::NodeType nt = e->node_type ();
1760 if ( nt != AST_Decl::NT_module
1761 && nt != AST_Decl::NT_param_holder
1762 && e->defined_in () == this
1763 && id->compare (*name_tmp))
1765 idl_global->err ()->redef_error (id->get_string (),
1766 (*name_tmp)->get_string ());
1767 return true;
1769 // No clash if one or the other of the identifiers was escaped.
1770 else if (!(id->escaped () ^ (*name_tmp)->escaped ())
1771 && id->case_compare_quiet (*name_tmp))
1773 if (idl_global->case_diff_error ())
1775 idl_global->err ()->name_case_error (
1776 id->get_string (),
1777 (*name_tmp)->get_string ()
1780 else
1782 idl_global->err ()->name_case_warning (
1783 id->get_string (),
1784 (*name_tmp)->get_string ()
1788 return true;
1793 // Not found
1794 return false;
1797 bool
1798 UTL_Scope::has_prefix (void)
1800 return this->has_prefix_;
1803 void
1804 UTL_Scope::has_prefix (bool val)
1806 this->has_prefix_ = val;
1809 // Redefinition of inherited virtual operations.
1811 // AST Dumping.
1812 void
1813 UTL_Scope::dump (ACE_OSTREAM_TYPE &o)
1815 if (!idl_global->indent ())
1817 UTL_Indenter *idnt = 0;
1818 ACE_NEW (idnt, UTL_Indenter);
1819 idl_global->set_indent (idnt);
1821 idl_global->indent ()->increase ();
1823 if (0 < this->pd_locals_used)
1825 o << '\n';
1826 idl_global->indent ()->skip_to (o);
1827 o << ACE_TEXT ("/* Locally defined types: */\n");
1829 for (UTL_ScopeActiveIterator i (this, IK_localtypes);
1830 !i.is_done ();
1831 i.next ())
1833 AST_Decl *d = i.item ();
1835 if (d->should_be_dumped () && !d->imported ())
1837 idl_global->indent ()->skip_to (o);
1838 o << *d << ACE_TEXT (";\n");
1843 if (0 < this->pd_decls_used)
1845 o << '\n';
1846 idl_global->indent ()->skip_to (o);
1847 o << ACE_TEXT ("/* Declarations: */\n");
1849 for (UTL_ScopeActiveIterator j (this, IK_decls);
1850 !j.is_done ();
1851 j.next ())
1853 AST_Decl *d = j.item ();
1855 if (d->should_be_dumped () && !d->imported ())
1857 idl_global->indent ()->skip_to (o);
1858 o << *d << ACE_TEXT (";\n");
1863 idl_global->indent ()->decrease ();
1867 UTL_Scope::ast_accept (ast_visitor *visitor)
1869 return visitor->visit_scope (this);
1872 // How many entries are defined?
1873 unsigned long
1874 UTL_Scope::nmembers (void)
1876 return this->pd_decls_used;
1879 AST_Param_Holder *
1880 UTL_Scope::match_param (UTL_ScopedName *e)
1882 // If this call returns a zero value, we are not in the scope
1883 // of a template module.
1884 FE_Utils::T_PARAMLIST_INFO const *params =
1885 idl_global->current_params ();
1887 if (params == 0)
1889 return 0;
1892 const char *name = e->first_component ()->get_string ();
1893 FE_Utils::T_Param_Info *param = 0;
1894 unsigned long index = 0;
1896 UTL_StrList *alias_params =
1897 const_cast<UTL_StrList *> (idl_global->for_new_holder ());
1899 if (alias_params == 0)
1901 alias_params =
1902 const_cast<UTL_StrList *> (idl_global->alias_params ());
1905 UTL_String *alias_param = 0;
1907 for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR i (*params);
1908 i.next (param);
1909 i.advance (), ++index)
1911 if (param->name_ == name)
1913 /// If we are parsing this template module as a
1914 /// reference, the param holder we create must have
1915 /// the name of the corresponding aliased param.
1916 if (alias_params != 0)
1918 unsigned long slot = 0;
1920 for (UTL_StrlistActiveIterator iter (alias_params);
1921 !iter.is_done ();
1922 iter.next (), ++slot)
1924 if (slot == index)
1926 alias_param = iter.item ();
1927 break;
1931 if (alias_param == 0)
1933 ACE_ERROR_RETURN ((LM_ERROR,
1934 ACE_TEXT ("UTL_Scope::match_param - ")
1935 ACE_TEXT ("param not matched\n")),
1939 Identifier id (alias_param->get_string ());
1940 UTL_ScopedName sn (&id, 0);
1942 return
1943 idl_global->gen ()->create_param_holder (
1944 &sn,
1945 param);
1947 else
1949 return
1950 idl_global->gen ()->create_param_holder (
1952 param);
1957 return 0;
1960 bool
1961 UTL_Scope::inherited_op_attr_clash (AST_Decl *t)
1963 AST_Interface *i = AST_Interface::narrow_from_scope (this);
1964 if (!i)
1966 return false;
1969 AST_Decl *d = i->look_in_inherited (t->name (), false);
1970 if (d)
1972 AST_Decl::NodeType nt = d->node_type ();
1973 if ( nt == AST_Decl::NT_attr
1974 || nt == AST_Decl::NT_op)
1976 idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
1980 return true;
1984 return false;
1987 bool
1988 UTL_Scope::arg_specific_error (AST_Decl *t)
1990 AST_Operation *op = AST_Operation::narrow_from_scope (this);
1991 if (!op)
1993 return false;
1996 AST_Argument *arg = AST_Argument::narrow_from_decl (t);
1997 AST_Argument::Direction d = arg->direction ();
1999 // Cannot add OUT or INOUT argument to oneway operation.
2000 if (( d == AST_Argument::dir_OUT
2001 || d == AST_Argument::dir_INOUT)
2002 && op->flags () == AST_Operation::OP_oneway)
2004 idl_global->err ()->error2 (UTL_Error::EIDL_ONEWAY_CONFLICT,
2006 op);
2007 return true;
2010 // This error is not caught in y.tab.cpp so we check for it here.
2011 AST_Type *arg_type = arg->field_type ();
2012 if ( arg_type->node_type () == AST_Decl::NT_array
2013 && arg_type->anonymous ())
2015 idl_global->err ()->syntax_error (idl_global->parse_state ());
2016 return true;
2019 return false;
2022 void
2023 UTL_Scope::smart_local_add (AST_Decl *t)
2025 // Catches struct, union * exception
2026 AST_Structure *s = AST_Structure::narrow_from_scope (this);
2028 // Catches AST_Field and AST_UnionBranch.
2029 AST_Field *f = AST_Field::narrow_from_decl (t);
2031 // Decls inside a struct/union/exception are also referenced by
2032 // fields, and so must be handled differently.
2033 if (s && !f)
2035 this->add_to_local_types (t);
2037 else
2039 this->add_to_scope (t);
2042 // If we have an enum discriminator, add the label names to
2043 // the name_referenced list before we add the union branch,
2044 // so a branch name clash with a label name will be caught.
2045 AST_Union *u = AST_Union::narrow_from_scope (this);
2046 AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (t);
2047 if (u && ub)
2049 if (u->udisc_type () == AST_Expression::EV_enum)
2051 ub->add_labels (u);
2053 else
2055 ub->coerce_labels (u);
2060 // Determines if a name is global.
2061 bool
2062 UTL_Scope::is_global_name (Identifier *i)
2064 if (!i)
2066 return false;
2069 ACE_CString cmp (i->get_string (), 0, false);
2070 return (cmp == "" || cmp == "::");
2073 AST_Decl *
2074 UTL_Scope::iter_lookup_by_name_local (AST_Decl *d,
2075 UTL_ScopedName *e,
2076 bool full_def_only)
2078 // Remove all the layers of typedefs.
2079 while (d && d->node_type () == AST_Decl::NT_typedef)
2081 AST_Typedef *td = AST_Typedef::narrow_from_decl (d);
2082 if (!td)
2084 return 0;
2087 d = td->base_type ();
2090 if (!d)
2092 return 0;
2095 // Try to convert the AST_Decl to a UTL_Scope.
2096 UTL_Scope *sc = DeclAsScope (d);
2097 if (!sc)
2099 return 0;
2102 AST_Decl *result = 0;
2103 if (0 < sc->nmembers ())
2105 // Look up the first component of the scoped name.
2106 result = sc->lookup_by_name_local (e->head (),
2107 full_def_only);
2109 else
2111 AST_Interface *i = AST_Interface::narrow_from_decl (d);
2112 result = i ? i->look_in_inherited_local (e->head ())
2113 : sc->look_in_prev_mods_local (e->head (), true);
2116 UTL_ScopedName *sn = (UTL_ScopedName *) e->tail ();
2117 if (!result)
2119 if (!sn)
2121 result = UTL_Scope::match_param (e);
2124 else if (sn)
2126 // Look up the next component of the scoped name.
2127 result = iter_lookup_by_name_local (result,
2129 full_def_only);
2132 return result;
2135 IMPL_NARROW_FROM_SCOPE(UTL_Scope)
2137 // UTL_SCOPE_ACTIVE_ITERATOR
2139 // Constructor.
2140 UTL_ScopeActiveIterator::UTL_ScopeActiveIterator (
2141 UTL_Scope *s,
2142 UTL_Scope::ScopeIterationKind i
2144 : iter_source (s),
2145 ik (i),
2146 stage (i == UTL_Scope::IK_both ? UTL_Scope::IK_localtypes : i),
2147 il (0)
2151 // Public operations.
2153 // Advance to next item.
2154 void
2155 UTL_ScopeActiveIterator::next (void)
2157 this->il++;
2160 // Get current item.
2161 AST_Decl *
2162 UTL_ScopeActiveIterator::item (void)
2164 if (this->is_done ())
2166 return 0;
2169 if (stage == UTL_Scope::IK_decls)
2171 return this->iter_source->pd_decls[il];
2174 if (stage == UTL_Scope::IK_localtypes)
2176 return this->iter_source->pd_local_types[il];
2179 return 0;
2182 // Is this iteration done?
2183 bool
2184 UTL_ScopeActiveIterator::is_done (void)
2186 long limit =
2187 (stage == UTL_Scope::IK_decls)
2188 ? iter_source->pd_decls_used
2189 : iter_source->pd_locals_used;
2191 for (;;)
2193 // Last element?
2194 if (this->il < limit)
2196 return false;
2199 // Only want decls?
2200 if (this->stage == UTL_Scope::IK_decls)
2202 return true;
2205 // Already done local types?
2206 if (this->ik == UTL_Scope::IK_localtypes)
2208 return true;
2211 // Switch to next stage.
2212 this->stage = UTL_Scope::IK_decls;
2213 this->il = 0;
2214 limit = this->iter_source->pd_decls_used;
2218 // What kind of iterator is this?
2219 UTL_Scope::ScopeIterationKind
2220 UTL_ScopeActiveIterator::iteration_kind (void)
2222 return this->ik;
2225 // And where are we in the iteration?
2226 UTL_Scope::ScopeIterationKind
2227 UTL_ScopeActiveIterator::iteration_stage (void)
2229 return this->stage;
2232 AST_Annotation_Decl *
2233 UTL_Scope::fe_add_annotation_decl (AST_Annotation_Decl * /*annotation_decl*/)
2235 return 0;
2238 AST_Annotation_Member *
2239 UTL_Scope::fe_add_annotation_member (AST_Annotation_Member * /*annotation_member*/)
2241 return 0;
2244 AST_Decl *
2245 UTL_Scope::lookup_by_name (const char *name)
2247 AST_Decl *node = 0;
2248 UTL_ScopedName *scoped_name = FE_Utils::string_to_scoped_name (name);
2249 node = lookup_by_name (scoped_name);
2250 scoped_name->destroy ();
2251 delete scoped_name;
2252 return node;