Remove redundant void from tao_idl
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_argument / argument.cpp
blobee1487c2e3241c9a6c11f239dcabb8cc7ebfb1ae
2 //=============================================================================
3 /**
4 * @file argument.cpp
6 * generic visitor for Argument node
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "argument.h"
13 #include "argument.h"
15 be_visitor_args::be_visitor_args (be_visitor_context *ctx)
16 : be_visitor_decl (ctx),
17 fixed_direction_ (-1)
21 be_visitor_args::~be_visitor_args ()
25 int be_visitor_args::visit_argument (be_argument *)
27 return -1;
30 // Helper that returns the type name either as a nested type name (for header
31 // files) or as a fully scoped name. In addition, we make sure that if the type
32 // is an alias, we use that name.
33 const char *
34 be_visitor_args::type_name (be_type *node,
35 const char *suffix)
37 static char namebuf [NAMEBUFSIZE];
38 ACE_OS::memset (namebuf,
39 '\0',
40 NAMEBUFSIZE);
42 be_type *bt = 0;
44 // Use the typedefed name if that is the one
45 // used in the IDL defn.
46 if (this->ctx_->alias ())
48 bt = this->ctx_->alias ();
50 else
52 bt = node;
55 ACE_OS::sprintf (namebuf,
56 "::%s",
57 bt->full_name ());
59 if (suffix)
61 ACE_OS::strcat (namebuf,
62 suffix);
65 return namebuf;
68 // Helper that returns the direction type of the argument
69 AST_Argument::Direction
70 be_visitor_args::direction ()
72 if (this->fixed_direction_ != -1)
74 return AST_Argument::Direction (this->fixed_direction_);
77 // Grab the argument node. We know that our context has stored the right
78 // argument node.
79 be_argument *arg =
80 dynamic_cast<be_argument*> (this->ctx_->node ());
82 return arg->direction ();
85 void
86 be_visitor_args::set_fixed_direction (AST_Argument::Direction direction)
88 this->fixed_direction_ = direction;
91 int
92 be_visitor_args::gen_pd_arg (be_predefined_type *node,
93 bool for_stub)
95 TAO_CodeGen::CG_SUB_STATE ss = this->ctx_->sub_state ();
96 AST_Argument::Direction d = this->direction ();
98 bool in_arg = (d == AST_Argument::dir_IN);
99 bool out_arg = (d == AST_Argument::dir_OUT);
100 bool out_stream = (ss == TAO_CodeGen::TAO_CDR_OUTPUT);
101 bool in_stream = (ss == TAO_CodeGen::TAO_CDR_INPUT);
103 bool skip = (in_arg && for_stub && in_stream)
104 || (in_arg && !for_stub && out_stream)
105 || (out_arg && for_stub && out_stream)
106 || (out_arg && !for_stub && in_stream);
108 if (skip)
110 return 0;
113 TAO_OutStream *os = this->ctx_->stream ();
114 const char *var_call = "";
115 const char *any_deref = "";
117 AST_PredefinedType::PredefinedType pt = node->pt ();
118 bool is_any = (pt == AST_PredefinedType::PT_any);
120 if (for_stub)
122 if (in_stream && out_arg)
124 var_call = ".ptr ()";
125 any_deref = "*";
128 else if (out_stream)
130 var_call = ".in ()";
132 if (is_any && !out_arg)
134 var_call = "";
137 else if (!is_any)
139 var_call = ".out ()";
142 ACE_CString to_from_str = (in_stream
143 ? "::ACE_InputCDR::to_"
144 : "::ACE_OutputCDR::from_");
146 const char *to_from = to_from_str.c_str ();
148 be_argument *arg =
149 dynamic_cast<be_argument*> (this->ctx_->node ());
150 const char *lname = arg->local_name ()->get_string ();
152 switch (pt)
154 case AST_PredefinedType::PT_any:
155 *os << any_deref;
156 // fallthrough
157 case AST_PredefinedType::PT_pseudo:
158 case AST_PredefinedType::PT_object:
159 *os << lname << var_call;
160 break;
161 case AST_PredefinedType::PT_char:
162 *os << to_from << "char (" << lname << ")";
163 break;
164 case AST_PredefinedType::PT_wchar:
165 *os << to_from << "wchar (" << lname << ")";
166 break;
167 case AST_PredefinedType::PT_boolean:
168 *os << to_from << "boolean (" << lname << ")";
169 break;
170 case AST_PredefinedType::PT_octet:
171 *os << to_from << "octet (" << lname << ")";
172 break;
173 default:
174 *os << lname;
175 break;
178 return 0;