Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_decl.cpp
blob7c45a62d0d844b25a9de10b9a8e880c46eb419c4
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 <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>
79 #include <utl_err.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,
88 bool abstract)
89 : is_local_ (local),
90 is_abstract_ (abstract)
94 COMMON_Base::~COMMON_Base ()
98 void
99 COMMON_Base::destroy ()
103 bool
104 COMMON_Base::is_local ()
106 return this->is_local_;
109 void
110 COMMON_Base::is_local (bool val)
112 this->is_local_ = val;
115 bool
116 COMMON_Base::is_abstract () const
118 return this->is_abstract_;
121 void
122 COMMON_Base::is_abstract (bool val)
124 this->is_abstract_ = val;
127 AST_Decl::AST_Decl (NodeType nt,
128 UTL_ScopedName *n,
129 bool anonymous)
130 : COMMON_Base (),
131 repoID_ (nullptr),
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 ()
140 : nullptr),
141 pd_node_type (nt),
142 pd_line (idl_global->lineno ()),
143 pd_name (nullptr),
144 pd_local_name (n ? n->last_component ()->copy () : nullptr),
145 pd_original_local_name (nullptr),
146 full_name_ (nullptr),
147 prefix_ (nullptr),
148 version_ (nullptr),
149 anonymous_ (anonymous),
150 typeid_set_ (false),
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 : "");
165 if (n)
167 // The function body creates its own copy.
168 this->original_local_name (n->last_component ());
171 this->compute_repoID ();
174 AST_Decl::AST_Decl (
175 UTL_ScopedName *name,
176 AST_Decl *other)
177 : COMMON_Base (),
178 repoID_ (nullptr),
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 ()
187 : nullptr),
188 pd_node_type (other->node_type ()),
189 pd_line (idl_global->lineno ()),
190 pd_name (nullptr),
191 pd_local_name (name ? name->last_component ()->copy () : nullptr),
192 pd_original_local_name (nullptr),
193 full_name_ (nullptr),
194 prefix_ (nullptr),
195 version_ (nullptr),
196 anonymous_ (other->anonymous ()),
197 typeid_set_ (false),
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 : "");
212 if (name)
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 ()
225 void
226 AST_Decl::destroy ()
228 // These are not set for the root node.
229 if (this->pd_name)
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;
276 AST_Decl *
277 AST_Decl::adjust_found (
278 bool /*ignore_fwd*/,
279 bool /*full_def_only*/)
281 return this; // Defaults to no adjustment
284 bool
285 AST_Decl::is_fwd ()
287 return false; // Not a fwd declared type (by default)
290 // Private operations.
292 // Compute our private UTL_ScopedName member.
293 void
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.
299 if (!n)
301 return;
304 // Global scope?
305 if (!this->defined_in ())
307 this->pd_name = (UTL_IdList *) n->copy ();
308 return;
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 ());
318 if (d)
320 cn = d->name ();
321 if (cn)
323 this->pd_name = (UTL_IdList *) cn->copy ();
327 if (this->pd_local_name)
329 if (this->pd_name)
331 UTL_ScopedName *conc_name = nullptr;
332 ACE_NEW (conc_name,
333 UTL_ScopedName (this->pd_local_name->copy (), nullptr));
334 this->pd_name->nconc (conc_name);
336 else
338 ACE_NEW (this->pd_name,
339 UTL_ScopedName (this->pd_local_name->copy (), nullptr));
344 void
345 AST_Decl::set_prefix_with_typeprefix_r (const char *value,
346 UTL_Scope *appeared_in)
348 if (this->typeid_set_)
350 return;
353 if (this->prefix_scope_)
355 AST_Decl *decl = ScopeAsDecl (this->prefix_scope_);
356 bool const overridden =
357 decl->has_ancestor (ScopeAsDecl (appeared_in));
358 if (overridden)
360 return;
364 delete [] this->repoID_;
365 this->repoID_ = nullptr;
366 this->prefix (value);
367 this->prefix_scope_ = appeared_in;
369 UTL_Scope *s = DeclAsScope (this);
370 if (s)
372 for (UTL_ScopeActiveIterator i (s, UTL_Scope::IK_decls);
373 !i.is_done ();
374 i.next ())
376 AST_Decl *tmp = i.item ();
377 UTL_Scope *s_tmp = DeclAsScope (tmp);
378 if (s_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);
392 !si.is_done ();
393 si.next ())
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.
410 void
411 AST_Decl::compute_full_name ()
413 if (!this->full_name_)
415 size_t namelen = 0;
416 long first = true;
417 long second = false;
418 char *name = nullptr;
420 for (UTL_IdListActiveIterator i (this->name ());
421 !i.is_done ();
422 i.next ())
424 if (!first)
426 namelen += 2; // for "::"
428 else if (second)
430 first = second = false;
433 // Print the identifier.
434 name = i.item ()->get_string ();
435 namelen += ACE_OS::strlen (name);
436 if (first)
438 if (ACE_OS::strcmp (name, ""))
440 // Does not start with a "".
441 first = false;
443 else
445 second = true;
450 ACE_NEW (this->full_name_, char [namelen + 1]);
451 this->full_name_ [0] = '\0';
452 first = true;
453 second = false;
455 for (UTL_IdListActiveIterator j (this->name ());
456 !j.is_done ();
457 j.next ())
459 if (!first)
461 ACE_OS::strcat (this->full_name_, "::");
463 else if (second)
465 first = second = false;
468 // Print the identifier.
469 name = j.item ()->get_string ();
470 ACE_OS::strcat (this->full_name_, name);
471 if (first)
473 if (ACE_OS::strcmp (name, ""))
475 // Does not start with a "".
476 first = false;
478 else
480 second = true;
487 // Compute stringified repository ID.
488 void
489 AST_Decl::compute_repoID ()
491 if (this->repoID_)
493 return;
496 size_t namelen = 4; // for the prefix "IDL:"
497 long first = true;
498 long second = false;
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 ())
511 break;
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 ();
533 if (version)
535 // Version member string + ':'
536 namelen += ACE_OS::strlen (version) + 1;
538 else
540 // For ":1.0"
541 namelen += 4;
544 for (UTL_IdListActiveIterator i (this->name ());
545 !i.is_done ();
546 i.next ())
548 if (!first)
550 namelen += 1; // for "/"
552 else if (second)
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_"));
565 else
567 namelen += item_len;
570 if (first)
572 if (ACE_OS::strcmp (name, ""))
574 // Does not start with a "".
575 first = false;
577 else
579 second = true;
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_, "/");
593 first = true;
594 second = false;
596 for (UTL_IdListActiveIterator j (this->name ());
597 !j.is_done ();
598 j.next ())
600 if (!first)
602 ACE_OS::strcat (this->repoID_, "/");
604 else if (second)
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_"));
617 else
619 ACE_OS::strcat (this->repoID_, name);
622 if (first)
624 if (ACE_OS::strcmp (name, ""))
626 // Does not start with a "".
627 first = false;
629 else
631 second = true;
636 if (version)
638 ACE_OS::strcat (this->repoID_, ":");
639 ACE_OS::strcat (this->repoID_, version);
641 else
643 ACE_OS::strcat (this->repoID_, ":1.0");
647 // Public operations.
649 const char *
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.
661 void
662 AST_Decl::compute_flat_name ()
664 if (this->flat_name_ == nullptr)
666 size_t namelen = 0;
667 long first = true;
668 long second = false;
669 char *item_name = nullptr;
671 // In the first loop, compute the total length.
672 for (UTL_IdListActiveIterator i (this->name ());
673 !i.is_done ();
674 i.next ())
676 if (!first)
678 namelen += 1; // for "_"
680 else if (second)
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);
692 if (first)
694 if (ACE_OS::strcmp (item_name, "") != 0)
696 // Does not start with a "".
697 first = false;
699 else
701 second = true;
705 tmp->destroy ();
706 delete tmp;
707 tmp = nullptr;
710 ACE_NEW (this->flat_name_, char [namelen + 1]);
711 this->flat_name_ [0] = '\0';
712 first = true;
713 second = false;
715 for (UTL_IdListActiveIterator j (this->name ());
716 !j.is_done ();
717 j.next ())
719 if (!first)
721 ACE_OS::strcat (this->flat_name_, "_");
723 else if (second)
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);
735 if (first)
737 if (ACE_OS::strcmp (item_name, ""))
739 // Does not start with a "".
740 first = false;
742 else
744 second = true;
748 tmp->destroy ();
749 delete tmp;
750 tmp = nullptr;
755 const char *
756 AST_Decl::node_type_to_string (NodeType nt)
758 switch (nt)
760 case NT_module:
761 return "module";
763 case NT_interface:
764 case NT_interface_fwd:
765 return "interface";
767 case NT_valuetype:
768 case NT_valuetype_fwd:
769 case NT_valuebox:
770 return "valuetype";
772 case NT_const:
773 return "const";
775 case NT_except:
776 return "exception";
778 case NT_attr:
779 return "attribute";
781 case NT_union:
782 case NT_union_fwd:
783 return "union";
785 case NT_struct:
786 case NT_struct_fwd:
787 return "struct";
789 case NT_enum:
790 return "enum";
792 case NT_string:
793 return "string";
795 case NT_wstring:
796 return "wstring";
798 case NT_array:
799 return "array";
801 case NT_sequence:
802 return "sequence";
804 case NT_map:
805 return "map";
807 case NT_typedef:
808 return "typedef";
810 case NT_pre_defined:
811 return "primitive";
813 case NT_native:
814 return "native";
816 case NT_factory:
817 return "factory";
819 case NT_component:
820 case NT_component_fwd:
821 return "component";
823 case NT_home:
824 return "home";
826 case NT_eventtype:
827 case NT_eventtype_fwd:
828 return "eventtype";
830 case NT_type:
831 return "typename";
833 case NT_fixed:
834 return "fixed";
836 case NT_porttype:
837 return "porttype";
839 case NT_provides:
840 return "provides";
842 case NT_uses:
843 return "uses";
845 case NT_publishes:
846 return "publishes";
848 case NT_emits:
849 return "emits";
851 case NT_consumes:
852 return "consumes";
854 // No useful output for these.
855 default:
856 return "";
860 // Return TRUE if one of my ancestor scopes is "s"
861 // and FALSE otherwise.
862 bool
863 AST_Decl::has_ancestor (AST_Decl *s)
865 AST_Decl *work = this;
868 if (work == s)
870 return true;
873 AST_Module *m = dynamic_cast<AST_Module*> (s);
874 if (m)
876 while (!!(m = m->previous_opening ()))
878 if (static_cast<AST_Decl *> (m) == s)
880 return true;
885 work = work->pd_defined_in ?
886 ScopeAsDecl (work->pd_defined_in) :
887 nullptr;
888 } while (work);
890 return false;
893 bool
894 AST_Decl::is_child (AST_Decl *s)
896 if (this->defined_in ())
898 AST_Decl *d = ScopeAsDecl (this->defined_in ());
899 if (!d)
901 return false;
904 if (!ACE_OS::strcmp (d->full_name (), s->full_name ()))
906 return true;
910 return false; // Not a child.
913 bool
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.
924 void
925 AST_Decl::dump (ACE_OSTREAM_TYPE &o)
927 this->pd_local_name->dump (o);
930 void
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.
935 o << ACE_CString(s);
939 AST_Decl::ast_accept (ast_visitor *visitor)
941 return visitor->visit_decl (this);
944 // Data accessors.
946 const char *
947 AST_Decl::full_name ()
949 if (!this->full_name_)
951 this->compute_full_name ();
954 return this->full_name_;
957 const char *
958 AST_Decl::repoID ()
960 if (this->pd_node_type == NT_root)
962 delete [] this->repoID_;
963 this->repoID_ = ACE::strnew ("");
966 if (!this->repoID_)
968 this->compute_repoID ();
971 return this->repoID_;
974 void
975 AST_Decl::repoID (char *value)
977 delete [] this->repoID_;
978 this->repoID_ = value;
981 const char *
982 AST_Decl::prefix ()
984 return this->prefix_;
987 void
988 AST_Decl::prefix (const char *value)
990 delete [] this->prefix_;
991 this->prefix_ = ACE::strnew (value);
994 const char *
995 AST_Decl::version ()
997 if (!this->version_)
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;
1007 if (repo_id)
1009 tail1 = ACE_OS::strchr (repo_id, ':');
1012 if (tail1)
1014 tail2 = ACE_OS::strchr (tail1 + 1, ':');
1017 if (!this->typeid_set_ && tail2)
1019 this->version_ = ACE::strnew (tail2 + 1);
1021 else
1023 this->version_ = ACE::strnew ("1.0");
1027 return this->version_;
1030 void
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
1041 // is as well.
1042 if (this->repoID_)
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 ());
1054 else
1056 idl_global->err ()->version_reset_error ();
1060 bool
1061 AST_Decl::anonymous () const
1063 return this->anonymous_;
1066 void
1067 AST_Decl::anonymous (bool val)
1069 this->anonymous_ = val;
1072 bool
1073 AST_Decl::typeid_set () const
1075 return this->typeid_set_;
1078 void
1079 AST_Decl::typeid_set (bool val)
1081 this->typeid_set_ = val;
1084 void
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)
1104 break;
1106 else
1108 idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, this);
1109 return;
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:
1125 break;
1127 default:
1128 idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, this);
1129 return;
1132 delete [] this->repoID_;
1133 this->repoID_ = nullptr;
1134 this->repoID (ACE::strnew (value));
1135 this->typeid_set_ = true;
1138 void
1139 AST_Decl::set_prefix_with_typeprefix (const char *value)
1141 // Are we a legal type for 'typeprefix'? This is checked only at
1142 // the top level.
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:
1152 break;
1154 default:
1155 idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEPREFIX, this);
1156 return;
1159 this->set_prefix_with_typeprefix_r (value, DeclAsScope (this));
1162 bool
1163 AST_Decl::imported ()
1165 return this->pd_imported;
1168 void
1169 AST_Decl::set_imported (bool is_it)
1171 this->pd_imported = is_it;
1174 bool
1175 AST_Decl::in_main_file ()
1177 return this->pd_in_main_file;
1180 void
1181 AST_Decl::set_in_main_file (bool is_it)
1183 this->pd_in_main_file = is_it;
1186 UTL_Scope *
1187 AST_Decl::defined_in ()
1189 return this->pd_defined_in;
1192 void
1193 AST_Decl::set_defined_in (UTL_Scope *s)
1195 this->pd_defined_in = s;
1198 AST_Decl::NodeType
1199 AST_Decl::node_type ()
1201 return this->pd_node_type;
1204 long
1205 AST_Decl::line ()
1207 return this->pd_line;
1210 void
1211 AST_Decl::set_line (long l)
1213 this->pd_line = l;
1216 ACE_CString &
1217 AST_Decl::file_name ()
1219 return this->pd_file_name;
1222 void
1223 AST_Decl::set_file_name (ACE_CString s)
1225 this->pd_file_name = s;
1228 UTL_ScopedName *
1229 AST_Decl::name ()
1231 return this->pd_name;
1234 // @@ Wherever compute_* are called, we should remember to delete them
1235 // after use.
1237 // Variation of the <name>. Computes scoped name string, applying
1238 // prefix and suffix to the local name component.
1239 UTL_ScopedName *
1240 AST_Decl::compute_name (const char *prefix,
1241 const char *suffix)
1243 if (!prefix || !suffix)
1245 return nullptr;
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 ()),
1261 nullptr);
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),
1267 nullptr);
1269 // Global scope?
1270 UTL_ScopedName *result_name = nullptr;
1271 if (!this->defined_in ())
1273 result_name = result_local_name;
1275 else
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 ());
1281 if (d)
1283 UTL_ScopedName *cn = d->name ();
1284 if (cn)
1286 result_name = (UTL_ScopedName *) cn->copy ();
1287 if (result_name)
1289 result_name->nconc (result_local_name);
1291 else
1293 result_name = result_local_name;
1299 return result_name;
1302 void
1303 AST_Decl::set_name (UTL_ScopedName *n)
1305 if (this->pd_name == n)
1307 return;
1310 if (this->pd_name)
1312 this->pd_name->destroy ();
1313 delete this->pd_name;
1316 this->pd_name = n;
1318 if (n)
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;
1349 Identifier *
1350 AST_Decl::local_name () const
1352 return this->pd_local_name;
1355 void
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;
1367 Identifier *
1368 AST_Decl::compute_local_name (const char *prefix,
1369 const char *suffix)
1371 if (!prefix || !suffix)
1373 return nullptr;
1376 // Init the result with prefix.
1377 ACE_CString result_str (prefix);
1379 // Put local.
1380 result_str += ACE_CString (this->local_name ()->get_string ());
1382 // Put suffix.
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 ()),
1389 nullptr);
1391 return result_id;
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
1398 // "_cxx_" prefix.
1399 void
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 ());
1409 // Remove _cxx_.
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 ()));
1416 else
1418 this->pd_original_local_name = local_name->copy ();
1422 Identifier *
1423 AST_Decl::original_local_name ()
1425 return this->pd_original_local_name;
1428 bool
1429 AST_Decl::is_defined ()
1431 // AST_Interface, AST_Structure, and AST_Union will
1432 // override this, as will AST_InterfaceFwd, etc.
1433 return true;
1436 UTL_ScopedName *
1437 AST_Decl::last_referenced_as () const
1439 return this->last_referenced_as_;
1442 void
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;
1454 UTL_Scope *
1455 AST_Decl::prefix_scope ()
1457 return this->prefix_scope_;
1460 void
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 ();
1478 break;
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 ();
1487 break;
1490 case AST_Decl::NT_sequence:
1492 AST_Sequence *s = dynamic_cast<AST_Sequence*> (this);
1493 this->contains_wstring_ = s->base_type ()->contains_wstring ();
1494 break;
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 ();
1503 break;
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 ();
1511 break;
1514 case AST_Decl::NT_wstring:
1515 this->contains_wstring_ = 1;
1516 break;
1518 default:
1519 this->contains_wstring_ = 0;
1520 break;
1524 return this->contains_wstring_;
1527 // Non-virtual - no need to override this one.
1528 void
1529 AST_Decl::contains_wstring (int val)
1531 this->contains_wstring_ = val;
1534 bool
1535 AST_Decl::masking_checks (AST_Decl *mod)
1537 if (!this->pd_local_name->case_compare (mod->local_name ()))
1539 return true;
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);
1547 if (po_mod)
1549 while (!!(po_mod = po_mod->previous_opening ()))
1551 if (po_mod == me_mod)
1553 return true;
1559 return false;
1562 bool
1563 AST_Decl::in_tmpl_mod_not_aliased () const
1565 return this->in_tmpl_mod_not_aliased_;
1568 void
1569 AST_Decl::in_tmpl_mod_not_aliased (bool val)
1571 this->in_tmpl_mod_not_aliased_ = val;
1574 void
1575 AST_Decl::annotation_appls (const AST_Annotation_Appls &annotations)
1577 if (annotatable ())
1579 annotation_appls () = annotations;
1581 else
1583 ACE_ERROR ((LM_ERROR,
1584 ACE_TEXT ("WARNING: %C is annotated but its type can't be annotated!\n"),
1585 full_name ()
1590 AST_Annotation_Appls&
1591 AST_Decl::annotation_appls ()
1593 if (!annotation_appls_)
1595 annotation_appls_ = new AST_Annotation_Appls ();
1597 return *annotation_appls_;
1600 void
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 ();
1609 a->dump (o);
1610 if (print_inline)
1612 dump_i (o, " ");
1614 else
1616 dump_i (o, "\n");
1617 idl_global->indent ()->skip_to (o);
1622 void
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);
1630 dump (o);
1633 ACE_OSTREAM_TYPE &
1634 operator<< (ACE_OSTREAM_TYPE &o, AST_Decl &d)
1636 d.dump_with_annotations (o, d.dump_annotations_inline ());
1638 return o;
1641 bool
1642 AST_Decl::annotatable () const
1644 return true;
1647 bool
1648 AST_Decl::dump_annotations_inline () const
1650 return false;
1653 bool
1654 AST_Decl::auto_dump_annotations () const
1656 return true;
1659 bool
1660 AST_Decl::builtin () const
1662 return builtin_;
1665 bool
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 ();
1677 bool
1678 AST_Decl::ami_visit ()
1680 return true;