Remove redundant void from tao_idl
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_decl.cpp
blobfcc0dabb3d8be584bfcec1ff68787e6a3d05128b
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_ (0),
132 flat_name_ (0),
133 contains_wstring_ (-1),
134 annotation_appls_ (0),
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 : 0),
141 pd_node_type (nt),
142 pd_line (idl_global->lineno ()),
143 pd_name (0),
144 pd_local_name (n ? n->last_component ()->copy () : 0),
145 pd_original_local_name (0),
146 full_name_ (0),
147 prefix_ (0),
148 version_ (0),
149 anonymous_ (anonymous),
150 typeid_set_ (false),
151 last_referenced_as_ (0),
152 prefix_scope_ (0),
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 = 0;
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_ (0),
179 flat_name_ (0),
180 contains_wstring_ (-1),
181 annotation_appls_ (0),
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 : 0),
188 pd_node_type (other->node_type ()),
189 pd_line (idl_global->lineno ()),
190 pd_name (0),
191 pd_local_name (name ? name->last_component ()->copy () : 0),
192 pd_original_local_name (0),
193 full_name_ (0),
194 prefix_ (0),
195 version_ (0),
196 anonymous_ (other->anonymous ()),
197 typeid_set_ (false),
198 last_referenced_as_ (0),
199 prefix_scope_ (0),
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 = 0;
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 = 0;
236 if (this->pd_local_name)
238 this->pd_local_name->destroy ();
239 delete this->pd_local_name;
240 this->pd_local_name = 0;
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 = 0;
250 if (this->last_referenced_as_)
252 this->last_referenced_as_->destroy ();
253 delete this->last_referenced_as_;
254 this->last_referenced_as_ = 0;
257 delete [] this->full_name_;
258 this->full_name_ = 0;
260 delete [] this->repoID_;
261 this->repoID_ = 0;
263 delete [] this->prefix_;
264 this->prefix_ = 0;
266 delete [] this->version_;
267 this->version_ = 0;
269 delete [] this->flat_name_;
270 this->flat_name_ = 0;
272 delete annotation_appls_;
273 annotation_appls_ = 0;
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 = 0;
314 // OK, not global. So copy name of containing scope, then
315 // smash last cdr of copy with new component
316 UTL_ScopedName *cn = 0;
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 = 0;
332 ACE_NEW (conc_name,
333 UTL_ScopedName (this->pd_local_name->copy (), 0));
334 this->pd_name->nconc (conc_name);
336 else
338 ACE_NEW (this->pd_name,
339 UTL_ScopedName (this->pd_local_name->copy (), 0));
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_ = 0;
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 = 0;
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 = 0;
500 const char *prefix = (this->prefix_ ? this->prefix_ : "");
501 UTL_Scope *scope = this->defined_in ();
502 const char *parent_prefix = 0;
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_ == 0)
666 size_t namelen = 0;
667 long first = true;
668 long second = false;
669 char *item_name = 0;
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 = 0;
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 = 0;
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_typedef:
805 return "typedef";
807 case NT_pre_defined:
808 return "primitive";
810 case NT_native:
811 return "native";
813 case NT_factory:
814 return "factory";
816 case NT_component:
817 case NT_component_fwd:
818 return "component";
820 case NT_home:
821 return "home";
823 case NT_eventtype:
824 case NT_eventtype_fwd:
825 return "eventtype";
827 case NT_type:
828 return "typename";
830 case NT_fixed:
831 return "fixed";
833 case NT_porttype:
834 return "porttype";
836 case NT_provides:
837 return "provides";
839 case NT_uses:
840 return "uses";
842 case NT_publishes:
843 return "publishes";
845 case NT_emits:
846 return "emits";
848 case NT_consumes:
849 return "consumes";
851 // No useful output for these.
852 default:
853 return "";
857 // Return TRUE if one of my ancestor scopes is "s"
858 // and FALSE otherwise.
859 bool
860 AST_Decl::has_ancestor (AST_Decl *s)
862 AST_Decl *work = this;
865 if (work == s)
867 return true;
870 AST_Module *m = dynamic_cast<AST_Module*> (s);
871 if (m)
873 while (!!(m = m->previous_opening ()))
875 if (static_cast<AST_Decl *> (m) == s)
877 return true;
882 work = work->pd_defined_in ?
883 ScopeAsDecl (work->pd_defined_in) :
885 } while (work);
887 return false;
890 bool
891 AST_Decl::is_child (AST_Decl *s)
893 if (this->defined_in ())
895 AST_Decl *d = ScopeAsDecl (this->defined_in ());
896 if (!d)
898 return 0;
901 if (!ACE_OS::strcmp (d->full_name (), s->full_name ()))
903 return 1;
907 return 0; // Not a child.
910 bool
911 AST_Decl::is_nested ()
913 AST_Decl *d = ScopeAsDecl (this->defined_in ());
915 // If we have an outermost scope and if that scope is not that of the Root,
916 // then we are defined at some nesting level.
917 return (d && d->node_type () != AST_Decl::NT_root);
920 // Dump this AST_Decl to the ostream o.
921 void
922 AST_Decl::dump (ACE_OSTREAM_TYPE &o)
924 this->pd_local_name->dump (o);
927 void
928 AST_Decl::dump_i (ACE_OSTREAM_TYPE &o, const char *s) const
930 // Have to use ACE_CString here to avoid ambiguous overload error, see
931 // SString.h for an the overloaded operator << () methods.
932 o << ACE_CString(s);
936 AST_Decl::ast_accept (ast_visitor *visitor)
938 return visitor->visit_decl (this);
941 // Data accessors.
943 const char *
944 AST_Decl::full_name ()
946 if (!this->full_name_)
948 this->compute_full_name ();
951 return this->full_name_;
954 const char *
955 AST_Decl::repoID ()
957 if (this->pd_node_type == NT_root)
959 delete [] this->repoID_;
960 this->repoID_ = ACE::strnew ("");
963 if (!this->repoID_)
965 this->compute_repoID ();
968 return this->repoID_;
971 void
972 AST_Decl::repoID (char *value)
974 delete [] this->repoID_;
975 this->repoID_ = value;
978 const char *
979 AST_Decl::prefix ()
981 return this->prefix_;
984 void
985 AST_Decl::prefix (const char *value)
987 delete [] this->prefix_;
988 this->prefix_ = ACE::strnew (value);
991 const char *
992 AST_Decl::version ()
994 if (!this->version_)
996 // Calling the method will compute if necessary.
997 const char *repo_id = this->repoID ();
999 // All forms of repo id should contain two colons, the
1000 // version coming after the second one.
1001 const char *tail1 = 0;
1002 const char *tail2 = 0;
1004 if (repo_id)
1006 tail1 = ACE_OS::strchr (repo_id, ':');
1009 if (tail1)
1011 tail2 = ACE_OS::strchr (tail1 + 1, ':');
1014 if (!this->typeid_set_ && tail2)
1016 this->version_ = ACE::strnew (tail2 + 1);
1018 else
1020 this->version_ = ACE::strnew ("1.0");
1024 return this->version_;
1027 void
1028 AST_Decl::version (char *value)
1030 // Previous #pragma version or #pragma id make this illegal.
1031 if ((!this->version_ || !ACE_OS::strcmp (this->version_, value))
1032 && !this->typeid_set_)
1034 delete [] this->version_;
1035 this->version_ = value;
1037 // Repo id is now computed eagerly, so a version set must update
1038 // is as well.
1039 if (this->repoID_)
1041 ACE_CString tmp (this->repoID_);
1042 ACE_CString::size_type const pos = tmp.rfind (':');
1043 if (pos != ACE_CString::npos)
1045 tmp = tmp.substr (0, pos + 1) + value;
1046 delete [] this->repoID_;
1047 this->repoID_ = ACE::strnew (tmp.fast_rep ());
1051 else
1053 idl_global->err ()->version_reset_error ();
1057 bool
1058 AST_Decl::anonymous () const
1060 return this->anonymous_;
1063 void
1064 AST_Decl::anonymous (bool val)
1066 this->anonymous_ = val;
1069 bool
1070 AST_Decl::typeid_set () const
1072 return this->typeid_set_;
1075 void
1076 AST_Decl::typeid_set (bool val)
1078 this->typeid_set_ = val;
1081 void
1082 AST_Decl::set_id_with_typeid (char *value)
1084 // Can't call 'typeid' twice, even with the same value.
1085 if (this->typeid_set ())
1087 idl_global->err ()->error1 (UTL_Error::EIDL_TYPEID_RESET, this);
1090 // Are we a legal type for 'typeid'?
1091 switch (this->pd_node_type)
1093 case AST_Decl::NT_field:
1095 AST_Decl::NodeType nt =
1096 ScopeAsDecl (this->defined_in ())->node_type ();
1098 if ( nt == AST_Decl::NT_valuetype
1099 || nt == AST_Decl::NT_eventtype)
1101 break;
1103 else
1105 idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, this);
1106 return;
1110 case AST_Decl::NT_module:
1111 case AST_Decl::NT_interface:
1112 case AST_Decl::NT_const:
1113 case AST_Decl::NT_typedef:
1114 case AST_Decl::NT_except:
1115 case AST_Decl::NT_attr:
1116 case AST_Decl::NT_op:
1117 case AST_Decl::NT_enum:
1118 case AST_Decl::NT_factory:
1119 case AST_Decl::NT_component:
1120 case AST_Decl::NT_home:
1121 case AST_Decl::NT_eventtype:
1122 break;
1124 default:
1125 idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, this);
1126 return;
1129 delete [] this->repoID_;
1130 this->repoID_ = 0;
1131 this->repoID (ACE::strnew (value));
1132 this->typeid_set_ = true;
1135 void
1136 AST_Decl::set_prefix_with_typeprefix (const char *value)
1138 // Are we a legal type for 'typeprefix'? This is checked only at
1139 // the top level.
1140 switch (this->pd_node_type)
1142 case AST_Decl::NT_module:
1143 case AST_Decl::NT_interface:
1144 case AST_Decl::NT_valuetype:
1145 case AST_Decl::NT_eventtype:
1146 case AST_Decl::NT_struct:
1147 case AST_Decl::NT_union:
1148 case AST_Decl::NT_except:
1149 break;
1151 default:
1152 idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEPREFIX, this);
1153 return;
1156 this->set_prefix_with_typeprefix_r (value, DeclAsScope (this));
1159 bool
1160 AST_Decl::imported ()
1162 return this->pd_imported;
1165 void
1166 AST_Decl::set_imported (bool is_it)
1168 this->pd_imported = is_it;
1171 bool
1172 AST_Decl::in_main_file ()
1174 return this->pd_in_main_file;
1177 void
1178 AST_Decl::set_in_main_file (bool is_it)
1180 this->pd_in_main_file = is_it;
1183 UTL_Scope *
1184 AST_Decl::defined_in ()
1186 return this->pd_defined_in;
1189 void
1190 AST_Decl::set_defined_in (UTL_Scope *s)
1192 this->pd_defined_in = s;
1195 AST_Decl::NodeType
1196 AST_Decl::node_type ()
1198 return this->pd_node_type;
1201 long
1202 AST_Decl::line ()
1204 return this->pd_line;
1207 void
1208 AST_Decl::set_line (long l)
1210 this->pd_line = l;
1213 ACE_CString &
1214 AST_Decl::file_name ()
1216 return this->pd_file_name;
1219 void
1220 AST_Decl::set_file_name (ACE_CString s)
1222 this->pd_file_name = s;
1225 UTL_ScopedName *
1226 AST_Decl::name ()
1228 return this->pd_name;
1231 // @@ Wherever compute_* are called, we should remember to delete them
1232 // after use.
1234 // Variation of the <name>. Computes scoped name string, applying
1235 // prefix and suffix to the local name component.
1236 UTL_ScopedName *
1237 AST_Decl::compute_name (const char *prefix,
1238 const char *suffix)
1240 if (!prefix || !suffix)
1242 return 0;
1245 // Prepare prefix_<local_name>_suffix string.
1247 ACE_CString suffix_str (suffix);
1248 ACE_CString local_str (this->local_name ()->get_string ());
1250 ACE_CString result_local_str (prefix);
1251 result_local_str += local_str;
1252 result_local_str += suffix_str;
1254 // Identifier for the resulting local name.
1255 Identifier *result_local_id = 0;
1256 ACE_NEW_RETURN (result_local_id,
1257 Identifier (result_local_str.c_str ()),
1260 // UTL_Scoped name for the resulting local name.
1261 UTL_ScopedName *result_local_name = 0;
1262 ACE_NEW_RETURN (result_local_name,
1263 UTL_ScopedName (result_local_id, 0),
1266 // Global scope?
1267 UTL_ScopedName *result_name = 0;
1268 if (!this->defined_in ())
1270 result_name = result_local_name;
1272 else
1274 // OK, not global. So copy name of containing scope, then
1275 // smash last cdr of copy with new component.
1277 AST_Decl *d = ScopeAsDecl (this->defined_in ());
1278 if (d)
1280 UTL_ScopedName *cn = d->name ();
1281 if (cn)
1283 result_name = (UTL_ScopedName *) cn->copy ();
1284 if (result_name)
1286 result_name->nconc (result_local_name);
1288 else
1290 result_name = result_local_name;
1296 return result_name;
1299 void
1300 AST_Decl::set_name (UTL_ScopedName *n)
1302 if (this->pd_name == n)
1304 return;
1307 if (this->pd_name)
1309 this->pd_name->destroy ();
1310 delete this->pd_name;
1313 this->pd_name = n;
1315 if (n)
1317 if (this->pd_local_name)
1319 this->pd_local_name->destroy ();
1320 delete this->pd_local_name;
1323 this->pd_local_name = n->last_component ()->copy ();
1325 // The name without _cxx_ prefix removed, if there was any.
1326 if (this->pd_original_local_name)
1328 this->pd_original_local_name->destroy ();
1329 delete this->pd_original_local_name;
1332 this->original_local_name (n->last_component ());
1334 // These will be recomputed on demand.
1335 delete [] this->flat_name_;
1336 this->flat_name_ = 0;
1338 delete [] this->full_name_;
1339 this->full_name_ = 0;
1341 delete [] this->repoID_;
1342 this->repoID_ = 0;
1346 Identifier *
1347 AST_Decl::local_name () const
1349 return this->pd_local_name;
1352 void
1353 AST_Decl::local_name (Identifier *id)
1355 if (this->pd_local_name)
1357 this->pd_local_name->destroy ();
1360 delete this->pd_local_name;
1361 this->pd_local_name = id;
1364 Identifier *
1365 AST_Decl::compute_local_name (const char *prefix,
1366 const char *suffix)
1368 if (!prefix || !suffix)
1370 return 0;
1373 // Init the result with prefix.
1374 ACE_CString result_str (prefix);
1376 // Put local.
1377 result_str += ACE_CString (this->local_name ()->get_string ());
1379 // Put suffix.
1380 result_str += ACE_CString (suffix);
1382 // Identifier for the resulting local name.
1383 Identifier *result_id = 0;
1384 ACE_NEW_RETURN (result_id,
1385 Identifier (result_str.c_str ()),
1388 return result_id;
1391 // If there is _cxx_ in the beginning, we will remove that and keep
1392 // a copy of the original name. TAO IDL's front end adds _cxx_
1393 // prefix to the all the reserved keywords. But when we invoke the
1394 // operation remotely, we should be sending only the name with out
1395 // "_cxx_" prefix.
1396 void
1397 AST_Decl::original_local_name (Identifier *local_name)
1399 // Remove _cxx_ if it is present.
1400 if (ACE_OS::strstr (local_name->get_string (), "_cxx_")
1401 == local_name->get_string ())
1403 // AACE_CString class is good to do this stuff.
1404 ACE_CString name_str (local_name->get_string ());
1406 // Remove _cxx_.
1407 name_str = name_str.substr (ACE_OS::strlen ("_cxx_"));
1409 // Assign to the Identifier variable.
1410 ACE_NEW (this->pd_original_local_name,
1411 Identifier (name_str.c_str ()));
1413 else
1415 this->pd_original_local_name = local_name->copy ();
1419 Identifier *
1420 AST_Decl::original_local_name ()
1422 return this->pd_original_local_name;
1425 bool
1426 AST_Decl::is_defined ()
1428 // AST_Interface, AST_Structure, and AST_Union will
1429 // override this, as will AST_InterfaceFwd, etc.
1430 return true;
1433 UTL_ScopedName *
1434 AST_Decl::last_referenced_as () const
1436 return this->last_referenced_as_;
1439 void
1440 AST_Decl::last_referenced_as (UTL_ScopedName *n)
1442 if (this->last_referenced_as_)
1444 this->last_referenced_as_->destroy ();
1447 delete this->last_referenced_as_;
1448 this->last_referenced_as_ = n;
1451 UTL_Scope *
1452 AST_Decl::prefix_scope ()
1454 return this->prefix_scope_;
1457 void
1458 AST_Decl::prefix_scope (UTL_Scope *s)
1460 this->prefix_scope_ = s;
1463 // Container types will override this.
1465 AST_Decl::contains_wstring ()
1467 if (this->contains_wstring_ == -1)
1469 switch (this->node_type ())
1471 case AST_Decl::NT_array:
1473 AST_Array *a = dynamic_cast<AST_Array*> (this);
1474 this->contains_wstring_ = a->base_type ()->contains_wstring ();
1475 break;
1478 case AST_Decl::NT_except:
1479 case AST_Decl::NT_struct:
1480 case AST_Decl::NT_union:
1482 AST_Structure *s = dynamic_cast<AST_Structure*> (this);
1483 this->contains_wstring_ = s->contains_wstring ();
1484 break;
1487 case AST_Decl::NT_sequence:
1489 AST_Sequence *s = dynamic_cast<AST_Sequence*> (this);
1490 this->contains_wstring_ = s->base_type ()->contains_wstring ();
1491 break;
1494 case AST_Decl::NT_attr:
1495 case AST_Decl::NT_field:
1496 case AST_Decl::NT_union_branch:
1498 AST_Field *f = dynamic_cast<AST_Field*> (this);
1499 this->contains_wstring_ = f->field_type ()->contains_wstring ();
1500 break;
1503 case AST_Decl::NT_typedef:
1505 AST_Typedef *td = dynamic_cast<AST_Typedef*> (this);
1506 this->contains_wstring_ =
1507 td->primitive_base_type ()->contains_wstring ();
1508 break;
1511 case AST_Decl::NT_wstring:
1512 this->contains_wstring_ = 1;
1513 break;
1515 default:
1516 this->contains_wstring_ = 0;
1517 break;
1521 return this->contains_wstring_;
1524 // Non-virtual - no need to override this one.
1525 void
1526 AST_Decl::contains_wstring (int val)
1528 this->contains_wstring_ = val;
1531 bool
1532 AST_Decl::masking_checks (AST_Decl *mod)
1534 if (!this->pd_local_name->case_compare (mod->local_name ()))
1536 return true;
1539 AST_Module *me_mod = dynamic_cast<AST_Module*> (this);
1541 if (me_mod != 0)
1543 AST_Module *po_mod = dynamic_cast<AST_Module*> (mod);
1544 if (po_mod)
1546 while (!!(po_mod = po_mod->previous_opening ()))
1548 if (po_mod == me_mod)
1550 return true;
1556 return false;
1559 bool
1560 AST_Decl::in_tmpl_mod_not_aliased () const
1562 return this->in_tmpl_mod_not_aliased_;
1565 void
1566 AST_Decl::in_tmpl_mod_not_aliased (bool val)
1568 this->in_tmpl_mod_not_aliased_ = val;
1571 //Narrowing methods for AST_Decl.
1573 IMPL_NARROW_FROM_DECL(AST_Decl)
1576 void
1577 AST_Decl::annotation_appls (const AST_Annotation_Appls &annotations)
1579 if (annotatable ())
1581 annotation_appls () = annotations;
1583 else
1585 ACE_ERROR ((LM_ERROR,
1586 ACE_TEXT ("WARNING: %C is annotated but its type can't be annotated!\n"),
1587 full_name ()
1592 AST_Annotation_Appls&
1593 AST_Decl::annotation_appls ()
1595 if (!annotation_appls_)
1597 annotation_appls_ = new AST_Annotation_Appls ();
1599 return *annotation_appls_;
1602 void
1603 AST_Decl::dump_annotations (ACE_OSTREAM_TYPE &o, bool print_inline)
1605 AST_Annotation_Appls::iterator
1606 i = annotation_appls ().begin (),
1607 finished = annotation_appls ().end ();
1608 for (; i != finished; ++i)
1610 AST_Annotation_Appl* a = i->get ();
1611 a->dump (o);
1612 if (print_inline)
1614 dump_i (o, " ");
1616 else
1618 dump_i (o, "\n");
1619 idl_global->indent ()->skip_to (o);
1624 void
1625 AST_Decl::dump_with_annotations (ACE_OSTREAM_TYPE &o, bool inline_annotations)
1627 if (annotatable () && auto_dump_annotations())
1629 dump_annotations (o, inline_annotations);
1632 dump (o);
1635 ACE_OSTREAM_TYPE &
1636 operator<< (ACE_OSTREAM_TYPE &o, AST_Decl &d)
1638 d.dump_with_annotations (o, d.dump_annotations_inline ());
1640 return o;
1643 bool
1644 AST_Decl::annotatable () const
1646 return true;
1649 bool
1650 AST_Decl::dump_annotations_inline () const
1652 return false;
1655 bool
1656 AST_Decl::auto_dump_annotations () const
1658 return true;
1661 bool
1662 AST_Decl::builtin () const
1664 return builtin_;
1667 bool
1668 AST_Decl::should_be_dumped () const
1670 return !builtin () || idl_global->dump_builtins_;
1673 AST_Annotation_Appls &
1674 AST_Decl::annotations ()
1676 return annotation_appls ();
1679 bool
1680 AST_Decl::ami_visit ()
1682 return true;