OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Private Member Functions | List of all members
langmap_generator Class Reference

#include <langmap_generator.h>

Inheritance diagram for langmap_generator:
Inheritance graph
[legend]
Collaboration diagram for langmap_generator:
Collaboration graph
[legend]

Public Member Functions

void init ()
 
- Public Member Functions inherited from dds_generator
virtual ~dds_generator ()=0
 
virtual bool do_included_files () const
 
virtual void gen_prologue ()
 
virtual void gen_epilogue ()
 
virtual bool gen_interf (AST_Interface *, UTL_ScopedName *, bool, const std::vector< AST_Interface *> &, const std::vector< AST_Interface *> &, const std::vector< AST_Attribute *> &, const std::vector< AST_Operation *> &, const char *)
 
virtual bool gen_native (AST_Native *, UTL_ScopedName *, const char *)
 

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)
 

Additional Inherited Members

- Static Public Member Functions inherited from dds_generator
static std::string get_tag_name (const std::string &base_name, bool nested_key_only=false)
 
static std::string get_xtag_name (UTL_ScopedName *name)
 
static bool cxx_escaped (const std::string &s)
 
static std::string valid_var_name (const std::string &str)
 
static std::string to_string (Identifier *id, EscapeContext ec=EscapeContext_Normal)
 
static std::string scoped_helper (UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
 
static std::string module_scope_helper (UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
 

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 14 of file langmap_generator.h.

Member Function Documentation

◆ gen_const()

bool langmap_generator::gen_const ( UTL_ScopedName *  name,
bool  nestedInInteface,
AST_Constant *  constant 
)
privatevirtual

Reimplemented from dds_generator.

Definition at line 1839 of file langmap_generator.cpp.

References be_global, scoped(), dds_generator::scoped_helper(), and OpenDDS::DCPS::to_string().

1841 {
1842  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1843  const char* const nm = name->last_component()->get_string();
1844 
1845  const AST_Expression::ExprType type = constant->et();
1846  const bool is_enum = (type == AST_Expression::EV_enum);
1847  const std::string type_name = is_enum
1848  ? scoped(constant->enum_full_name()) : generator_->map_type(type);
1849  be_global->lang_header_ <<
1850  generator_->const_keyword(type) << ' ' << type_name << ' ' << nm << " = ";
1851 
1852  if (is_enum) {
1853  UTL_ScopedName* const enumerator = constant->constant_value()->n();
1854  if (generator_->scoped_enum()) {
1855  be_global->lang_header_ << type_name << "::"
1856  << to_string(enumerator->last_component()) << ";\n";
1857  } else {
1858  be_global->lang_header_ << dds_generator::scoped_helper(enumerator, "::") << ";\n";
1859  }
1860  } else {
1861  be_global->lang_header_ << *constant->constant_value()->ev() << ";\n";
1862  }
1863  return true;
1864 }
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)

◆ gen_enum()

bool langmap_generator::gen_enum ( AST_Enum *  ,
UTL_ScopedName *  name,
const std::vector< AST_EnumVal *> &  contents,
const char *  repoid 
)
privatevirtual

Reimplemented from dds_generator.

Definition at line 1866 of file langmap_generator.cpp.

References be_global.

1869 {
1870  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1871  const char* const nm = name->last_component()->get_string();
1872  const char* scoped_enum = generator_->scoped_enum() ? "class " : "";
1873  const std::string enum_base = generator_->enum_base();
1874  be_global->lang_header_ <<
1875  "enum " << scoped_enum << nm << enum_base << " {\n";
1876  for (size_t i = 0; i < contents.size(); ++i) {
1877  be_global->lang_header_ <<
1878  " " << contents[i]->local_name()->get_string()
1879  << ((i < contents.size() - 1) ? ",\n" : "\n");
1880  }
1881  be_global->lang_header_ <<
1882  "};\n\n";
1883  generator_->gen_simple_out(nm);
1884  gen_typecode(name);
1885  return true;
1886 }
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_interf_fwd()

bool langmap_generator::gen_interf_fwd ( UTL_ScopedName *  name)
privatevirtual

Reimplemented from dds_generator.

Definition at line 1985 of file langmap_generator.cpp.

References be_global.

1986 {
1987  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
1988  return true;
1989  }
1990 
1991  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1992 
1993  be_global->add_include("<tao/Objref_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
1994  const char* const nm = name->last_component()->get_string();
1995  be_global->lang_header_ <<
1996  "class " << nm << ";\n"
1997  "typedef " << nm << '*' << nm << "_ptr;\n"
1998  "typedef TAO_Objref_Var_T<" << nm << "> " << nm << "_var;\n"
1999  "typedef TAO_Objref_Out_T<" << nm << "> " << nm << "_out;\n";
2000 
2001  return true;
2002 }
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_struct()

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 
)
privatevirtual

Implements dds_generator.

Definition at line 1896 of file langmap_generator.cpp.

References be_global, and name.

1900 {
1901  return generator_->gen_struct(s, name, fields, size, x);
1902 }
const char *const name
Definition: debug.cpp:60

◆ gen_struct_fwd()

bool langmap_generator::gen_struct_fwd ( UTL_ScopedName *  name,
AST_Type::SIZE_TYPE  size 
)
privatevirtual

Reimplemented from dds_generator.

Definition at line 1888 of file langmap_generator.cpp.

References be_global.

1890 {
1891  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1892  generator_->struct_decls(name, size);
1893  return true;
1894 }
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_typedef()

bool langmap_generator::gen_typedef ( AST_Typedef *  ,
UTL_ScopedName *  name,
AST_Type *  type,
const char *  repoid 
)
privatevirtual

Implements dds_generator.

Definition at line 1919 of file langmap_generator.cpp.

References be_global, and AstTypeClassification::resolveActualType().

1921 {
1922  AST_Array* arr = 0;
1923  {
1924  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1925  const char* const nm = name->last_component()->get_string();
1926 
1927  switch (base->node_type()) {
1928  case AST_Decl::NT_sequence:
1929  generator_->gen_sequence(name, dynamic_cast<AST_Sequence*>(base));
1930  break;
1931  case AST_Decl::NT_array:
1932  generator_->gen_array(name, arr = dynamic_cast<AST_Array*>(base));
1933  break;
1934  case AST_Decl::NT_fixed:
1935 # ifdef ACE_HAS_CDR_FIXED
1936  gen_fixed(name, dynamic_cast<AST_Fixed*>(base));
1937  break;
1938 # else
1939  std::cerr << "ERROR: fixed data type (for " << nm << ") is not supported"
1940  " with this version of ACE+TAO\n";
1941  return false;
1942 # endif
1943  default:
1944  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
1945  be_global->lang_header_ <<
1946  "using " << nm << " = " << generator_->map_type(base) << ";\n";
1947  } else {
1948  be_global->lang_header_ <<
1949  "typedef " << generator_->map_type(base) << ' ' << nm << ";\n";
1950  }
1951 
1952  generator_->gen_typedef_varout(nm, base);
1953 
1954  AST_Type* actual_base = resolveActualType(base);
1955  if (actual_base->node_type() == AST_Decl::NT_array) {
1956  generator_->gen_array_typedef(nm, base);
1957  }
1958 
1959  break;
1960  }
1961 
1962  gen_typecode(name);
1963  }
1964  if (arr) generator_->gen_array_traits(name, arr);
1965  return true;
1966 }
AST_Type * resolveActualType(AST_Type *element)
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_union()

bool langmap_generator::gen_union ( AST_Union *  u,
UTL_ScopedName *  name,
const std::vector< AST_UnionBranch *> &  branches,
AST_Type *  discriminator,
const char *  repoid 
)
privatevirtual

Implements dds_generator.

Definition at line 1977 of file langmap_generator.cpp.

1981 {
1982  return generator_->gen_union(u, name, branches, discriminator);
1983 }
const char *const name
Definition: debug.cpp:60

◆ gen_union_fwd()

bool langmap_generator::gen_union_fwd ( AST_UnionFwd *  node,
UTL_ScopedName *  name,
AST_Type::SIZE_TYPE  size 
)
privatevirtual

Reimplemented from dds_generator.

Definition at line 1968 of file langmap_generator.cpp.

References be_global.

1971 {
1972  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1973  generator_->struct_decls(name, node->full_definition()->size_type(), "class");
1974  return true;
1975 }
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ init()

void langmap_generator::init ( void  )

Definition at line 1817 of file langmap_generator.cpp.

References be_global, FaceGenerator::init(), SafetyProfileGenerator::init(), Cxx11Generator::init(), FaceGenerator::instance, SafetyProfileGenerator::instance, and Cxx11Generator::instance.

1818 {
1819  switch (be_global->language_mapping()) {
1820  case BE_GlobalData::LANGMAP_FACE_CXX:
1821  string_ns = "::FACE";
1822  generator_ = &FaceGenerator::instance;
1823  generator_->init();
1824  break;
1825  case BE_GlobalData::LANGMAP_SP_CXX:
1826  string_ns = "::CORBA";
1827  generator_ = &SafetyProfileGenerator::instance;
1828  generator_->init();
1829  break;
1830  case BE_GlobalData::LANGMAP_CXX11:
1831  string_ns = "::CORBA";
1832  generator_ = &Cxx11Generator::instance;
1833  generator_->init();
1834  break;
1835  default: break;
1836  }
1837 }
static Cxx11Generator instance
static SafetyProfileGenerator instance
static FaceGenerator instance
BE_GlobalData * be_global
Definition: be_global.cpp:43
virtual void init()

The documentation for this class was generated from the following files: