OpenDDS  Snapshot(2023/04/28-20:55)
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, const std::string &qualifier="")
 
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 1840 of file langmap_generator.cpp.

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

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

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

References be_global.

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

◆ gen_interf_fwd()

bool langmap_generator::gen_interf_fwd ( UTL_ScopedName *  name)
privatevirtual

Reimplemented from dds_generator.

Definition at line 1986 of file langmap_generator.cpp.

References be_global.

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

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

References be_global, and name.

1901 {
1902  return generator_->gen_struct(s, name, fields, size, x);
1903 }
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 1889 of file langmap_generator.cpp.

References be_global.

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

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

References be_global, and AstTypeClassification::resolveActualType().

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

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

1982 {
1983  return generator_->gen_union(u, name, branches, discriminator);
1984 }
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 1969 of file langmap_generator.cpp.

References be_global.

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

◆ init()

void langmap_generator::init ( void  )

Definition at line 1818 of file langmap_generator.cpp.

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

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

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