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
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
56 Mountain View, California 94043
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // AST_Modules denote IDL module declarations
66 // AST_Modules are subclasses of AST_Decl (they are not a type!) and
69 #include "ast_module.h"
70 #include "ast_template_module_inst.h"
71 #include "ast_predefined_type.h"
72 #include "ast_valuebox.h"
73 #include "ast_valuetype.h"
74 #include "ast_valuetype_fwd.h"
75 #include "ast_eventtype.h"
76 #include "ast_eventtype_fwd.h"
77 #include "ast_component.h"
78 #include "ast_component_fwd.h"
79 #include "ast_porttype.h"
80 #include "ast_connector.h"
82 #include "ast_constant.h"
83 #include "ast_exception.h"
84 #include "ast_union.h"
85 #include "ast_union_fwd.h"
86 #include "ast_structure_fwd.h"
88 #include "ast_enum_val.h"
89 #include "ast_typedef.h"
90 #include "ast_native.h"
91 #include "ast_generator.h"
92 #include "ast_visitor.h"
93 #include "ast_extern.h"
96 #include "utl_identifier.h"
97 #include "utl_indenter.h"
99 #include "global_extern.h"
100 #include "nr_extern.h"
102 AST_Decl::NodeType
const
103 AST_Module::NT
= AST_Decl::NT_module
;
105 AST_Module::AST_Module (UTL_ScopedName
*n
, AST_Module
*previous
)
106 : AST_Decl (AST_Decl::NT_module
, n
),
107 UTL_Scope (AST_Decl::NT_module
),
108 pd_has_nested_valuetype_ (0),
109 previous_opening_ (previous
),
110 last_in_same_parent_scope_ (this),
114 // NOTE previous passed into this constructor should be
115 // the FIRST module that is a previous opening of this same
116 // module in the scope in which it is stored. Later on if
117 // the module is validated and added to it's scope, the
118 // previous_opening_ will be adjusted to be the immediatly
119 // previous opening of this module. See fe_add_module ()
123 AST_Module::~AST_Module (void)
128 AST_Module::destroy (void)
130 this->UTL_Scope::destroy ();
131 this->AST_Decl::destroy ();
134 IMPL_NARROW_FROM_DECL(AST_Module
)
135 IMPL_NARROW_FROM_SCOPE(AST_Module
)
137 // Dump this AST_Module node to the ostream o.
139 AST_Module::dump (ACE_OSTREAM_TYPE
&o
)
141 this->dump_i (o
, "module ");
142 this->local_name ()->dump (o
);
143 this->dump_i (o
, " {\n");
145 idl_global
->indent ()->skip_to (o
);
146 this->dump_i (o
, "}");
149 // We actually want to match the LAST module found in
150 // the scope being searched not the FIRST one in the
153 AST_Module::adjust_found (
155 bool /*full_def_only*/)
157 return this->last_in_same_parent_scope_
;
160 // Involved in OBV_ namespace generation.
162 AST_Module::set_has_nested_valuetype (void)
164 UTL_Scope
*parent
= this->defined_in ();
165 if (parent
&& !this->pd_has_nested_valuetype_
)
167 AST_Module
*pm
= dynamic_cast<AST_Module
*> (parent
);
170 pm
->set_has_nested_valuetype ();
174 this->pd_has_nested_valuetype_
= 1;
178 AST_Module::has_nested_valuetype (void)
180 return this->pd_has_nested_valuetype_
;
184 AST_Module::be_add_interface (AST_Interface
*i
,
188 this->add_to_scope (i
, ix
);
190 // Add it to set of locally referenced symbols.
191 this->add_to_referenced (i
,
199 AST_Module::be_add_valuetype (AST_ValueType
*v
)
202 this->add_to_scope (v
);
204 // Add it to set of locally referenced symbols.
205 this->add_to_referenced (v
,
211 // Has this node been referenced here before?
213 AST_Module::referenced (AST_Decl
*e
,
216 bool refd
= this->UTL_Scope::referenced (e
, id
);
223 this->look_in_prev_mods_local (e
->local_name (), true);
229 AST_Type
*t
= dynamic_cast<AST_Type
*> (d
);
230 return (!t
|| t
->is_defined ());
234 AST_Module::previous_opening ()
236 return this->previous_opening_
;
240 AST_Module::look_in_prev_mods_local (Identifier
*e
,
243 for (AST_Module
*po
= this->previous_opening_
;
245 po
= po
->previous_opening_
)
247 for (UTL_ScopeActiveIterator
iter (po
, UTL_Scope::IK_decls
);
251 AST_Decl
*d
= iter
.item ();
252 if ((!ignore_fwd
|| !d
->is_fwd ())
253 && !!(d
= d
->adjust_found (ignore_fwd
, false))
254 && e
->case_compare (d
->local_name ()))
265 AST_Module::look_in_prev_mods (UTL_ScopedName
*e
,
267 AST_Decl
*&final_parent_decl
)
269 for (AST_Module
*po
= this->previous_opening_
;
271 po
= po
->previous_opening_
)
273 for (UTL_ScopeActiveIterator
iter (po
, UTL_Scope::IK_decls
);
278 iter
.item ()->adjust_found (full_def_only
, full_def_only
);
280 if (d
&& e
->head ()->case_compare (d
->local_name ()))
283 static_cast<UTL_ScopedName
*> (e
->tail ());
286 final_parent_decl
= static_cast<AST_Decl
*> (po
);
287 return d
; // Nothing left in path, found wanted name
290 UTL_Scope
*s
= DeclAsScope (d
);
293 // Recurse down what is left of the path
294 return s
->lookup_by_name_r (sn
, full_def_only
, final_parent_decl
);
297 // Find next match, this one didn't work out.
302 return 0; // Not found.
306 AST_Module::ast_accept (ast_visitor
*visitor
)
308 return visitor
->visit_module (this);
311 AST_Template_Module_Inst
*
312 AST_Module::from_inst (void) const
314 return this->from_inst_
;
318 AST_Module::from_inst (AST_Template_Module_Inst
*node
)
320 this->from_inst_
= node
;
323 AST_Template_Module_Ref
*
324 AST_Module::from_ref (void) const
326 return this->from_ref_
;
330 AST_Module::from_ref (AST_Template_Module_Ref
*node
)
332 this->from_ref_
= node
;
336 AST_Module::special_lookup (UTL_ScopedName
*e
,
338 AST_Decl
*&final_parent_decl
)
340 return this->look_in_prev_mods (e
, full_def_only
, final_parent_decl
);
343 //================================================
346 AST_Module::fe_add_predefined_type (AST_PredefinedType
*t
)
348 return dynamic_cast<AST_PredefinedType
*> (this->fe_add_decl (t
));
352 AST_Module::fe_add_module (AST_Module
*t
)
354 // If our prefix is empty, we check to see if an ancestor has one.
355 if (!ACE_OS::strcmp (t
->prefix (), ""))
357 UTL_Scope
*scope
= t
->defined_in ();
360 AST_Decl
*parent
= ScopeAsDecl (scope
);
361 const char *prefix_holder
= parent
->prefix ();
365 break; // We have reached global scope.
368 t
->prefix (const_cast<char *> (prefix_holder
));
370 if (ACE_OS::strcmp (t
->prefix (), ""))
375 scope
= parent
->defined_in ();
379 // Already defined and cannot be redefined? Or already used?
381 AST_Decl
*d
= this->lookup_for_add (t
);
385 if (!FE_Utils::can_be_redefined (d
, t
))
387 idl_global
->err ()->error3 (UTL_Error::EIDL_REDEF
,
394 // has_ancestor() returns TRUE if both nodes are the same.
395 m
= dynamic_cast<AST_Module
*> (d
);
396 if (t
!= m
&& t
->has_ancestor (d
))
398 idl_global
->err ()->redefinition_in_scope (t
, d
);
402 const char *prev_prefix
= d
->prefix ();
403 const char *this_prefix
= t
->prefix ();
405 if (!ACE_OS::strcmp (this_prefix
, ""))
407 t
->prefix (const_cast<char *> (prev_prefix
));
409 else if (!ACE_OS::strcmp (prev_prefix
, ""))
411 d
->prefix (const_cast<char *> (this_prefix
));
415 // Now we are actually adding this new module to the active
416 // scopes, ensure that the previous openings are all updated
417 // so that this new module is recorded as the current
418 // "last module" definition in our scope.
419 AST_Module
*first_opening
= t
->previous_opening_
;
422 // When we created the module we simply stored the first
423 // previous module we found (if any), we actually want
424 // to refer to that module's LAST opening in that same scope
425 // except this module itself (which isn't yet recorded anyway).
426 t
->previous_opening_
= first_opening
->last_in_same_parent_scope_
;
427 if (first_opening
->defined_in () == this)
429 // Since the previous openings are in our own scope,
430 // make sure that these all point to this new module.
431 for (AST_Module
*pm
= t
->previous_opening_
;
433 pm
= pm
->previous_opening_
)
435 pm
->last_in_same_parent_scope_
= t
;
436 if (pm
== first_opening
)
438 // Even if there are still more previous modules,
439 // the ones before this one are in a different
440 // scope and do not need to be updated.
447 // If this node is not a reopened module, add it to scope and referenced.
451 this->add_to_scope (t
);
453 // Add it to set of locally referenced symbols.
454 this->add_to_referenced (t
,
462 AST_Template_Module_Inst
*
463 AST_Module::fe_add_template_module_inst (AST_Template_Module_Inst
*t
)
465 return dynamic_cast<AST_Template_Module_Inst
*> (this->fe_add_ref_decl (t
));
469 AST_Module::fe_add_interface (AST_Interface
*t
)
471 return this->fe_add_full_intf_decl
<AST_Interface
> (t
);
475 AST_Module::fe_add_valuebox (AST_ValueBox
*t
)
477 return dynamic_cast<AST_ValueBox
*> (this->fe_add_decl (t
));
481 AST_Module::fe_add_valuetype (AST_ValueType
*t
)
483 return this->fe_add_full_intf_decl
<AST_ValueType
> (t
);
487 AST_Module::fe_add_eventtype (AST_EventType
*t
)
489 return this->fe_add_full_intf_decl
<AST_EventType
> (t
);
493 AST_Module::fe_add_component (AST_Component
*t
)
495 return this->fe_add_full_intf_decl
<AST_Component
> (t
);
499 AST_Module::fe_add_connector (AST_Connector
*t
)
501 return dynamic_cast<AST_Connector
*> (this->fe_add_decl (t
));
505 AST_Module::fe_add_home (AST_Home
*t
)
507 return dynamic_cast<AST_Home
*> (this->fe_add_decl (t
));
511 AST_Module::fe_add_interface_fwd (AST_InterfaceFwd
*t
)
513 return this->fe_add_fwd_intf_decl
<AST_Interface
> (t
);
517 AST_Module::fe_add_valuetype_fwd (AST_ValueTypeFwd
*t
)
519 return this->fe_add_fwd_intf_decl
<AST_ValueType
> (t
);
523 AST_Module::fe_add_eventtype_fwd (AST_EventTypeFwd
*t
)
525 return this->fe_add_fwd_intf_decl
<AST_EventType
> (t
);
529 AST_Module::fe_add_component_fwd (AST_ComponentFwd
*t
)
531 return this->fe_add_fwd_intf_decl
<AST_Component
> (t
);
535 AST_Module::fe_add_constant (AST_Constant
*t
)
537 return dynamic_cast<AST_Constant
*> (this->fe_add_decl (t
));
541 AST_Module::fe_add_exception (AST_Exception
*t
)
543 return dynamic_cast<AST_Exception
*> (this->fe_add_decl (t
));
547 AST_Module::fe_add_union (AST_Union
*t
)
549 return dynamic_cast<AST_Union
*> (this->fe_add_full_struct_type (t
));
553 AST_Module::fe_add_union_fwd (AST_UnionFwd
*t
)
555 return dynamic_cast<AST_UnionFwd
*> (this->fe_add_fwd_struct_type (t
));
559 AST_Module::fe_add_structure (AST_Structure
*t
)
561 return this->fe_add_full_struct_type (t
);
565 AST_Module::fe_add_structure_fwd (AST_StructureFwd
*t
)
567 return this->fe_add_fwd_struct_type (t
);
571 AST_Module::fe_add_enum (AST_Enum
*t
)
573 return dynamic_cast<AST_Enum
*> (this->fe_add_decl (t
));
576 // Add an AST_EnumVal node (an enumerator) to this scope.
577 // This is done to conform to the C++ scoping rules which declare
578 // enumerators in the enclosing scope (in addition to declaring them
579 // in the enum itself).
581 AST_Module::fe_add_enum_val (AST_EnumVal
*t
)
583 return dynamic_cast<AST_EnumVal
*> (this->fe_add_decl (t
));
587 AST_Module::fe_add_typedef (AST_Typedef
*t
)
589 return dynamic_cast<AST_Typedef
*> (this->fe_add_ref_decl (t
));
593 AST_Module::fe_add_native (AST_Native
*t
)
595 return dynamic_cast<AST_Native
*> (this->fe_add_decl (t
));
599 AST_Module::fe_add_porttype (AST_PortType
*t
)
601 return dynamic_cast<AST_PortType
*> (this->fe_add_decl (t
));
605 AST_Module::reset_last_in_same_parent_scope (void)
607 this->last_in_same_parent_scope_
= this;
610 AST_Annotation_Decl
*
611 AST_Module::fe_add_annotation_decl (
612 AST_Annotation_Decl
*annotation_decl
)
614 return dynamic_cast<AST_Annotation_Decl
*> (fe_add_decl (annotation_decl
));