v8_generator Class Reference

#include <v8_generator.h>

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

List of all members.

Public Member Functions

 v8_generator ()

Private Member Functions

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_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 *type, const char *repoid)
void gen_includes ()

Detailed Description

Definition at line 13 of file v8_generator.h.


Constructor & Destructor Documentation

v8_generator::v8_generator (  )  [inline]

Definition at line 16 of file v8_generator.h.

00016 {}


Member Function Documentation

bool v8_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 21 of file v8_generator.cpp.

00023 {
00024   return true;
00025 }

void v8_generator::gen_includes (  )  [private]

Definition at line 15 of file v8_generator.cpp.

References be_global.

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

00016 {
00017   be_global->add_include("<v8.h>", BE_GlobalData::STREAM_H);
00018   be_global->add_include("<nan.h>", BE_GlobalData::STREAM_CPP);
00019 }

Here is the caller graph for this function:

bool v8_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 166 of file v8_generator.cpp.

References Function::addArg(), be_global, Function::endArgs(), gen_includes(), and scoped().

00169 {
00170   gen_includes();
00171   {
00172     NamespaceGuard ng;
00173     const std::string clazz = scoped(name);
00174     {
00175       Function ctv("copyToV8", "v8::Local<v8::Object>");
00176       ctv.addArg("src", "const " + clazz + '&');
00177       ctv.endArgs();
00178       be_global->impl_ <<
00179         "  const v8::Local<v8::Object> stru = Nan::New<v8::Object>();\n";
00180       std::for_each(fields.begin(), fields.end(),
00181                     gen_field_copyto("stru", "src"));
00182       be_global->impl_ <<
00183         "  return stru;\n";
00184     }
00185   }
00186 
00187   if (idl_global->is_dcps_type(name)) {
00188     be_global->add_include("dds/DCPS/V8TypeConverter.h",
00189                            BE_GlobalData::STREAM_CPP);
00190     ScopedNamespaceGuard cppGuard(name, be_global->impl_);
00191     const std::string lname = name->last_component()->get_string(),
00192       tsv8 = lname + "TypeSupportV8Impl";
00193     be_global->impl_ <<
00194       "class " << tsv8 << "\n"
00195       "  : public virtual " << lname << "TypeSupportImpl\n"
00196       "  , public virtual OpenDDS::DCPS::V8TypeConverter {\n\n"
00197       "  v8::Local<v8::Object> toV8(const void* source) const\n"
00198       "  {\n"
00199       "    return OpenDDS::DCPS::copyToV8(*static_cast<const " << lname
00200                << "*>(source));\n"
00201       "  }\n\n"
00202       "public:\n"
00203       "  struct Initializer {\n"
00204       "    Initializer()\n"
00205       "    {\n"
00206       "      " << lname << "TypeSupport_var ts = new " << tsv8 << ";\n"
00207       "      ts->register_type(0, \"\");\n"
00208       "    }\n"
00209       "  };\n"
00210       "};\n\n" <<
00211       tsv8 << "::Initializer init_tsv8_" << lname << ";\n";
00212   }
00213   return true;
00214 }

Here is the call graph for this function:

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

Implements dds_generator.

Definition at line 216 of file v8_generator.cpp.

References Function::addArg(), be_global, Function::endArgs(), gen_includes(), and scoped().

00218 {
00219   gen_includes();
00220   switch (type->node_type()) {
00221   case AST_Decl::NT_sequence: {
00222     NamespaceGuard ng;
00223     AST_Sequence* seq = AST_Sequence::narrow_from_decl(type);
00224     const std::string cxx = scoped(name);
00225     AST_Type* elem = seq->base_type();
00226     {
00227       Function ctv("copyToV8", "v8::Local<v8::Object>");
00228       ctv.addArg("src", "const " + cxx + '&');
00229       ctv.endArgs();
00230       be_global->impl_ <<
00231         "  const v8::Local<v8::Array> tgt(Nan::New<v8::Array>(src.length()));\n"
00232         "  for (CORBA::ULong i = 0; i < src.length(); ++i) {\n"
00233         "  ";
00234       gen_copyto("tgt", "src[i]", elem, "i");
00235       be_global->impl_ <<
00236         "  }\n"
00237         "  return tgt;\n";
00238     }
00239     break;
00240   }
00241   case AST_Decl::NT_array: {
00242     //TODO: support arrays
00243     break;
00244   }
00245   default:
00246     return true;
00247   }
00248   return true;
00249 }

Here is the call graph for this function:

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

Implements dds_generator.

Definition at line 265 of file v8_generator.cpp.

References Function::addArg(), be_global, Function::endArgs(), gen_includes(), generateSwitchForUnion(), and scoped().

00268 {
00269   gen_includes();
00270   NamespaceGuard ng;
00271   const std::string clazz = scoped(name);
00272   {
00273     Function ctv("copyToV8", "v8::Local<v8::Object>");
00274     ctv.addArg("src", "const " + clazz + '&');
00275     ctv.endArgs();
00276     be_global->impl_ <<
00277       "  const v8::Local<v8::Object> uni = Nan::New<v8::Object>();\n";
00278     gen_copyto("uni", "src._d()", discriminator, "Nan::New<v8::String>(\"_d\").ToLocalChecked()");
00279     generateSwitchForUnion("src._d()", branchGen, branches, discriminator,
00280                            "", "", clazz.c_str(), false, false);
00281     be_global->impl_ <<
00282       "  return uni;\n";
00283   }
00284   return true;
00285 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1