Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_context.cpp
blob358281ed669b2034c8bdb9f2125eb72b100507e0
2 //=============================================================================
3 /**
4 * @file be_visitor_context.cpp
6 * Maintains the context information for visitors
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "be_visitor_context.h"
13 #include "be_extern.h"
14 #include "be_helper.h"
16 be_visitor_context::be_visitor_context (void)
17 : ast_visitor_context (),
18 state_ (TAO_CodeGen::TAO_INITIAL),
19 sub_state_ (TAO_CodeGen::TAO_SUB_STATE_UNKNOWN),
20 os_ (0),
21 scope_ (0),
22 node_ (0),
23 alias_ (0),
24 tdef_ (0),
25 attr_ (0),
26 exception_ (0),
27 comma_ (0),
28 interface_ (0)
32 be_visitor_context::be_visitor_context (const be_visitor_context &ctx)
33 : ast_visitor_context (ctx),
34 state_ (ctx.state_),
35 sub_state_ (ctx.sub_state_),
36 os_ (ctx.os_),
37 scope_ (ctx.scope_),
38 node_ (ctx.node_),
39 alias_ (ctx.alias_),
40 tdef_ (ctx.tdef_),
41 attr_ (ctx.attr_),
42 exception_ (ctx.exception_),
43 comma_ (ctx.comma_),
44 interface_ (ctx.interface_),
45 port_prefix_ (ctx.port_prefix_)
49 be_visitor_context &
50 be_visitor_context::operator= (const be_visitor_context &ctx)
52 this->state_ = ctx.state_;
53 this->sub_state_ = ctx.sub_state_;
54 this->os_ = ctx.os_;
55 this->scope_ = ctx.scope_;
56 this->node_ = ctx.node_;
57 this->alias_ = ctx.alias_;
58 this->tdef_ = ctx.tdef_;
59 this->attr_ = ctx.attr_;
60 this->exception_ = ctx.exception_;
61 this->comma_ = ctx.comma_;
62 this->interface_ = ctx.interface_;
63 this->template_args_ = ctx.template_args_;
64 this->template_params_ = ctx.template_params_;
65 this->port_prefix_ = ctx.port_prefix_;
67 return *this;
70 be_visitor_context::~be_visitor_context (void)
72 // We do not own anything.
75 //= helpers
77 void
78 be_visitor_context::reset (void)
80 this->state_ = TAO_CodeGen::TAO_INITIAL;
81 this->sub_state_ = TAO_CodeGen::TAO_SUB_STATE_UNKNOWN;
82 this->os_ = 0;
83 this->scope_ = 0;
84 this->node_ = 0;
85 this->alias_ = 0;
86 this->tdef_ = 0;
87 this->attr_ = 0;
88 this->exception_ = 0;
89 this->comma_ = 0;
90 this->interface_ = 0;
91 this->template_args_ = 0;
92 this->template_params_ = 0;
93 this->port_prefix_ = "";
96 void
97 be_visitor_context::stream (TAO_OutStream *os)
99 this->os_ = os;
102 TAO_OutStream *
103 be_visitor_context::stream (void)
105 static TAO_OutStream null_stream;
106 return os_ ? os_ : &null_stream;
109 void
110 be_visitor_context::scope (be_scope *s)
112 this->scope_ = s;
115 be_scope *
116 be_visitor_context::scope (void)
118 return this->scope_;
121 void
122 be_visitor_context::node (be_decl *n)
124 this->node_ = n;
127 be_decl *
128 be_visitor_context::node (void)
130 return this->node_;
133 void
134 be_visitor_context::state (TAO_CodeGen::CG_STATE st)
136 this->state_ = st;
139 TAO_CodeGen::CG_STATE
140 be_visitor_context::state (void)
142 return this->state_;
145 void
146 be_visitor_context::sub_state (TAO_CodeGen::CG_SUB_STATE st)
148 this->sub_state_ = st;
151 TAO_CodeGen::CG_SUB_STATE
152 be_visitor_context::sub_state (void)
154 return this->sub_state_;
157 void
158 be_visitor_context::tdef (be_typedef *node)
160 this->tdef_ = node;
163 be_typedef *
164 be_visitor_context::tdef (void)
166 return this->tdef_;
169 void
170 be_visitor_context::alias (be_typedef *node)
172 this->alias_ = node;
175 be_typedef *
176 be_visitor_context::alias (void)
178 return this->alias_;
181 void
182 be_visitor_context::attribute (be_attribute *node)
184 this->attr_ = node;
187 be_attribute *
188 be_visitor_context::attribute (void)
190 return this->attr_;
193 void
194 be_visitor_context::exception (bool ib)
196 this->exception_ = ib;
199 bool
200 be_visitor_context::exception (void)
202 return this->exception_;
205 void
206 be_visitor_context::comma (bool ib)
208 this->comma_ = ib;
211 bool
212 be_visitor_context::comma (void)
214 return this->comma_;
217 void
218 be_visitor_context::interface (be_interface *interface)
220 this->interface_ = interface;
223 be_interface *
224 be_visitor_context::interface (void) const
226 return this->interface_;
229 ACE_CString &
230 be_visitor_context::port_prefix (void)
232 return this->port_prefix_;
235 const char *
236 be_visitor_context::export_macro (void) const
238 switch (this->state_)
240 // If -GA is used, but the anyop macro hasn't been set,
241 // default to the stub macro.
242 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
243 return (be_global->gen_anyop_files ()
244 ? this->non_null_export_macro ()
245 : be_global->stub_export_macro ());
246 case TAO_CodeGen::TAO_ARRAY_CH:
247 case TAO_CodeGen::TAO_INTERFACE_CH:
248 case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CH:
249 case TAO_CodeGen::TAO_ROOT_CH:
250 return be_global->stub_export_macro ();
251 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH:
252 case TAO_CodeGen::TAO_INTERFACE_AMH_RH_SH:
253 case TAO_CodeGen::TAO_ROOT_SH:
254 return be_global->skel_export_macro ();
255 default:
256 return "";
260 const char *
261 be_visitor_context::non_null_export_macro (void) const
263 const char *anyop_export = be_global->anyop_export_macro ();
265 return (ACE_OS::strcmp (anyop_export, "") == 0
266 ? be_global->stub_export_macro ()
267 : anyop_export);