2 //=============================================================================
4 * @file discriminant_ch.cpp
6 * Visitor generating code for discriminant of the Union
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 be_visitor_union_discriminant_ch::be_visitor_union_discriminant_ch (
15 be_visitor_context
*ctx
)
16 : be_visitor_decl (ctx
)
20 be_visitor_union_discriminant_ch::~be_visitor_union_discriminant_ch ()
25 be_visitor_union_discriminant_ch::visit_enum (be_enum
*node
)
27 // Get the enclosing union backend.
29 dynamic_cast<be_union
*> (this->ctx_
->node ());
30 be_type
*bt
= nullptr;
32 // Check if we are visiting this node via a visit to a typedef node.
33 if (this->ctx_
->alias ())
35 bt
= this->ctx_
->alias ();
42 TAO_OutStream
*os
= this->ctx_
->stream ();
44 // Not a typedef and bt is defined inside the union.
45 if (bt
->node_type () != AST_Decl::NT_typedef
48 // Instantiate a visitor context with a copy of our context. This info
49 // will be modified based on what type of node we are visiting.
50 be_visitor_context
ctx (*this->ctx_
);
53 // First generate the enum declaration.
54 be_visitor_enum_ch
visitor (&ctx
);
56 if (node
->accept (&visitor
) == -1)
58 ACE_ERROR_RETURN ((LM_ERROR
,
59 "(%N:%l) be_visitor_union_discriminant_ch::"
66 TAO_INSERT_COMMENT (os
);
70 << "void _d (" << bt
->nested_type_name (bu
) << ");" << be_nl
;
72 *os
<< bt
->nested_type_name (bu
) << " _d () const;";
78 be_visitor_union_discriminant_ch::visit_predefined_type (be_predefined_type
81 // get the enclosing union backend.
83 dynamic_cast<be_union
*> (this->ctx_
->node ());
84 be_type
*bt
= nullptr;
86 // Check if we are visiting this node via a visit to a typedef node.
87 if (this->ctx_
->alias ())
89 bt
= this->ctx_
->alias ();
96 TAO_OutStream
*os
= this->ctx_
->stream ();
98 TAO_INSERT_COMMENT (os
);
102 << "void _d ( " << bt
->nested_type_name (bu
) << ");" << be_nl
;
104 *os
<< bt
->nested_type_name (bu
) << " _d () const;";
110 be_visitor_union_discriminant_ch::visit_typedef (be_typedef
*node
)
112 this->ctx_
->alias (node
);
114 // The node to be visited in the base primitve type that gets typedefed.
115 be_type
*bt
= node
->primitive_base_type ();
117 if (!bt
|| (bt
->accept (this) == -1))
119 ACE_ERROR_RETURN ((LM_ERROR
,
120 "(%N:%l) be_visitor_union_discriminant_ch::"
122 "Bad primitive type\n"),
126 this->ctx_
->alias (nullptr);