Skip to content

Commit 147a65c

Browse files
committed
Adapt literals and expressions parsing to new xtype APIs
Signed-off-by: Yangbo Long <[email protected]>
1 parent d143e73 commit 147a65c

File tree

3 files changed

+519
-531
lines changed

3 files changed

+519
-531
lines changed

examples/cpp/dds/IdlParserExample/IdlParser_main.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ int main(
5050
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test00);
5151
}
5252

53-
// std::cout << "Processing literals, expressions, and consts:" << std::endl;
54-
// std::string test01 =
55-
// R"(
56-
// // boolean literals in IDL are case sensitive and should be exactly TRUE or FALSE
57-
// const boolean C_BOOL = TRUE;
58-
// const string<100> C_STR = "hello";
59-
// const int32 C_LITERALS1 = (0x5 | (4 + 3)) + (4 << 1) * 2; // 23
60-
// const int32 C_LITERALS2 = (02 + 0x1) * 2; // 6
61-
// const int32 C_LITERALS3 = 4 / ( 07 & 0x2 ); // 2
62-
// const int32 C_LITERALS4 = -(5 * ( 03 + 0xF )); // -90
63-
// const int32 C_LITERALS5 = 0xf0 & ~(4 * ( 0x7 - 02 )); // 224
64-
// const int32 C_LITERALS6 = (0x7 | 0x9) & ~(6 * ( 024 - 5 )); // 5
65-
// const float C_LITERALS7 = (2 + 4) / 3.0d; /* 2.0 */
66-
// const float C_LITERALS8 = (2e0 + 4) / 3.0d; /* 2.0 */
67-
// )";
68-
// idl::Context context01 = idl::parse(test01);
53+
std::cout << "Processing literals, expressions, and consts:" << std::endl;
54+
std::string test01 =
55+
R"(
56+
// boolean literals in IDL are case sensitive and should be exactly TRUE or FALSE
57+
const boolean C_BOOL = TRUE;
58+
const string<100> C_STR = "hello";
59+
const int32 C_LITERALS1 = (0x5 | (4 + 3)) + (4 << 1) * 2; // 23
60+
const int32 C_LITERALS2 = (02 + 0x1) * 2; // 6
61+
const int32 C_LITERALS3 = 4 / ( 07 & 0x2 ); // 2
62+
const int32 C_LITERALS4 = -(5 * ( 03 + 0xF )); // -90
63+
const int32 C_LITERALS5 = 0xf0 & ~(4 * ( 0x7 - 02 )); // 224
64+
const int32 C_LITERALS6 = (0x7 | 0x9) & ~(6 * ( 024 - 5 )); // 5
65+
const float C_LITERALS7 = (2 + 4) / 3.0d; /* 2.0 */
66+
const float C_LITERALS8 = (2e0 + 4) / 3.0d; /* 2.0 */
67+
)";
68+
DynamicTypeBuilder::_ref_type literal_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test01);
6969

7070
// std::cout << "Processing IDL string:" << std::endl;
7171
// std::string test02 =

src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlModule.hpp

+27-33
Original file line numberDiff line numberDiff line change
@@ -365,39 +365,33 @@ class Module
365365
// return std::find(from_enum_.begin(), from_enum_.end(), name) != from_enum_.end();
366366
// }
367367

368-
// bool create_constant(
369-
// const std::string& name,
370-
// v1_3::DynamicData_ptr value,
371-
// bool replace = false,
372-
// bool from_enumeration = false)
373-
// {
374-
// if (name.find("::") != std::string::npos)
375-
// {
376-
// return false; // Cannot add a symbol with scoped name.
377-
// }
368+
bool create_constant(
369+
const std::string& name,
370+
DynamicData::_ref_type xdata,
371+
bool replace = false,
372+
bool from_enumeration = false)
373+
{
374+
if (name.find("::") != std::string::npos)
375+
{
376+
return false; // Cannot add a symbol with scoped name.
377+
}
378378

379-
// if (replace)
380-
// {
381-
// auto it = constants_.find(name);
382-
// if (it != constants_.end())
383-
// {
384-
// constants_.erase(it);
385-
// constants_types_.erase(constants_types_.find(name));
386-
// }
387-
// }
379+
if (replace)
380+
{
381+
auto it = constants_.find(name);
382+
if (it != constants_.end())
383+
{
384+
constants_.erase(it);
385+
}
386+
}
388387

389-
// auto inserted = constants_types_.emplace(name, Type(*this, *value->get_type()));
390-
// if (inserted.second)
391-
// {
392-
// auto result = constants_.emplace(name, value);
393-
// if (result.second && from_enumeration)
394-
// {
395-
// from_enum_.push_back(name);
396-
// }
397-
// return result.second;
398-
// }
399-
// return false;
400-
// }
388+
auto result = constants_.emplace(name, xdata);
389+
if (result.second && from_enumeration)
390+
{
391+
from_enum_.push_back(name);
392+
}
393+
return result.second;
394+
}
401395

402396
// bool has_enum_32(
403397
// const std::string& name) const
@@ -533,8 +527,8 @@ class Module
533527

534528
std::map<std::string, DynamicTypeBuilder::_ref_type> aliases_;
535529
// std::map<std::string, Type> constants_types_;
536-
// std::map<std::string, v1_3::DynamicData_ptr> constants_;
537-
// std::vector<std::string> from_enum_;
530+
std::map<std::string, DynamicData::_ref_type> constants_;
531+
std::vector<std::string> from_enum_;
538532
std::map<std::string, DynamicTypeBuilder::_ref_type> enumerations_32_;
539533
std::map<std::string, DynamicTypeBuilder::_ref_type> structs_;
540534
std::map<std::string, DynamicTypeBuilder::_ref_type> unions_;

0 commit comments

Comments
 (0)