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
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
56 Mountain View, California 94043
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // AST_Operation nodes denote IDL operation declarations
66 // AST_Operations are a subclass of AST_Decl (they are not a type!)
67 // and of UTL_Scope (the arguments are managed in a scope).
68 // AST_Operations have a return type (a subclass of AST_Type),
69 // a bitfield for denoting various properties of the operation (the
70 // values are ORed together from constants defined in the enum
71 // AST_Operation::FLags), a name (a UTL_ScopedName), a context
72 // (implemented as a list of Strings, a UTL_StrList), and a raises
73 // clause (implemented as an array of AST_Exceptions).
75 #include "ast_operation.h"
76 #include "ast_predefined_type.h"
77 #include "ast_argument.h"
78 #include "ast_exception.h"
79 #include "ast_param_holder.h"
80 #include "ast_typedef.h"
81 #include "ast_visitor.h"
84 #include "utl_namelist.h"
85 #include "utl_exceptlist.h"
86 #include "utl_identifier.h"
87 #include "utl_string.h"
88 #include "utl_strlist.h"
90 #include "global_extern.h"
92 AST_Decl::NodeType
const
93 AST_Operation::NT
= AST_Decl::NT_op
;
95 AST_Operation::AST_Operation (AST_Type
*rt
,
100 : COMMON_Base (local
,
102 AST_Decl(AST_Decl::NT_op
,
104 UTL_Scope(AST_Decl::NT_op
),
109 argument_count_ (-1),
110 has_in_arguments_ (false),
113 AST_PredefinedType
*pdt
= 0;
115 // Check that if the operation is oneway, the return type must be void.
116 if (rt
!= 0 && pd_flags
== OP_oneway
)
118 if (rt
->node_type () != AST_Decl::NT_pre_defined
)
120 idl_global
->err ()->error1 (UTL_Error::EIDL_NONVOID_ONEWAY
,
125 pdt
= dynamic_cast<AST_PredefinedType
*> (rt
);
127 if (pdt
== 0 || pdt
->pt () != AST_PredefinedType::PT_void
)
129 idl_global
->err ()->error1 (UTL_Error::EIDL_NONVOID_ONEWAY
,
136 AST_Operation::~AST_Operation (void)
140 // Public operations.
143 AST_Operation::void_return_type (void)
145 AST_Type
* type
= this->return_type ();
147 return (type
->node_type () == AST_Decl::NT_pre_defined
148 && (dynamic_cast<AST_PredefinedType
*> (type
)->pt ()
149 == AST_PredefinedType::PT_void
));
152 // Return the member count.
154 AST_Operation::argument_count (void)
156 this->compute_argument_attr ();
158 return this->argument_count_
;
161 // Return the IN/INOUT member flag.
163 AST_Operation::has_in_arguments (void)
165 this->compute_argument_attr ();
167 return this->has_in_arguments_
;
171 AST_Operation::count_arguments_with_direction (int direction_mask
)
175 for (UTL_ScopeActiveIterator
si (this, UTL_Scope::IK_decls
);
179 AST_Argument
*arg
= dynamic_cast<AST_Argument
*> (si
.item ());
181 if ((arg
->direction () & direction_mask
) != 0)
191 // Return if any argument or the return type is a <native> type.
193 AST_Operation::has_native (void)
195 this->compute_argument_attr ();
197 return this->has_native_
;
201 AST_Operation::destroy (void)
203 // No need to delete our exception list, the
204 // destroy() method does it. The UTL_ExceptList
205 // destroy() method does NOT delete the contained
208 if (this->pd_exceptions
!= 0)
210 this->pd_exceptions
->destroy ();
211 this->pd_exceptions
= 0;
214 this->UTL_Scope::destroy ();
215 this->AST_Decl::destroy ();
219 AST_Operation::be_add_exceptions (UTL_ExceptList
*t
)
221 if (this->pd_exceptions
!= 0)
223 idl_global
->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES
,
228 this->pd_exceptions
= t
;
231 return this->pd_exceptions
;
234 // Private operations.
236 // Compute total number of members.
238 AST_Operation::compute_argument_attr (void)
240 if (this->argument_count_
!= -1)
247 AST_Argument
*arg
= 0;
249 this->argument_count_
= 0;
251 // If there are elements in this scope.
252 if (this->nmembers () > 0)
254 // Instantiate a scope iterator.
255 for (UTL_ScopeActiveIterator
si (this, UTL_Scope::IK_decls
);
259 // Get the next AST decl node.
262 if (d
->node_type () == AST_Decl::NT_argument
)
264 this->argument_count_
++;
266 arg
= dynamic_cast<AST_Argument
*> (d
);
268 if (arg
->direction() == AST_Argument::dir_IN
||
269 arg
->direction() == AST_Argument::dir_INOUT
)
271 this->has_in_arguments_
= true;
275 type
= dynamic_cast<AST_Type
*> (arg
->field_type ());
277 if (type
->node_type () == AST_Decl::NT_native
)
279 this->has_native_
= 1;
285 type
= dynamic_cast<AST_Type
*> (this->return_type ());
287 if (type
->node_type () == AST_Decl::NT_native
)
289 this->has_native_
= 1;
295 // Add this context (a UTL_StrList) to this scope.
297 AST_Operation::fe_add_context (UTL_StrList
*t
)
299 this->pd_context
= t
;
304 // Add these exceptions (identified by name) to this scope.
305 // This looks up each name to resolve it to the name of a known
306 // exception, and then adds the referenced exception to the list
307 // exceptions that this operation can raise.
309 // NOTE: No attempt is made to ensure that exceptions are mentioned
312 AST_Operation::fe_add_exceptions (UTL_NameList
*t
)
319 UTL_ScopedName
*nl_n
= 0;
323 this->pd_exceptions
= 0;
325 for (UTL_NamelistActiveIterator
nl_i (t
); !nl_i
.is_done (); nl_i
.next ())
328 d
= this->lookup_by_name (nl_n
, true);
332 idl_global
->err ()->lookup_error (nl_n
);
336 AST_Decl::NodeType nt
= d
->node_type ();
340 case AST_Decl::NT_except
:
342 case AST_Decl::NT_param_holder
:
344 AST_Param_Holder
*ph
= dynamic_cast<AST_Param_Holder
*> (d
);
346 nt
= ph
->info ()->type_
;
348 if (nt
!= AST_Decl::NT_except
349 && nt
!= AST_Decl::NT_type
)
351 idl_global
->err ()->mismatched_template_param (
352 ph
->info ()->name_
.c_str ());
357 case AST_Decl::NT_typedef
:
359 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (d
);
361 nt
= td
->primitive_base_type ()->node_type ();
363 if (nt
!= AST_Decl::NT_except
)
365 idl_global
->err ()->error1 (
366 UTL_Error::EIDL_ILLEGAL_RAISES
,
372 case AST_Decl::NT_native
:
374 // This is the only use case for this node type.
376 ACE_OS::strcmp (d
->local_name ()->get_string (),
377 "UserExceptionBase");
381 idl_global
->err ()->error1 (
382 UTL_Error::EIDL_ILLEGAL_RAISES
,
389 idl_global
->err ()->error1 (
390 UTL_Error::EIDL_ILLEGAL_RAISES
,
397 (this->flags () == AST_Operation::OP_oneway
);
399 fe
= dynamic_cast<AST_Type
*> (d
);
401 if (oneway_op
&& fe
!= 0)
403 idl_global
->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES
,
409 idl_global
->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES
,
414 if (this->pd_exceptions
== 0)
416 ACE_NEW_RETURN (this->pd_exceptions
,
423 UTL_ExceptList
*el
= 0;
429 this->pd_exceptions
->nconc (el
);
433 // This return value is never used, it's easier to
434 // destroy it here and return 0 than to destroy it
435 // each place it is passed in.
443 AST_Operation::fe_add_argument (AST_Argument
*t
)
445 return dynamic_cast<AST_Argument
*> (this->fe_add_decl (t
));
448 // Dump this AST_Operation node (an operation) to the ostream o.
450 AST_Operation::dump (ACE_OSTREAM_TYPE
&o
)
456 if (this->pd_flags
== OP_oneway
)
458 this->dump_i (o
, "oneway ");
460 else if (this->pd_flags
== OP_idempotent
)
462 this->dump_i (o
, "idempotent ");
465 this->pd_return_type
->name ()->dump (o
);
466 this->dump_i (o
, " ");
467 this->local_name ()->dump (o
);
468 this->dump_i (o
, "(");
470 // Must advance the iterator explicity inside the loop.
471 for (UTL_ScopeActiveIterator
i (this, IK_decls
); !i
.is_done ();)
479 this->dump_i (o
, ", ");
483 this->dump_i (o
, ")");
485 if (this->pd_exceptions
!= 0)
487 this->dump_i (o
, " raises(");
489 // Must advance the iterator explicity inside the loop.
490 for (UTL_ExceptlistActiveIterator
ei (this->pd_exceptions
);
495 e
->local_name ()->dump (o
);
499 this->dump_i (o
, ", ");
503 this->dump_i (o
, ")");
506 if (this->pd_context
!= 0)
508 this->dump_i (o
, " context(");
510 // Must advance the iterator explicity inside the loop.
511 for (UTL_StrlistActiveIterator
si (this->pd_context
); !si
.is_done();)
515 this->dump_i (o
, s
->get_string ());
519 this->dump_i (o
, ", ");
523 this->dump_i (o
, ")");
528 AST_Operation::ast_accept (ast_visitor
*visitor
)
530 return visitor
->visit_operation (this);
536 AST_Operation::return_type (void)
538 return this->pd_return_type
;
542 AST_Operation::flags (void)
544 return this->pd_flags
;
548 AST_Operation::context (void)
550 return this->pd_context
;
554 AST_Operation::exceptions (void)
556 return this->pd_exceptions
;
560 AST_Operation::annotatable () const
565 IMPL_NARROW_FROM_DECL(AST_Operation
)
566 IMPL_NARROW_FROM_SCOPE(AST_Operation
)