10 #include <utl_identifier.h> 18 const std::string cxx_escape =
"_cxx_";
23 return s.substr(0, cxx_escape.size()) == cxx_escape;
30 const std::string invalid_chars(
"<>()[]*.: ");
32 char last_char =
'\0';
33 for (
size_t i = 0; i < str.size(); ++i) {
34 const char c = str[i];
35 if (invalid_chars.find(c) == std::string::npos) {
42 }
else if (last_char !=
'_') {
49 if (s.size() > 1 && s[0] ==
'_') {
50 if (!cxx_escaped(s)) {
54 if (s.size() > 1 && s[s.size() - 1] ==
'_') {
55 s.erase(s.size() - 1, 1);
63 return valid_var_name(base_name) + qualifier +
"_tag";
68 return scoped_helper(name,
"_") +
"_xtag";
73 string str =
id->get_string();
78 if (cxx_escaped(str)) {
80 str = str.substr(cxx_escape.size() - 1);
88 if (id->escaped() && cxx_escaped(str)) {
91 str = str.substr(cxx_escape.size());
104 for (; sn; sn =
static_cast<UTL_ScopedName*
>(sn->tail())) {
105 const bool not_last = sn->tail();
109 if (sname.size() && not_last) {
121 for (; sn && sn->tail(); sn =
static_cast<UTL_ScopedName*
>(sn->tail())) {
134 for (vector<dds_generator*>::iterator it(components_.begin());
135 it != components_.end(); ++it) {
136 (*it)->gen_prologue();
142 for (vector<dds_generator*>::iterator it(components_.begin());
143 it != components_.end(); ++it) {
144 (*it)->gen_epilogue();
149 AST_Constant* constant)
151 for (vector<dds_generator*>::iterator it(components_.begin());
152 it != components_.end(); ++it) {
153 if (!constant->imported() || (*it)->do_included_files())
154 if (!(*it)->gen_const(name, nestedInInteface, constant))
162 const std::vector<AST_EnumVal*>& contents,
const char* repoid)
164 for (vector<dds_generator*>::iterator it(components_.begin());
165 it != components_.end(); ++it) {
166 if (!node->imported() || (*it)->do_included_files())
167 if (!(*it)->gen_enum(node, name, contents, repoid))
175 const vector<AST_Field*>& fields, AST_Type::SIZE_TYPE size,
178 for (vector<dds_generator*>::iterator it(components_.begin());
179 it != components_.end(); ++it) {
180 if (!node->imported() || (*it)->do_included_files())
181 if (!(*it)->gen_struct(node, name, fields, size, repoid))
189 AST_Type::SIZE_TYPE size)
191 for (vector<dds_generator*>::iterator it(components_.begin());
192 it != components_.end(); ++it) {
193 if (!(*it)->gen_struct_fwd(name, size))
203 for (vector<dds_generator*>::iterator it(components_.begin());
204 it != components_.end(); ++it) {
205 if (!node->imported() || (*it)->do_included_files())
206 if (!(*it)->gen_typedef(node, name, base, repoid))
214 const std::vector<AST_Interface*>& inherits,
215 const std::vector<AST_Interface*>& inh_flat,
216 const std::vector<AST_Attribute*>& attrs,
217 const std::vector<AST_Operation*>& ops,
const char* repoid)
219 for (vector<dds_generator*>::iterator it(components_.begin());
220 it != components_.end(); ++it) {
221 if (!node->imported() || (*it)->do_included_files())
222 if (!(*it)->gen_interf(node, name, local, inherits, inh_flat,
232 for (vector<dds_generator*>::iterator it(components_.begin());
233 it != components_.end(); ++it) {
234 if (!(*it)->gen_interf_fwd(name))
243 for (vector<dds_generator*>::iterator it(components_.begin());
244 it != components_.end(); ++it) {
245 if (!node->imported() || (*it)->do_included_files())
246 if (!(*it)->gen_native(node, name, repoid))
254 UTL_ScopedName*
name,
255 const std::vector<AST_UnionBranch*>& branches,
256 AST_Type* discriminator,
259 for (vector<dds_generator*>::iterator it(components_.begin());
260 it != components_.end(); ++it) {
261 if (!node->imported() || (*it)->do_included_files())
262 if (!(*it)->gen_union(node, name, branches, discriminator, repoid))
270 AST_Type::SIZE_TYPE size)
272 for (vector<dds_generator*>::iterator it(components_.begin());
273 it != components_.end(); ++it) {
274 if (!(*it)->gen_union_fwd(uf, name, size))
282 AST_Array* arr, std::string& indent,
287 std::ostringstream index_oss;
290 for (; i <
n_; ++i) {
292 indent <<
"for (" << type <<
' ' << prefix << i <<
" = 0; " <<
293 prefix << i <<
" < " << arr->dims()[i - j]->ev()->u.ulval <<
"; ++" <<
294 prefix << i <<
") {\n";
296 index_oss <<
"[" << prefix << i <<
"]";
298 if (!followTypedefs) {
301 AST_Type*
const base =
303 if (base->node_type() == AST_Decl::NT_array) {
304 arr =
dynamic_cast<AST_Array*
>(base);
316 for (
size_t i = 0; i <
n_; ++i) {
323 bool is_anonymous,
bool is_union,
bool use_cxx11,
Classification fld_cls)
328 if (temp.size() > 2 && temp.substr(temp.size() - 2, 2) ==
"()") {
329 temp.erase(temp.size() - 2);
332 replace(temp.begin(), temp.end(),
'.',
'_');
333 replace(temp.begin(), temp.end(),
'[',
'_');
334 replace(temp.begin(), temp.end(),
']',
'_');
338 n = n.substr(0, n.rfind(
"::") + 2) +
"AnonymousType_" + type->local_name()->get_string();
339 n = (fld_cls == AST_Decl::NT_sequence) ? (n +
"_seq") : n;
342 (is_union ?
"tmp" :
name) +
"));\n";
344 string n =
scoped(type->name());
346 n = n.substr(0, n.rfind(
"::") + 2) +
"_" + type->local_name()->get_string();
347 n = (fld_cls == AST_Decl::NT_sequence) ? (n +
"_seq") : n;
349 val = indent + n +
"_forany " + temp +
"(const_cast<" 350 + n +
"_slice*>(" + (is_union ?
"tmp":
name) +
"));\n";
351 val += indent +
"set_default(" + temp +
");\n";
354 val += indent + name +
"(tmp);\n";
360 bool is_anonymous,
bool is_union)
364 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
366 std::string pre =
" = ";
373 return indent +
"set_default(" + name + (is_union ?
"()" :
"") +
");\n";
376 indent, type, name, is_anonymous, is_union, use_cxx11, fld_cls);
377 }
else if (fld_cls &
CL_ENUM) {
380 AST_Enum* enu =
dynamic_cast<AST_Enum*
>(actual_type);
381 UTL_ScopeActiveIterator i(enu, UTL_Scope::IK_decls);
382 AST_EnumVal *item =
dynamic_cast<AST_EnumVal*
>(i.item());
384 def_val =
scoped(type->name()) +
"::" + item->local_name()->get_string();
386 def_val =
scoped(item->name());
389 string seq_resize_func = (use_cxx11) ?
"resize" :
"length";
391 return indent +
"tmp." + seq_resize_func +
"(0);\n" 392 + indent + name +
"(tmp);\n";
394 return indent + name +
"." + seq_resize_func +
"(0);\n";
397 def_val = (fld_cls &
CL_WIDE) ?
"L\"\"" :
"\"\"";
398 if (!use_cxx11 && (fld_cls &
CL_WIDE)) def_val =
"TAO::WString_Manager::s_traits::default_initializer()";
400 AST_PredefinedType* pt =
dynamic_cast<AST_PredefinedType*
>(actual_type);
401 if (pt && (pt->pt() == AST_PredefinedType::PT_longdouble)) {
405 string temp_val =
"ACE_CDR::LongDouble val = ACE_CDR_LONG_DOUBLE_INITIALIZER";
408 return indent + temp_val +
";\n" +
409 indent + name + pre + def_val + post +
";\n";
411 def_val =
"ACE_CDR_LONG_DOUBLE_ASSIGNMENT(" + name +
", val)";
412 return indent +
"{\n" 413 " " + indent + temp_val +
";\n" 414 " " + indent + def_val +
";\n" +
422 return indent + name + pre + def_val + post +
";\n";
428 field_type = field->field_type();
444 AST_Type* consider = type;
445 AST_Type* named_type = type;
446 while (consider->node_type() == AST_Decl::NT_typedef) {
447 named_type = consider;
448 consider =
dynamic_cast<AST_Typedef*
>(named_type)->base_type();
Classification classify(AST_Type *type)
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
std::string string_type(AstTypeClassification::Classification cls)
const Classification CL_STRING
string type_to_default(const std::string &indent, AST_Type *type, const string &name, bool is_anonymous, bool is_union)
const Classification CL_WIDE
std::string field_type_name(AST_Field *field, AST_Type *field_type)
virtual ~dds_generator()=0
const Classification CL_PRIMITIVE
static std::string get_xtag_name(UTL_ScopedName *name)
bool gen_union(AST_Union *node, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *repoid)
NestedForLoops(const char *type, const char *prefix, AST_Array *arr, std::string &indent, bool followTypedefs=false)
bool gen_const(UTL_ScopedName *name, bool nestedInInteface, AST_Constant *constant)
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
bool gen_interf_fwd(UTL_ScopedName *name)
AST_Type * deepest_named_type(AST_Type *type)
bool gen_native(AST_Native *node, UTL_ScopedName *name, const char *repoid)
This is for everything else.
bool gen_interf(AST_Interface *node, UTL_ScopedName *name, bool local, const std::vector< AST_Interface *> &inherits, const std::vector< AST_Interface *> &inherits_flat, const std::vector< AST_Attribute *> &attrs, const std::vector< AST_Operation *> &ops, const char *repoid)
const Classification CL_ARRAY
static bool cxx_escaped(const std::string &s)
string type_to_default_array(const std::string &indent, AST_Type *type, const string &name, bool is_anonymous, bool is_union, bool use_cxx11, Classification fld_cls)
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)
const std::string scoped_type_
bool gen_typedef(AST_Typedef *node, UTL_ScopedName *name, AST_Type *base, const char *repoid)
static std::string valid_var_name(const std::string &str)
AST_Type * resolveActualType(AST_Type *element)
This is for generated IDL. (Like *TypeSupport.idl)
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
static std::string module_scope_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
const Classification CL_FIXED
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
const Classification CL_STRUCTURE
BE_GlobalData * be_global
const char * to_string(MessageId value)
bool gen_struct_fwd(UTL_ScopedName *name, AST_Type::SIZE_TYPE size)
const Classification CL_ENUM
const Classification CL_SEQUENCE
bool gen_union_fwd(AST_UnionFwd *, UTL_ScopedName *name, AST_Type::SIZE_TYPE size)
bool gen_struct(AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)
const Classification CL_UNION
bool gen_enum(AST_Enum *node, UTL_ScopedName *name, const std::vector< AST_EnumVal *> &contents, const char *repoid)