Skip to content

Commit

Permalink
Fix parser error for structs that use type* pointer syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 15, 2022
1 parent d663065 commit 16c0159
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
4 changes: 3 additions & 1 deletion flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37584,7 +37584,9 @@ const char* parse_c_identifier(
goto error;
}

while ((ch = *ptr) && !isspace(ch) && ch != ';' && ch != ',' && ch != ')' && ch != '>' && ch != '}') {
while ((ch = *ptr) && !isspace(ch) && ch != ';' && ch != ',' && ch != ')' &&
ch != '>' && ch != '}' && ch != '*')
{
/* Type definitions can contain macros or templates */
if (ch == '(' || ch == '<') {
if (!params) {
Expand Down
4 changes: 3 additions & 1 deletion src/addons/meta_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ const char* parse_c_identifier(
goto error;
}

while ((ch = *ptr) && !isspace(ch) && ch != ';' && ch != ',' && ch != ')' && ch != '>' && ch != '}') {
while ((ch = *ptr) && !isspace(ch) && ch != ';' && ch != ',' && ch != ')' &&
ch != '>' && ch != '}' && ch != '*')
{
/* Type definitions can contain macros or templates */
if (ch == '(' || ch == '<') {
if (!params) {
Expand Down
3 changes: 2 additions & 1 deletion test/meta/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@
"struct_w_nested",
"enum_nospace",
"struct_nospace",
"identifier_w_underscore"
"identifier_w_underscore",
"struct_w_ptr"
]
}, {
"id": "Vars",
Expand Down
26 changes: 25 additions & 1 deletion test/meta/src/MetaUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ECS_STRUCT(Struct_2_f64, {
double y;
});


ECS_STRUCT(_Struct_w_underscore, {
double value;
});
Expand All @@ -43,6 +42,11 @@ ECS_STRUCT(Struct_w_underscore_member_type, {
_Struct_w_underscore value;
});

ECS_STRUCT(Struct_w_ptrs, {
void *ptr_a;
void* ptr_b;
});

ECS_ENUM(Enum_Default, {
Red, Green, Blue
});
Expand Down Expand Up @@ -364,3 +368,23 @@ void MetaUtils_identifier_w_underscore() {

ecs_fini(world);
}

void MetaUtils_struct_w_ptr() {
ecs_world_t *world = ecs_init();

ECS_META_COMPONENT(world, Struct_w_ptrs);

test_assert(ecs_id(Struct_w_ptrs) != 0);
ecs_entity_t s = ecs_id(Struct_w_ptrs);

{
ecs_entity_t m = ecs_lookup_child(world, s, "ptr_a");
test_assert(m != 0);
}
{
ecs_entity_t m = ecs_lookup_child(world, s, "ptr_b");
test_assert(m != 0);
}

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/meta/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ void MetaUtils_struct_w_nested(void);
void MetaUtils_enum_nospace(void);
void MetaUtils_struct_nospace(void);
void MetaUtils_identifier_w_underscore(void);
void MetaUtils_struct_w_ptr(void);

// Testsuite 'Vars'
void Vars_declare_1_var(void);
Expand Down Expand Up @@ -3119,6 +3120,10 @@ bake_test_case MetaUtils_testcases[] = {
{
"identifier_w_underscore",
MetaUtils_identifier_w_underscore
},
{
"struct_w_ptr",
MetaUtils_struct_w_ptr
}
};

Expand Down Expand Up @@ -3658,7 +3663,7 @@ static bake_test_suite suites[] = {
"MetaUtils",
NULL,
NULL,
16,
17,
MetaUtils_testcases
},
{
Expand Down

0 comments on commit 16c0159

Please sign in to comment.