Public Member Functions | |
virtual void | init () |
virtual void | gen_sequence (UTL_ScopedName *tdname, AST_Sequence *seq) |
bool | gen_struct (AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *) |
Static Public Attributes | |
static SafetyProfileGenerator | instance |
Definition at line 801 of file langmap_generator.cpp.
virtual void SafetyProfileGenerator::gen_sequence | ( | UTL_ScopedName * | tdname, | |
AST_Sequence * | seq | |||
) | [inline, virtual] |
Implements GeneratorBase.
Definition at line 841 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), exporter(), helpers_, HLP_SEQ, HLP_SEQ_FIX_VAR, HLP_SEQ_NS, HLP_SEQ_OUT, HLP_SEQ_VAR_VAR, BE_GlobalData::lang_header_, map_type(), primtype_, and BE_GlobalData::STREAM_LANG_H.
00842 { 00843 be_global->add_include("<tao/Seq_Out_T.h>", BE_GlobalData::STREAM_LANG_H); 00844 be_global->add_include("dds/DCPS/SafetyProfileSequence.h", BE_GlobalData::STREAM_LANG_H); 00845 be_global->add_include("dds/DCPS/SafetyProfileSequenceVar.h", BE_GlobalData::STREAM_LANG_H); 00846 const char* const nm = tdname->last_component()->get_string(); 00847 AST_Type* elem = seq->base_type(); 00848 const Classification elem_cls = classify(elem); 00849 const bool bounded = !seq->unbounded(); 00850 const Helper var = (elem->size_type() == AST_Type::VARIABLE) 00851 ? HLP_SEQ_VAR_VAR : HLP_SEQ_FIX_VAR, 00852 out = HLP_SEQ_OUT; 00853 00854 std::string elem_type = map_type(elem), extra_tmp_args; 00855 if (elem_cls & CL_STRING) { 00856 const AST_Expression::ExprType char_type = (elem_cls & CL_WIDE) 00857 ? AST_Expression::EV_wchar : AST_Expression::EV_char; 00858 extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::StringEltPolicy< " 00859 + map_type(char_type) + ">"; 00860 } else if (elem_cls & CL_ARRAY) { 00861 extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::ArrayEltPolicy<" 00862 + elem_type + "_forany>"; 00863 } else if (elem->size_type() == AST_Type::VARIABLE) { 00864 extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::VariEltPolicy<" 00865 + elem_type + ">"; 00866 } 00867 00868 std::string bound = helpers_[HLP_SEQ_NS] + "::Unbounded"; 00869 if (bounded) { 00870 std::ostringstream oss; 00871 oss << helpers_[HLP_SEQ_NS] << "::Bounded<" 00872 << seq->max_size()->ev()->u.ulval << '>'; 00873 bound = oss.str(); 00874 } 00875 00876 const std::string base = helpers_[HLP_SEQ] + "< " + elem_type + ", " + bound 00877 + extra_tmp_args + " >", 00878 len_type = primtype_[AST_PredefinedType::PT_ulong], 00879 flag_type = primtype_[AST_PredefinedType::PT_boolean]; 00880 00881 be_global->lang_header_ << 00882 "class " << nm << ";\n" 00883 "typedef " << helpers_[var] << '<' << nm << "> " << nm << "_var;\n" 00884 "typedef " << helpers_[out] << '<' << nm << "> " << nm << "_out;\n\n" 00885 "class " << exporter() << nm << " : public " << base << " {\n" 00886 "public:\n" 00887 " typedef " << nm << "_var _var_type;\n" 00888 " typedef " << nm << "_out _out_type;\n\n" 00889 " " << nm << "() {}\n" 00890 " " << nm << "(const " << nm << "& seq) : " << base << "(seq) {}\n" 00891 " friend void swap(" << nm << "& a, " << nm << "& b) { a.swap(b); }\n" 00892 " " << nm << "& operator=(const " << nm << "& rhs)\n" 00893 " {\n" 00894 " " << nm << " tmp(rhs);\n" 00895 " swap(tmp);\n" 00896 " return *this;\n" 00897 " }\n"; 00898 00899 if (bounded) { 00900 be_global->lang_header_ << 00901 " " << nm << "(" << len_type << " length, " << elem_type << "* data, " 00902 << flag_type << " release = false)\n" 00903 " : " << base << "(0u, length, data, release) {}\n"; 00904 } else { 00905 be_global->lang_header_ << 00906 " " << nm << "(" << len_type << " maximum)\n" 00907 " : " << base << "(maximum, 0u, 0, true) {}\n" 00908 " " << nm << "(" << len_type << " maximum, " << len_type << " length, " 00909 << elem_type << "* data, " << flag_type << " release = false)\n" 00910 " : " << base << "(maximum, length, data, release) {}\n"; 00911 } 00912 be_global->lang_header_ << 00913 "};\n\n"; 00914 00915 be_global->lang_header_ << 00916 "inline ACE_CDR::Boolean operator<< (ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n"; 00917 00918 be_global->lang_header_ << 00919 "inline ACE_CDR::Boolean operator>> (ACE_InputCDR&, " << nm << "&) { return true; }\n\n"; 00920 }
bool SafetyProfileGenerator::gen_struct | ( | AST_Structure * | , | |
UTL_ScopedName * | name, | |||
const std::vector< AST_Field * > & | fields, | |||
AST_Type::SIZE_TYPE | size, | |||
const char * | ||||
) | [inline, virtual] |
Implements GeneratorBase.
Definition at line 922 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), array_dims(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), exporter(), gen_typecode(), helpers_, HLP_STR_MGR, HLP_WSTR_MGR, BE_GlobalData::impl_, NestedForLoops::index_, BE_GlobalData::lang_header_, map_type(), AstTypeClassification::resolveActualType(), BE_GlobalData::STREAM_CPP, BE_GlobalData::STREAM_LANG_H, and struct_decls().
00926 { 00927 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 00928 const char* const nm = name->last_component()->get_string(); 00929 struct_decls(name, size); 00930 be_global->lang_header_ << 00931 "\n" 00932 "struct " << exporter() << nm << " \n" 00933 "{\n" 00934 " typedef " << nm << "_var _var_type;\n" 00935 " typedef " << nm << "_out _out_type;\n\n"; 00936 00937 for (size_t i = 0; i < fields.size(); ++i) { 00938 AST_Type* field_type = fields[i]->field_type(); 00939 const std::string field_name = fields[i]->local_name()->get_string(); 00940 std::string type_name = map_type(field_type); 00941 const Classification cls = classify(field_type); 00942 if (cls & CL_STRING) { 00943 type_name = helpers_[(cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR]; 00944 } 00945 be_global->lang_header_ << 00946 " " << type_name << ' ' << field_name << ";\n"; 00947 } 00948 00949 be_global->lang_header_ << "\n" 00950 " bool operator==(const " << nm << "& rhs) const;\n" 00951 " bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n" 00952 " OPENDDS_POOL_ALLOCATION_HOOKS\n" 00953 "};\n\n"; 00954 00955 be_global->add_include("dds/DCPS/PoolAllocationBase.h"); 00956 be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H); 00957 00958 if (size == AST_Type::VARIABLE) { 00959 be_global->lang_header_ << 00960 exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n"; 00961 } 00962 00963 be_global->lang_header_ << 00964 exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n"; 00965 be_global->lang_header_ << 00966 exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n"; 00967 00968 { 00969 const ScopedNamespaceGuard guard(name, be_global->impl_); 00970 be_global->impl_ << 00971 "bool " << nm << "::operator==(const " << nm << "& rhs) const\n" 00972 "{\n"; 00973 for (size_t i = 0; i < fields.size(); ++i) { 00974 const std::string field_name = fields[i]->local_name()->get_string(); 00975 AST_Type* field_type = resolveActualType(fields[i]->field_type()); 00976 const Classification cls = classify(field_type); 00977 if (cls & CL_ARRAY) { 00978 std::string indent(" "); 00979 NestedForLoops nfl("int", "i", 00980 AST_Array::narrow_from_decl(field_type), indent, true); 00981 be_global->impl_ << 00982 indent << "if (" << field_name << nfl.index_ << " != rhs." 00983 << field_name << nfl.index_ << ") {\n" << 00984 indent << " return false;\n" << 00985 indent << "}\n"; 00986 } else { 00987 be_global->impl_ << 00988 " if (" << field_name << " != rhs." << field_name << ") {\n" 00989 " return false;\n" 00990 " }\n"; 00991 } 00992 } 00993 be_global->impl_ << " return true;\n}\n\n"; 00994 00995 if (size == AST_Type::VARIABLE) { 00996 be_global->impl_ << 00997 "void swap(" << nm << "& lhs, " << nm << "& rhs)\n" 00998 "{\n" 00999 " using std::swap;\n"; 01000 for (size_t i = 0; i < fields.size(); ++i) { 01001 const std::string fn = fields[i]->local_name()->get_string(); 01002 AST_Type* field_type = resolveActualType(fields[i]->field_type()); 01003 const Classification cls = classify(field_type); 01004 if (cls & CL_ARRAY) { 01005 ACE_CDR::ULong elems = 1; 01006 const std::string flat_fn = fn + array_dims(field_type, elems); 01007 be_global->add_include("<algorithm>", BE_GlobalData::STREAM_CPP); 01008 be_global->impl_ << 01009 " std::swap_ranges(lhs." << flat_fn << ", lhs." << flat_fn 01010 << " + " << elems << ", rhs." << flat_fn << ");\n"; 01011 } else { 01012 be_global->impl_ << 01013 " swap(lhs." << fn << ", rhs." << fn << ");\n"; 01014 } 01015 } 01016 be_global->impl_ << "}\n\n"; 01017 } 01018 01019 be_global->impl_ << 01020 "ACE_CDR::Boolean operator<< (ACE_OutputCDR &, const " << nm << "&) { return true; }\n\n"; 01021 be_global->impl_ << 01022 "ACE_CDR::Boolean operator>> (ACE_InputCDR &, " << nm << "&) { return true; }\n\n"; 01023 } 01024 01025 gen_typecode(name); 01026 return true; 01027 }
virtual void SafetyProfileGenerator::init | ( | ) | [inline, virtual] |
Implements GeneratorBase.
Definition at line 804 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), be_global, helpers_, HLP_ARR_FIX_VAR, HLP_ARR_FORANY, HLP_ARR_OUT, HLP_ARR_VAR_VAR, HLP_FIX_VAR, HLP_OUT, HLP_SEQ, HLP_SEQ_FIX_VAR, HLP_SEQ_NS, HLP_SEQ_OUT, HLP_SEQ_VAR_VAR, HLP_STR_MGR, HLP_STR_OUT, HLP_STR_VAR, HLP_VAR_VAR, HLP_WSTR_MGR, HLP_WSTR_OUT, HLP_WSTR_VAR, primtype_, and BE_GlobalData::STREAM_LANG_H.
00805 { 00806 be_global->add_include("tao/String_Manager_T.h", BE_GlobalData::STREAM_LANG_H); 00807 be_global->add_include("tao/CORBA_String.h", BE_GlobalData::STREAM_LANG_H); 00808 primtype_[AST_PredefinedType::PT_long] = "CORBA::Long"; 00809 primtype_[AST_PredefinedType::PT_ulong] = "CORBA::ULong"; 00810 primtype_[AST_PredefinedType::PT_longlong] = "CORBA::LongLong"; 00811 primtype_[AST_PredefinedType::PT_ulonglong] = "CORBA::UnsignedLongLong"; 00812 primtype_[AST_PredefinedType::PT_short] = "CORBA::Short"; 00813 primtype_[AST_PredefinedType::PT_ushort] = "CORBA::UShort"; 00814 primtype_[AST_PredefinedType::PT_float] = "CORBA::Float"; 00815 primtype_[AST_PredefinedType::PT_double] = "CORBA::Double"; 00816 primtype_[AST_PredefinedType::PT_longdouble] = "CORBA::LongDouble"; 00817 primtype_[AST_PredefinedType::PT_char] = "CORBA::Char"; 00818 primtype_[AST_PredefinedType::PT_wchar] = "CORBA::WChar"; 00819 primtype_[AST_PredefinedType::PT_boolean] = "CORBA::Boolean"; 00820 primtype_[AST_PredefinedType::PT_octet] = "CORBA::Octet"; 00821 helpers_[HLP_STR_VAR] = "CORBA::String_var"; 00822 helpers_[HLP_STR_OUT] = "CORBA::String_out"; 00823 helpers_[HLP_WSTR_VAR] = "CORBA::WString_var"; 00824 helpers_[HLP_WSTR_OUT] = "CORBA::WString_out"; 00825 helpers_[HLP_STR_MGR] = "::TAO::String_Manager"; 00826 helpers_[HLP_WSTR_MGR] = "CORBA::WString_mgr"; 00827 helpers_[HLP_FIX_VAR] = "::TAO_Fixed_Var_T"; 00828 helpers_[HLP_VAR_VAR] = "::TAO_Var_Var_T"; 00829 helpers_[HLP_OUT] = "::TAO_Out_T"; 00830 helpers_[HLP_SEQ] = "::OpenDDS::SafetyProfile::Sequence"; 00831 helpers_[HLP_SEQ_NS] = "::OpenDDS::SafetyProfile"; 00832 helpers_[HLP_SEQ_VAR_VAR] = "::OpenDDS::SafetyProfile::SequenceVar"; 00833 helpers_[HLP_SEQ_FIX_VAR] = "::OpenDDS::SafetyProfile::SequenceVar"; 00834 helpers_[HLP_SEQ_OUT] = "::TAO_Seq_Out_T"; 00835 helpers_[HLP_ARR_VAR_VAR] = "::TAO_VarArray_Var_T"; 00836 helpers_[HLP_ARR_FIX_VAR] = "::TAO_FixedArray_Var_T"; 00837 helpers_[HLP_ARR_OUT] = "::TAO_Array_Out_T"; 00838 helpers_[HLP_ARR_FORANY] = "::TAO_Array_Forany_T"; 00839 }