Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_attr_assign.cpp
blob692367b1245254378abcf8b2c8f33a3afe2fb9e4
1 #include "be_visitor_attr_assign.h"
3 #include "be_visitor_context.h"
4 #include "be_array.h"
5 #include "be_component.h"
6 #include "be_enum.h"
7 #include "be_eventtype.h"
8 #include "be_home.h"
9 #include "be_predefined_type.h"
10 #include "be_sequence.h"
11 #include "be_string.h"
12 #include "be_structure.h"
13 #include "be_typedef.h"
14 #include "be_union.h"
15 #include "be_valuebox.h"
16 #include "be_valuetype.h"
18 be_visitor_attr_assign::be_visitor_attr_assign (
19 be_visitor_context *ctx)
20 : be_visitor_decl (ctx),
21 attr_name_ (0),
22 attr_name_string_ ("this->")
26 be_visitor_attr_assign::~be_visitor_attr_assign (void)
30 int
31 be_visitor_attr_assign::visit_array (be_array *node)
33 os_ << be_nl
34 << this->attr_name_string_.c_str () << " = "
35 << "::" << node->full_name () << "_dup ("
36 << this->attr_name_ << ");";
38 return 0;
41 int
42 be_visitor_attr_assign::visit_component (be_component *node)
44 os_ << be_nl
45 << this->attr_name_string_.c_str () << " = "
46 << "::" << node->full_name () << "::_duplicate ("
47 << this->attr_name_ << ");";
49 return 0;
52 int
53 be_visitor_attr_assign::visit_enum (be_enum *)
55 os_ << be_nl
56 << this->attr_name_string_.c_str () << " = "
57 << this->attr_name_ << ";";
59 return 0;
62 int
63 be_visitor_attr_assign::visit_eventtype (be_eventtype *)
65 os_ << be_nl
66 << this->attr_name_ << "->_add_ref ();" << be_nl
67 << this->attr_name_string_.c_str () << " = "
68 << this->attr_name_ << ";";
70 return 0;
73 int
74 be_visitor_attr_assign::visit_home (be_home *node)
76 os_ << be_nl
77 << this->attr_name_string_.c_str () << " = "
78 << "::" << node->full_name () << "::_duplicate ("
79 << this->attr_name_ << ");";
81 return 0;
84 int
85 be_visitor_attr_assign::visit_interface (
86 be_interface *node)
88 os_ << be_nl
89 << this->attr_name_string_.c_str () << " = "
90 << "::" << node->full_name () << "::_duplicate ("
91 << this->attr_name_ << ");";
93 return 0;
96 int
97 be_visitor_attr_assign::visit_predefined_type (
98 be_predefined_type *)
100 os_ << be_nl
101 << this->attr_name_string_.c_str () << " = "
102 << this->attr_name_ << ";";
104 return 0;
107 /// Unused if anonymous types are not allowed.
109 be_visitor_attr_assign::visit_sequence (be_sequence *)
111 be_type *bt = this->ctx_->alias ();
113 if (bt == 0)
115 /// Support anonymous types?
116 return -1;
119 os_ << be_nl
120 << "::" << bt->full_name () << " * _ciao_tmp = 0;" << be_nl
121 << "ACE_NEW (" << be_idt_nl
122 << "_ciao_tmp," << be_nl
123 << bt->full_name () << " (" << this->attr_name_
124 << "));" << be_uidt_nl << be_nl
125 << this->attr_name_string_.c_str () << " = _ciao_tmp;";
127 return 0;
131 be_visitor_attr_assign::visit_string (be_string *node)
133 os_ << be_nl
134 << this->attr_name_string_.c_str () << " = "
135 << "::CORBA::" << (node->width () == (ssize_t) sizeof (char) ? "" : "w")
136 << "string_dup (" << this->attr_name_ << ");";
138 return 0;
142 be_visitor_attr_assign::visit_structure (be_structure *node)
144 os_ << be_nl
145 << "::" << node->full_name () << " * _ciao_tmp = 0;" << be_nl
146 << "ACE_NEW (" << be_idt_nl
147 << "_ciao_tmp," << be_nl
148 << "::" << node->full_name () << ");" << be_uidt_nl << be_nl
149 << "*_ciao_tmp = " << this->attr_name_ << ";" << be_nl
150 << this->attr_name_string_.c_str () << " = _ciao_tmp;";
152 return 0;
156 be_visitor_attr_assign::visit_typedef (be_typedef *node)
158 this->ctx_->alias (node);
159 int const status = node->primitive_base_type ()->accept (this);
161 if (status == -1)
163 ACE_ERROR_RETURN ((LM_ERROR,
164 "be_visitor_memkber_type_decl::"
165 "visit_typedef - "
166 "accept on primitive type failed\n"),
167 -1);
170 this->ctx_->alias (0);
171 return 0;
175 be_visitor_attr_assign::visit_union (be_union *node)
177 os_ << be_nl
178 << "::" << node->full_name () << " * _ciao_tmp = 0;" << be_nl
179 << "ACE_NEW (" << be_idt_nl
180 << "_ciao_tmp," << be_nl
181 << "::" << node->full_name () << ");" << be_uidt_nl << be_nl
182 << "*_ciao_tmp = " << this->attr_name_ << ";" << be_nl
183 << this->attr_name_string_.c_str () << " = _ciao_tmp;";
185 return 0;
189 be_visitor_attr_assign::visit_valuebox (be_valuebox *)
191 os_ << be_nl
192 << this->attr_name_ << "->_add_ref ();" << be_nl
193 << this->attr_name_string_.c_str () << " = "
194 << this->attr_name_ << ";";
196 return 0;
200 be_visitor_attr_assign::visit_valuetype (be_valuetype *)
202 os_ << be_nl
203 << this->attr_name_ << "->_add_ref ();" << be_nl
204 << this->attr_name_string_.c_str () << " = "
205 << this->attr_name_ << ";";
207 return 0;
210 void
211 be_visitor_attr_assign::attr_name (const char *name)
213 // No need for copying, the lifetime of the attr
214 // the arg is from is longer than that of this visitor.
215 this->attr_name_ = name;
217 // Add to this string for convenience, it's generated
218 // in each method above at least once.
219 this->attr_name_string_ += this->ctx_->port_prefix ();
220 this->attr_name_string_ += name;
221 this->attr_name_string_ += '_';