1
// ast_union.cpp,v 1.31 2003/11/10 20:29:25 dhinton Exp
7
Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
8
States of America. All Rights Reserved.
10
This product is protected by copyright and distributed under the following
11
license restricting its use.
13
The Interface Definition Language Compiler Front End (CFE) is made
14
available for your use provided that you include this license and copyright
15
notice on all media and documentation and the software program in which
16
this product is incorporated in whole or part. You may copy and extend
17
functionality (but may not remove functionality) of the Interface
18
Definition Language CFE without charge, but you are not authorized to
19
license or distribute it to anyone else except as part of a product or
20
program developed by you or with the express written consent of Sun
21
Microsystems, Inc. ("Sun").
23
The names of Sun Microsystems, Inc. and any of its subsidiaries or
24
affiliates may not be used in advertising or publicity pertaining to
25
distribution of Interface Definition Language CFE as permitted herein.
27
This license is effective until terminated by Sun for failure to comply
28
with this license. Upon termination, you shall destroy or return all code
29
and documentation for the Interface Definition Language CFE.
31
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
32
ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
33
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
34
DEALING, USAGE OR TRADE PRACTICE.
36
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
37
ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
38
TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
40
SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
41
RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
42
INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
44
IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
45
ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
46
DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
48
Use, duplication, or disclosure by the government is subject to
49
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
50
Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
53
Sun, Sun Microsystems and the Sun logo are trademarks or registered
54
trademarks of Sun Microsystems, Inc.
58
Mountain View, California 94043
62
SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
63
trademarks or registered trademarks of Sun Microsystems, Inc.
67
// AST_Union nodes represent IDL union declarations.
68
// AST_Union is a subclass of AST_ConcreteType and of UTL_Scope (the
69
// union branches are managed in a scope).
70
// AST_Union nodes have a discriminator type (a subclass of AST_ConcreteType),
71
// a name (an UTL_ScopedName) and a field denoting the discriminator type if
72
// it is a primitive type (the value of this field is from the union
73
// AST_Expression::ExprType and serves as a cache). This field is used
74
// to compute coercions for labels based on the expected discriminator type.
76
#include "ast_union.h"
77
#include "ast_union_branch.h"
78
#include "ast_union_label.h"
79
#include "ast_field.h"
80
#include "ast_predefined_type.h"
82
#include "ast_enum_val.h"
83
#include "ast_visitor.h"
85
#include "utl_identifier.h"
86
#include "utl_indenter.h"
87
#include "global_extern.h"
89
// FUZZ: disable check_for_streams_include
90
#include "ace/streams.h"
94
"ast_union.cpp,v 1.31 2003/11/10 20:29:25 dhinton Exp")
96
AST_Union::AST_Union (void)
107
AST_Union::AST_Union (AST_ConcreteType *dt,
111
: COMMON_Base (local,
113
AST_Decl (AST_Decl::NT_union,
115
AST_Type (AST_Decl::NT_union,
117
AST_ConcreteType (AST_Decl::NT_union,
119
UTL_Scope (AST_Decl::NT_union),
125
this->default_value_.computed_ = -2;
127
AST_PredefinedType *pdt = 0;
131
this->pd_disc_type = 0;
132
this->pd_udisc_type = AST_Expression::EV_none;
136
// If the discriminator type is a predefined type
137
// then install the equivalent coercion target type in
138
// the pd_udisc_type field.
139
if (dt->node_type () == AST_Decl::NT_pre_defined)
141
pdt = AST_PredefinedType::narrow_from_decl (dt);
145
this->pd_disc_type = 0;
146
this->pd_udisc_type = AST_Expression::EV_none;
154
case AST_PredefinedType::PT_long:
155
this->pd_udisc_type = AST_Expression::EV_long;
157
case AST_PredefinedType::PT_ulong:
158
this->pd_udisc_type = AST_Expression::EV_ulong;
160
case AST_PredefinedType::PT_short:
161
this->pd_udisc_type = AST_Expression::EV_short;
163
case AST_PredefinedType::PT_ushort:
164
this->pd_udisc_type = AST_Expression::EV_ushort;
166
case AST_PredefinedType::PT_char:
167
this->pd_udisc_type = AST_Expression::EV_char;
169
case AST_PredefinedType::PT_wchar:
170
this->pd_udisc_type = AST_Expression::EV_wchar;
172
case AST_PredefinedType::PT_octet:
173
this->pd_udisc_type = AST_Expression::EV_octet;
175
case AST_PredefinedType::PT_boolean:
176
this->pd_udisc_type = AST_Expression::EV_bool;
179
this->pd_udisc_type = AST_Expression::EV_none;
180
this->pd_disc_type = 0;
184
else if (dt->node_type () == AST_Decl::NT_enum)
186
this->pd_udisc_type = AST_Expression::EV_enum;
187
this->pd_disc_type = dt;
191
this->pd_udisc_type = AST_Expression::EV_none;
192
this->pd_disc_type = 0;
195
if (this->pd_disc_type == 0)
197
idl_global->err ()->error2 (UTL_Error::EIDL_DISC_TYPE,
203
AST_Union::~AST_Union (void)
207
// Public operations.
210
AST_Union::redefine (AST_Structure *from)
212
AST_Union *u = AST_Union::narrow_from_decl (from);
216
idl_global->err ()->redef_error (from->local_name ()->get_string (),
217
this->local_name ()->get_string ());
221
// Copy over all the base class members.
222
this->AST_Structure::redefine (from);
224
this->pd_disc_type = u->pd_disc_type;
225
this->pd_udisc_type = u->pd_udisc_type;
226
this->default_index_ = u->default_index_;
227
this->default_value_ = u->default_value_;
230
// Return the default_index.
232
AST_Union::default_index (void)
234
if (this->default_index_ == -2)
236
this->compute_default_index ();
239
return this->default_index_;
242
// Are we or the parameter node involved in any recursion?
244
AST_Union::in_recursion (AST_Type *node)
248
// We are determining the recursive status for ourselves.
252
// Proceed if the number of members in our scope is greater than 0.
253
if (this->nmembers () > 0)
255
// Initialize an iterator to iterate thru our scope.
256
// Continue until each element is visited.
257
for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
261
AST_UnionBranch *field =
262
AST_UnionBranch::narrow_from_decl (si.item ());
265
// This will be an enum value or other legitimate non-field
266
// member - in any case, no recursion.
271
AST_Type *type = field->field_type ();
273
if (type->node_type () == AST_Decl::NT_typedef)
275
AST_Typedef *td = AST_Typedef::narrow_from_decl (type);
276
type = td->primitive_base_type ();
281
ACE_ERROR_RETURN ((LM_ERROR,
282
ACE_TEXT ("(%N:%l) AST_Union::")
283
ACE_TEXT ("in_recursion - ")
284
ACE_TEXT ("bad field type\n")),
288
if (type->in_recursion (node))
299
// Look up the default branch in union.
301
AST_Union::lookup_default (void)
303
AST_UnionBranch *b = 0;
306
for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_both);
312
if (d->node_type () == AST_Decl::NT_union_branch)
314
b = AST_UnionBranch::narrow_from_decl (d);
322
&& b->label ()->label_kind () == AST_UnionLabel::UL_default)
324
idl_global->err ()->error2 (UTL_Error::EIDL_MULTIPLE_BRANCH,
335
// Look up a branch by label.
337
AST_Union::lookup_label (AST_UnionBranch *b)
339
AST_UnionLabel *label = b->label ();
340
AST_Expression *lv = label->label_val ();
342
if (label->label_val () == 0)
348
AST_UnionBranch *fb = 0;
350
lv->set_ev (lv->coerce (this->pd_udisc_type));
354
idl_global->err ()->eval_error (lv);
358
for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls);
364
if (d->node_type () == AST_Decl::NT_union_branch)
366
fb = AST_UnionBranch::narrow_from_decl (d);
374
&& fb->label ()->label_kind () == AST_UnionLabel::UL_label
375
&& fb->label ()->label_val ()->compare (lv))
377
idl_global->err ()->error2 (UTL_Error::EIDL_MULTIPLE_BRANCH,
388
// Look up a branch in an enum which is the discriminator type for this
389
// union, based on the label value which must be an enumerator in that
392
AST_Union::lookup_enum (AST_UnionBranch *b)
394
AST_UnionLabel *label = b->label();
395
AST_Expression *lv = label->label_val ();
396
AST_Enum *e = AST_Enum::narrow_from_decl (this->pd_disc_type);
398
AST_UnionBranch *fb = 0;
410
// Expecting a symbol label.
411
if (lv->ec () != AST_Expression::EC_symbol)
413
idl_global->err ()->enum_val_expected (this,
418
// See if the symbol defines a constant in the discriminator enum.
419
UTL_ScopedName *sn = lv->n ();
420
d = e->lookup_by_name (sn,
423
if (d == 0 || d->defined_in () != e)
425
idl_global->err ()->enum_val_lookup_failure (this,
431
// OK, now see if this symbol is already used as the label of
432
// some other branch.
433
for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls);
439
if (d->node_type () == AST_Decl::NT_union_branch)
441
fb = AST_UnionBranch::narrow_from_decl (d);
449
&& fb->label ()->label_kind () == AST_UnionLabel::UL_label
450
&& fb->label ()->label_val ()->compare (lv))
452
idl_global->err ()->error2 (UTL_Error::EIDL_MULTIPLE_BRANCH,
463
// Look up a branch by value. This is the top level branch label resolution
464
// entry point. It dispatches to the right lookup function depending on the
465
// union discriminator type.
467
AST_Union::lookup_branch (AST_UnionBranch *branch)
469
AST_UnionLabel *label = 0;
473
label = branch->label ();
478
if (label->label_kind () == AST_UnionLabel::UL_default)
480
return this->lookup_default ();
483
if (this->pd_udisc_type == AST_Expression::EV_enum)
485
// CONVENTION: indicates enum discriminant.
486
return this->lookup_enum (branch);
489
return this->lookup_label (branch);
495
// Return the default value.
497
AST_Union::default_value (AST_Union::DefaultValue &dv)
499
if (this->default_value_.computed_ == -2)
501
// We need to compute it.
502
if (this->compute_default_value () == -1)
504
ACE_ERROR_RETURN ((LM_ERROR,
505
ACE_TEXT ("(%N:%l) AST_Union::")
506
ACE_TEXT ("default_value - ")
507
ACE_TEXT ("Error computing ")
508
ACE_TEXT ("default value\n")),
513
dv = this->default_value_;
517
// Determine the default value (if any).
519
AST_Union::compute_default_value (void)
521
// Check if we really need a default value. This will be true if there is an
522
// explicit default case OR if an implicit default exists because not all
523
// values of the discriminant type are covered by the cases.
525
// Compute the total true "case" labels i.e., exclude the "default" case.
526
int total_case_members = 0;
528
// Instantiate a scope iterator.
529
for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
533
// Get the next AST decl node.
534
AST_UnionBranch *ub =
535
AST_UnionBranch::narrow_from_decl (si.item ());
539
// If the label is a case label, increment by 1.
540
for (unsigned long i = 0; i < ub->label_list_length (); ++i)
542
if (ub->label (i)->label_kind () == AST_UnionLabel::UL_label)
544
++total_case_members;
550
// Check if the total_case_members cover the entire
551
// range of values that are permitted by the discriminant type. If they do,
552
// then a default value is not necessary. However, if such an explicit
553
// default case is provided, it must be flagged off as an error. Our
554
// front-end is not able to handle such a case since it is a semantic error
555
// and not a syntax error. Such an error is caught here.
557
switch (this->udisc_type ())
559
case AST_Expression::EV_short:
560
case AST_Expression::EV_ushort:
561
if (total_case_members == ACE_UINT16_MAX + 1)
563
this->default_value_.computed_ = 0;
567
case AST_Expression::EV_long:
568
case AST_Expression::EV_ulong:
569
if ((unsigned int) total_case_members > ACE_UINT32_MAX)
571
this->default_value_.computed_ = 0;
575
case AST_Expression::EV_longlong:
576
case AST_Expression::EV_ulonglong:
578
this->default_value_.computed_ = -1;
581
ACE_TEXT ("(%N:%l) AST_Union::compute_default_value ")
582
ACE_TEXT ("- unimplemented discriminant type ")
583
ACE_TEXT ("(longlong or ulonglong)\n")
587
ACE_NOTREACHED (break;)
588
case AST_Expression::EV_char:
589
if (total_case_members == ACE_OCTET_MAX + 1)
591
this->default_value_.computed_ = 0;
595
case AST_Expression::EV_wchar:
596
if (total_case_members == ACE_WCHAR_MAX + 1)
598
this->default_value_.computed_ = 0;
602
case AST_Expression::EV_bool:
603
if (total_case_members == 2)
605
this->default_value_.computed_ = 0;
609
case AST_Expression::EV_enum:
612
AST_Decl *d = AST_Decl::narrow_from_decl (this->disc_type ());
614
if (d->node_type () == AST_Decl::NT_typedef)
616
AST_Typedef *bt = AST_Typedef::narrow_from_decl (d);
617
d = bt->primitive_base_type ();
620
AST_Enum *en = AST_Enum::narrow_from_decl (d);
624
if (total_case_members == en->member_count ())
626
this->default_value_.computed_ = 0;
632
this->default_value_.computed_ = -1;
633
ACE_ERROR_RETURN ((LM_ERROR,
634
ACE_TEXT ("(%N:%l) AST_Union::")
635
ACE_TEXT ("compute_default_value ")
636
ACE_TEXT ("- disc type not an ENUM\n")),
643
this->default_value_.computed_ = -1;
644
ACE_ERROR_RETURN ((LM_ERROR,
645
ACE_TEXT ("(%N:%l) AST_Union::compute_default_value")
646
ACE_TEXT (" - Bad discriminant type\n")),
648
ACE_NOTREACHED (break;)
651
// If we have determined that we don't need a default case and even then a
652
// default case was provided, flag this off as error.
653
if ((this->default_value_.computed_ == 0)
654
&& (this->default_index () != -1))
657
this->default_value_.computed_ = -1;
658
ACE_ERROR_RETURN ((LM_ERROR,
659
ACE_TEXT ("(%N:%l) AST_Union::compute_default_value")
660
ACE_TEXT (" - default clause is invalid here\n")),
664
// Proceed only if necessary.
665
switch (this->default_value_.computed_)
668
// Error. We should never be here because errors
669
// have already been caught
673
// Nothing more to do.
676
// Proceed further down.
680
// Initialization of the default value data member.
681
switch (this->udisc_type ())
683
case AST_Expression::EV_short:
684
this->default_value_.u.short_val = ACE_INT16_MIN;
686
case AST_Expression::EV_ushort:
687
this->default_value_.u.ushort_val = 0;
689
case AST_Expression::EV_long:
690
// The +1 is to avert a warning on many compilers.
691
this->default_value_.u.long_val = ACE_INT32_MIN + 1;
693
case AST_Expression::EV_ulong:
694
this->default_value_.u.ulong_val = 0;
696
case AST_Expression::EV_char:
697
this->default_value_.u.char_val = 0;
699
case AST_Expression::EV_wchar:
700
this->default_value_.u.wchar_val = 0;
702
case AST_Expression::EV_bool:
703
this->default_value_.u.bool_val = 0;
705
case AST_Expression::EV_enum:
706
this->default_value_.u.enum_val = 0;
708
case AST_Expression::EV_longlong:
709
case AST_Expression::EV_ulonglong:
712
// Error caught earlier.
716
// Proceed until we have found the appropriate default value.
717
while (this->default_value_.computed_ == -2)
721
// Instantiate a scope iterator.
722
for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
723
!si.is_done () && break_loop == 0;
726
// Get the next AST decl node
727
AST_UnionBranch *ub =
728
AST_UnionBranch::narrow_from_decl (si.item ());
732
for (unsigned long i = 0;
733
i < ub->label_list_length () && !break_loop;
736
if (ub->label (i)->label_kind () == AST_UnionLabel::UL_label)
739
AST_Expression *expr = ub->label (i)->label_val ();
744
this->default_value_.computed_ = -1;
747
ACE_TEXT ("(%N:%l) AST_Union::")
748
ACE_TEXT ("compute_default_value - ")
749
ACE_TEXT ("Bad case label value\n")
755
switch (expr->ev ()->et)
757
// Check if they match in which case this
758
// cannot be the implicit default value. So
759
// start with a new value and try the whole loop
760
// again because our case labels may not be sorted.
761
case AST_Expression::EV_short:
762
if (this->default_value_.u.short_val
763
== expr->ev ()->u.sval)
765
this->default_value_.u.short_val++;
770
case AST_Expression::EV_ushort:
771
if (this->default_value_.u.ushort_val
772
== expr->ev ()->u.usval)
774
this->default_value_.u.ushort_val++;
779
case AST_Expression::EV_long:
780
if (this->default_value_.u.long_val
781
== expr->ev ()->u.lval)
783
this->default_value_.u.long_val++;
788
case AST_Expression::EV_ulong:
789
if (this->default_value_.u.ulong_val
790
== expr->ev ()->u.ulval)
792
this->default_value_.u.ulong_val++;
797
case AST_Expression::EV_char:
798
if (this->default_value_.u.char_val
799
== expr->ev ()->u.cval)
801
this->default_value_.u.char_val++;
806
case AST_Expression::EV_wchar:
807
if (this->default_value_.u.wchar_val
808
== expr->ev ()->u.wcval)
810
this->default_value_.u.wchar_val++;
815
case AST_Expression::EV_bool:
816
if (this->default_value_.u.bool_val
817
== expr->ev ()->u.bval)
819
this->default_value_.u.bool_val++;
824
case AST_Expression::EV_enum:
825
// this is the case of enums. We maintain
826
// evaluated values which always start with 0
827
if (this->default_value_.u.enum_val
828
== expr->ev ()->u.eval)
830
this->default_value_.u.enum_val++;
835
case AST_Expression::EV_longlong:
836
case AST_Expression::EV_ulonglong:
837
// Unimplemented. right now - flag as error.
842
} // if label_Kind == label
843
} // End of for loop going thru all labels.
844
} // If valid union branch.
845
} // End of while scope iterator loop.
847
// We have not aborted the inner loops which means we have found the
851
this->default_value_.computed_ = 1;
854
} // End of outer while (default_value.computed == -2).
859
// Private operations.
861
// Compute the default index.
863
AST_Union::compute_default_index (void)
866
AST_UnionBranch *ub = 0;
869
// If default case does not exist, it will have a value of -1 according to
871
this->default_index_ = -1;
873
// If there are elements in this scope...
874
if (this->nmembers () > 0)
876
// Instantiate a scope iterator.
877
for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
881
// Get the next AST decl node.
884
// If an enum is declared in our scope, its members are
885
// added to our scope as well, to detect clashes.
886
if (d->node_type () == AST_Decl::NT_enum_val)
893
ub = AST_UnionBranch::narrow_from_decl (d);
895
for (unsigned long j = 0; j < ub->label_list_length (); ++j)
897
// Check if we are printing the default case.
898
AST_UnionLabel::UnionLabel ulk = ub->label ()->label_kind ();
899
if (ulk == AST_UnionLabel::UL_default)
901
// Zero based indexing.
902
this->default_index_ = i;
906
// TAO's Typecode class keeps only a member count (not
907
// a label count) so this increment has been moved
908
// out of the inner loop.
917
// Redefinition of inherited virtual operations
919
// Add this AST_UnionBranch node (a node representing one branch in a
920
// union declaration) to this scope
922
AST_Union::fe_add_union_branch (AST_UnionBranch *t)
926
// If this is a malformed branch, don't do anything with it.
927
if (t == 0 || t->label() == 0)
932
// If branch with that label already exists, complain.
933
if (lookup_branch (t) != 0)
935
idl_global->err ()->error2 (UTL_Error::EIDL_MULTIPLE_BRANCH,
941
// If branch with same field name exists, complain.
942
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
944
if (!can_be_redefined (d))
946
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
953
if (this->referenced (d, t->local_name ()))
955
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
962
if (t->has_ancestor (d))
964
idl_global->err ()->redefinition_in_scope (t,
971
this->add_to_scope (t);
973
// Add it to set of locally referenced symbols.
974
this->add_to_referenced (t,
978
AST_Type *ft = t->field_type ();
979
UTL_ScopedName *mru = ft->last_referenced_as ();
983
this->add_to_referenced (ft,
985
mru->first_component ());
988
this->fields_.enqueue_tail (t);
993
// Add this AST_Union (manifest union type) to this scope.
995
AST_Union::fe_add_union (AST_Union *t)
999
// Already defined and cannot be redefined? Or already used?
1000
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
1002
if (!can_be_redefined (d))
1004
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
1011
if (this->referenced (d, t->local_name ()))
1013
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
1020
if (t->has_ancestor (d))
1022
idl_global->err ()->redefinition_in_scope (t,
1028
// Add it to local types.
1029
this->add_to_local_types (t);
1031
// Add it to set of locally referenced symbols.
1032
this->add_to_referenced (t,
1039
// Add this AST_Structure node (manifest struct type) to this scope.
1041
AST_Union::fe_add_structure (AST_Structure *t)
1045
// Already defined and cannot be redefined? Or already used?
1046
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
1048
if (!can_be_redefined (d))
1050
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
1057
if (this->referenced (d, t->local_name ()))
1059
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
1066
if (t->has_ancestor (d))
1068
idl_global->err ()->redefinition_in_scope (t,
1074
// Add it to local types.
1075
this->add_to_local_types (t);
1077
// Add it to set of locally referenced symbols.
1078
this->add_to_referenced (t,
1085
// Add this AST_Enum node (manifest enum type) to this scope.
1087
AST_Union::fe_add_enum (AST_Enum *t)
1091
// Already defined and cannot be redefined? Or already used?
1092
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
1094
if (!can_be_redefined (d))
1096
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
1103
if (this->referenced (d, t->local_name ()))
1105
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
1112
if (t->has_ancestor (d))
1114
idl_global->err ()->redefinition_in_scope (t,
1120
// Add it to local types.
1121
this->add_to_local_types (t);
1123
// Add it to set of locally referenced symbols.
1124
this->add_to_referenced (t,
1131
// Add this AST_EnumVal node (enumerator declaration) to this scope.
1132
// This is done to conform to the C++ scoping rules which declare
1133
// enumerators in the enclosing scope (in addition to declaring them
1134
// in the enum itself).
1136
AST_Union::fe_add_enum_val (AST_EnumVal *t)
1140
// Already defined and cannot be redefined? Or already used?
1141
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
1143
if (!can_be_redefined (d))
1145
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
1152
if (this->referenced (d, t->local_name ()))
1154
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
1161
if (t->has_ancestor (d))
1163
idl_global->err ()->redefinition_in_scope (t,
1170
this->add_to_scope (t);
1172
// Add it to set of locally referenced symbols.
1173
this->add_to_referenced (t,
1180
// Dump this AST_Union node to the ostream o.
1182
AST_Union::dump (ACE_OSTREAM_TYPE &o)
1185
this->local_name ()->dump (o);
1187
this->pd_disc_type->local_name ()->dump (o);
1189
UTL_Scope::dump (o);
1190
idl_global->indent ()->skip_to (o);
1194
// Compute the size type of the node in question.
1196
AST_Union::compute_size_type (void)
1198
for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
1202
// Get the next AST decl node.
1203
AST_Decl *d = si.item ();
1205
if (d->node_type () == AST_Decl::NT_enum_val)
1210
AST_Field *f = AST_Field::narrow_from_decl (d);
1214
AST_Type *t = f->field_type ();
1215
// Our sizetype depends on the sizetype of our members. Although
1216
// previous value of sizetype may get overwritten, we are
1217
// guaranteed by the "size_type" call that once the value reached
1218
// be_decl::VARIABLE, nothing else can overwrite it.
1219
this->size_type (t->size_type ());
1223
ACE_DEBUG ((LM_DEBUG,
1224
"WARNING (%N:%l) be_union::compute_size_type - "
1225
"narrow_from_decl returned 0\n"));
1233
AST_Union::ast_accept (ast_visitor *visitor)
1235
return visitor->visit_union (this);
1241
AST_Union::disc_type (void)
1243
return this->pd_disc_type;
1246
AST_Expression::ExprType
1247
AST_Union::udisc_type (void)
1249
return this->pd_udisc_type;
1253
IMPL_NARROW_METHODS1(AST_Union, AST_Structure)
1254
IMPL_NARROW_FROM_DECL(AST_Union)
1255
IMPL_NARROW_FROM_SCOPE(AST_Union)