#include "metaclass_generator.h"
#include "be_extern.h"
#include "utl_identifier.h"
Include dependency graph for metaclass_generator.cpp:
Go to the source code of this file.
Functions | |
void | delegateToNested (const std::string &fieldName, AST_Field *field, const std::string &firstArg, bool skip=false) |
void | gen_field_getValue (AST_Field *field) |
std::string | to_cxx_type (AST_Type *type, int &size) |
void | gen_field_getValueFromSerialized (AST_Field *field) |
void | gen_field_createQC (AST_Field *field) |
void | print_field_name (AST_Field *field) |
void | get_raw_field (AST_Field *field) |
void | assign_field (AST_Field *field) |
void | compare_field (AST_Field *field) |
static std::string | func (const std::string &, AST_Type *br_type, const std::string &, std::string &, const std::string &) |
Variables | |
bool | activate_ |
void @93::assign_field | ( | AST_Field * | field | ) | [static] |
Definition at line 251 of file metaclass_generator.cpp.
References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), BE_GlobalData::impl_, NestedForLoops::index_, AstTypeClassification::resolveActualType(), scoped(), and BE_GlobalData::STREAM_CPP.
Referenced by metaclass_generator::gen_struct().
00252 { 00253 Classification cls = classify(field->field_type()); 00254 if (!cls) return; // skip CL_UNKNOWN types 00255 const char* fieldName = field->local_name()->get_string(); 00256 const std::string fieldType = (cls & CL_STRING) ? 00257 ((cls & CL_WIDE) ? "TAO::WString_Manager" : "TAO::String_Manager") 00258 : scoped(field->field_type()->name()); 00259 if (cls & (CL_SCALAR | CL_STRUCTURE | CL_SEQUENCE | CL_UNION)) { 00260 be_global->impl_ << 00261 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n" 00262 " static_cast<T*>(lhs)->" << fieldName << 00263 " = *static_cast<const " << fieldType << 00264 "*>(rhsMeta.getRawField(rhs, rhsFieldSpec));\n" 00265 " return;\n" 00266 " }\n"; 00267 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00268 } else if (cls & CL_ARRAY) { 00269 AST_Type* unTD = resolveActualType(field->field_type()); 00270 AST_Array* arr = AST_Array::narrow_from_decl(unTD); 00271 be_global->impl_ << 00272 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n" 00273 " " << fieldType << "* lhsArr = &static_cast<T*>(lhs)->" << 00274 fieldName << ";\n" 00275 " const " << fieldType << "* rhsArr = static_cast<const " << 00276 fieldType << "*>(rhsMeta.getRawField(rhs, rhsFieldSpec));\n"; 00277 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00278 AST_Type* elem = arr->base_type(); 00279 AST_Type* elemUnTD = resolveActualType(elem); 00280 if (classify(elemUnTD) & CL_ARRAY) { 00281 // array-of-array case, fall back on the Serializer 00282 be_global->impl_ << 00283 " " << fieldType << "_forany rhsForany(const_cast<" << 00284 fieldType << "_slice*>(*rhsArr));\n" 00285 " size_t size = 0, padding = 0;\n" 00286 " gen_find_size(rhsForany, size, padding);\n" 00287 " ACE_Message_Block mb(size);\n" 00288 " Serializer ser_out(&mb);\n" 00289 " ser_out << rhsForany;\n" 00290 " " << fieldType << "_forany lhsForany(*lhsArr);\n" 00291 " Serializer ser_in(&mb);\n" 00292 " ser_in >> lhsForany;\n"; 00293 } else { 00294 std::string indent = " "; 00295 NestedForLoops nfl("CORBA::ULong", "i", arr, indent); 00296 be_global->impl_ << 00297 indent << "(*lhsArr)" << nfl.index_ << " = (*rhsArr)" << 00298 nfl.index_ << ";\n"; 00299 } 00300 be_global->impl_ << 00301 " return;\n" 00302 " }\n"; 00303 } 00304 }
void @93::compare_field | ( | AST_Field * | field | ) | [static] |
Definition at line 306 of file metaclass_generator.cpp.
References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_STRING, AstTypeClassification::classify(), BE_GlobalData::impl_, and BE_GlobalData::STREAM_CPP.
Referenced by metaclass_generator::gen_struct().
00307 { 00308 Classification cls = classify(field->field_type()); 00309 if (!(cls & CL_SCALAR)) return; 00310 const char* fieldName = field->local_name()->get_string(); 00311 be_global->impl_ << 00312 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n"; 00313 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00314 if (cls & CL_STRING) { 00315 be_global->impl_ << // ACE_OS::strcmp has overloads for narrow & wide 00316 " return 0 == ACE_OS::strcmp(static_cast<const T*>(lhs)->" 00317 << fieldName << ".in(), static_cast<const T*>(rhs)->" << fieldName 00318 << ".in());\n"; 00319 } else { 00320 be_global->impl_ << 00321 " return static_cast<const T*>(lhs)->" << fieldName << 00322 " == static_cast<const T*>(rhs)->" << fieldName << ";\n"; 00323 } 00324 be_global->impl_ << " }\n"; 00325 }
void @93::delegateToNested | ( | const std::string & | fieldName, | |
AST_Field * | field, | |||
const std::string & | firstArg, | |||
bool | skip = false | |||
) | [static] |
Definition at line 56 of file metaclass_generator.cpp.
References be_global, BE_GlobalData::impl_, and scoped().
Referenced by gen_field_getValue(), and gen_field_getValueFromSerialized().
00058 { 00059 const size_t n = fieldName.size() + 1 /* 1 for the dot */; 00060 const std::string fieldType = scoped(field->field_type()->name()); 00061 be_global->impl_ << 00062 " if (std::strncmp(field, \"" << fieldName << ".\", " << n 00063 << ") == 0) {\n" 00064 " return getMetaStruct<" << fieldType << ">().getValue(" 00065 << firstArg << ", field + " << n << ");\n" 00066 " }" << (skip ? "" : "\n"); 00067 if (skip) { 00068 be_global->impl_ << " else {\n" 00069 " gen_skip_over(" << firstArg << ", static_cast<" << fieldType 00070 << "*>(0));\n" 00071 " }\n"; 00072 } 00073 }
static std::string func | ( | const std::string & | , | |
AST_Type * | br_type, | |||
const std::string & | , | |||
std::string & | , | |||
const std::string & | ||||
) | [static] |
Definition at line 522 of file metaclass_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), scoped(), and to_cxx_type().
Referenced by metaclass_generator::gen_union().
00527 { 00528 std::stringstream ss; 00529 const Classification br_cls = classify(br_type); 00530 if (br_cls & CL_STRING) { 00531 ss << 00532 " ACE_CDR::ULong len;\n" 00533 " ser >> len;\n" 00534 " ser.skip(len);\n"; 00535 } else if (br_cls & CL_WIDE) { 00536 ss << 00537 " ACE_CDR::Octet len;\n" 00538 " ser >> ACE_InputCDR::to_octet(len);\n" 00539 " ser.skip(len);\n"; 00540 } else if (br_cls & CL_SCALAR) { 00541 int sz = 1; 00542 to_cxx_type(br_type, sz); 00543 ss << 00544 " ser.skip(1, " << sz << ");\n"; 00545 } else { 00546 ss << 00547 " gen_skip_over(ser, static_cast<" << scoped(br_type->name()) 00548 << ((br_cls & CL_ARRAY) ? "_forany" : "") << "*>(0));\n"; 00549 } 00550 00551 return ss.str(); 00552 }
void @93::gen_field_createQC | ( | AST_Field * | field | ) | [static] |
Definition at line 213 of file metaclass_generator.cpp.
References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::classify(), BE_GlobalData::impl_, scoped(), and BE_GlobalData::STREAM_CPP.
Referenced by metaclass_generator::gen_struct().
00214 { 00215 Classification cls = classify(field->field_type()); 00216 const std::string fieldName = field->local_name()->get_string(); 00217 if (cls & CL_SCALAR) { 00218 be_global->impl_ << 00219 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n" 00220 " return make_field_cmp(&T::" << fieldName << ", next);\n" 00221 " }\n"; 00222 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00223 } else if (cls & CL_STRUCTURE) { 00224 size_t n = fieldName.size() + 1 /* 1 for the dot */; 00225 std::string fieldType = scoped(field->field_type()->name()); 00226 be_global->impl_ << 00227 " if (std::strncmp(field, \"" << fieldName << ".\", " << n << 00228 ") == 0) {\n" 00229 " return make_struct_cmp(&T::" << fieldName << 00230 ", getMetaStruct<" << fieldType << ">().create_qc_comparator(" 00231 "field + " << n << ", 0), next);\n" 00232 " }\n"; 00233 } 00234 }
void @93::gen_field_getValue | ( | AST_Field * | field | ) | [static] |
Definition at line 75 of file metaclass_generator.cpp.
References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::classify(), delegateToNested(), BE_GlobalData::impl_, AstTypeClassification::resolveActualType(), dds_generator::scoped_helper(), and BE_GlobalData::STREAM_CPP.
Referenced by metaclass_generator::gen_struct().
00076 { 00077 const Classification cls = classify(field->field_type()); 00078 const std::string fieldName = field->local_name()->get_string(); 00079 if (cls & CL_SCALAR) { 00080 std::string prefix, suffix; 00081 if (cls & CL_ENUM) { 00082 AST_Type* enum_type = resolveActualType(field->field_type()); 00083 prefix = "gen_" + 00084 dds_generator::scoped_helper(enum_type->name(), "_") 00085 + "_names["; 00086 suffix = "]"; 00087 } 00088 be_global->impl_ << 00089 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n" 00090 " return " + prefix + "typed." + fieldName 00091 + (cls & CL_STRING ? ".in()" : "") + suffix + ";\n" 00092 " }\n"; 00093 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00094 } else if (cls & CL_STRUCTURE) { 00095 delegateToNested(fieldName, field, "&typed." + fieldName); 00096 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00097 } 00098 }
void @93::gen_field_getValueFromSerialized | ( | AST_Field * | field | ) | [static] |
Definition at line 162 of file metaclass_generator.cpp.
References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), delegateToNested(), getWrapper(), BE_GlobalData::impl_, AstTypeClassification::resolveActualType(), to_cxx_type(), and WD_INPUT.
Referenced by metaclass_generator::gen_struct().
00163 { 00164 AST_Type* type = field->field_type(); 00165 const Classification cls = classify(type); 00166 const std::string fieldName = field->local_name()->get_string(); 00167 int size = 0; 00168 const std::string cxx_type = to_cxx_type(type, size); 00169 if (cls & CL_SCALAR) { 00170 type = resolveActualType(type); 00171 const std::string val = 00172 (cls & CL_STRING) ? "val.out()" : getWrapper("val", type, WD_INPUT); 00173 be_global->impl_ << 00174 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n" 00175 " " << cxx_type << " val;\n" 00176 " if (!(ser >> " << val << ")) {\n" 00177 " throw std::runtime_error(\"Field '" << fieldName << "' could " 00178 "not be deserialized\");\n" 00179 " }\n" 00180 " return val;\n" 00181 " } else {\n"; 00182 if (cls & CL_STRING) { 00183 be_global->impl_ << 00184 " ACE_CDR::ULong len;\n" 00185 " if (!(ser >> len)) {\n" 00186 " throw std::runtime_error(\"String '" << fieldName << 00187 "' length could not be deserialized\");\n" 00188 " }\n" 00189 " ser.skip(len);\n"; 00190 } else if (cls & CL_WIDE) { 00191 be_global->impl_ << 00192 " ACE_CDR::Octet len;\n" 00193 " if (!(ser >> ACE_InputCDR::to_octet(len))) {\n" 00194 " throw std::runtime_error(\"WChar '" << fieldName << 00195 "' length could not be deserialized\");\n" 00196 " }\n" 00197 " ser.skip(len);\n"; 00198 } else { 00199 be_global->impl_ << 00200 " ser.skip(1, " << size << ");\n"; 00201 } 00202 be_global->impl_ << 00203 " }\n"; 00204 } else if (cls & CL_STRUCTURE) { 00205 delegateToNested(fieldName, field, "ser", true); 00206 } else { // array, sequence, union: 00207 be_global->impl_ << 00208 " gen_skip_over(ser, static_cast<" << cxx_type 00209 << ((cls & CL_ARRAY) ? "_forany" : "") << "*>(0));\n"; 00210 } 00211 }
void @93::get_raw_field | ( | AST_Field * | field | ) | [static] |
Definition at line 241 of file metaclass_generator.cpp.
References BE_GlobalData::add_include(), be_global, BE_GlobalData::impl_, and BE_GlobalData::STREAM_CPP.
Referenced by metaclass_generator::gen_struct().
00242 { 00243 const char* fieldName = field->local_name()->get_string(); 00244 be_global->impl_ << 00245 " if (std::strcmp(field, \"" << fieldName << "\") == 0) {\n" 00246 " return &static_cast<const T*>(stru)->" << fieldName << ";\n" 00247 " }\n"; 00248 be_global->add_include("<cstring>", BE_GlobalData::STREAM_CPP); 00249 }
void @93::print_field_name | ( | AST_Field * | field | ) | [static] |
Definition at line 236 of file metaclass_generator.cpp.
References be_global, and BE_GlobalData::impl_.
Referenced by metaclass_generator::gen_struct().
std::string @93::to_cxx_type | ( | AST_Type * | type, | |
int & | size | |||
) | [static] |
Definition at line 100 of file metaclass_generator.cpp.
References AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), AstTypeClassification::resolveActualType(), and scoped().
Referenced by func(), gen_field_getValueFromSerialized(), and metaclass_generator::gen_typedef().
00101 { 00102 const Classification cls = classify(type); 00103 if (cls & CL_ENUM) { 00104 size = 4; 00105 return "ACE_CDR::ULong"; 00106 } 00107 if (cls & CL_STRING) { 00108 size = 4; // encoding of str length is 4 bytes 00109 return ((cls & CL_WIDE) ? "TAO::W" : "TAO::") 00110 + std::string("String_Manager"); 00111 } 00112 if (cls & CL_PRIMITIVE) { 00113 type = resolveActualType(type); 00114 AST_PredefinedType* p = AST_PredefinedType::narrow_from_decl(type); 00115 switch (p->pt()) { 00116 case AST_PredefinedType::PT_long: 00117 size = 4; 00118 return "ACE_CDR::Long"; 00119 case AST_PredefinedType::PT_ulong: 00120 size = 4; 00121 return "ACE_CDR::ULong"; 00122 case AST_PredefinedType::PT_longlong: 00123 size = 8; 00124 return "ACE_CDR::LongLong"; 00125 case AST_PredefinedType::PT_ulonglong: 00126 size = 8; 00127 return "ACE_CDR::ULongLong"; 00128 case AST_PredefinedType::PT_short: 00129 size = 2; 00130 return "ACE_CDR::Short"; 00131 case AST_PredefinedType::PT_ushort: 00132 size = 2; 00133 return "ACE_CDR::UShort"; 00134 case AST_PredefinedType::PT_float: 00135 size = 4; 00136 return "ACE_CDR::Float"; 00137 case AST_PredefinedType::PT_double: 00138 size = 8; 00139 return "ACE_CDR::Double"; 00140 case AST_PredefinedType::PT_longdouble: 00141 size = 16; 00142 return "ACE_CDR::LongDouble"; 00143 case AST_PredefinedType::PT_char: 00144 size = 1; 00145 return "ACE_CDR::Char"; 00146 case AST_PredefinedType::PT_wchar: 00147 size = 1; // encoding of wchar length is 1 byte 00148 return "ACE_CDR::WChar"; 00149 case AST_PredefinedType::PT_boolean: 00150 size = 1; 00151 return "ACE_CDR::Boolean"; 00152 case AST_PredefinedType::PT_octet: 00153 size = 1; 00154 return "ACE_CDR::Octet"; 00155 default: 00156 break; 00157 } 00158 } 00159 return scoped(type->name()); 00160 }
bool activate_ |
Definition at line 34 of file metaclass_generator.cpp.