2 //=============================================================================
6 * Generic visitor for code generation for Arrays
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 be_visitor_array::be_visitor_array (be_visitor_context
*ctx
)
15 : be_visitor_decl (ctx
)
19 be_visitor_array::~be_visitor_array ()
23 int be_visitor_array::visit_array (be_array
*)
25 // Must be overloaded by derived visitors.
30 be_visitor_array::visit_enum (be_enum
*node
)
32 return this->visit_node (node
);
36 be_visitor_array::visit_interface (be_interface
*node
)
38 return this->emit_common (node
);
42 be_visitor_array::visit_interface_fwd (be_interface_fwd
*node
)
44 return this->emit_common (node
);
48 be_visitor_array::visit_valuebox (be_valuebox
*node
)
50 return this->emit_common (node
);
54 be_visitor_array::visit_valuetype (be_valuetype
*node
)
56 return this->emit_common (node
);
60 be_visitor_array::visit_valuetype_fwd (be_valuetype_fwd
*node
)
62 return this->emit_common (node
);
66 be_visitor_array::visit_predefined_type (be_predefined_type
*node
)
68 TAO_OutStream
*os
= this->ctx_
->stream ();
69 AST_PredefinedType::PredefinedType pt
= node
->pt ();
73 if (pt
== AST_PredefinedType::PT_pseudo
74 || pt
== AST_PredefinedType::PT_object
)
76 *os
<< node
->name () << "_var";
87 be_visitor_array::visit_sequence (be_sequence
*node
)
89 return this->visit_node (node
);
93 be_visitor_array::visit_string (be_string
*node
)
95 TAO_OutStream
*os
= this->ctx_
->stream ();
97 if (node
->width () == (long) sizeof (char))
99 *os
<< "::TAO::String_Manager";
103 *os
<< "::TAO::WString_Manager";
110 be_visitor_array::visit_structure (be_structure
*node
)
112 return this->visit_node (node
);
116 be_visitor_array::visit_union (be_union
*node
)
118 return this->visit_node (node
);
122 be_visitor_array::visit_typedef (be_typedef
*node
)
124 TAO_OutStream
*os
= this->ctx_
->stream ();
125 AST_Type
*pbt
= node
->primitive_base_type ();
126 AST_Decl::NodeType nt
= pbt
->node_type ();
127 AST_PredefinedType::PredefinedType pt
= AST_PredefinedType:: PT_void
;
130 // We check for these first, because in these cases, we replace the
131 // entire slice type with one of the strings below, instead of using
132 // the node's type name, possibly suffixed with '_var'.
133 if (nt
== AST_Decl::NT_string
)
135 *os
<< "::TAO::String_Manager";
139 else if (nt
== AST_Decl::NT_wstring
)
141 *os
<< "::TAO::WString_Manager";
146 result
= this->visit_node (node
);
148 if (nt
== AST_Decl::NT_pre_defined
)
150 AST_PredefinedType
*pdt
= dynamic_cast<AST_PredefinedType
*> (pbt
);
154 // We must append a "_var" for typedefs of interfaces, CORBA::Objects or
156 if (nt
== AST_Decl::NT_interface
157 || nt
== AST_Decl::NT_interface_fwd
158 || pt
== AST_PredefinedType::PT_pseudo
159 || pt
== AST_PredefinedType::PT_object
)
169 be_visitor_array::visit_node (be_type
*node
)
171 TAO_OutStream
*os
= this->ctx_
->stream ();
172 be_type
*bt
= nullptr;
174 if (this->ctx_
->alias ())
176 bt
= this->ctx_
->alias ();
183 if (this->ctx_
->state () == TAO_CodeGen::TAO_ARRAY_CH
)
185 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
196 be_visitor_array::emit_common (be_type
*node
)
198 TAO_OutStream
*os
= this->ctx_
->stream ();
199 be_type
*bt
= nullptr;
201 if (this->ctx_
->alias ())
203 bt
= this->ctx_
->alias ();
210 if (this->ctx_
->state () == TAO_CodeGen::TAO_ARRAY_CH
)
212 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl (), "_var");
216 *os
<< bt
->name () << "_var";