Skip to content

Commit 6c8f882

Browse files
committed
Refs #23128: Fix enum members annotated using keyword notation
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
1 parent 73d1ff2 commit 6c8f882

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ struct const_dcl : seq<kw_const, const_type, opt<ws>, identifier, equal_op, cons
329329
struct annotation_appl_param : seq<identifier, equal_op, const_expr> {};
330330
struct annotation_appl_params : sor<seq<annotation_appl_param, star<seq<comma, annotation_appl_param>>>, const_expr> {};
331331
struct annotation_begin : TAO_PEGTL_STRING("@"){};
332-
struct annotation_appl : seq<annotation_begin, scoped_name, opt<open_parentheses, annotation_appl_params, close_parentheses>> {};
332+
struct annotation_param_context_begin: open_parentheses {};
333+
struct annotation_param_context_end: close_parentheses {};
334+
struct annotation_appl : seq<annotation_begin, scoped_name, opt<annotation_param_context_begin, annotation_appl_params, annotation_param_context_end>> {};
333335
struct any_const_type : kw_any {};
334336
struct annotation_member_type : sor<const_type, any_const_type, scoped_name> {};
335337
struct annotation_member : seq<opt<ws>, annotation_member_type, opt<ws>, simple_declarator, opt<seq<kw_default, const_expr>>, semicolon> {};

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,27 @@ struct action<identifier>
362362
}
363363
else
364364
{
365-
state["enum_member_names"] += scoped_identifier_name + ";";
366-
367-
if (state.count("annotation_names") && !state["annotation_names"].empty())
365+
if (state.count("parsing_annotation") && state["parsing_annotation"] == "true")
366+
{
367+
// identifier is an annotation's name, and handled in action<scoped_name>. Do nothing
368+
return;
369+
}
370+
if (state.count("parsing_annotation_params") && state["parsing_annotation_params"] == "true")
371+
{
372+
// identifier is an annotation's parameter name, and handled in action<annotation_appl_param>. Do nothing
373+
return;
374+
}
375+
else
368376
{
369-
state["annotation_member_name"] = identifier_name;
370-
if (!ctx->annotations().update_pending_annotations(state))
377+
state["enum_member_names"] += scoped_identifier_name + ";";
378+
if (state.count("annotation_names") && !state["annotation_names"].empty())
371379
{
372-
EPROSIMA_LOG_ERROR(IDLPARSER, "Error annotating enum member");
373-
return;
380+
state["annotation_member_name"] = identifier_name;
381+
if (!ctx->annotations().update_pending_annotations(state))
382+
{
383+
EPROSIMA_LOG_ERROR(IDLPARSER, "Error annotating enum member");
384+
return;
385+
}
374386
}
375387
}
376388
}
@@ -1901,7 +1913,7 @@ struct action<enum_dcl>
19011913

19021914
if (RETCODE_OK != builder->add_member(member_descriptor))
19031915
{
1904-
EPROSIMA_LOG_ERROR(IDLPARSER, "Error adding member to union: " << scoped_enum_name
1916+
EPROSIMA_LOG_ERROR(IDLPARSER, "Error adding member to enum: " << scoped_enum_name
19051917
<< ", member: " << member_name);
19061918
return;
19071919
}
@@ -1995,7 +2007,6 @@ struct action<struct_def>
19952007

19962008
}
19972009
cleanup_guard{state, ctx};
1998-
19992010
auto module = ctx->modules().current();
20002011
const std::string scoped_struct_name = module->create_scoped_name(state["struct_name"]);
20012012

@@ -2703,6 +2714,36 @@ struct action<annotation_begin>
27032714

27042715
};
27052716

2717+
template<>
2718+
struct action<annotation_param_context_begin>
2719+
{
2720+
template<typename Input>
2721+
static void apply(
2722+
const Input& /*in*/,
2723+
Context* /*ctx*/,
2724+
std::map<std::string, std::string>& state,
2725+
std::vector<traits<DynamicData>::ref_type>& /*operands*/)
2726+
{
2727+
state["parsing_annotation_params"] = "true";
2728+
}
2729+
};
2730+
2731+
template<>
2732+
struct action<annotation_param_context_end>
2733+
{
2734+
template<typename Input>
2735+
static void apply(
2736+
const Input& /*in*/,
2737+
Context* /*ctx*/,
2738+
std::map<std::string, std::string>& state,
2739+
std::vector<traits<DynamicData>::ref_type>& /*operands*/)
2740+
{
2741+
assert(state.count("parsing_annotation_params"));
2742+
state.erase("parsing_annotation_params");
2743+
}
2744+
};
2745+
2746+
27062747
template<>
27072748
struct action<annotation_appl_params>
27082749
{

0 commit comments

Comments
 (0)