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_ (false),
109 previous_opening_ (previous
),
110 last_in_same_parent_scope_ (this),
111 from_inst_ (nullptr),
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 ()
128 AST_Module::destroy ()
130 this->UTL_Scope::destroy ();
131 this->AST_Decl::destroy ();
134 // Dump this AST_Module node to the ostream o.
136 AST_Module::dump (ACE_OSTREAM_TYPE
&o
)
138 this->dump_i (o
, "module ");
139 this->local_name ()->dump (o
);
140 this->dump_i (o
, " {\n");
142 idl_global
->indent ()->skip_to (o
);
143 this->dump_i (o
, "}");
146 // We actually want to match the LAST module found in
147 // the scope being searched not the FIRST one in the
150 AST_Module::adjust_found (
152 bool /*full_def_only*/)
154 return this->last_in_same_parent_scope_
;
157 // Involved in OBV_ namespace generation.
159 AST_Module::set_has_nested_valuetype ()
161 UTL_Scope
*parent
= this->defined_in ();
162 if (parent
&& !this->pd_has_nested_valuetype_
)
164 AST_Module
*pm
= dynamic_cast<AST_Module
*> (parent
);
167 pm
->set_has_nested_valuetype ();
171 this->pd_has_nested_valuetype_
= true;
175 AST_Module::has_nested_valuetype ()
177 return this->pd_has_nested_valuetype_
;
181 AST_Module::be_add_interface (AST_Interface
*i
,
185 this->add_to_scope (i
, ix
);
187 // Add it to set of locally referenced symbols.
188 this->add_to_referenced (i
,
196 AST_Module::be_add_valuetype (AST_ValueType
*v
)
199 this->add_to_scope (v
);
201 // Add it to set of locally referenced symbols.
202 this->add_to_referenced (v
,
208 // Has this node been referenced here before?
210 AST_Module::referenced (AST_Decl
*e
,
213 bool refd
= this->UTL_Scope::referenced (e
, id
);
220 this->look_in_prev_mods_local (e
->local_name (), true);
226 AST_Type
*t
= dynamic_cast<AST_Type
*> (d
);
227 return (!t
|| t
->is_defined ());
231 AST_Module::previous_opening ()
233 return this->previous_opening_
;
237 AST_Module::look_in_prev_mods_local (Identifier
*e
,
240 for (AST_Module
*po
= this->previous_opening_
;
242 po
= po
->previous_opening_
)
244 for (UTL_ScopeActiveIterator
iter (po
, UTL_Scope::IK_decls
);
248 AST_Decl
*d
= iter
.item ();
249 if ((!ignore_fwd
|| !d
->is_fwd ())
250 && !!(d
= d
->adjust_found (ignore_fwd
, false))
251 && e
->case_compare (d
->local_name ()))
262 AST_Module::look_in_prev_mods (UTL_ScopedName
*e
,
264 AST_Decl
*&final_parent_decl
)
266 for (AST_Module
*po
= this->previous_opening_
;
268 po
= po
->previous_opening_
)
270 for (UTL_ScopeActiveIterator
iter (po
, UTL_Scope::IK_decls
);
275 iter
.item ()->adjust_found (full_def_only
, full_def_only
);
277 if (d
&& e
->head ()->case_compare (d
->local_name ()))
280 static_cast<UTL_ScopedName
*> (e
->tail ());
283 final_parent_decl
= static_cast<AST_Decl
*> (po
);
284 return d
; // Nothing left in path, found wanted name
287 UTL_Scope
*s
= DeclAsScope (d
);
290 // Recurse down what is left of the path
291 return s
->lookup_by_name_r (sn
, full_def_only
, final_parent_decl
);
294 // Find next match, this one didn't work out.
299 return nullptr; // Not found.
303 AST_Module::ast_accept (ast_visitor
*visitor
)
305 return visitor
->visit_module (this);
308 AST_Template_Module_Inst
*
309 AST_Module::from_inst () const
311 return this->from_inst_
;
315 AST_Module::from_inst (AST_Template_Module_Inst
*node
)
317 this->from_inst_
= node
;
320 AST_Template_Module_Ref
*
321 AST_Module::from_ref () const
323 return this->from_ref_
;
327 AST_Module::from_ref (AST_Template_Module_Ref
*node
)
329 this->from_ref_
= node
;
333 AST_Module::special_lookup (UTL_ScopedName
*e
,
335 AST_Decl
*&final_parent_decl
)
337 return this->look_in_prev_mods (e
, full_def_only
, final_parent_decl
);
340 //================================================
343 AST_Module::fe_add_predefined_type (AST_PredefinedType
*t
)
345 return dynamic_cast<AST_PredefinedType
*> (this->fe_add_decl (t
));
349 AST_Module::fe_add_module (AST_Module
*t
)
351 // If our prefix is empty, we check to see if an ancestor has one.
352 if (!ACE_OS::strcmp (t
->prefix (), ""))
354 UTL_Scope
*scope
= t
->defined_in ();
357 AST_Decl
*parent
= ScopeAsDecl (scope
);
358 const char *prefix_holder
= parent
->prefix ();
362 break; // We have reached global scope.
365 t
->prefix (const_cast<char *> (prefix_holder
));
367 if (ACE_OS::strcmp (t
->prefix (), ""))
372 scope
= parent
->defined_in ();
376 // Already defined and cannot be redefined? Or already used?
377 AST_Module
*m
= nullptr;
378 AST_Decl
*d
= this->lookup_for_add (t
);
382 if (!FE_Utils::can_be_redefined (d
, t
))
384 idl_global
->err ()->error3 (UTL_Error::EIDL_REDEF
,
391 // has_ancestor() returns TRUE if both nodes are the same.
392 m
= dynamic_cast<AST_Module
*> (d
);
393 if (t
!= m
&& t
->has_ancestor (d
))
395 idl_global
->err ()->redefinition_in_scope (t
, d
);
399 const char *prev_prefix
= d
->prefix ();
400 const char *this_prefix
= t
->prefix ();
402 if (!ACE_OS::strcmp (this_prefix
, ""))
404 t
->prefix (const_cast<char *> (prev_prefix
));
406 else if (!ACE_OS::strcmp (prev_prefix
, ""))
408 d
->prefix (const_cast<char *> (this_prefix
));
412 // Now we are actually adding this new module to the active
413 // scopes, ensure that the previous openings are all updated
414 // so that this new module is recorded as the current
415 // "last module" definition in our scope.
416 AST_Module
*first_opening
= t
->previous_opening_
;
419 // When we created the module we simply stored the first
420 // previous module we found (if any), we actually want
421 // to refer to that module's LAST opening in that same scope
422 // except this module itself (which isn't yet recorded anyway).
423 t
->previous_opening_
= first_opening
->last_in_same_parent_scope_
;
424 if (first_opening
->defined_in () == this)
426 // Since the previous openings are in our own scope,
427 // make sure that these all point to this new module.
428 for (AST_Module
*pm
= t
->previous_opening_
;
430 pm
= pm
->previous_opening_
)
432 pm
->last_in_same_parent_scope_
= t
;
433 if (pm
== first_opening
)
435 // Even if there are still more previous modules,
436 // the ones before this one are in a different
437 // scope and do not need to be updated.
444 // If this node is not a reopened module, add it to scope and referenced.
448 this->add_to_scope (t
);
450 // Add it to set of locally referenced symbols.
451 this->add_to_referenced (t
,
459 AST_Template_Module_Inst
*
460 AST_Module::fe_add_template_module_inst (AST_Template_Module_Inst
*t
)
462 return dynamic_cast<AST_Template_Module_Inst
*> (this->fe_add_ref_decl (t
));
466 AST_Module::fe_add_interface (AST_Interface
*t
)
468 return this->fe_add_full_intf_decl
<AST_Interface
> (t
);
472 AST_Module::fe_add_valuebox (AST_ValueBox
*t
)
474 return dynamic_cast<AST_ValueBox
*> (this->fe_add_decl (t
));
478 AST_Module::fe_add_valuetype (AST_ValueType
*t
)
480 return this->fe_add_full_intf_decl
<AST_ValueType
> (t
);
484 AST_Module::fe_add_eventtype (AST_EventType
*t
)
486 return this->fe_add_full_intf_decl
<AST_EventType
> (t
);
490 AST_Module::fe_add_component (AST_Component
*t
)
492 return this->fe_add_full_intf_decl
<AST_Component
> (t
);
496 AST_Module::fe_add_connector (AST_Connector
*t
)
498 return dynamic_cast<AST_Connector
*> (this->fe_add_decl (t
));
502 AST_Module::fe_add_home (AST_Home
*t
)
504 return dynamic_cast<AST_Home
*> (this->fe_add_decl (t
));
508 AST_Module::fe_add_interface_fwd (AST_InterfaceFwd
*t
)
510 return this->fe_add_fwd_intf_decl
<AST_Interface
> (t
);
514 AST_Module::fe_add_valuetype_fwd (AST_ValueTypeFwd
*t
)
516 return this->fe_add_fwd_intf_decl
<AST_ValueType
> (t
);
520 AST_Module::fe_add_eventtype_fwd (AST_EventTypeFwd
*t
)
522 return this->fe_add_fwd_intf_decl
<AST_EventType
> (t
);
526 AST_Module::fe_add_component_fwd (AST_ComponentFwd
*t
)
528 return this->fe_add_fwd_intf_decl
<AST_Component
> (t
);
532 AST_Module::fe_add_constant (AST_Constant
*t
)
534 return dynamic_cast<AST_Constant
*> (this->fe_add_decl (t
));
538 AST_Module::fe_add_exception (AST_Exception
*t
)
540 return dynamic_cast<AST_Exception
*> (this->fe_add_decl (t
));
544 AST_Module::fe_add_union (AST_Union
*t
)
546 return dynamic_cast<AST_Union
*> (this->fe_add_full_struct_type (t
));
550 AST_Module::fe_add_union_fwd (AST_UnionFwd
*t
)
552 return dynamic_cast<AST_UnionFwd
*> (this->fe_add_fwd_struct_type (t
));
556 AST_Module::fe_add_structure (AST_Structure
*t
)
558 return this->fe_add_full_struct_type (t
);
562 AST_Module::fe_add_structure_fwd (AST_StructureFwd
*t
)
564 return this->fe_add_fwd_struct_type (t
);
568 AST_Module::fe_add_enum (AST_Enum
*t
)
570 return dynamic_cast<AST_Enum
*> (this->fe_add_decl (t
));
573 // Add an AST_EnumVal node (an enumerator) to this scope.
574 // This is done to conform to the C++ scoping rules which declare
575 // enumerators in the enclosing scope (in addition to declaring them
576 // in the enum itself).
578 AST_Module::fe_add_enum_val (AST_EnumVal
*t
)
580 return dynamic_cast<AST_EnumVal
*> (this->fe_add_decl (t
));
584 AST_Module::fe_add_typedef (AST_Typedef
*t
)
586 return dynamic_cast<AST_Typedef
*> (this->fe_add_ref_decl (t
));
590 AST_Module::fe_add_native (AST_Native
*t
)
592 return dynamic_cast<AST_Native
*> (this->fe_add_decl (t
));
596 AST_Module::fe_add_porttype (AST_PortType
*t
)
598 return dynamic_cast<AST_PortType
*> (this->fe_add_decl (t
));
602 AST_Module::reset_last_in_same_parent_scope ()
604 this->last_in_same_parent_scope_
= this;
607 AST_Annotation_Decl
*
608 AST_Module::fe_add_annotation_decl (
609 AST_Annotation_Decl
*annotation_decl
)
611 return dynamic_cast<AST_Annotation_Decl
*> (fe_add_decl (annotation_decl
));