#include "langmap_generator.h"
#include "be_extern.h"
#include "utl_identifier.h"
#include "ace/Version.h"
#include "ace/CDR_Base.h"
#include <map>
#include <iostream>
Include dependency graph for langmap_generator.cpp:
Go to the source code of this file.
Classes | |
class | GeneratorBase |
struct | GeneratorBase::GenerateGettersAndSetters |
class | FaceGenerator |
class | SafetyProfileGenerator |
Enumerations | |
enum | Helper { HLP_STR_VAR, HLP_STR_OUT, HLP_WSTR_VAR, HLP_WSTR_OUT, HLP_STR_MGR, HLP_WSTR_MGR, HLP_FIX_VAR, HLP_VAR_VAR, HLP_OUT, HLP_SEQ, HLP_SEQ_NS, HLP_SEQ_VAR_VAR, HLP_SEQ_FIX_VAR, HLP_SEQ_OUT, HLP_ARR_VAR_VAR, HLP_ARR_FIX_VAR, HLP_ARR_OUT, HLP_ARR_FORANY, HLP_FIXED, HLP_FIXED_CONSTANT } |
Functions | |
std::string | map_type (AST_Type *type) |
std::string | map_type (AST_Expression::ExprType type) |
std::string | exporter () |
void | struct_decls (UTL_ScopedName *name, AST_Type::SIZE_TYPE size, const char *struct_or_class="struct") |
std::string | array_dims (AST_Type *type, ACE_CDR::ULong &elems) |
void | gen_typecode (UTL_ScopedName *name) |
void | gen_array (UTL_ScopedName *tdname, AST_Array *arr) |
void | gen_array_traits (UTL_ScopedName *tdname, AST_Array *arr) |
Variables | |
std::map< AST_PredefinedType::PredefinedType, std::string > | primtype_ |
std::map< Helper, std::string > | helpers_ |
enum Helper |
Definition at line 25 of file langmap_generator.cpp.
00025 { 00026 HLP_STR_VAR, HLP_STR_OUT, HLP_WSTR_VAR, HLP_WSTR_OUT, 00027 HLP_STR_MGR, HLP_WSTR_MGR, 00028 HLP_FIX_VAR, HLP_VAR_VAR, HLP_OUT, 00029 HLP_SEQ, HLP_SEQ_NS, HLP_SEQ_VAR_VAR, HLP_SEQ_FIX_VAR, HLP_SEQ_OUT, 00030 HLP_ARR_VAR_VAR, HLP_ARR_FIX_VAR, HLP_ARR_OUT, HLP_ARR_FORANY, 00031 HLP_FIXED, HLP_FIXED_CONSTANT 00032 };
std::string @86::array_dims | ( | AST_Type * | type, | |
ACE_CDR::ULong & | elems | |||
) | [static] |
Definition at line 118 of file langmap_generator.cpp.
References AstTypeClassification::resolveActualType().
Referenced by SafetyProfileGenerator::gen_struct(), and FaceGenerator::gen_struct().
00118 { 00119 AST_Array* const arr = AST_Array::narrow_from_decl(type); 00120 std::string ret; 00121 for (ACE_CDR::ULong dim = 0; dim < arr->n_dims(); ++dim) { 00122 elems *= arr->dims()[dim]->ev()->u.ulval; 00123 if (dim) ret += "[0]"; 00124 } 00125 AST_Type* base = resolveActualType(arr->base_type()); 00126 if (AST_Array::narrow_from_decl(base)) { 00127 ret += "[0]" + array_dims(base, elems); 00128 } 00129 return ret; 00130 }
std::string @86::exporter | ( | ) | [static] |
Definition at line 91 of file langmap_generator.cpp.
References be_global, and BE_GlobalData::export_macro().
Referenced by Function::Function(), gen_array(), gen_array_traits(), SafetyProfileGenerator::gen_sequence(), FaceGenerator::gen_sequence(), SafetyProfileGenerator::gen_struct(), FaceGenerator::gen_struct(), gen_typecode(), GeneratorBase::gen_union(), and face_ts_generator::generate().
00091 { 00092 return be_global->export_macro().empty() ? "" 00093 : be_global->export_macro().c_str() + std::string(" "); 00094 }
void @87::gen_array | ( | UTL_ScopedName * | tdname, | |
AST_Array * | arr | |||
) | [static] |
Definition at line 1070 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), exporter(), helpers_, HLP_ARR_FIX_VAR, HLP_ARR_FORANY, HLP_ARR_OUT, HLP_ARR_VAR_VAR, HLP_STR_MGR, HLP_WSTR_MGR, BE_GlobalData::impl_, NestedForLoops::index_, BE_GlobalData::lang_header_, map_type(), and BE_GlobalData::STREAM_LANG_H.
Referenced by marshal_generator::gen_typedef(), and langmap_generator::gen_typedef().
01071 { 01072 be_global->add_include("<tao/Array_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H); 01073 be_global->add_include("dds/DCPS/SafetyProfilePool.h", BE_GlobalData::STREAM_LANG_H); 01074 const char* const nm = tdname->last_component()->get_string(); 01075 AST_Type* elem = arr->base_type(); 01076 const Classification elem_cls = classify(elem); 01077 const Helper var = (elem->size_type() == AST_Type::VARIABLE) 01078 ? HLP_ARR_VAR_VAR : HLP_ARR_FIX_VAR, 01079 out = HLP_ARR_OUT, 01080 forany = HLP_ARR_FORANY; 01081 01082 std::ostringstream bound, nofirst, total; 01083 std::string zeros; 01084 for (ACE_CDR::ULong dim = 0; dim < arr->n_dims(); ++dim) { 01085 const ACE_CDR::ULong extent = arr->dims()[dim]->ev()->u.ulval; 01086 bound << '[' << extent << ']'; 01087 if (dim) { 01088 nofirst << '[' << extent << ']'; 01089 zeros += "[0]"; 01090 total << " * "; 01091 } 01092 total << extent; 01093 } 01094 01095 std::string elem_type = map_type(elem); 01096 if (elem_cls & CL_STRING) { 01097 elem_type = helpers_[(elem_cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR]; 01098 } 01099 01100 std::string out_type = nm; 01101 if (elem->size_type() == AST_Type::VARIABLE) { 01102 out_type = helpers_[out] + '<' + nm + ", " + nm + "_var, " + nm + 01103 "_slice, " + nm + "_tag>"; 01104 } 01105 01106 be_global->lang_header_ << 01107 "typedef " << elem_type << ' ' << nm << bound.str() << ";\n" 01108 "typedef " << elem_type << ' ' << nm << "_slice" << nofirst.str() << ";\n" 01109 "struct " << nm << "_tag {};\n" 01110 "typedef " << helpers_[var] << '<' << nm << ", " << nm << "_slice, " 01111 << nm << "_tag> " << nm << "_var;\n" 01112 "typedef " << out_type << ' ' << nm << "_out;\n" 01113 "typedef " << helpers_[forany] << '<' << nm << ", " << nm << "_slice, " 01114 << nm << "_tag> " << nm << "_forany;\n\n" << 01115 exporter() << nm << "_slice* " << nm << "_alloc();\n" << 01116 exporter() << "void " << nm << "_init_i(" << elem_type << "* begin);\n" << 01117 exporter() << "void " << nm << "_fini_i(" << elem_type << "* begin);\n" << 01118 exporter() << "void " << nm << "_free(" << nm << "_slice* slice);\n" << 01119 exporter() << nm << "_slice* " << nm << "_dup(const " << nm 01120 << "_slice* slice);\n" << 01121 exporter() << "void " << nm << "_copy(" << nm << "_slice* dst, const " 01122 << nm << "_slice* src);\n\n"; 01123 const ScopedNamespaceGuard namespaces(tdname, be_global->impl_); 01124 be_global->impl_ << 01125 nm << "_slice* " << nm << "_alloc()\n" 01126 "{\n" 01127 " void* const raw = ACE_Allocator::instance()->malloc" 01128 "(sizeof(" << nm << "));\n" 01129 " " << nm << "_slice* const slice = static_cast<" << nm << "_slice*" 01130 << ">(raw);\n" 01131 " " << nm << "_init_i(slice" << zeros << ");\n" 01132 " return slice;\n" 01133 "}\n\n" 01134 "void " << nm << "_init_i(" << elem_type << "* begin)\n" 01135 "{\n"; 01136 01137 if (elem_cls & (CL_PRIMITIVE | CL_ENUM)) { 01138 be_global->impl_ << " ACE_UNUSED_ARG(begin);\n"; 01139 } else if (elem_cls & CL_ARRAY) { 01140 std::string indent = " "; 01141 const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent); 01142 be_global->impl_ << 01143 indent << elem_type << "_init_i(begin" << nfl.index_ << ");\n"; 01144 } else { 01145 be_global->impl_ << 01146 " std::uninitialized_fill_n(begin, " << total.str() << ", " 01147 << elem_type << "());\n"; 01148 } 01149 01150 be_global->impl_ << 01151 "}\n\n" 01152 "void " << nm << "_fini_i(" << elem_type << "* begin)\n" 01153 "{\n"; 01154 01155 if (elem_cls & (CL_PRIMITIVE | CL_ENUM)) { 01156 be_global->impl_ << " ACE_UNUSED_ARG(begin);\n"; 01157 } else if (elem_cls & CL_ARRAY) { 01158 std::string indent = " "; 01159 const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent); 01160 be_global->impl_ << 01161 indent << elem_type << "_fini_i(begin" << nfl.index_ << ");\n"; 01162 } else { 01163 const std::string::size_type idx_last = elem_type.rfind("::"); 01164 const std::string elem_last = 01165 (elem_cls & CL_STRING) ? "StringManager" : 01166 ((idx_last == std::string::npos) ? elem_type 01167 : elem_type.substr(idx_last + 2)); 01168 be_global->impl_ << 01169 " for (int i = 0; i < " << total.str() << "; ++i) {\n" 01170 " begin[i]." 01171 #ifdef __SUNPRO_CC 01172 << elem_type << "::" 01173 #endif 01174 "~" << elem_last << "();\n" 01175 " }\n"; 01176 } 01177 01178 be_global->impl_ << 01179 "}\n\n" 01180 "void " << nm << "_free(" << nm << "_slice* slice)\n" 01181 "{\n" 01182 " if (!slice) return;\n" 01183 " " << nm << "_fini_i(slice" << zeros << ");\n" 01184 " ACE_Allocator::instance()->free(slice);\n" 01185 "}\n\n" << 01186 nm << "_slice* " << nm << "_dup(const " << nm << "_slice* slice)\n" 01187 "{\n" 01188 " " << nm << "_slice* const arr = " << nm << "_alloc();\n" 01189 " if (arr) " << nm << "_copy(arr, slice);\n" 01190 " return arr;\n" 01191 "}\n\n" 01192 "void " << nm << "_copy(" << nm << "_slice* dst, const " << nm 01193 << "_slice* src)\n" 01194 "{\n" 01195 " if (!src || !dst) return;\n"; 01196 01197 { 01198 std::string indent = " "; 01199 const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent); 01200 if (elem_cls & CL_ARRAY) { 01201 be_global->impl_ << 01202 indent << elem_type << "_copy(dst" << nfl.index_ << ", src" 01203 << nfl.index_ << ");\n"; 01204 } else { 01205 be_global->impl_ << 01206 indent << "dst" << nfl.index_ << " = src" << nfl.index_ << ";\n"; 01207 } 01208 } 01209 01210 be_global->impl_ << 01211 "}\n\n"; 01212 01213 01214 be_global->lang_header_ << 01215 "inline ACE_CDR::Boolean operator<<(ACE_OutputCDR &, const " << nm << "_forany&) { return true; }\n\n" 01216 "inline ACE_CDR::Boolean operator>>(ACE_InputCDR &, " << nm << "_forany&) { return true; }\n\n"; 01217 }
void @88::gen_array_traits | ( | UTL_ScopedName * | tdname, | |
AST_Array * | arr | |||
) | [static] |
Definition at line 1260 of file langmap_generator.cpp.
References be_global, exporter(), BE_GlobalData::lang_header_, and scoped().
Referenced by langmap_generator::gen_typedef().
01261 { 01262 const std::string nm = scoped(tdname); 01263 std::string zeros; 01264 for (ACE_CDR::ULong i = 1; i < arr->n_dims(); ++i) zeros += "[0]"; 01265 be_global->lang_header_ << 01266 "namespace TAO {\n" 01267 "template <>\n" 01268 "struct " << exporter() << "Array_Traits<" << nm << "_forany>\n" 01269 "{\n" 01270 " static void free(" << nm << "_slice* slice)\n" 01271 " {\n" 01272 " " << nm << "_free(slice);\n" 01273 " }\n\n" 01274 " static " << nm << "_slice* dup(const " << nm << "_slice* slice)\n" 01275 " {\n" 01276 " return " << nm << "_dup(slice);\n" 01277 " }\n\n" 01278 " static void copy(" << nm << "_slice* dst, const " << nm 01279 << "_slice* src)\n" 01280 " {\n" 01281 " " << nm << "_copy(dst, src);\n" 01282 " }\n\n" 01283 " static " << nm << "_slice* alloc()\n" 01284 " {\n" 01285 " return " << nm << "_alloc();\n" 01286 " }\n\n" 01287 " static void zero(" << nm << "_slice* slice)\n" 01288 " {\n" 01289 " " << nm << "_fini_i(slice" << zeros << ");\n" 01290 " " << nm << "_init_i(slice" << zeros << ");\n" 01291 " }\n" 01292 " static void construct(" << nm << "_slice* slice)\n" 01293 " {\n" 01294 " " << nm << "_init_i(slice" << zeros << ");\n" 01295 " }\n" 01296 " static void destroy(" << nm << "_slice* slice)\n" 01297 " {\n" 01298 " " << nm << "_fini_i(slice" << zeros << ");\n" 01299 " }\n" 01300 "};\n}\n\n"; 01301 }
void @86::gen_typecode | ( | UTL_ScopedName * | name | ) | [static] |
Definition at line 132 of file langmap_generator.cpp.
References be_global, exporter(), BE_GlobalData::impl_, BE_GlobalData::lang_header_, and BE_GlobalData::suppress_typecode().
Referenced by langmap_generator::gen_enum(), SafetyProfileGenerator::gen_struct(), FaceGenerator::gen_struct(), langmap_generator::gen_typedef(), and GeneratorBase::gen_union().
00133 { 00134 if (be_global->suppress_typecode()) { 00135 return; 00136 } 00137 const char* const nm = name->last_component()->get_string(); 00138 be_global->lang_header_ << 00139 "extern " << exporter() << "const ::CORBA::TypeCode_ptr _tc_" << nm 00140 << ";\n"; 00141 const ScopedNamespaceGuard cppNs(name, be_global->impl_); 00142 be_global->impl_ << 00143 "const ::CORBA::TypeCode_ptr _tc_" << nm << " = 0;\n"; 00144 }
std::string @86::map_type | ( | AST_Expression::ExprType | type | ) | [static] |
Definition at line 59 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), be_global, and BE_GlobalData::STREAM_LANG_H.
00060 { 00061 AST_PredefinedType::PredefinedType pt = AST_PredefinedType::PT_void; 00062 switch (type) 00063 { 00064 case AST_Expression::EV_short: pt = AST_PredefinedType::PT_short; break; 00065 case AST_Expression::EV_ushort: pt = AST_PredefinedType::PT_ushort; break; 00066 case AST_Expression::EV_long: pt = AST_PredefinedType::PT_long; break; 00067 case AST_Expression::EV_ulong: pt = AST_PredefinedType::PT_ulong; break; 00068 case AST_Expression::EV_longlong: pt = AST_PredefinedType::PT_longlong; break; 00069 case AST_Expression::EV_ulonglong: pt = AST_PredefinedType::PT_ulonglong; break; 00070 case AST_Expression::EV_float: pt = AST_PredefinedType::PT_float; break; 00071 case AST_Expression::EV_double: pt = AST_PredefinedType::PT_double; break; 00072 case AST_Expression::EV_longdouble: pt = AST_PredefinedType::PT_longdouble; break; 00073 case AST_Expression::EV_char: pt = AST_PredefinedType::PT_char; break; 00074 case AST_Expression::EV_wchar: pt = AST_PredefinedType::PT_wchar; break; 00075 case AST_Expression::EV_octet: pt = AST_PredefinedType::PT_octet; break; 00076 case AST_Expression::EV_bool: pt = AST_PredefinedType::PT_boolean; break; 00077 case AST_Expression::EV_string: pt = AST_PredefinedType::PT_char; break; 00078 case AST_Expression::EV_wstring: pt = AST_PredefinedType::PT_wchar; break; 00079 #ifdef ACE_HAS_CDR_FIXED 00080 case AST_Expression::EV_fixed: 00081 be_global->add_include("FACE/Fixed.h", BE_GlobalData::STREAM_LANG_H); 00082 return helpers_[HLP_FIXED_CONSTANT]; 00083 #endif 00084 default: break; 00085 } 00086 if (type == AST_Expression::EV_string || type == AST_Expression::EV_wstring) 00087 return primtype_[pt] + "* const"; 00088 return primtype_[pt]; 00089 }
std::string @86::map_type | ( | AST_Type * | type | ) | [static] |
Definition at line 35 of file langmap_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_INTERFACE, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), AstTypeClassification::resolveActualType(), and scoped().
Referenced by gen_array(), langmap_generator::gen_const(), SafetyProfileGenerator::gen_sequence(), FaceGenerator::gen_sequence(), SafetyProfileGenerator::gen_struct(), FaceGenerator::gen_struct(), langmap_generator::gen_typedef(), GeneratorBase::generate_union_field(), GeneratorBase::generateAssign(), GeneratorBase::generateCopyCtor(), GeneratorBase::generateReset(), and GeneratorBase::GenerateGettersAndSetters::operator()().
00036 { 00037 if (AST_Typedef::narrow_from_decl(type)) { 00038 return scoped(type->name()); 00039 } 00040 const Classification cls = classify(type); 00041 if (cls & CL_PRIMITIVE) { 00042 AST_Type* actual = resolveActualType(type); 00043 return primtype_[AST_PredefinedType::narrow_from_decl(actual)->pt()]; 00044 } 00045 if (cls & CL_STRING) { 00046 const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE) 00047 ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char; 00048 return primtype_[chartype] + '*'; 00049 } 00050 if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_ARRAY | CL_ENUM | CL_FIXED)) { 00051 return scoped(type->name()); 00052 } 00053 if (cls & CL_INTERFACE) { 00054 return scoped(type->name()) + "_var"; 00055 } 00056 return "<<unknown>>"; 00057 }
void @86::struct_decls | ( | UTL_ScopedName * | name, | |
AST_Type::SIZE_TYPE | size, | |||
const char * | struct_or_class = "struct" | |||
) | [static] |
Definition at line 96 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), be_global, HLP_FIX_VAR, HLP_OUT, HLP_VAR_VAR, BE_GlobalData::lang_header_, and BE_GlobalData::STREAM_LANG_H.
Referenced by SafetyProfileGenerator::gen_struct(), FaceGenerator::gen_struct(), langmap_generator::gen_struct_fwd(), GeneratorBase::gen_union(), and langmap_generator::gen_union_fwd().
00097 { 00098 be_global->add_include("<tao/VarOut_T.h>", BE_GlobalData::STREAM_LANG_H); 00099 const char* const nm = name->last_component()->get_string(); 00100 be_global->lang_header_ << 00101 struct_or_class << ' ' << nm << ";\n"; 00102 switch (size) { 00103 case AST_Type::SIZE_UNKNOWN: 00104 be_global->lang_header_ << "/* Unknown size */\n"; 00105 case AST_Type::FIXED: 00106 be_global->lang_header_ << 00107 "typedef " << helpers_[HLP_FIX_VAR] << '<' << nm << "> " << nm << "_var;\n" << 00108 "typedef " << nm << "& " << nm << "_out;\n"; 00109 break; 00110 case AST_Type::VARIABLE: 00111 be_global->lang_header_ << 00112 "typedef " << helpers_[HLP_VAR_VAR] << '<' << nm << "> " << nm << "_var;\n" << 00113 "typedef " << helpers_[HLP_OUT] << '<' << nm << "> " << nm << "_out;\n"; 00114 break; 00115 } 00116 }
Definition at line 33 of file langmap_generator.cpp.
Referenced by gen_array(), SafetyProfileGenerator::gen_sequence(), FaceGenerator::gen_sequence(), SafetyProfileGenerator::gen_struct(), FaceGenerator::gen_struct(), langmap_generator::gen_typedef(), SafetyProfileGenerator::init(), FaceGenerator::init(), and GeneratorBase::GenerateGettersAndSetters::operator()().
std::map<AST_PredefinedType::PredefinedType, std::string> primtype_ [static] |
Definition at line 23 of file langmap_generator.cpp.
Referenced by SafetyProfileGenerator::gen_sequence(), FaceGenerator::gen_sequence(), GeneratorBase::generate_union_field(), SafetyProfileGenerator::init(), FaceGenerator::init(), and GeneratorBase::GenerateGettersAndSetters::operator()().