diff --git a/examples/cpp/dds/IdlParserExample/IdlParser_main.cpp b/examples/cpp/dds/IdlParserExample/IdlParser_main.cpp index 0043d3a4cc0..b2b86d0d49e 100644 --- a/examples/cpp/dds/IdlParserExample/IdlParser_main.cpp +++ b/examples/cpp/dds/IdlParserExample/IdlParser_main.cpp @@ -34,164 +34,120 @@ int main( Log::SetVerbosity(Log::Kind::Info); Log::SetCategoryFilter(std::regex("IDLPARSER")); - std::cout << "Processing forward declarations:" << std::endl; - std::string test00 = - R"( - struct StructDcl; - union UnionDcl; - )"; - DynamicType::_ref_type fwd_dcl_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test00)->build(); - if (nullptr != fwd_dcl_type) - { - EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test00); - } - else - { - EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test00); - } - - std::cout << "Processing literals, expressions, and consts:" << std::endl; - std::string test01 = - R"( - // boolean literals in IDL are case sensitive and should be exactly TRUE or FALSE - const boolean C_BOOL = TRUE; - const string<100> C_STR = "hello"; - const int32 C_LITERALS1 = (0x5 | (4 + 3)) + (4 << 1) * 2; // 23 - const int32 C_LITERALS2 = (02 + 0x1) * 2; // 6 - const int32 C_LITERALS3 = 4 / ( 07 & 0x2 ); // 2 - const int32 C_LITERALS4 = -(5 * ( 03 + 0xF )); // -90 - const int32 C_LITERALS5 = 0xf0 & ~(4 * ( 0x7 - 02 )); // 224 - const int32 C_LITERALS6 = (0x7 | 0x9) & ~(6 * ( 024 - 5 )); // 5 - const float C_LITERALS7 = (2 + 4) / 3.0d; /* 2.0 */ - const float C_LITERALS8 = (2e0 + 4) / 3.0d; /* 2.0 */ - )"; - DynamicTypeBuilder::_ref_type literal_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test01); - - // std::cout << "Processing IDL string:" << std::endl; - // std::string test02 = - // R"( - // struct InnerType - // { - // uint32 im1; - // float im2; - // }; - // )"; - // idl::Context context02 = idl::parse(test02); - - // std::cout << "Processing IDL file:" << std::endl; - // idl::Context context03 = idl::parse_file("idl/test02.idl"); - - // std::string test04 = - // R"( - // enum e_test { a, b, c }; - // )"; - // idl::Context context04 = idl::parse(test04); - - // std::string test05 = - // R"( - // struct Test05 - // { - // long my_long; - // short my_short; - // long long my_llong; - // int32 my_int; - // unsigned short my_ushort; - // unsigned long my_ulong; - // long double my_ldouble; - // float my_float; - // double my_double; - // }; - // )"; - // idl::Context context05 = idl::parse(test05); - - // std::string test06 = - // R"( - // struct Point { - // float x; - // float y; - // float z; - // }; - // typedef Point PointAlias; - // typedef Point PointArrayOf10[ 10 /**/]; - // typedef PointAlias TwoDimPointArray[5][3]; - // )"; - // idl::Context context06 = idl::parse(test06); + std::cout << "Processing forward declarations:" << std::endl; + std::string test00 = + R"( + struct StructDcl; + union UnionDcl; + )"; + DynamicType::_ref_type fwd_dcl_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test00)->build(); + if (nullptr != fwd_dcl_type) + { + EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test00); + } + else + { + EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test00); + } - // std::string test07 = - // R"( - // union MyUnion switch (int32) { - // case 0: - // case 1: - // long myLong; - // case 2: - // double myDouble; - // default: - // char myChar; - // }; - // )"; - // idl::Context context07 = idl::parse(test07); + std::cout << "Processing literals, expressions, and consts:" << std::endl; + std::string test01 = + R"( + // boolean literals in IDL are case sensitive and should be exactly TRUE or FALSE + const boolean C_BOOL = TRUE; + const string<100> C_STR = "hello"; + const int32 C_LITERALS1 = (0x5 | (4 + 3)) + (4 << 1) * 2; // 23 + const int32 C_LITERALS2 = (02 + 0x1) * 2; // 6 + const int32 C_LITERALS3 = 4 / ( 07 & 0x2 ); // 2 + const int32 C_LITERALS4 = -(5 * ( 03 + 0xF )); // -90 + const int32 C_LITERALS5 = 0xf0 & ~(4 * ( 0x7 - 02 )); // 224 + const int32 C_LITERALS6 = (0x7 | 0x9) & ~(6 * ( 024 - 5 )); // 5 + const float C_LITERALS7 = (2 + 4) / 3.0d; /* 2.0 */ + const float C_LITERALS8 = (2e0 + 4) / 3.0d; /* 2.0 */ + )"; + DynamicTypeBuilder::_ref_type null_builder = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test01); - std::string idl_spec = + std::string test02 = R"( - struct InnerType + struct Test02 { - uint32 im1; - float im2; + long my_long; + short my_short; + long long my_llong; + int32 my_int; + unsigned short my_ushort; + unsigned long my_ulong; + long double my_ldouble; + float my_float; + double my_double; }; )"; - - DynamicType::_ref_type inner_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(idl_spec)->build(); - if (nullptr != inner_type) + DynamicType::_ref_type struct_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test02)->build(); + if (nullptr != struct_type) { - EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << idl_spec); + EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test02); } else { - EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << idl_spec); + EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test02); } - // idl::Context context = idl::parse(idl_spec); - // v1_3::DynamicType inner = context.module().structure("InnerType"); - - // v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance(); - // v1_3::DynamicTypeBuilder_ptr builder = factory.create_struct_type(); - // builder->set_name("OuterType"); - // builder->add_member(0, "om1", factory.get_string_type()); - // auto outer = builder->build(); - - // idl::Module root; - // idl::Module& submod_a = root.create_submodule("a"); - // idl::Module& submod_b = root.create_submodule("b"); - // idl::Module& submod_aa = submod_a.create_submodule("a"); - // submod_aa.structure(std::move(const_cast(*outer))); - // submod_b.structure(inner); - // /* - // root - // \_a - // | \_ a _ OuterType - // | - // \_ b _ InnerType - // */ - // std::cout << std::boolalpha; - // std::cout << "Does a::a::OuterType exists?: " << root.has_structure("a::a::OuterType") << std::endl; - // std::cout << "Does ::InnerType exists?: " << root.has_structure("::InnerType") << std::endl; - // std::cout << "Does InnerType exists?: " << root.has_structure("InnerType") << std::endl; - // std::cout << "Does OuterType exists?: " << root.has_structure("OuterType") << std::endl; - // std::cout << "Does ::b::InnerType exists?: " << root.has_structure("::b::InnerType") << std::endl; - // std::cout << "Does b::InnerType exists?: " << root.has_structure("b::InnerType") << std::endl; + std::string test03 = + R"( + enum e_test { a, b, c }; + )"; + DynamicType::_ref_type enum_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test03)->build(); + if (nullptr != enum_type) + { + EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test03); + } + else + { + EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test03); + } - // v1_3::DynamicData* outer_data = v1_3::DynamicDataFactory::get_instance()->create_data( - // std::make_shared(root["a"]["a"].structure("OuterType")) - // ); // ::a::a::OuterType - // v1_3::MemberId member_id = outer_data->get_member_id_by_name("om1"); - // outer_data->set_string_value("This is a string.", member_id); + std::string test04 = + R"( + struct Point { + float x; + float y; + float z; + }; + typedef Point PointAlias; + typedef Point PointArrayOf10[ 10 /**/]; + typedef PointAlias TwoDimPointArray[5][3]; + )"; + DynamicType::_ref_type alias_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test04)->build(); + if (nullptr != alias_type) + { + EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test04); + } + else + { + EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test04); + } - // std::string scope_inner_type = inner.get_name(); // b::InnerType - // v1_3::DynamicData* inner_data = v1_3::DynamicDataFactory::get_instance()->create_data( - // std::make_shared(root.structure(scope_inner_type)) - // ); - // inner_data->set_uint32_value(32u, inner_data->get_member_id_by_name("im1")); - // inner_data->set_float32_value(3.14159265f, inner_data->get_member_id_by_name("im2")); + std::string test05 = + R"( + union MyUnion switch (int32) { + case 0: + case 1: + long myLong; + case 2: + double myDouble; + default: + char myChar; + }; + )"; + DynamicType::_ref_type union_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test05)->build(); + if (nullptr != union_type) + { + EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test05); + } + else + { + EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test05); + } Log::Flush(); Log::Reset(); diff --git a/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlModule.hpp b/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlModule.hpp index 8a0a1fa5ff6..98985a0db5d 100644 --- a/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlModule.hpp +++ b/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlModule.hpp @@ -20,8 +20,6 @@ #include -// #include "IdlTypeBuilder.hpp" - namespace eprosima { namespace fastdds { namespace dds { @@ -151,17 +149,17 @@ class Module return false; } - // bool has_structure( - // const std::string& name) const - // { - // // Solve scope - // PairModuleSymbol module = resolve_scope(name); - // if (module.first == nullptr) - // { - // return false; - // } - // return module.first->structs_.count(module.second) > 0; - // } + bool has_structure( + const std::string& name) const + { + // Solve scope + PairModuleSymbol module = resolve_scope(name); + if (module.first == nullptr) + { + return false; + } + return module.first->structs_.count(module.second) > 0; + } // v1_3::DynamicType& structure( // const std::string& name) @@ -232,10 +230,10 @@ class Module // } bool structure( - DynamicTypeBuilder::_ref_type type_builder, + DynamicTypeBuilder::_ref_type builder, bool replace = false) { - std::string name(type_builder->get_name()); + std::string name(builder->get_name()); if (name.find("::") != std::string::npos) { return false; // Cannot add a symbol with scoped name. @@ -252,24 +250,24 @@ class Module std::string name_space = scope(); TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; - type_builder->get_descriptor(type_descriptor); + builder->get_descriptor(type_descriptor); type_descriptor->name(name_space + (name_space.empty() ? "" : "::") + name); - auto result = structs_.emplace(name, type_builder); + auto result = structs_.emplace(name, builder); return result.second; } - // bool has_union( - // const std::string& name) const - // { - // // Solve scope - // PairModuleSymbol module = resolve_scope(name); - // if (module.first == nullptr) - // { - // return false; - // } - // return module.first->unions_.count(module.second) > 0; - // } + bool has_union( + const std::string& name) const + { + // Solve scope + PairModuleSymbol module = resolve_scope(name); + if (module.first == nullptr) + { + return false; + } + return module.first->unions_.count(module.second) > 0; + } // const v1_3::DynamicType union_switch( // const std::string& name) const @@ -313,23 +311,23 @@ class Module // return const_cast(*it->second.get()); // } - // bool union_switch( - // v1_3::DynamicType& union_type) - // { - // if (union_type.get_name().find("::") != std::string::npos) - // { - // return false; // Cannot add a symbol with scoped name. - // } + bool union_switch( + DynamicTypeBuilder::_ref_type builder) + { + std::string name(builder->get_name()); + if (name.find("::") != std::string::npos) + { + return false; // Cannot add a symbol with scoped name. + } - // std::string name = union_type.get_name(); - // std::string name_space = scope(); - // // TODO set name of union type? - // //union_type.set_name(name_space + (name_space.empty() ? "" : "::") + name); - // auto result = unions_.emplace( - // name, - // Type(*this, union_type)); - // return result.second; - // } + std::string name_space = scope(); + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + builder->get_descriptor(type_descriptor); + type_descriptor->name(name_space + (name_space.empty() ? "" : "::") + name); + auto result = unions_.emplace(name, builder); + + return result.second; + } // bool union_switch( // v1_3::DynamicType&& union_type, @@ -393,135 +391,136 @@ class Module return result.second; } - // bool has_enum_32( - // const std::string& name) const - // { - // return enumerations_32_.count(name) > 0; - // } + bool has_enum_32( + const std::string& name) const + { + return enumerations_32_.count(name) > 0; + } - // bool enum_32( - // const std::string& name, - // v1_3::DynamicType_ptr enum_type, - // bool replace = false) - // { - // if (name.find("::") != std::string::npos) - // { - // return false; // Cannot add a symbol with scoped name. - // } + bool enum_32( + const std::string& name, + DynamicTypeBuilder::_ref_type builder, + bool replace = false) + { + if (name.find("::") != std::string::npos) + { + return false; // Cannot add a symbol with scoped name. + } - // if (replace) - // { - // auto it = enumerations_32_.find(name); - // if (it != enumerations_32_.end()) - // { - // enumerations_32_.erase(it); - // } - // } + if (replace) + { + auto it = enumerations_32_.find(name); + if (it != enumerations_32_.end()) + { + enumerations_32_.erase(it); + } + } - // std::string name_space = scope(); - // // TODO set name of enum type? - // //enum_type.set_name(name_space + (name_space.empty() ? "" : "::") + name); - // auto result = enumerations_32_.emplace( - // name, - // Type(*this, *enum_type)); - // return result.second; - // } + std::string name_space = scope(); + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + builder->get_descriptor(type_descriptor); + type_descriptor->name(name_space + (name_space.empty() ? "" : "::") + name); + auto result = enumerations_32_.emplace(name, builder); - // bool has_alias( - // const std::string& name) const - // { - // // Solve scope - // PairModuleSymbol module = resolve_scope(name); - // if (module.first == nullptr) - // { - // return false; - // } + return result.second; + } - // auto it = module.first->aliases_.find(module.second); - // return it != module.first->aliases_.end(); - // } + bool has_alias( + const std::string& name) const + { + // Solve scope + PairModuleSymbol module = resolve_scope(name); + if (module.first == nullptr) + { + return false; + } - // bool create_alias( - // const std::string& name, - // v1_3::DynamicType_ptr type) - // { - // if (name.find("::") != std::string::npos || has_alias(name)) - // { - // return false; // Cannot define alias with scoped name (or already defined). - // } + auto it = module.first->aliases_.find(module.second); + return it != module.first->aliases_.end(); + } - // std::string name_space = scope(); - // std::string alias_name = name_space + (name_space.empty() ? "" : "::") + name; - // v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance(); - // v1_3::DynamicTypeBuilder_ptr alias_builder = factory.create_alias_type(*type, alias_name); - // auto alias_type = alias_builder->build(); + bool create_alias( + const std::string& name, + DynamicTypeBuilder::_ref_type builder) + { + if (name.find("::") != std::string::npos || has_alias(name)) + { + return false; // Cannot define alias with scoped name (or already defined). + } - // auto result = aliases_.emplace(name, Type(*this, *alias_type)); - // return result.second; - // } + std::string name_space = scope(); + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + builder->get_descriptor(type_descriptor); + type_descriptor->name(name_space + (name_space.empty() ? "" : "::") + name); + auto result = aliases_.emplace(name, builder); - // // Generic type retrieval. - // v1_3::DynamicType_ptr type( - // const std::string& name, - // bool recursive = false) - // { - // v1_3::DynamicType_ptr ret_type; + return result.second; + } - // if (recursive) - // { - // for (auto& pair : inner_) - // { - // const std::string& key = pair.first; - // std::shared_ptr& mod = pair.second; - // ret_type = mod->type(name, recursive); - // } - // } + // Generic type builder retrieval + DynamicTypeBuilder::_ref_type get_builder( + const std::string& name, + bool recursive = false) + { + DynamicTypeBuilder::_ref_type builder; - // // Solve scope - // PairModuleSymbol module = resolve_scope(name); - // if (module.first == nullptr) - // { - // return ret_type; - // } + if (recursive) + { + for (auto& pair : inner_) + { + const std::string& key = pair.first; + std::shared_ptr& mod = pair.second; + builder = mod->get_builder(name, recursive); + } + } - // // Check enums - // if (module.first->has_enum_32(module.second)) - // { - // ret_type = module.first->enumerations_32_.at(module.second).get(); - // } + // Solve scope + PairModuleSymbol module = resolve_scope(name); + if (module.first == nullptr) + { + return builder; + } - // // Check structs - // if (module.first->has_structure(module.second)) - // { - // ret_type = module.first->structs_.at(module.second).get(); - // } + // Check enums + if (module.first->has_enum_32(module.second)) + { + builder = module.first->enumerations_32_.at(module.second); + } - // // Check unions - // if (module.first->has_union(module.second)) - // { - // ret_type = module.first->unions_.at(module.second).get(); - // } + // Check structs + if (module.first->has_structure(module.second)) + { + builder = module.first->structs_.at(module.second); + } - // // Check aliases - // if (module.first->has_alias(module.second)) - // { - // ret_type = module.first->aliases_.at(module.second).get(); - // } + // Check unions + if (module.first->has_union(module.second)) + { + builder = module.first->unions_.at(module.second); + } - // //if (name.find("::") == 0) - // //{ - // // // Scope ambiguity solver was originally used, add it to the retrieved DynamicType - // // ret_type->name(name); - // //} + // Check aliases + if (module.first->has_alias(module.second)) + { + builder = module.first->aliases_.at(module.second); + } - // // Check bitsets - // // TODO + if (name.find("::") == 0) + { + // Scope ambiguity solver was originally used, add it to the retrieved DynamicTypeBuilder + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + builder->get_descriptor(type_descriptor); + type_descriptor->name(name); + } - // // Check bitmasks - // // TODO + // Check bitsets + // TODO - // return ret_type; - // } + // Check bitmasks + // TODO + + return builder; + } protected: @@ -548,95 +547,95 @@ class Module // Auxiliar method to resolve scoped. It will return the Module up to the last "::" by calling // recursively resolving each scoped name, looking for the scope path, and the symbol name without the scope. // If the path cannot be resolved, it will return nullptr as path, and the full given symbol name. - // PairModuleSymbol resolve_scope( - // const std::string& symbol_name) const - // { - // return resolve_scope(symbol_name, symbol_name, true); - // } + PairModuleSymbol resolve_scope( + const std::string& symbol_name) const + { + return resolve_scope(symbol_name, symbol_name, true); + } - // PairModuleSymbol resolve_scope( - // const std::string& symbol_name, - // const std::string& original_name, - // bool first = false) const - // { - // if (!first && symbol_name == original_name) - // { - // // Loop trying to resolve the name. Abort failing. - // PairModuleSymbol pair; - // pair.first = nullptr; - // pair.second = original_name; - // return pair; - // } + PairModuleSymbol resolve_scope( + const std::string& symbol_name, + const std::string& original_name, + bool first = false) const + { + if (!first && symbol_name == original_name) + { + // Loop trying to resolve the name. Abort failing. + PairModuleSymbol pair; + pair.first = nullptr; + pair.second = original_name; + return pair; + } - // std::string name = symbol_name; - // // Solve scope - // if (symbol_name.find("::") != std::string::npos) // It is an scoped name - // { - // if (symbol_name.find("::") == 0) // Looking for root - // { - // if (outer_ == nullptr) // We are the root, now go down. - // { - // return resolve_scope(symbol_name.substr(2), original_name); - // } - // else // We are not the root, go up, with the original name. - // { - // return outer_->resolve_scope(original_name, original_name, true); - // } - // } - // else // not looking for root - // { - // std::string inner_scope = symbol_name.substr(0, symbol_name.find("::")); - // // Maybe the current scope its me? - // if (inner_scope == name_) - // { - // std::string innest_scope = inner_scope.substr(0, inner_scope.find("::")); - // if (inner_.count(innest_scope) > 0) - // { - // std::string inner_name = symbol_name.substr(symbol_name.find("::") + 2); - // const auto& it = inner_.find(innest_scope); - // PairModuleSymbol result = it->second->resolve_scope(inner_name, original_name); - // if (result.first != nullptr) - // { - // return result; - // } - // } - // } - // // Do we have a inner scope that matches? - // if (inner_.count(inner_scope) > 0) - // { - // std::string inner_name = symbol_name.substr(symbol_name.find("::") + 2); - // const auto& it = inner_.find(inner_scope); - // return it->second->resolve_scope(inner_name, original_name); - // } - // // Try going back - // if (outer_ != nullptr && first) - // { - // return outer_->resolve_scope(original_name, original_name, true); - // } - // // Unknown scope - // PairModuleSymbol pair; - // pair.first = nullptr; - // pair.second = original_name; - // return pair; - // } - // } + std::string name = symbol_name; + // Solve scope + if (symbol_name.find("::") != std::string::npos) // It is an scoped name + { + if (symbol_name.find("::") == 0) // Looking for root + { + if (outer_ == nullptr) // We are the root, now go down. + { + return resolve_scope(symbol_name.substr(2), original_name); + } + else // We are not the root, go up, with the original name. + { + return outer_->resolve_scope(original_name, original_name, true); + } + } + else // not looking for root + { + std::string inner_scope = symbol_name.substr(0, symbol_name.find("::")); + // Maybe the current scope its me? + if (inner_scope == name_) + { + std::string innest_scope = inner_scope.substr(0, inner_scope.find("::")); + if (inner_.count(innest_scope) > 0) + { + std::string inner_name = symbol_name.substr(symbol_name.find("::") + 2); + const auto& it = inner_.find(innest_scope); + PairModuleSymbol result = it->second->resolve_scope(inner_name, original_name); + if (result.first != nullptr) + { + return result; + } + } + } + // Do we have a inner scope that matches? + if (inner_.count(inner_scope) > 0) + { + std::string inner_name = symbol_name.substr(symbol_name.find("::") + 2); + const auto& it = inner_.find(inner_scope); + return it->second->resolve_scope(inner_name, original_name); + } + // Try going back + if (outer_ != nullptr && first) + { + return outer_->resolve_scope(original_name, original_name, true); + } + // Unknown scope + PairModuleSymbol pair; + pair.first = nullptr; + pair.second = original_name; + return pair; + } + } - // if (has_symbol(name, false)) - // { - // return std::make_pair(this, std::move(name)); - // } + if (has_symbol(name, false)) + { + return std::make_pair(this, std::move(name)); + } - // if (outer_ != nullptr) - // { - // return outer_->resolve_scope(symbol_name, original_name, true); - // } + if (outer_ != nullptr) + { + return outer_->resolve_scope(symbol_name, original_name, true); + } - // // Failed, not found - // PairModuleSymbol pair; - // pair.first = nullptr; - // pair.second = original_name; - // return pair; - // } + // Failed, not found + PairModuleSymbol pair; + pair.first = nullptr; + pair.second = original_name; + return pair; + } }; // class Module diff --git a/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlParser.hpp b/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlParser.hpp index 8134186e503..7db9473996d 100644 --- a/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlParser.hpp +++ b/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlParser.hpp @@ -378,7 +378,7 @@ struct action std::map& state, std::vector::ref_type>& operands) { - std::cout << "Rule: " << typeid(Rule).name() << " " << in.string() << std::endl; + // std::cout << "Rule: " << typeid(Rule).name() << " " << in.string() << std::endl; } }; @@ -981,12 +981,12 @@ struct action TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; type_descriptor->kind(TK_STRUCTURE); type_descriptor->name(struct_name); - DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + DynamicTypeBuilder::_ref_type builder {factory->create_type(type_descriptor)}; EPROSIMA_LOG_INFO(IDLPARSER, "Found forward struct declaration: " << struct_name); - module.structure(type_builder); + module.structure(builder); - ctx->builder = type_builder; + ctx->builder = builder; state.erase("struct_name"); state.erase("struct_member_types"); @@ -995,41 +995,44 @@ struct action }; -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// Module& module = ctx->module(); -// const std::string& union_name = state["union_name"]; -// if (module.has_symbol(union_name, false)) -// { -// EPROSIMA_LOG_ERROR(IDLPARSER, "Union " << union_name << " was already declared."); -// throw std::runtime_error("Union " + union_name + " was already declared."); -// } - -// v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance(); -// v1_3::DynamicTypeBuilder_cptr discriminator = factory.create_int32_type(); -// auto discriminant_type = discriminator->build(); -// v1_3::DynamicTypeBuilder_ptr builder = factory.create_union_type(*discriminant_type); -// builder->set_name(union_name); -// auto union_type = builder->build(); -// EPROSIMA_LOG_INFO(IDLPARSER, "Found forward union declaration: " << union_name); -// module.union_switch(std::move(const_cast(*union_type))); - -// state.erase("union_name"); -// state.erase("union_discriminant"); -// state.erase("union_labels"); -// state.erase("union_member_types"); -// state.erase("union_member_names"); -// } - -// }; +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + Module& module = ctx->module(); + const std::string& union_name = state["union_name"]; + if (module.has_symbol(union_name, false)) + { + EPROSIMA_LOG_ERROR(IDLPARSER, "Union " << union_name << " was already declared."); + throw std::runtime_error("Union " + union_name + " was already declared."); + } + + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_UNION); + type_descriptor->name(union_name); + type_descriptor->discriminator_type(factory->get_primitive_type(TK_INT32)); + DynamicTypeBuilder::_ref_type builder {factory->create_type(type_descriptor)}; + + EPROSIMA_LOG_INFO(IDLPARSER, "Found forward union declaration: " << union_name); + module.union_switch(builder); + + ctx->builder = builder; + + state.erase("union_name"); + state.erase("union_discriminant"); + state.erase("union_labels"); + state.erase("union_member_types"); + state.erase("union_member_names"); + } + +}; template<> struct action @@ -1056,61 +1059,67 @@ struct action }; -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// // Create empty enum states to indicate the start of parsing enum -// state["enum_name"] = ""; -// state["enum_member_names"] = ""; -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// Module& module = ctx->module(); - -// v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance(); -// v1_3::DynamicTypeBuilder_ptr builder = factory.create_enum_type(); - -// std::vector tokens = ctx->split_string(state["enum_member_names"], ';'); - -// for (int i = 0; i < tokens.size(); i++) -// { -// v1_3::DynamicTypeBuilder_cptr member_builder = factory.create_uint32_type(); -// auto member_type = member_builder->build(); -// v1_3::DynamicData_ptr data(v1_3::DynamicDataFactory::get_instance()->create_data(member_type)); - -// builder->add_member(i, tokens[i]); -// module.create_constant(tokens[i], data, false, true); // Mark it as "from_enum" -// } - -// const std::string& enum_name = state["enum_name"]; -// builder->set_name(enum_name); -// auto enum_type = builder->build(); -// EPROSIMA_LOG_INFO(IDLPARSER, "Found enum: " << enum_name); -// module.enum_32(enum_name, enum_type); - -// state.erase("enum_name"); -// state.erase("enum_member_names"); -// } - -// }; +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + // Create empty enum states to indicate the start of parsing enum + state["enum_name"] = ""; + state["enum_member_names"] = ""; + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + Module& module = ctx->module(); + const std::string& enum_name = state["enum_name"]; + + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_ENUM); + type_descriptor->name(enum_name); + DynamicTypeBuilder::_ref_type builder {factory->create_type(type_descriptor)}; + + std::vector tokens = ctx->split_string(state["enum_member_names"], ';'); + + for (size_t i = 0; i < tokens.size(); i++) + { + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(tokens[i]); + member_descriptor->type(factory->get_primitive_type(TK_UINT32)); + builder->add_member(member_descriptor); + + DynamicType::_ref_type member_type {factory->get_primitive_type(TK_UINT32)}; // TODO what about value? + DynamicData::_ref_type member_data {DynamicDataFactory::get_instance()->create_data(member_type)}; + + module.create_constant(tokens[i], member_data, false, true); // Mark it as "from_enum" + } + + EPROSIMA_LOG_INFO(IDLPARSER, "Found enum: " << enum_name); + module.enum_32(enum_name, builder); + + ctx->builder = builder; + + state.erase("enum_name"); + state.erase("enum_member_names"); + } + +}; template<> struct action @@ -1146,23 +1155,23 @@ struct action TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; type_descriptor->kind(TK_STRUCTURE); type_descriptor->name(state["struct_name"]); - DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + DynamicTypeBuilder::_ref_type builder {factory->create_type(type_descriptor)}; std::vector types = ctx->split_string(state["struct_member_types"], ';'); std::vector names = ctx->split_string(state["struct_member_names"], ';'); - for (int i = 0; i < types.size(); i++) + for (size_t i = 0; i < types.size(); i++) { MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; member_descriptor->name(names[i]); member_descriptor->type(ctx->get_type(state, types[i])); - type_builder->add_member(member_descriptor); + builder->add_member(member_descriptor); } EPROSIMA_LOG_INFO(IDLPARSER, "Found struct: " << state["struct_name"]); - module.structure(type_builder); + module.structure(builder); - ctx->builder = type_builder; + ctx->builder = builder; state.erase("struct_name"); state.erase("struct_member_types"); @@ -1171,246 +1180,264 @@ struct action }; -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// // Create empty union states to indicate the start of parsing union -// state["union_name"] = ""; -// state["union_discriminant"] = ""; -// state["union_labels"] = ""; -// state["union_member_names"] = ""; -// state["union_member_types"] = ""; -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// Module& module = ctx->module(); -// std::string label; - -// for (char c : in.string()) -// { -// if (std::isdigit(c)) { -// label += c; -// } -// } -// if (label.empty() && in.string().find("default") != std::string::npos) -// { -// if (state["union_labels"].empty() || state["union_labels"].back() == ';') -// { -// state["union_labels"] += "default"; -// } -// else -// { -// state["union_labels"] += ",default"; -// } -// } -// else -// { -// if (state["union_labels"].empty() || state["union_labels"].back() == ';') -// { -// state["union_labels"] += label; -// } -// else -// { -// state["union_labels"] += "," + label; -// } -// } - -// if (state["union_discriminant"].empty()) -// { -// state["union_discriminant"] = state["type"]; -// } -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// Module& module = ctx->module(); - -// state["union_labels"] += ";"; -// state["union_member_types"] += ";"; -// state["union_member_names"] += ";"; -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// Module& module = ctx->module(); - -// auto discriminant_type = ctx->get_type(state, state["union_discriminant"]); -// v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance(); -// v1_3::DynamicTypeBuilder_ptr builder = factory.create_union_type(*discriminant_type); - -// const std::string& union_name = state["union_name"]; -// std::vector label_groups = ctx->split_string(state["union_labels"], ';'); -// std::vector types = ctx->split_string(state["union_member_types"], ';'); -// std::vector names = ctx->split_string(state["union_member_names"], ';'); - -// std::vector> labels; -// int idx = 0; -// for (int i = 0; i < label_groups.size(); i++) -// { -// if (label_groups[i].empty()) continue; // Skip empty strings -// std::vector numbers_str = ctx->split_string(label_groups[i], ','); -// std::vector numbers; -// for (const auto& num_str : numbers_str) -// { -// if (num_str == "default") -// { -// numbers.push_back(std::numeric_limits::max()); -// idx = i; // mark the index of default label -// } -// else -// { -// numbers.push_back(std::stoi(num_str)); -// } -// } -// if (!numbers.empty()) labels.push_back(numbers); -// } - -// for (int i = 0; i < types.size(); i++) -// { -// auto member_type = ctx->get_type(state, types[i]); -// builder->add_member(v1_3::MemberId{ i }, names[i], member_type, "", labels[i], i == idx ? true : false); -// } -// builder->set_name(union_name); -// auto union_type = builder->build(); -// EPROSIMA_LOG_INFO(IDLPARSER, "Found union: " << union_name); -// module.union_switch(std::move(const_cast(*union_type))); - -// state.erase("union_name"); -// state.erase("union_discriminant"); -// state.erase("union_labels"); -// state.erase("union_member_types"); -// state.erase("union_member_names"); -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// // Create empty alias states to indicate the start of parsing alias -// state["alias"] = ""; -// state["alias_sizes"] = ""; -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// if (state.count("alias") && !state["alias"].empty()) -// { -// std::string str = in.string(); - -// // Find the opening and closing brackets -// size_t start_pos = str.find('['); -// size_t end_pos = str.find(']'); - -// // Extract the substring between the brackets and trim spaces -// std::string size = str.substr(start_pos + 1, end_pos - start_pos - 1); -// size.erase(0, size.find_first_not_of(" \t\n\r")); -// size.erase(size.find_last_not_of(" \t\n\r") + 1); - -// state["alias_sizes"] += size + ";"; -// } -// } - -// }; - -// template<> -// struct action -// { -// template -// static void apply( -// const Input& in, -// Context* ctx, -// std::map& state, -// std::vector& operands) -// { -// Module& module = ctx->module(); - -// std::string alias_name; -// std::vector sizes_str = ctx->split_string(state["alias_sizes"], ';'); - -// std::stringstream ss(state["alias"]); -// std::getline(ss, state["type"], ','); -// std::getline(ss, alias_name, ','); - -// auto alias_type = ctx->get_type(state, state["type"]); -// if (sizes_str.empty()) -// { -// module.create_alias(alias_name, alias_type); -// } -// else -// { -// std::vector sizes; -// for (const auto& size : sizes_str) -// { -// sizes.push_back(static_cast(std::stoul(size))); -// } -// v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance(); -// v1_3::DynamicTypeBuilder_ptr array_type_builder = factory.create_array_type(*alias_type, sizes); -// auto array_type = array_type_builder->build(); - -// module.create_alias(alias_name, array_type); -// } - -// state.erase("alias"); -// state.erase("alias_sizes"); -// } - -// }; +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + // Create empty union states to indicate the start of parsing union + state["union_name"] = ""; + state["union_discriminant"] = ""; + state["union_labels"] = ""; + state["union_member_names"] = ""; + state["union_member_types"] = ""; + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + Module& module = ctx->module(); + std::string label; + + for (char c : in.string()) + { + if (std::isdigit(c)) { + label += c; + } + } + if (label.empty() && in.string().find("default") != std::string::npos) + { + if (state["union_labels"].empty() || state["union_labels"].back() == ';') + { + state["union_labels"] += "default"; + } + else + { + state["union_labels"] += ",default"; + } + } + else + { + if (state["union_labels"].empty() || state["union_labels"].back() == ';') + { + state["union_labels"] += label; + } + else + { + state["union_labels"] += "," + label; + } + } + + if (state["union_discriminant"].empty()) + { + state["union_discriminant"] = state["type"]; + } + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + Module& module = ctx->module(); + + state["union_labels"] += ";"; + state["union_member_types"] += ";"; + state["union_member_names"] += ";"; + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + Module& module = ctx->module(); + const std::string& union_name = state["union_name"]; + + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + DynamicType::_ref_type discriminant_type = ctx->get_type(state, state["union_discriminant"]); + type_descriptor->kind(TK_UNION); + type_descriptor->name(union_name); + type_descriptor->discriminator_type(discriminant_type); + DynamicTypeBuilder::_ref_type builder {factory->create_type(type_descriptor)}; + + std::vector label_groups = ctx->split_string(state["union_labels"], ';'); + std::vector types = ctx->split_string(state["union_member_types"], ';'); + std::vector names = ctx->split_string(state["union_member_names"], ';'); + + std::vector> labels; + int default_label_index = 0; + for (size_t i = 0; i < label_groups.size(); i++) + { + if (label_groups[i].empty()) continue; // Skip empty strings + std::vector numbers_str = ctx->split_string(label_groups[i], ','); + std::vector numbers; + for (const auto& num_str : numbers_str) + { + if (num_str == "default") + { + numbers.push_back(std::numeric_limits::max()); + default_label_index = i; // mark the index of default label + } + else + { + numbers.push_back(std::stoi(num_str)); + } + } + if (!numbers.empty()) labels.push_back(numbers); + } + + for (size_t i = 0; i < types.size(); i++) + { + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(names[i]); + member_descriptor->type(ctx->get_type(state, types[i])); + member_descriptor->id(i); + member_descriptor->label(labels[i]); + member_descriptor->is_default_label(i == default_label_index); + builder->add_member(member_descriptor); + } + + EPROSIMA_LOG_INFO(IDLPARSER, "Found union: " << union_name); + module.union_switch(builder); + + ctx->builder = builder; + + state.erase("union_name"); + state.erase("union_discriminant"); + state.erase("union_labels"); + state.erase("union_member_types"); + state.erase("union_member_names"); + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + // Create empty alias states to indicate the start of parsing alias + state["alias"] = ""; + state["alias_sizes"] = ""; + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + if (state.count("alias") && !state["alias"].empty()) + { + std::string str = in.string(); + + // Find the opening and closing brackets + size_t start_pos = str.find('['); + size_t end_pos = str.find(']'); + + // Extract the substring between the brackets and trim spaces + std::string size = str.substr(start_pos + 1, end_pos - start_pos - 1); + size.erase(0, size.find_first_not_of(" \t\n\r")); + size.erase(size.find_last_not_of(" \t\n\r") + 1); + + state["alias_sizes"] += size + ";"; + } + } + +}; + +template<> +struct action +{ + template + static void apply( + const Input& in, + Context* ctx, + std::map& state, + std::vector::ref_type>& operands) + { + Module& module = ctx->module(); + + std::string alias_name; + std::vector sizes_str = ctx->split_string(state["alias_sizes"], ';'); + + std::stringstream ss(state["alias"]); + std::getline(ss, state["type"], ','); + std::getline(ss, alias_name, ','); + + DynamicType::_ref_type alias_type = ctx->get_type(state, state["type"]); + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + if (sizes_str.empty()) + { + type_descriptor->kind(TK_ALIAS); + type_descriptor->name(alias_name); + } + else + { + std::vector sizes; + for (const auto& size : sizes_str) + { + sizes.push_back(static_cast(std::stoul(size))); + } + type_descriptor->kind(TK_ARRAY); + type_descriptor->element_type(alias_type); + type_descriptor->bound(sizes); + } + + DynamicTypeBuilder::_ref_type builder {factory->create_type(type_descriptor)}; + + EPROSIMA_LOG_INFO(IDLPARSER, "Found alias: " << alias_name); + module.create_alias(alias_name, builder); + + ctx->builder = builder; + + state.erase("alias"); + state.erase("alias_sizes"); + } + +}; class Parser : public std::enable_shared_from_this @@ -1569,98 +1596,101 @@ class Parser { DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; DynamicTypeBuilder::_ref_type builder; - traits::ref_type dtype; + DynamicType::_ref_type xtype; if (type == "boolean") { - dtype = factory->get_primitive_type(TK_BOOLEAN); + xtype = factory->get_primitive_type(TK_BOOLEAN); } else if (type == "int8") { - dtype = factory->get_primitive_type(TK_INT8); + xtype = factory->get_primitive_type(TK_INT8); } else if (type == "uint8") { - dtype = factory->get_primitive_type(TK_UINT8); + xtype = factory->get_primitive_type(TK_UINT8); } else if (type == "int16") { - dtype = factory->get_primitive_type(TK_INT16); + xtype = factory->get_primitive_type(TK_INT16); } else if (type == "uint16") { - dtype = factory->get_primitive_type(TK_UINT16); + xtype = factory->get_primitive_type(TK_UINT16); } else if (type == "int32") { - dtype = factory->get_primitive_type(TK_INT32); + xtype = factory->get_primitive_type(TK_INT32); } else if (type == "uint32") { - dtype = factory->get_primitive_type(TK_UINT32); + xtype = factory->get_primitive_type(TK_UINT32); } else if (type == "int64") { - dtype = factory->get_primitive_type(TK_INT64); + xtype = factory->get_primitive_type(TK_INT64); } else if (type == "uint64") { - dtype = factory->get_primitive_type(TK_UINT64); + xtype = factory->get_primitive_type(TK_UINT64); } else if (type == "float") { - dtype = factory->get_primitive_type(TK_FLOAT32); + xtype = factory->get_primitive_type(TK_FLOAT32); } else if (type == "double") { - dtype = factory->get_primitive_type(TK_FLOAT64); + xtype = factory->get_primitive_type(TK_FLOAT64); } else if (type == "long double") { - dtype = factory->get_primitive_type(TK_FLOAT128); + xtype = factory->get_primitive_type(TK_FLOAT128); + } + else if (type == "char") + { + xtype = factory->get_primitive_type(TK_CHAR8); + } + else if (type == "wchar" || type == "char16") + { + xtype = factory->get_primitive_type(TK_CHAR16); } - // else if (type == "char") - // { - // builder = factory.create_char8_type(); - // dtype = builder->build(); - // } - // else if (type == "wchar" || type == "char16") - // { - // builder = factory.create_char16_type(); - // dtype = builder->build(); - // } - // else if (type == "string") - // { - // if (state.count("string_size")) - // { - // builder = factory.create_string_type(std::atoi(state["string_size"].c_str())); - // state.erase("string_size"); - // } - // else - // { - // builder = factory.create_string_type(); - // } - // dtype = builder->build(); - // } - // else if (type == "wstring") - // { - // if (state.count("wstring_size")) - // { - // builder = factory.create_wstring_type(std::atoi(state["wstring_size"].c_str())); - // state.erase("wstring_size"); - // } - // else - // { - // builder = factory.create_wstring_type(); - // } - // dtype = builder->build(); - // } - // else - // { - // dtype = context_->module().type(type); - // } - - return dtype; + else if (type == "string") + { + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRING8); + type_descriptor->element_type(factory->get_primitive_type(TK_CHAR8)); + + if (state.count("string_size")) + { + uint32_t size = std::atoi(state["string_size"].c_str()); + type_descriptor->bound({size}); + state.erase("string_size"); + } + builder = factory->create_type(type_descriptor); + xtype = builder->build(); + } + else if (type == "wstring") + { + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRING16); + type_descriptor->element_type(factory->get_primitive_type(TK_CHAR16)); + + if (state.count("wstring_size")) + { + uint32_t size = std::atoi(state["wstring_size"].c_str()); + type_descriptor->bound({size}); + state.erase("wstring_size"); + } + builder = factory->create_type(type_descriptor); + xtype = builder->build(); + } + else + { + builder = context_->module().get_builder(type); + xtype = builder->build(); + } + + return xtype; } }; // class Parser diff --git a/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlTypeBuilder.hpp b/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlTypeBuilder.hpp deleted file mode 100644 index 11072640122..00000000000 --- a/src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlTypeBuilder.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef FASTDDS_XTYPES_DYNAMIC_TYPES_IDL_PARSER_IDLTYPE_HPP -#define FASTDDS_XTYPES_DYNAMIC_TYPES_IDL_PARSER_IDLTYPE_HPP - -#include - -namespace eprosima { -namespace fastdds { -namespace dds { -namespace idlparser { - -class Module; - -class Type -{ -public: - - Type( - Module& parent, - const v1_3::DynamicType& type) - : type_(std::make_shared(type)) - , parent_(parent) - { - } - - Type( - Module& parent, - v1_3::DynamicType&& type) - : type_(std::make_shared(type)) - , parent_(parent) - { - } - - Type( - Type&& type) = default; - - Module& parent() const - { - return parent_; - } - - v1_3::DynamicType_ptr& get() - { - return type_; - } - - const v1_3::DynamicType_ptr& get() const - { - return type_; - } - - const v1_3::DynamicType& operator * () const - { - return *type_; - } - - const v1_3::DynamicType* operator -> () const - { - return type_.get(); - } - -private: - - Type( - const Type& type) = delete; - - DynamicTypeBuilder::_ref_type type_; - - Module& parent_; - -}; // class Type - -} // namespace idlparser -} // namespace dds -} // namespace fastdds -} // namespace eprosima - -#endif // FASTDDS_XTYPES_DYNAMIC_TYPES_IDL_PARSER_IDLTYPE_HPP