langmap_generator Class Reference

#include <langmap_generator.h>

Inheritance diagram for langmap_generator:

Inheritance graph
[legend]
Collaboration diagram for langmap_generator:

Collaboration graph
[legend]
List of all members.

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

GeneratorBasegenerator_

Detailed Description

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.


Constructor & Destructor Documentation

langmap_generator::langmap_generator (  )  [inline]

Definition at line 19 of file langmap_generator.h.

00019 : generator_(0) {}


Member Function Documentation

bool langmap_generator::gen_const ( UTL_ScopedName *  name,
bool  nestedInInteface,
AST_Constant *  constant 
) [private, virtual]

Reimplemented from dds_generator.

Definition at line 1048 of file langmap_generator.cpp.

References be_global, BE_GlobalData::lang_header_, map_type(), and scoped().

01050 {
01051   const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
01052   const char* const nm = name->last_component()->get_string();
01053 
01054   const AST_Expression::ExprType type = constant->et();
01055   const bool is_enum = (type == AST_Expression::EV_enum);
01056   const std::string type_name = is_enum
01057     ? scoped(constant->enum_full_name()) : map_type(type);
01058   be_global->lang_header_ <<
01059     "const " << type_name << ' ' << nm << " = ";
01060 
01061   if (is_enum) {
01062     be_global->lang_header_ << scoped(constant->constant_value()->n()) << ";\n";
01063   } else {
01064     be_global->lang_header_ << *constant->constant_value()->ev() << ";\n";
01065   }
01066   return true;
01067 }

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 1220 of file langmap_generator.cpp.

References be_global, gen_typecode(), and BE_GlobalData::lang_header_.

01223 {
01224   const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
01225   const char* const nm = name->last_component()->get_string();
01226   be_global->lang_header_ <<
01227     "enum " << nm << " {\n";
01228   for (size_t i = 0; i < contents.size(); ++i) {
01229     be_global->lang_header_ <<
01230       "  " << contents[i]->local_name()->get_string()
01231       << ((i < contents.size() - 1) ? ",\n" : "\n");
01232   }
01233   be_global->lang_header_ <<
01234     "};\n\n"
01235     "typedef " << nm << "& " << nm << "_out;\n";
01236   gen_typecode(name);
01237   return true;
01238 }

bool langmap_generator::gen_interf_fwd ( UTL_ScopedName *  name  )  [private, virtual]

Reimplemented from dds_generator.

Definition at line 1396 of file langmap_generator.cpp.

References BE_GlobalData::add_include(), be_global, BE_GlobalData::lang_header_, and BE_GlobalData::STREAM_LANG_H.

01397 {
01398   const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
01399 
01400   be_global->add_include("<tao/Objref_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
01401   const char* const nm = name->last_component()->get_string();
01402   be_global->lang_header_ <<
01403     "class " << nm << ";\n"
01404     "typedef " << nm << '*' << nm << "_ptr;\n"
01405     "typedef TAO_Objref_Var_T<" << nm << "> " << nm << "_var;\n"
01406     "typedef TAO_Objref_Out_T<" << nm << "> " << nm << "_out;\n";
01407 
01408   return true;
01409 }

bool langmap_generator::gen_struct ( AST_Structure *  ,
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 1248 of file langmap_generator.cpp.

References GeneratorBase::gen_struct(), and generator_.

01252 {
01253   return generator_->gen_struct(s, name, fields, size, x);
01254 }

bool langmap_generator::gen_struct_fwd ( UTL_ScopedName *  name,
AST_Type::SIZE_TYPE  size 
) [private, virtual]

Reimplemented from dds_generator.

Definition at line 1240 of file langmap_generator.cpp.

References be_global, BE_GlobalData::lang_header_, and struct_decls().

01242 {
01243   const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
01244   struct_decls(name, size);
01245   return true;
01246 }

bool langmap_generator::gen_typedef ( AST_Typedef *  ,
UTL_ScopedName *  name,
AST_Type *  type,
const char *  repoid 
) [private, virtual]

Implements dds_generator.

Definition at line 1316 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), gen_array(), gen_array_traits(), GeneratorBase::gen_sequence(), gen_typecode(), generator_, helpers_, HLP_STR_OUT, HLP_STR_VAR, HLP_WSTR_OUT, HLP_WSTR_VAR, BE_GlobalData::lang_header_, map_type(), and AstTypeClassification::resolveActualType().

01318 {
01319   AST_Array* arr = 0;
01320   {
01321     const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
01322     const char* const nm = name->last_component()->get_string();
01323 
01324     const Classification cls = classify(base);
01325 
01326     switch (base->node_type()) {
01327     case AST_Decl::NT_sequence:
01328       generator_->gen_sequence(name, AST_Sequence::narrow_from_decl(base));
01329       break;
01330     case AST_Decl::NT_array:
01331       gen_array(name, arr = AST_Array::narrow_from_decl(base));
01332       break;
01333     case AST_Decl::NT_fixed:
01334 # ifdef ACE_HAS_CDR_FIXED
01335       gen_fixed(name, AST_Fixed::narrow_from_decl(base));
01336       break;
01337 # else
01338       std::cerr << "ERROR: fixed data type (for " << nm << ") is not supported"
01339         " with this version of ACE+TAO\n";
01340       return false;
01341 # endif
01342     default:
01343       be_global->lang_header_ <<
01344         "typedef " << map_type(base) << ' ' << nm << ";\n";
01345       if ((cls & CL_STRING) == 0) {
01346           be_global->lang_header_ <<
01347             "typedef " << map_type(base) << "_out " << nm << "_out;\n";
01348         }
01349 
01350       AST_Type* actual_base = resolveActualType(base);
01351       if (actual_base->node_type() == AST_Decl::NT_array) {
01352         be_global->lang_header_ <<
01353           "typedef " << map_type(base) << "_var " << nm << "_var;\n" <<
01354           "typedef " << map_type(base) << "_slice " << nm << "_slice;\n" <<
01355           "typedef " << map_type(base) << "_forany " << nm << "_forany;\n\n" <<
01356           "inline " << nm << "_slice *" << nm << "_alloc() { return " << map_type(base) << "_alloc(); }\n" <<
01357           "inline " << nm << "_slice* " << nm << "_dup(" << nm << "_slice *a) { return " << map_type(base) << "_dup(a); }\n" <<
01358           "inline void " << nm << "_copy(" << nm << "_slice* to, const " << nm << "_slice* from) { " << map_type(base) << "_copy(to, from); }\n" <<
01359           "inline void " << nm << "_free(" << nm << "_slice *a) { " << map_type(base) << "_free(a); }\n";
01360       }
01361 
01362       break;
01363     }
01364 
01365     if (cls & CL_STRING) {
01366       const Helper var = (cls & CL_WIDE) ? HLP_WSTR_VAR : HLP_STR_VAR,
01367         out = (cls & CL_WIDE) ? HLP_WSTR_OUT : HLP_STR_OUT;
01368       be_global->lang_header_ <<
01369         "typedef " << helpers_[var] << ' ' << nm << "_var;\n"
01370         "typedef " << helpers_[out] << ' ' << nm << "_out;\n";
01371     }
01372 
01373     gen_typecode(name);
01374   }
01375   if (arr) gen_array_traits(name, arr);
01376   return true;
01377 }

bool langmap_generator::gen_union ( AST_Union *  ,
UTL_ScopedName *  name,
const std::vector< AST_UnionBranch * > &  branches,
AST_Type *  discriminator,
const char *  repoid 
) [private, virtual]

Implements dds_generator.

Definition at line 1388 of file langmap_generator.cpp.

References GeneratorBase::gen_union(), and generator_.

01392 {
01393   return generator_->gen_union(u, name, branches, discriminator);
01394 }

bool langmap_generator::gen_union_fwd ( AST_UnionFwd *  ,
UTL_ScopedName *  name,
AST_Type::SIZE_TYPE  size 
) [private, virtual]

Reimplemented from dds_generator.

Definition at line 1379 of file langmap_generator.cpp.

References be_global, BE_GlobalData::lang_header_, and struct_decls().

01382 {
01383   const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
01384   struct_decls(name, node->full_definition()->size_type());
01385   return true;
01386 }

void langmap_generator::init (  ) 

Definition at line 1033 of file langmap_generator.cpp.

References be_global, generator_, GeneratorBase::init(), SafetyProfileGenerator::instance, FaceGenerator::instance, BE_GlobalData::LANGMAP_FACE_CXX, BE_GlobalData::LANGMAP_SP_CXX, and BE_GlobalData::language_mapping().

Referenced by dds_visitor::dds_visitor().

01034 {
01035   switch (be_global->language_mapping()) {
01036   case BE_GlobalData::LANGMAP_FACE_CXX:
01037     generator_ = &FaceGenerator::instance;
01038     generator_->init();
01039     break;
01040   case BE_GlobalData::LANGMAP_SP_CXX:
01041     generator_ = &SafetyProfileGenerator::instance;
01042     generator_->init();
01043     break;
01044   default: break;
01045   }
01046 }


Member Data Documentation

GeneratorBase* langmap_generator::generator_ [private]

Definition at line 48 of file langmap_generator.h.

Referenced by gen_struct(), gen_typedef(), gen_union(), and init().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:05:57 2016 for OpenDDS by  doxygen 1.4.7