Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_factory.cpp
blobde340aaaea0580080cd4bf2e702d5b8749e02efc
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_Factory nodes denote OBV or component home factory
66 // construct declarations.
67 // AST_Factory is a subclass of AST_Decl (it is not a type!)
68 // and of UTL_Scope (the arguments are managed in a scope).
70 #include "ast_factory.h"
71 #include "ast_argument.h"
72 #include "ast_exception.h"
73 #include "ast_visitor.h"
74 #include "global_extern.h"
75 #include "utl_err.h"
76 #include "utl_identifier.h"
77 #include "utl_exceptlist.h"
78 #include "utl_namelist.h"
80 AST_Decl::NodeType const
81 AST_Factory::NT = AST_Decl::NT_factory;
83 AST_Factory::AST_Factory (UTL_ScopedName *n)
84 : COMMON_Base (true,
85 false), //@@ Always local, never abstract
86 AST_Decl (AST_Decl::NT_factory,
87 n),
88 UTL_Scope (AST_Decl::NT_factory),
89 pd_exceptions (nullptr),
90 pd_n_exceptions (0),
91 argument_count_ (-1),
92 has_native_ (0)
96 AST_Factory::~AST_Factory ()
100 // Public operations.
102 UTL_ExceptList *
103 AST_Factory::exceptions ()
105 return this->pd_exceptions;
109 AST_Factory::n_exceptions ()
111 return this->pd_n_exceptions;
114 // Return the member count.
116 AST_Factory::argument_count ()
118 this->compute_argument_attr ();
120 return this->argument_count_;
123 // Return if any argument or the return type is a <native> type.
125 AST_Factory::has_native ()
127 this->compute_argument_attr ();
129 return this->has_native_;
132 void
133 AST_Factory::destroy ()
135 if (nullptr != this->pd_exceptions)
137 this->pd_exceptions->destroy ();
138 this->pd_exceptions = nullptr;
141 this->AST_Decl::destroy ();
142 this->UTL_Scope::destroy ();
145 UTL_ExceptList *
146 AST_Factory::be_add_exceptions (UTL_ExceptList *t)
148 if (this->pd_exceptions != nullptr)
150 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES,
151 this);
153 else
155 this->pd_exceptions = t;
156 this->pd_n_exceptions = (t == nullptr ? 0 : t->length ());
159 return this->pd_exceptions;
162 // Private operations.
164 // Compute total number of members.
166 AST_Factory::compute_argument_attr ()
168 if (this->argument_count_ != -1)
170 return 0;
173 AST_Decl *d = nullptr;
174 AST_Type *type = nullptr;
175 AST_Argument *arg = nullptr;
177 this->argument_count_ = 0;
179 // If there are elements in this scope.
180 if (this->nmembers () > 0)
182 for (UTL_ScopeActiveIterator i (this, IK_decls);
183 !i.is_done ();
184 i.next ())
186 // Get the next AST decl node.
187 d = i.item ();
189 if (d->node_type () == AST_Decl::NT_argument)
191 this->argument_count_++;
193 arg = dynamic_cast<AST_Argument*> (d);
195 type = dynamic_cast<AST_Type*> (arg->field_type ());
197 if (type->node_type () == AST_Decl::NT_native)
199 this->has_native_ = 1;
205 return 0;
208 AST_Argument *
209 AST_Factory::fe_add_argument (AST_Argument *t)
211 return dynamic_cast<AST_Argument*> (this->fe_add_ref_decl (t));
214 UTL_NameList *
215 AST_Factory::fe_add_exceptions (UTL_NameList *t)
217 UTL_ScopedName *nl_n = nullptr;
218 AST_Type *fe = nullptr;
219 AST_Decl *d = nullptr;
221 this->pd_exceptions = nullptr;
223 for (UTL_NamelistActiveIterator nl_i (t);
224 !nl_i.is_done ();
225 nl_i.next ())
227 nl_n = nl_i.item ();
229 d = this->defined_in ()->lookup_by_name (nl_n, true);
231 if (d == nullptr)
233 idl_global->err ()->lookup_error (nl_n);
234 return nullptr;
237 AST_Decl::NodeType nt = d->node_type ();
239 if (nt != AST_Decl::NT_except
240 && nt != AST_Decl::NT_param_holder)
242 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES,
243 this);
244 return nullptr;
247 fe = dynamic_cast<AST_Type*> (d);
249 UTL_ExceptList *el = nullptr;
250 ACE_NEW_RETURN (el,
251 UTL_ExceptList (fe, nullptr),
252 nullptr);
254 if (this->pd_exceptions == nullptr)
256 this->pd_exceptions = el;
258 else
260 this->pd_exceptions->nconc (el);
263 this->pd_n_exceptions++;
266 // This return value is never used, it's easier to
267 // destroy it here and return 0 than to destroy it
268 // each place it is passed in.
269 t->destroy ();
270 delete t;
271 t = nullptr;
273 return t;
276 // Dump this AST_Factory node to the ostream o.
277 void
278 AST_Factory::dump (ACE_OSTREAM_TYPE &o)
280 AST_Decl *d = nullptr;
282 this->dump_i (o, "factory ");
283 this->local_name ()->dump (o);
284 this->dump_i (o, "(");
286 // Iterator must be explicitly advanced inside the loop.
287 for (UTL_ScopeActiveIterator i (this, IK_decls);
288 !i.is_done ();)
290 d = i.item ();
291 d->dump (o);
292 i.next ();
294 if (!i.is_done())
296 this->dump_i (o, ", ");
300 this->dump_i (o, ")");
304 AST_Factory::ast_accept (ast_visitor *visitor)
306 return visitor->visit_factory (this);