Skip to content

Commit

Permalink
Adapt literals and expressions parsing to new xtype APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Yangbo Long <yangbo.long.mav@gmail.com>
  • Loading branch information
YangboLong committed Jun 23, 2024
1 parent 67c8b91 commit 0e89724
Show file tree
Hide file tree
Showing 3 changed files with 519 additions and 531 deletions.
32 changes: 16 additions & 16 deletions examples/cpp/dds/IdlParserExample/IdlParser_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ int main(
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 */
// )";
// idl::Context context01 = idl::parse(test01);
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 =
Expand Down
60 changes: 27 additions & 33 deletions src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,39 +365,33 @@ class Module
// return std::find(from_enum_.begin(), from_enum_.end(), name) != from_enum_.end();
// }

// bool create_constant(
// const std::string& name,
// v1_3::DynamicData_ptr value,
// bool replace = false,
// bool from_enumeration = false)
// {
// if (name.find("::") != std::string::npos)
// {
// return false; // Cannot add a symbol with scoped name.
// }
bool create_constant(
const std::string& name,
DynamicData::_ref_type xdata,
bool replace = false,
bool from_enumeration = false)
{
if (name.find("::") != std::string::npos)
{
return false; // Cannot add a symbol with scoped name.
}

// if (replace)
// {
// auto it = constants_.find(name);
// if (it != constants_.end())
// {
// constants_.erase(it);
// constants_types_.erase(constants_types_.find(name));
// }
// }
if (replace)
{
auto it = constants_.find(name);
if (it != constants_.end())
{
constants_.erase(it);
}
}

// auto inserted = constants_types_.emplace(name, Type(*this, *value->get_type()));
// if (inserted.second)
// {
// auto result = constants_.emplace(name, value);
// if (result.second && from_enumeration)
// {
// from_enum_.push_back(name);
// }
// return result.second;
// }
// return false;
// }
auto result = constants_.emplace(name, xdata);
if (result.second && from_enumeration)
{
from_enum_.push_back(name);
}
return result.second;
}

// bool has_enum_32(
// const std::string& name) const
Expand Down Expand Up @@ -533,8 +527,8 @@ class Module

std::map<std::string, DynamicTypeBuilder::_ref_type> aliases_;
// std::map<std::string, Type> constants_types_;
// std::map<std::string, v1_3::DynamicData_ptr> constants_;
// std::vector<std::string> from_enum_;
std::map<std::string, DynamicData::_ref_type> constants_;
std::vector<std::string> from_enum_;
std::map<std::string, DynamicTypeBuilder::_ref_type> enumerations_32_;
std::map<std::string, DynamicTypeBuilder::_ref_type> structs_;
std::map<std::string, DynamicTypeBuilder::_ref_type> unions_;
Expand Down
Loading

0 comments on commit 0e89724

Please sign in to comment.