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 #include <ast_interface.h>
66 #include <ast_module.h>
67 #include <ast_array.h>
68 #include <ast_field.h>
69 #include <ast_structure.h>
70 #include <ast_sequence.h>
71 #include <ast_string.h>
72 #include <ast_typedef.h>
73 #include <ast_visitor.h>
74 #include <global_extern.h>
75 #include <nr_extern.h>
76 #include <utl_identifier.h>
77 #include <utl_string.h>
78 #include <utl_scope.h>
80 #include <ast_annotation_appl.h>
81 #include <utl_indenter.h>
83 // FUZZ: disable check_for_streams_include
84 #include <ace/streams.h>
85 #include <ace/OS_NS_stdio.h>
87 COMMON_Base::COMMON_Base (bool local
,
90 is_abstract_ (abstract
)
94 COMMON_Base::~COMMON_Base ()
99 COMMON_Base::destroy ()
104 COMMON_Base::is_local ()
106 return this->is_local_
;
110 COMMON_Base::is_local (bool val
)
112 this->is_local_
= val
;
116 COMMON_Base::is_abstract () const
118 return this->is_abstract_
;
122 COMMON_Base::is_abstract (bool val
)
124 this->is_abstract_
= val
;
127 AST_Decl::AST_Decl (NodeType nt
,
132 flat_name_ (nullptr),
133 contains_wstring_ (-1),
134 annotation_appls_ (nullptr),
135 builtin_ (idl_global
->in_eval_
),
136 pd_imported (idl_global
->imported ()),
137 pd_in_main_file (idl_global
->in_main_file ()),
138 pd_defined_in (idl_global
->scopes ().depth () > 0
139 ? idl_global
->scopes ().top ()
142 pd_line (idl_global
->lineno ()),
144 pd_local_name (n
? n
->last_component ()->copy () : nullptr),
145 pd_original_local_name (nullptr),
146 full_name_ (nullptr),
149 anonymous_ (anonymous
),
151 last_referenced_as_ (nullptr),
152 prefix_scope_ (nullptr),
153 in_tmpl_mod_not_aliased_ (idl_global
->in_tmpl_mod_no_alias ())
155 // If this is the root node, the filename won't have been set yet.
156 UTL_String
*fn
= idl_global
->filename ();
157 this->pd_file_name
= (fn
? fn
->get_string () : "");
159 this->compute_full_name (n
);
161 char *prefix
= nullptr;
162 idl_global
->pragma_prefixes ().top (prefix
);
163 this->prefix_
= ACE::strnew (prefix
? prefix
: "");
167 // The function body creates its own copy.
168 this->original_local_name (n
->last_component ());
171 this->compute_repoID ();
175 UTL_ScopedName
*name
,
179 flat_name_ (nullptr),
180 contains_wstring_ (-1),
181 annotation_appls_ (nullptr),
182 builtin_ (idl_global
->in_eval_
),
183 pd_imported (idl_global
->imported ()),
184 pd_in_main_file (idl_global
->in_main_file ()),
185 pd_defined_in (idl_global
->scopes ().depth () > 0
186 ? idl_global
->scopes ().top ()
188 pd_node_type (other
->node_type ()),
189 pd_line (idl_global
->lineno ()),
191 pd_local_name (name
? name
->last_component ()->copy () : nullptr),
192 pd_original_local_name (nullptr),
193 full_name_ (nullptr),
196 anonymous_ (other
->anonymous ()),
198 last_referenced_as_ (nullptr),
199 prefix_scope_ (nullptr),
200 in_tmpl_mod_not_aliased_ (idl_global
->in_tmpl_mod_no_alias ())
202 // If this is the root node, the filename won't have been set yet.
203 UTL_String
*fn
= idl_global
->filename ();
204 this->pd_file_name
= (fn
? fn
->get_string () : "");
206 this->compute_full_name (name
);
208 char *prefix
= nullptr;
209 idl_global
->pragma_prefixes ().top (prefix
);
210 this->prefix_
= ACE::strnew (prefix
? prefix
: "");
214 // The function body creates its own copy.
215 this->original_local_name (name
->last_component ());
218 this->compute_repoID ();
221 AST_Decl::~AST_Decl ()
228 // These are not set for the root node.
231 this->pd_name
->destroy ();
232 delete this->pd_name
;
233 this->pd_name
= nullptr;
236 if (this->pd_local_name
)
238 this->pd_local_name
->destroy ();
239 delete this->pd_local_name
;
240 this->pd_local_name
= nullptr;
243 if (this->pd_original_local_name
)
245 this->pd_original_local_name
->destroy ();
246 delete this->pd_original_local_name
;
247 this->pd_original_local_name
= nullptr;
250 if (this->last_referenced_as_
)
252 this->last_referenced_as_
->destroy ();
253 delete this->last_referenced_as_
;
254 this->last_referenced_as_
= nullptr;
257 delete [] this->full_name_
;
258 this->full_name_
= nullptr;
260 delete [] this->repoID_
;
261 this->repoID_
= nullptr;
263 delete [] this->prefix_
;
264 this->prefix_
= nullptr;
266 delete [] this->version_
;
267 this->version_
= nullptr;
269 delete [] this->flat_name_
;
270 this->flat_name_
= nullptr;
272 delete annotation_appls_
;
273 annotation_appls_
= nullptr;
277 AST_Decl::adjust_found (
279 bool /*full_def_only*/)
281 return this; // Defaults to no adjustment
287 return false; // Not a fwd declared type (by default)
290 // Private operations.
292 // Compute our private UTL_ScopedName member.
294 AST_Decl::compute_full_name (UTL_ScopedName
*n
)
296 // This should happen only when we are a non-void predefined type,
297 // in which case our scoped name has already been created by the
298 // AST_PredefinedType constructor.
305 if (!this->defined_in ())
307 this->pd_name
= (UTL_IdList
*) n
->copy ();
311 // Initialize this name to 0.
312 this->pd_name
= nullptr;
314 // OK, not global. So copy name of containing scope, then
315 // smash last cdr of copy with new component
316 UTL_ScopedName
*cn
= nullptr;
317 AST_Decl
*d
= ScopeAsDecl (this->defined_in ());
323 this->pd_name
= (UTL_IdList
*) cn
->copy ();
327 if (this->pd_local_name
)
331 UTL_ScopedName
*conc_name
= nullptr;
333 UTL_ScopedName (this->pd_local_name
->copy (), nullptr));
334 this->pd_name
->nconc (conc_name
);
338 ACE_NEW (this->pd_name
,
339 UTL_ScopedName (this->pd_local_name
->copy (), nullptr));
345 AST_Decl::set_prefix_with_typeprefix_r (const char *value
,
346 UTL_Scope
*appeared_in
)
348 if (this->typeid_set_
)
353 if (this->prefix_scope_
)
355 AST_Decl
*decl
= ScopeAsDecl (this->prefix_scope_
);
356 bool const overridden
=
357 decl
->has_ancestor (ScopeAsDecl (appeared_in
));
364 delete [] this->repoID_
;
365 this->repoID_
= nullptr;
366 this->prefix (value
);
367 this->prefix_scope_
= appeared_in
;
369 UTL_Scope
*s
= DeclAsScope (this);
372 for (UTL_ScopeActiveIterator
i (s
, UTL_Scope::IK_decls
);
376 AST_Decl
*tmp
= i
.item ();
377 UTL_Scope
*s_tmp
= DeclAsScope (tmp
);
380 tmp
->set_prefix_with_typeprefix_r (value
, appeared_in
);
385 // This will recursively catch all previous openings of a module.
386 if (this->node_type () == AST_Decl::NT_module
)
388 AST_Module
*m
= dynamic_cast<AST_Module
*> (this);
389 while (!!(m
= m
->previous_opening ()))
391 for (UTL_ScopeActiveIterator
si (m
, UTL_Scope::IK_decls
);
395 AST_Decl
*d
= si
.item ();
396 if (d
->node_type () != AST_Decl::NT_pre_defined
)
398 d
->set_prefix_with_typeprefix_r (value
, appeared_in
);
404 this->compute_repoID ();
407 // Protected operations.
409 // Compute stringified fully scoped name.
411 AST_Decl::compute_full_name ()
413 if (!this->full_name_
)
418 char *name
= nullptr;
420 for (UTL_IdListActiveIterator
i (this->name ());
426 namelen
+= 2; // for "::"
430 first
= second
= false;
433 // Print the identifier.
434 name
= i
.item ()->get_string ();
435 namelen
+= ACE_OS::strlen (name
);
438 if (ACE_OS::strcmp (name
, ""))
440 // Does not start with a "".
450 ACE_NEW (this->full_name_
, char [namelen
+ 1]);
451 this->full_name_
[0] = '\0';
455 for (UTL_IdListActiveIterator
j (this->name ());
461 ACE_OS::strcat (this->full_name_
, "::");
465 first
= second
= false;
468 // Print the identifier.
469 name
= j
.item ()->get_string ();
470 ACE_OS::strcat (this->full_name_
, name
);
473 if (ACE_OS::strcmp (name
, ""))
475 // Does not start with a "".
487 // Compute stringified repository ID.
489 AST_Decl::compute_repoID ()
496 size_t namelen
= 4; // for the prefix "IDL:"
499 char *name
= nullptr;
500 const char *prefix
= (this->prefix_
? this->prefix_
: "");
501 UTL_Scope
*scope
= this->defined_in ();
502 const char *parent_prefix
= nullptr;
504 // If our prefix is empty, we check to see if an ancestor has one.
505 while (scope
&& !ACE_OS::strcmp (prefix
, ""))
507 AST_Decl
*parent
= ScopeAsDecl (scope
);
508 if (parent
->node_type () == AST_Decl::NT_root
509 && parent
->imported ())
514 parent_prefix
= parent
->prefix ();
515 prefix
= (parent_prefix
? parent_prefix
: "");
516 scope
= parent
->defined_in ();
519 // in the first loop compute the total length
520 namelen
+= ACE_OS::strlen (prefix
) + 1;
522 const char *version
= this->version_
;
523 scope
= this->defined_in ();
525 // If our version is has not bee set, we use the parent's, if any.
526 while (!version
&& scope
)
528 AST_Decl
*parent
= ScopeAsDecl (scope
);
529 version
= parent
->version_
;
530 scope
= parent
->defined_in ();
535 // Version member string + ':'
536 namelen
+= ACE_OS::strlen (version
) + 1;
544 for (UTL_IdListActiveIterator
i (this->name ());
550 namelen
+= 1; // for "/"
554 first
= second
= false;
557 // Print the identifier.
558 name
= i
.item ()->get_string ();
559 size_t item_len
= ACE_OS::strlen (name
);
561 if (ACE_OS::strstr (name
, "_cxx_") == name
)
563 namelen
+= (item_len
- ACE_OS::strlen ("_cxx_"));
572 if (ACE_OS::strcmp (name
, ""))
574 // Does not start with a "".
584 ACE_NEW (this->repoID_
, char [namelen
+ 1]);
585 ACE_OS::sprintf (this->repoID_
, "IDL:");
587 if (ACE_OS::strcmp (prefix
, ""))
589 ACE_OS::strcat (this->repoID_
, prefix
);
590 ACE_OS::strcat (this->repoID_
, "/");
596 for (UTL_IdListActiveIterator
j (this->name ());
602 ACE_OS::strcat (this->repoID_
, "/");
606 first
= second
= false;
609 // Print the identifier.
610 name
= j
.item ()->get_string ();
612 if (ACE_OS::strstr (name
, "_cxx_") == name
)
614 ACE_OS::strcat (this->repoID_
,
615 name
+ ACE_OS::strlen ("_cxx_"));
619 ACE_OS::strcat (this->repoID_
, name
);
624 if (ACE_OS::strcmp (name
, ""))
626 // Does not start with a "".
638 ACE_OS::strcat (this->repoID_
, ":");
639 ACE_OS::strcat (this->repoID_
, version
);
643 ACE_OS::strcat (this->repoID_
, ":1.0");
647 // Public operations.
650 AST_Decl::flat_name ()
652 if (!this->flat_name_
)
654 this->compute_flat_name ();
657 return this->flat_name_
;
660 // Compute stringified flattened fully scoped name.
662 AST_Decl::compute_flat_name ()
664 if (this->flat_name_
== nullptr)
669 char *item_name
= nullptr;
671 // In the first loop, compute the total length.
672 for (UTL_IdListActiveIterator
i (this->name ());
678 namelen
+= 1; // for "_"
682 first
= second
= false;
685 // Print the identifier, leaving out
686 // _cxx_ prefix, if any.
687 Identifier
*tmp
= i
.item ()->copy ();
688 FE_Utils::original_local_name (tmp
);
689 item_name
= tmp
->get_string ();
690 namelen
+= ACE_OS::strlen (item_name
);
694 if (ACE_OS::strcmp (item_name
, "") != 0)
696 // Does not start with a "".
710 ACE_NEW (this->flat_name_
, char [namelen
+ 1]);
711 this->flat_name_
[0] = '\0';
715 for (UTL_IdListActiveIterator
j (this->name ());
721 ACE_OS::strcat (this->flat_name_
, "_");
725 first
= second
= false;
728 // Print the identifier, leaving out
729 // _cxx_ prefix, if any.
730 Identifier
*tmp
= j
.item ()->copy ();
731 FE_Utils::original_local_name (tmp
);
732 item_name
= tmp
->get_string ();
733 ACE_OS::strcat (this->flat_name_
, item_name
);
737 if (ACE_OS::strcmp (item_name
, ""))
739 // Does not start with a "".
756 AST_Decl::node_type_to_string (NodeType nt
)
764 case NT_interface_fwd
:
768 case NT_valuetype_fwd
:
820 case NT_component_fwd
:
827 case NT_eventtype_fwd
:
854 // No useful output for these.
860 // Return TRUE if one of my ancestor scopes is "s"
861 // and FALSE otherwise.
863 AST_Decl::has_ancestor (AST_Decl
*s
)
865 AST_Decl
*work
= this;
873 AST_Module
*m
= dynamic_cast<AST_Module
*> (s
);
876 while (!!(m
= m
->previous_opening ()))
878 if (static_cast<AST_Decl
*> (m
) == s
)
885 work
= work
->pd_defined_in
?
886 ScopeAsDecl (work
->pd_defined_in
) :
894 AST_Decl::is_child (AST_Decl
*s
)
896 if (this->defined_in ())
898 AST_Decl
*d
= ScopeAsDecl (this->defined_in ());
904 if (!ACE_OS::strcmp (d
->full_name (), s
->full_name ()))
910 return false; // Not a child.
914 AST_Decl::is_nested ()
916 AST_Decl
*d
= ScopeAsDecl (this->defined_in ());
918 // If we have an outermost scope and if that scope is not that of the Root,
919 // then we are defined at some nesting level.
920 return (d
&& d
->node_type () != AST_Decl::NT_root
);
923 // Dump this AST_Decl to the ostream o.
925 AST_Decl::dump (ACE_OSTREAM_TYPE
&o
)
927 this->pd_local_name
->dump (o
);
931 AST_Decl::dump_i (ACE_OSTREAM_TYPE
&o
, const char *s
) const
933 // Have to use ACE_CString here to avoid ambiguous overload error, see
934 // SString.h for an the overloaded operator << () methods.
939 AST_Decl::ast_accept (ast_visitor
*visitor
)
941 return visitor
->visit_decl (this);
947 AST_Decl::full_name ()
949 if (!this->full_name_
)
951 this->compute_full_name ();
954 return this->full_name_
;
960 if (this->pd_node_type
== NT_root
)
962 delete [] this->repoID_
;
963 this->repoID_
= ACE::strnew ("");
968 this->compute_repoID ();
971 return this->repoID_
;
975 AST_Decl::repoID (char *value
)
977 delete [] this->repoID_
;
978 this->repoID_
= value
;
984 return this->prefix_
;
988 AST_Decl::prefix (const char *value
)
990 delete [] this->prefix_
;
991 this->prefix_
= ACE::strnew (value
);
999 // Calling the method will compute if necessary.
1000 const char *repo_id
= this->repoID ();
1002 // All forms of repo id should contain two colons, the
1003 // version coming after the second one.
1004 const char *tail1
= nullptr;
1005 const char *tail2
= nullptr;
1009 tail1
= ACE_OS::strchr (repo_id
, ':');
1014 tail2
= ACE_OS::strchr (tail1
+ 1, ':');
1017 if (!this->typeid_set_
&& tail2
)
1019 this->version_
= ACE::strnew (tail2
+ 1);
1023 this->version_
= ACE::strnew ("1.0");
1027 return this->version_
;
1031 AST_Decl::version (char *value
)
1033 // Previous #pragma version or #pragma id make this illegal.
1034 if ((!this->version_
|| !ACE_OS::strcmp (this->version_
, value
))
1035 && !this->typeid_set_
)
1037 delete [] this->version_
;
1038 this->version_
= value
;
1040 // Repo id is now computed eagerly, so a version set must update
1044 ACE_CString
tmp (this->repoID_
);
1045 ACE_CString::size_type
const pos
= tmp
.rfind (':');
1046 if (pos
!= ACE_CString::npos
)
1048 tmp
= tmp
.substr (0, pos
+ 1) + value
;
1049 delete [] this->repoID_
;
1050 this->repoID_
= ACE::strnew (tmp
.fast_rep ());
1056 idl_global
->err ()->version_reset_error ();
1061 AST_Decl::anonymous () const
1063 return this->anonymous_
;
1067 AST_Decl::anonymous (bool val
)
1069 this->anonymous_
= val
;
1073 AST_Decl::typeid_set () const
1075 return this->typeid_set_
;
1079 AST_Decl::typeid_set (bool val
)
1081 this->typeid_set_
= val
;
1085 AST_Decl::set_id_with_typeid (char *value
)
1087 // Can't call 'typeid' twice, even with the same value.
1088 if (this->typeid_set ())
1090 idl_global
->err ()->error1 (UTL_Error::EIDL_TYPEID_RESET
, this);
1093 // Are we a legal type for 'typeid'?
1094 switch (this->pd_node_type
)
1096 case AST_Decl::NT_field
:
1098 AST_Decl::NodeType nt
=
1099 ScopeAsDecl (this->defined_in ())->node_type ();
1101 if ( nt
== AST_Decl::NT_valuetype
1102 || nt
== AST_Decl::NT_eventtype
)
1108 idl_global
->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID
, this);
1113 case AST_Decl::NT_module
:
1114 case AST_Decl::NT_interface
:
1115 case AST_Decl::NT_const
:
1116 case AST_Decl::NT_typedef
:
1117 case AST_Decl::NT_except
:
1118 case AST_Decl::NT_attr
:
1119 case AST_Decl::NT_op
:
1120 case AST_Decl::NT_enum
:
1121 case AST_Decl::NT_factory
:
1122 case AST_Decl::NT_component
:
1123 case AST_Decl::NT_home
:
1124 case AST_Decl::NT_eventtype
:
1128 idl_global
->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID
, this);
1132 delete [] this->repoID_
;
1133 this->repoID_
= nullptr;
1134 this->repoID (ACE::strnew (value
));
1135 this->typeid_set_
= true;
1139 AST_Decl::set_prefix_with_typeprefix (const char *value
)
1141 // Are we a legal type for 'typeprefix'? This is checked only at
1143 switch (this->pd_node_type
)
1145 case AST_Decl::NT_module
:
1146 case AST_Decl::NT_interface
:
1147 case AST_Decl::NT_valuetype
:
1148 case AST_Decl::NT_eventtype
:
1149 case AST_Decl::NT_struct
:
1150 case AST_Decl::NT_union
:
1151 case AST_Decl::NT_except
:
1155 idl_global
->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEPREFIX
, this);
1159 this->set_prefix_with_typeprefix_r (value
, DeclAsScope (this));
1163 AST_Decl::imported ()
1165 return this->pd_imported
;
1169 AST_Decl::set_imported (bool is_it
)
1171 this->pd_imported
= is_it
;
1175 AST_Decl::in_main_file ()
1177 return this->pd_in_main_file
;
1181 AST_Decl::set_in_main_file (bool is_it
)
1183 this->pd_in_main_file
= is_it
;
1187 AST_Decl::defined_in ()
1189 return this->pd_defined_in
;
1193 AST_Decl::set_defined_in (UTL_Scope
*s
)
1195 this->pd_defined_in
= s
;
1199 AST_Decl::node_type ()
1201 return this->pd_node_type
;
1207 return this->pd_line
;
1211 AST_Decl::set_line (long l
)
1217 AST_Decl::file_name ()
1219 return this->pd_file_name
;
1223 AST_Decl::set_file_name (ACE_CString s
)
1225 this->pd_file_name
= s
;
1231 return this->pd_name
;
1234 // @@ Wherever compute_* are called, we should remember to delete them
1237 // Variation of the <name>. Computes scoped name string, applying
1238 // prefix and suffix to the local name component.
1240 AST_Decl::compute_name (const char *prefix
,
1243 if (!prefix
|| !suffix
)
1248 // Prepare prefix_<local_name>_suffix string.
1250 ACE_CString
suffix_str (suffix
);
1251 ACE_CString
local_str (this->local_name ()->get_string ());
1253 ACE_CString
result_local_str (prefix
);
1254 result_local_str
+= local_str
;
1255 result_local_str
+= suffix_str
;
1257 // Identifier for the resulting local name.
1258 Identifier
*result_local_id
= nullptr;
1259 ACE_NEW_RETURN (result_local_id
,
1260 Identifier (result_local_str
.c_str ()),
1263 // UTL_Scoped name for the resulting local name.
1264 UTL_ScopedName
*result_local_name
= nullptr;
1265 ACE_NEW_RETURN (result_local_name
,
1266 UTL_ScopedName (result_local_id
, nullptr),
1270 UTL_ScopedName
*result_name
= nullptr;
1271 if (!this->defined_in ())
1273 result_name
= result_local_name
;
1277 // OK, not global. So copy name of containing scope, then
1278 // smash last cdr of copy with new component.
1280 AST_Decl
*d
= ScopeAsDecl (this->defined_in ());
1283 UTL_ScopedName
*cn
= d
->name ();
1286 result_name
= (UTL_ScopedName
*) cn
->copy ();
1289 result_name
->nconc (result_local_name
);
1293 result_name
= result_local_name
;
1303 AST_Decl::set_name (UTL_ScopedName
*n
)
1305 if (this->pd_name
== n
)
1312 this->pd_name
->destroy ();
1313 delete this->pd_name
;
1320 if (this->pd_local_name
)
1322 this->pd_local_name
->destroy ();
1323 delete this->pd_local_name
;
1326 this->pd_local_name
= n
->last_component ()->copy ();
1328 // The name without _cxx_ prefix removed, if there was any.
1329 if (this->pd_original_local_name
)
1331 this->pd_original_local_name
->destroy ();
1332 delete this->pd_original_local_name
;
1335 this->original_local_name (n
->last_component ());
1337 // These will be recomputed on demand.
1338 delete [] this->flat_name_
;
1339 this->flat_name_
= nullptr;
1341 delete [] this->full_name_
;
1342 this->full_name_
= nullptr;
1344 delete [] this->repoID_
;
1345 this->repoID_
= nullptr;
1350 AST_Decl::local_name () const
1352 return this->pd_local_name
;
1356 AST_Decl::local_name (Identifier
*id
)
1358 if (this->pd_local_name
)
1360 this->pd_local_name
->destroy ();
1363 delete this->pd_local_name
;
1364 this->pd_local_name
= id
;
1368 AST_Decl::compute_local_name (const char *prefix
,
1371 if (!prefix
|| !suffix
)
1376 // Init the result with prefix.
1377 ACE_CString
result_str (prefix
);
1380 result_str
+= ACE_CString (this->local_name ()->get_string ());
1383 result_str
+= ACE_CString (suffix
);
1385 // Identifier for the resulting local name.
1386 Identifier
*result_id
= nullptr;
1387 ACE_NEW_RETURN (result_id
,
1388 Identifier (result_str
.c_str ()),
1394 // If there is _cxx_ in the beginning, we will remove that and keep
1395 // a copy of the original name. TAO IDL's front end adds _cxx_
1396 // prefix to the all the reserved keywords. But when we invoke the
1397 // operation remotely, we should be sending only the name with out
1400 AST_Decl::original_local_name (Identifier
*local_name
)
1402 // Remove _cxx_ if it is present.
1403 if (ACE_OS::strstr (local_name
->get_string (), "_cxx_")
1404 == local_name
->get_string ())
1406 // AACE_CString class is good to do this stuff.
1407 ACE_CString
name_str (local_name
->get_string ());
1410 name_str
= name_str
.substr (ACE_OS::strlen ("_cxx_"));
1412 // Assign to the Identifier variable.
1413 ACE_NEW (this->pd_original_local_name
,
1414 Identifier (name_str
.c_str ()));
1418 this->pd_original_local_name
= local_name
->copy ();
1423 AST_Decl::original_local_name ()
1425 return this->pd_original_local_name
;
1429 AST_Decl::is_defined ()
1431 // AST_Interface, AST_Structure, and AST_Union will
1432 // override this, as will AST_InterfaceFwd, etc.
1437 AST_Decl::last_referenced_as () const
1439 return this->last_referenced_as_
;
1443 AST_Decl::last_referenced_as (UTL_ScopedName
*n
)
1445 if (this->last_referenced_as_
)
1447 this->last_referenced_as_
->destroy ();
1450 delete this->last_referenced_as_
;
1451 this->last_referenced_as_
= n
;
1455 AST_Decl::prefix_scope ()
1457 return this->prefix_scope_
;
1461 AST_Decl::prefix_scope (UTL_Scope
*s
)
1463 this->prefix_scope_
= s
;
1466 // Container types will override this.
1468 AST_Decl::contains_wstring ()
1470 if (this->contains_wstring_
== -1)
1472 switch (this->node_type ())
1474 case AST_Decl::NT_array
:
1476 AST_Array
*a
= dynamic_cast<AST_Array
*> (this);
1477 this->contains_wstring_
= a
->base_type ()->contains_wstring ();
1481 case AST_Decl::NT_except
:
1482 case AST_Decl::NT_struct
:
1483 case AST_Decl::NT_union
:
1485 AST_Structure
*s
= dynamic_cast<AST_Structure
*> (this);
1486 this->contains_wstring_
= s
->contains_wstring ();
1490 case AST_Decl::NT_sequence
:
1492 AST_Sequence
*s
= dynamic_cast<AST_Sequence
*> (this);
1493 this->contains_wstring_
= s
->base_type ()->contains_wstring ();
1497 case AST_Decl::NT_attr
:
1498 case AST_Decl::NT_field
:
1499 case AST_Decl::NT_union_branch
:
1501 AST_Field
*f
= dynamic_cast<AST_Field
*> (this);
1502 this->contains_wstring_
= f
->field_type ()->contains_wstring ();
1506 case AST_Decl::NT_typedef
:
1508 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (this);
1509 this->contains_wstring_
=
1510 td
->primitive_base_type ()->contains_wstring ();
1514 case AST_Decl::NT_wstring
:
1515 this->contains_wstring_
= 1;
1519 this->contains_wstring_
= 0;
1524 return this->contains_wstring_
;
1527 // Non-virtual - no need to override this one.
1529 AST_Decl::contains_wstring (int val
)
1531 this->contains_wstring_
= val
;
1535 AST_Decl::masking_checks (AST_Decl
*mod
)
1537 if (!this->pd_local_name
->case_compare (mod
->local_name ()))
1542 AST_Module
*me_mod
= dynamic_cast<AST_Module
*> (this);
1544 if (me_mod
!= nullptr)
1546 AST_Module
*po_mod
= dynamic_cast<AST_Module
*> (mod
);
1549 while (!!(po_mod
= po_mod
->previous_opening ()))
1551 if (po_mod
== me_mod
)
1563 AST_Decl::in_tmpl_mod_not_aliased () const
1565 return this->in_tmpl_mod_not_aliased_
;
1569 AST_Decl::in_tmpl_mod_not_aliased (bool val
)
1571 this->in_tmpl_mod_not_aliased_
= val
;
1575 AST_Decl::annotation_appls (const AST_Annotation_Appls
&annotations
)
1579 annotation_appls () = annotations
;
1583 ACE_ERROR ((LM_ERROR
,
1584 ACE_TEXT ("WARNING: %C is annotated but its type can't be annotated!\n"),
1590 AST_Annotation_Appls
&
1591 AST_Decl::annotation_appls ()
1593 if (!annotation_appls_
)
1595 annotation_appls_
= new AST_Annotation_Appls ();
1597 return *annotation_appls_
;
1601 AST_Decl::dump_annotations (ACE_OSTREAM_TYPE
&o
, bool print_inline
)
1603 AST_Annotation_Appls::iterator
1604 i
= annotation_appls ().begin (),
1605 finished
= annotation_appls ().end ();
1606 for (; i
!= finished
; ++i
)
1608 AST_Annotation_Appl
* a
= i
->get ();
1617 idl_global
->indent ()->skip_to (o
);
1623 AST_Decl::dump_with_annotations (ACE_OSTREAM_TYPE
&o
, bool inline_annotations
)
1625 if (annotatable () && auto_dump_annotations())
1627 dump_annotations (o
, inline_annotations
);
1634 operator<< (ACE_OSTREAM_TYPE
&o
, AST_Decl
&d
)
1636 d
.dump_with_annotations (o
, d
.dump_annotations_inline ());
1642 AST_Decl::annotatable () const
1648 AST_Decl::dump_annotations_inline () const
1654 AST_Decl::auto_dump_annotations () const
1660 AST_Decl::builtin () const
1666 AST_Decl::should_be_dumped () const
1668 return !builtin () || idl_global
->dump_builtins_
;
1671 AST_Annotation_Appls
&
1672 AST_Decl::annotations ()
1674 return annotation_appls ();
1678 AST_Decl::ami_visit ()