Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_attribute.cpp
blobaa222f9060c7cc7000cdad9909544d0fe28d738d
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_Attribute nodes denote IDL attribute declarations.
66 // AST_Attribute nodes are AST_Fields with a readonly indication.
67 // Hence they have a name (an UTL_ScopedName), a type (a subtype
68 // of AST_Type) and a boolean indicating whether the attribute is
69 // readonly.
71 #include "utl_namelist.h"
72 #include "utl_exceptlist.h"
73 #include "utl_scope.h"
74 #include "utl_err.h"
75 #include "global_extern.h"
77 #include "ast_attribute.h"
78 #include "ast_exception.h"
79 #include "ast_visitor.h"
81 AST_Decl::NodeType const
82 AST_Attribute::NT = AST_Decl::NT_attr;
84 AST_Attribute::AST_Attribute (bool ro,
85 AST_Type *ft,
86 UTL_ScopedName *n,
87 bool local,
88 bool abstract)
89 : COMMON_Base (local,
90 abstract),
91 AST_Decl (AST_Decl::NT_attr,
92 n),
93 AST_Field (AST_Decl::NT_attr,
94 ft,
95 n),
96 pd_readonly (ro),
97 pd_get_exceptions (0),
98 pd_set_exceptions (0)
102 AST_Attribute::~AST_Attribute (void)
106 // Redefinition of inherited virtual operations.
108 // Dump this AST_Attribute to the ostream o.
109 void
110 AST_Attribute::dump (ACE_OSTREAM_TYPE &o)
112 this->dump_i (o, (this->pd_readonly == true
113 ? "readonly attribute "
114 : "attribute "));
116 this->AST_Field::dump (o);
120 AST_Attribute::ast_accept (ast_visitor *visitor)
122 return visitor->visit_attribute (this);
125 void
126 AST_Attribute::destroy (void)
128 // No need to delete our exception lists, the
129 // destroy() method does it. The UTL_ExceptList
130 // destroy() method does NOT delete the contained
131 // exception nodes.
133 if (this->pd_get_exceptions != 0)
135 this->pd_get_exceptions->destroy ();
136 this->pd_get_exceptions = 0;
139 if (this->pd_set_exceptions != 0)
141 this->pd_set_exceptions->destroy ();
142 this->pd_set_exceptions = 0;
145 this->AST_Field::destroy ();
148 UTL_ExceptList *
149 AST_Attribute::be_add_get_exceptions (UTL_ExceptList *t)
151 if (this->pd_get_exceptions != 0)
153 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES,
154 this);
156 else
158 this->pd_get_exceptions = t;
161 return this->pd_get_exceptions;
164 UTL_ExceptList *
165 AST_Attribute::be_add_set_exceptions (UTL_ExceptList *t)
167 if (this->pd_set_exceptions != 0)
169 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES,
170 this);
172 else
174 this->pd_set_exceptions = t;
177 return this->pd_set_exceptions;
180 // Data accessors.
182 bool
183 AST_Attribute::readonly (void) const
185 return this->pd_readonly;
188 UTL_ExceptList *
189 AST_Attribute::get_get_exceptions (void) const
191 return this->pd_get_exceptions;
194 UTL_ExceptList *
195 AST_Attribute::get_set_exceptions (void) const
197 return this->pd_set_exceptions;
200 // NOTE: No attempt is made to ensure that exceptions are mentioned
201 // only once..
202 UTL_NameList *
203 AST_Attribute::fe_add_get_exceptions (UTL_NameList *t)
205 UTL_ScopedName *nl_n = 0;
206 AST_Type *fe = 0;
207 AST_Decl *d = 0;
209 this->pd_get_exceptions = 0;
211 for (UTL_NamelistActiveIterator nl_i (t);
212 !nl_i.is_done ();
213 nl_i.next ())
215 nl_n = nl_i.item ();
217 d = this->defined_in ()->lookup_by_name (nl_n, true);
219 if (d == 0)
221 idl_global->err ()->lookup_error (nl_n);
222 return 0;
225 AST_Decl::NodeType nt = d->node_type ();
227 if (nt != AST_Decl::NT_except
228 && nt != AST_Decl::NT_param_holder)
230 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES,
231 this);
232 return 0;
235 fe = dynamic_cast<AST_Type*> (d);
237 UTL_ExceptList *el = 0;
238 ACE_NEW_RETURN (el,
239 UTL_ExceptList (fe, 0),
242 if (this->pd_get_exceptions == 0)
244 this->pd_get_exceptions = el;
246 else
248 this->pd_get_exceptions->nconc (el);
252 return t;
255 // NOTE: No attempt is made to ensure that exceptions are mentioned
256 // only once..
257 UTL_NameList *
258 AST_Attribute::fe_add_set_exceptions (UTL_NameList *t)
260 UTL_ScopedName *nl_n = 0;
261 AST_Type *fe = 0;
262 AST_Decl *d = 0;
264 this->pd_set_exceptions = 0;
266 for (UTL_NamelistActiveIterator nl_i (t); !nl_i.is_done (); nl_i.next ())
268 nl_n = nl_i.item ();
270 d = this->defined_in ()->lookup_by_name (nl_n, true);
272 if (d == 0)
274 idl_global->err ()->lookup_error (nl_n);
275 return 0;
278 AST_Decl::NodeType nt = d->node_type ();
280 if (nt != AST_Decl::NT_except
281 && nt != AST_Decl::NT_param_holder)
283 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES,
284 this);
285 return 0;
288 fe = dynamic_cast<AST_Type*> (d);
290 UTL_ExceptList *el = 0;
291 ACE_NEW_RETURN (el,
292 UTL_ExceptList (fe, 0),
295 if (this->pd_set_exceptions == 0)
297 this->pd_set_exceptions = el;
299 else
301 this->pd_set_exceptions->nconc (el);
305 return t;
308 bool
309 AST_Attribute::annotatable () const
311 return true;
314 IMPL_NARROW_FROM_DECL(AST_Attribute)