Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_field.cpp
blobbacbf80714cccb3e4ab41e31593dea7706deb4d2
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 // AST_Fields denote fields in IDL structure, union and exception
66 // declarations. AST_Field is also used as a superclass of AST_Argument
67 // and AST_UnionBranch.
68 // AST_Fields have a field type (a subclass of AST_Type) and a name
69 // (a UTL_ScopedName).
71 // AST_Field supplies two constructors, one to be used in constructing
72 // AST_Field nodes, the other to be used in constructing AST_Argument
73 // nodes and AST_UnionBranch nodes.
75 #include "ast_field.h"
76 #include "ast_param_holder.h"
77 #include "ast_visitor.h"
79 #include "utl_identifier.h"
80 #include "utl_err.h"
82 #include "global_extern.h"
84 AST_Decl::NodeType const
85 AST_Field::NT = AST_Decl::NT_field;
87 AST_Field::AST_Field (AST_Type *ft,
88 UTL_ScopedName *n,
89 Visibility vis)
90 : COMMON_Base (),
91 AST_Decl (AST_Decl::NT_field,
92 n),
93 ref_type_ (ft),
94 visibility_ (vis),
95 owns_base_type_ (false)
97 FE_Utils::tmpl_mod_ref_check (this, ft);
99 AST_Decl::NodeType fnt = ft->node_type ();
101 // In each of these cases, we are responsible for destroying
102 // our ref_type_ member.
103 this->owns_base_type_ =
104 fnt == AST_Decl::NT_array
105 || fnt == AST_Decl::NT_sequence
106 || fnt == AST_Decl::NT_fixed
107 || fnt == AST_Decl::NT_param_holder;
109 if (fnt == AST_Decl::NT_param_holder)
111 AST_Param_Holder *ph = dynamic_cast<AST_Param_Holder*> (ft);
113 if (ph->info ()->type_ == AST_Decl::NT_const)
115 idl_global->err ()->not_a_type (ft);
118 else if (fnt == AST_Decl::NT_except)
120 idl_global->err ()->not_a_type (ft);
124 // To be used when constructing a node of a subclass of AST_Field.
125 AST_Field::AST_Field (AST_Decl::NodeType nt,
126 AST_Type *ft,
127 UTL_ScopedName *n,
128 Visibility vis)
129 : COMMON_Base (),
130 AST_Decl (nt,
132 ref_type_ (ft),
133 visibility_ (vis),
134 owns_base_type_ (false)
136 AST_Decl::NodeType fnt = ft->node_type ();
138 // In each of these cases, we are responsible for destroying
139 // our ref_type_ member.
140 this->owns_base_type_ =
141 fnt == AST_Decl::NT_array
142 || fnt == AST_Decl::NT_sequence
143 || fnt == AST_Decl::NT_fixed
144 || fnt == AST_Decl::NT_param_holder;
146 if (fnt == AST_Decl::NT_param_holder)
148 AST_Param_Holder *ph = dynamic_cast<AST_Param_Holder*> (ft);
150 if (ph->info ()->type_ == AST_Decl::NT_const)
152 idl_global->err ()->not_a_type (ft);
157 AST_Field::AST_Field (
158 UTL_ScopedName *name,
159 AST_Field *other)
160 : COMMON_Base (),
161 AST_Decl (name, dynamic_cast<AST_Decl*>(other)),
162 ref_type_ (other->field_type ()),
163 visibility_ (other->visibility ()),
164 owns_base_type_ (false)
166 // We definitely don't own the base type and the param holder check shouldn't
167 // be an issue here.
170 AST_Field::~AST_Field ()
174 void
175 AST_Field::dump (ACE_OSTREAM_TYPE &o)
177 switch (this->visibility_)
179 case vis_PRIVATE:
180 this->dump_i (o, "private ");
182 break;
183 case vis_PUBLIC:
184 this->dump_i (o, "public ");
186 break;
187 case vis_NA:
188 break;
191 this->ref_type_->local_name ()->dump (o);
193 this->dump_i (o, " ");
195 this->local_name ()->dump (o);
199 AST_Field::ast_accept (ast_visitor *visitor)
201 return visitor->visit_field (this);
204 void
205 AST_Field::destroy ()
207 if (this->owns_base_type_ && this->ref_type_)
209 this->ref_type_->destroy ();
210 delete this->ref_type_;
211 this->ref_type_ = nullptr;
214 this->AST_Decl::destroy ();
217 AST_Type *
218 AST_Field::field_type () const
220 return this->ref_type_;
223 AST_Field::Visibility
224 AST_Field::visibility () const
226 return this->visibility_;
229 void
230 AST_Field::visibility (AST_Field::Visibility val)
232 visibility_ = val;
236 AST_Field::contains_wstring ()
238 return this->ref_type_->contains_wstring ();
241 bool AST_Field::annotatable () const
243 return true;