#include <langmap_generator.h>
Public Member Functions | |
langmap_generator () | |
void | init () |
Private Member Functions | |
bool | gen_const (UTL_ScopedName *name, bool nestedInInteface, AST_Constant *constant) |
bool | gen_enum (AST_Enum *, UTL_ScopedName *name, const std::vector< AST_EnumVal * > &contents, const char *repoid) |
bool | gen_struct (AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *repoid) |
bool | gen_struct_fwd (UTL_ScopedName *name, AST_Type::SIZE_TYPE size) |
bool | gen_typedef (AST_Typedef *, UTL_ScopedName *name, AST_Type *type, const char *repoid) |
bool | gen_union (AST_Union *, UTL_ScopedName *name, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator, const char *repoid) |
bool | gen_union_fwd (AST_UnionFwd *, UTL_ScopedName *name, AST_Type::SIZE_TYPE size) |
bool | gen_interf_fwd (UTL_ScopedName *name) |
Private Attributes | |
GeneratorBase * | generator_ |
Generate code for the IDL -> Programming Language mapping For example, IDL structs -> C++ structs, etc. Enabled by the -L* command line options
Definition at line 16 of file langmap_generator.h.
langmap_generator::langmap_generator | ( | ) | [inline] |
Definition at line 19 of file langmap_generator.h.
00019 : generator_(0) {}
bool langmap_generator::gen_const | ( | UTL_ScopedName * | name, | |
bool | nestedInInteface, | |||
AST_Constant * | constant | |||
) | [private, virtual] |
Reimplemented from dds_generator.
Definition at line 1059 of file langmap_generator.cpp.
References be_global, and scoped().
01061 { 01062 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 01063 const char* const nm = name->last_component()->get_string(); 01064 01065 const AST_Expression::ExprType type = constant->et(); 01066 const bool is_enum = (type == AST_Expression::EV_enum); 01067 const std::string type_name = is_enum 01068 ? scoped(constant->enum_full_name()) : map_type(type); 01069 be_global->lang_header_ << 01070 "const " << type_name << ' ' << nm << " = "; 01071 01072 if (is_enum) { 01073 be_global->lang_header_ << scoped(constant->constant_value()->n()) << ";\n"; 01074 } else { 01075 be_global->lang_header_ << *constant->constant_value()->ev() << ";\n"; 01076 } 01077 return true; 01078 }
bool langmap_generator::gen_enum | ( | AST_Enum * | , | |
UTL_ScopedName * | name, | |||
const std::vector< AST_EnumVal * > & | contents, | |||
const char * | repoid | |||
) | [private, virtual] |
Reimplemented from dds_generator.
Definition at line 1231 of file langmap_generator.cpp.
References be_global.
01234 { 01235 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 01236 const char* const nm = name->last_component()->get_string(); 01237 be_global->lang_header_ << 01238 "enum " << nm << " {\n"; 01239 for (size_t i = 0; i < contents.size(); ++i) { 01240 be_global->lang_header_ << 01241 " " << contents[i]->local_name()->get_string() 01242 << ((i < contents.size() - 1) ? ",\n" : "\n"); 01243 } 01244 be_global->lang_header_ << 01245 "};\n\n" 01246 "typedef " << nm << "& " << nm << "_out;\n"; 01247 gen_typecode(name); 01248 return true; 01249 }
bool langmap_generator::gen_interf_fwd | ( | UTL_ScopedName * | name | ) | [private, virtual] |
Reimplemented from dds_generator.
Definition at line 1407 of file langmap_generator.cpp.
References be_global.
01408 { 01409 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 01410 01411 be_global->add_include("<tao/Objref_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H); 01412 const char* const nm = name->last_component()->get_string(); 01413 be_global->lang_header_ << 01414 "class " << nm << ";\n" 01415 "typedef " << nm << '*' << nm << "_ptr;\n" 01416 "typedef TAO_Objref_Var_T<" << nm << "> " << nm << "_var;\n" 01417 "typedef TAO_Objref_Out_T<" << nm << "> " << nm << "_out;\n"; 01418 01419 return true; 01420 }
bool langmap_generator::gen_struct | ( | AST_Structure * | s, | |
UTL_ScopedName * | name, | |||
const std::vector< AST_Field * > & | fields, | |||
AST_Type::SIZE_TYPE | size, | |||
const char * | repoid | |||
) | [private, virtual] |
Implements dds_generator.
Definition at line 1259 of file langmap_generator.cpp.
References GeneratorBase::gen_struct(), and generator_.
01263 { 01264 return generator_->gen_struct(s, name, fields, size, x); 01265 }
bool langmap_generator::gen_struct_fwd | ( | UTL_ScopedName * | name, | |
AST_Type::SIZE_TYPE | size | |||
) | [private, virtual] |
Reimplemented from dds_generator.
Definition at line 1251 of file langmap_generator.cpp.
References be_global.
01253 { 01254 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 01255 struct_decls(name, size); 01256 return true; 01257 }
bool langmap_generator::gen_typedef | ( | AST_Typedef * | , | |
UTL_ScopedName * | name, | |||
AST_Type * | type, | |||
const char * | repoid | |||
) | [private, virtual] |
Implements dds_generator.
Definition at line 1327 of file langmap_generator.cpp.
References be_global, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), GeneratorBase::gen_sequence(), generator_, and AstTypeClassification::resolveActualType().
01329 { 01330 AST_Array* arr = 0; 01331 { 01332 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 01333 const char* const nm = name->last_component()->get_string(); 01334 01335 const Classification cls = classify(base); 01336 01337 switch (base->node_type()) { 01338 case AST_Decl::NT_sequence: 01339 generator_->gen_sequence(name, AST_Sequence::narrow_from_decl(base)); 01340 break; 01341 case AST_Decl::NT_array: 01342 gen_array(name, arr = AST_Array::narrow_from_decl(base)); 01343 break; 01344 case AST_Decl::NT_fixed: 01345 # ifdef ACE_HAS_CDR_FIXED 01346 gen_fixed(name, AST_Fixed::narrow_from_decl(base)); 01347 break; 01348 # else 01349 std::cerr << "ERROR: fixed data type (for " << nm << ") is not supported" 01350 " with this version of ACE+TAO\n"; 01351 return false; 01352 # endif 01353 default: 01354 be_global->lang_header_ << 01355 "typedef " << map_type(base) << ' ' << nm << ";\n"; 01356 if ((cls & CL_STRING) == 0) { 01357 be_global->lang_header_ << 01358 "typedef " << map_type(base) << "_out " << nm << "_out;\n"; 01359 } 01360 01361 AST_Type* actual_base = resolveActualType(base); 01362 if (actual_base->node_type() == AST_Decl::NT_array) { 01363 be_global->lang_header_ << 01364 "typedef " << map_type(base) << "_var " << nm << "_var;\n" << 01365 "typedef " << map_type(base) << "_slice " << nm << "_slice;\n" << 01366 "typedef " << map_type(base) << "_forany " << nm << "_forany;\n\n" << 01367 "inline " << nm << "_slice *" << nm << "_alloc() { return " << map_type(base) << "_alloc(); }\n" << 01368 "inline " << nm << "_slice* " << nm << "_dup(" << nm << "_slice *a) { return " << map_type(base) << "_dup(a); }\n" << 01369 "inline void " << nm << "_copy(" << nm << "_slice* to, const " << nm << "_slice* from) { " << map_type(base) << "_copy(to, from); }\n" << 01370 "inline void " << nm << "_free(" << nm << "_slice *a) { " << map_type(base) << "_free(a); }\n"; 01371 } 01372 01373 break; 01374 } 01375 01376 if (cls & CL_STRING) { 01377 const Helper var = (cls & CL_WIDE) ? HLP_WSTR_VAR : HLP_STR_VAR, 01378 out = (cls & CL_WIDE) ? HLP_WSTR_OUT : HLP_STR_OUT; 01379 be_global->lang_header_ << 01380 "typedef " << helpers_[var] << ' ' << nm << "_var;\n" 01381 "typedef " << helpers_[out] << ' ' << nm << "_out;\n"; 01382 } 01383 01384 gen_typecode(name); 01385 } 01386 if (arr) gen_array_traits(name, arr); 01387 return true; 01388 }
bool langmap_generator::gen_union | ( | AST_Union * | u, | |
UTL_ScopedName * | name, | |||
const std::vector< AST_UnionBranch * > & | branches, | |||
AST_Type * | discriminator, | |||
const char * | repoid | |||
) | [private, virtual] |
Implements dds_generator.
Definition at line 1399 of file langmap_generator.cpp.
References GeneratorBase::gen_union(), and generator_.
01403 { 01404 return generator_->gen_union(u, name, branches, discriminator); 01405 }
bool langmap_generator::gen_union_fwd | ( | AST_UnionFwd * | node, | |
UTL_ScopedName * | name, | |||
AST_Type::SIZE_TYPE | size | |||
) | [private, virtual] |
Reimplemented from dds_generator.
Definition at line 1390 of file langmap_generator.cpp.
References be_global.
01393 { 01394 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 01395 struct_decls(name, node->full_definition()->size_type()); 01396 return true; 01397 }
void langmap_generator::init | ( | void | ) |
Definition at line 1044 of file langmap_generator.cpp.
References be_global, generator_, and GeneratorBase::init().
Referenced by dds_visitor::dds_visitor().
01045 { 01046 switch (be_global->language_mapping()) { 01047 case BE_GlobalData::LANGMAP_FACE_CXX: 01048 generator_ = &FaceGenerator::instance; 01049 generator_->init(); 01050 break; 01051 case BE_GlobalData::LANGMAP_SP_CXX: 01052 generator_ = &SafetyProfileGenerator::instance; 01053 generator_->init(); 01054 break; 01055 default: break; 01056 } 01057 }
GeneratorBase* langmap_generator::generator_ [private] |
Definition at line 48 of file langmap_generator.h.
Referenced by gen_struct(), gen_typedef(), gen_union(), and init().