#include "v8_generator.h"
#include "be_extern.h"
#include "utl_identifier.h"
Include dependency graph for v8_generator.cpp:
Go to the source code of this file.
Functions | |
std::string | getV8Type (AST_Type *type, AST_PredefinedType::PredefinedType *pt=0) |
bool | builtInSeq (AST_Type *type) |
void | gen_copyto (const char *tgt, const char *src, AST_Type *type, const char *prop) |
Variables | |
const std::string | tgt_ |
const std::string | src_ |
bool @95::builtInSeq | ( | AST_Type * | type | ) | [static] |
Definition at line 65 of file v8_generator.cpp.
References scoped().
Referenced by gen_copyto().
00066 { 00067 const std::string name = scoped(type->name()); 00068 static const char PRE[] = "CORBA::"; 00069 if (std::strncmp(name.c_str(), PRE, sizeof(PRE) - 1)) return false; 00070 return name.rfind("Seq") == name.size() - 3; 00071 }
void @95::gen_copyto | ( | const char * | tgt, | |
const char * | src, | |||
AST_Type * | type, | |||
const char * | prop | |||
) | [static] |
Definition at line 73 of file v8_generator.cpp.
References be_global, builtInSeq(), AstTypeClassification::CL_ENUM, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), getV8Type(), BE_GlobalData::impl_, AstTypeClassification::resolveActualType(), and dds_generator::scoped_helper().
Referenced by v8_generator::gen_typedef().
00075 { 00076 const Classification cls = classify(type); 00077 AST_PredefinedType::PredefinedType pt = AST_PredefinedType::PT_void; 00078 const std::string v8Type = getV8Type(type, &pt), 00079 propName = std::string(tgt) + "->Set(" + prop + ", "; 00080 00081 if (cls & CL_SCALAR) { 00082 std::string prefix, suffix, v8fn = "New"; 00083 00084 if (cls & CL_ENUM) { 00085 const std::string underscores = 00086 dds_generator::scoped_helper(type->name(), "_"), 00087 array = "gen_" + underscores + "_names"; 00088 prefix = '(' + std::string(src) + " >= sizeof(" + array + ")/sizeof(" + 00089 array + "[0])) ? \"<<invalid>>\" : " + array + "[static_cast<int>("; 00090 suffix = ")]"; 00091 00092 } else if (cls & CL_STRING) { 00093 if (cls & CL_WIDE) { 00094 be_global->impl_ << 00095 " {\n" 00096 " const size_t len = ACE_OS::strlen(" << src << ".in());\n" 00097 " uint16_t* const str = new uint16_t[len + 1];\n" 00098 " for (size_t i = 0; i <= len; ++i) {\n" 00099 " str[i] = " << src << "[i];\n" 00100 " }\n" 00101 " " << propName << "v8::String::New(str));\n" 00102 " delete[] str;\n" 00103 " }\n"; 00104 return; 00105 } 00106 suffix = ".in()"; 00107 00108 } else if (pt == AST_PredefinedType::PT_char) { 00109 be_global->impl_ << 00110 " {\n" 00111 " const char str[] = {" << src << ", 0};\n" 00112 " " << propName << "v8::String::New(str));\n" 00113 " }\n"; 00114 return; 00115 00116 } else if (pt == AST_PredefinedType::PT_wchar) { 00117 be_global->impl_ << 00118 " {\n" 00119 " const uint16_t str[] = {" << src << ", 0};\n" 00120 " " << propName << "v8::String::New(str));\n" 00121 " }\n"; 00122 return; 00123 00124 } else if (pt == AST_PredefinedType::PT_ulong) { 00125 v8fn = "NewFromUnsigned"; 00126 } 00127 00128 be_global->impl_ << 00129 " " << propName << "v8::" << v8Type << "::" << v8fn << '(' 00130 << prefix << src << suffix << "));\n"; 00131 00132 } else if ((cls & CL_SEQUENCE) && builtInSeq(type)) { 00133 AST_Type* real_type = resolveActualType(type); 00134 AST_Sequence* seq = AST_Sequence::narrow_from_decl(real_type); 00135 AST_Type* elem = seq->base_type(); 00136 be_global->impl_ << 00137 " {\n" 00138 " const v8::Local<v8::Array> seq = v8::Array::New(" << src 00139 << ".length());\n" 00140 " for (CORBA::ULong j = 0; j < " << src << ".length(); ++j) {\n"; 00141 gen_copyto("seq", (std::string(src) + "[j]").c_str(), elem, "j"); 00142 be_global->impl_ << 00143 " }\n" 00144 " " << propName << "seq" << ");\n" 00145 " }\n"; 00146 00147 } else { // struct, sequence, etc. 00148 be_global->impl_ << 00149 " " << propName << "v8::Handle<v8::Value>(copyToV8(" 00150 << src << ")));\n"; 00151 } 00152 }
std::string @95::getV8Type | ( | AST_Type * | type, | |
AST_PredefinedType::PredefinedType * | pt = 0 | |||
) | [static] |
Definition at line 35 of file v8_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().
Referenced by gen_copyto().
00037 { 00038 const Classification cls = classify(type); 00039 if (cls & (CL_ENUM | CL_STRING)) return "String"; 00040 if (cls & (CL_STRUCTURE | CL_UNION)) return "Object"; 00041 if (cls & (CL_ARRAY | CL_SEQUENCE)) return "Array"; 00042 if (cls & CL_PRIMITIVE) { 00043 AST_Type* actual = resolveActualType(type); 00044 AST_PredefinedType* p = AST_PredefinedType::narrow_from_decl(actual); 00045 if (pt) *pt = p->pt(); 00046 switch (p->pt()) { 00047 case AST_PredefinedType::PT_char: 00048 case AST_PredefinedType::PT_wchar: 00049 return "String"; 00050 case AST_PredefinedType::PT_boolean: 00051 return "Boolean"; 00052 case AST_PredefinedType::PT_octet: 00053 case AST_PredefinedType::PT_ushort: 00054 case AST_PredefinedType::PT_short: 00055 case AST_PredefinedType::PT_ulong: 00056 case AST_PredefinedType::PT_long: 00057 return "Integer"; 00058 default: 00059 return "Number"; 00060 } 00061 } 00062 return ""; 00063 }
const std::string src_ |
Definition at line 156 of file v8_generator.cpp.
const std::string tgt_ |
Definition at line 156 of file v8_generator.cpp.