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 fwd_decl ()

Private Attributes

bool first_

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 : first_(true) {}


Member Function Documentation

void v8_generator::fwd_decl (  )  [private]

Definition at line 15 of file v8_generator.cpp.

References BE_GlobalData::add_include(), be_global, first_, BE_GlobalData::header_, and BE_GlobalData::STREAM_CPP.

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

00016 {
00017   if (first_) {
00018     be_global->add_include("<v8.h>", BE_GlobalData::STREAM_CPP);
00019     first_ = false;
00020     be_global->header_ <<
00021       "namespace v8 {\n"
00022       "  class Value;\n"
00023       "}\n\n";
00024   }
00025 }

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 27 of file v8_generator.cpp.

00029 {
00030   return true;
00031 }

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 168 of file v8_generator.cpp.

References BE_GlobalData::add_include(), Function::addArg(), be_global, Function::endArgs(), fwd_decl(), BE_GlobalData::impl_, scoped(), and BE_GlobalData::STREAM_CPP.

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

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

Implements dds_generator.

Definition at line 218 of file v8_generator.cpp.

References Function::addArg(), be_global, Function::endArgs(), fwd_decl(), gen_copyto(), BE_GlobalData::impl_, and scoped().

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

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 253 of file v8_generator.cpp.

References fwd_decl().

00256 {
00257   fwd_decl();
00258   return true;
00259 }


Member Data Documentation

bool v8_generator::first_ [private]

Definition at line 34 of file v8_generator.h.

Referenced by fwd_decl().


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