Skip to content

Type: Improve type constraints formatting and parsing#6561

Draft
andersendsa wants to merge 4 commits into
rizinorg:devfrom
andersendsa:improve_constraints
Draft

Type: Improve type constraints formatting and parsing#6561
andersendsa wants to merge 4 commits into
rizinorg:devfrom
andersendsa:improve_constraints

Conversation

@andersendsa

@andersendsa andersendsa commented Jun 25, 2026

Copy link
Copy Markdown

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description
This Pr enhances type constraints formatting and parsing by:

  • Adding support for set notations like {a, b, c} for exact values.
  • Utilizing mathematical notation for intervals like [a, b], (a, b], [a, b), and (a, b).
  • Replacing the simple regex-based parser with a more robust parser capable of handling the new notations and mixed constraints joined by ||.
  • Updating the tests in test/db/cmd/cmd_afv to reflect these changes.

Closes:#6498

Test plan

  • test/db/asm/: Assembly and disassembly tests.
  • test/db/cmd/: Command tests. (This is where the tests for afv constraints lie, and what I updated).
  • test/unit/: Unit tests.
  • test/integration/: Integration tests.

...

Closing issues

...

This commit enhances type constraints formatting and parsing by:
- Adding support for set notations like `{a, b, c}` for exact values.
- Utilizing mathematical notation for intervals like `[a, b]`, `(a, b]`, `[a, b)`, and `(a, b)`.
- Replacing the simple regex-based parser with a more robust parser capable of handling the new notations and mixed constraints joined by `||`.
- Updating the tests in `test/db/cmd/cmd_afv` to reflect these changes.
Comment thread librz/type/helpers.c Outdated
Comment on lines +839 to +867
const char *start = p;
if (*p == '<' || *p == '>' || *p == '=' || *p == '!') {
while (*p == '<' || *p == '>' || *p == '=' || *p == '!') {
p++;
}
} else if (isalpha((unsigned char)*p)) {
while (isalpha((unsigned char)*p)) {
p++;
}
}
if (p == start) {
ok = false;
break;
}
char *op = rz_str_ndup(start, p - start);
RzTypeCond cond = rz_type_cond_fromstring(op);
free(op);
if (cond != RZ_TYPE_COND_LE && cond != RZ_TYPE_COND_LT &&
cond != RZ_TYPE_COND_GE && cond != RZ_TYPE_COND_GT &&
cond != RZ_TYPE_COND_EQ && cond != RZ_TYPE_COND_NE) {
ok = false;
break;
}
ut64 val;
if (!parse_value(&p, &val)) {
ok = false;
break;
}
RzTypeConstraint c = { .cond = cond, .val = val };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this into a function

Comment thread librz/type/helpers.c Outdated
Comment on lines +790 to +837
while (*p) {
ut64 val;
if (!parse_value(&p, &val)) {
ok = false;
break;
}
RzTypeConstraint c = { .cond = RZ_TYPE_COND_EQ, .val = val };
rz_vector_push(constraints, &c);
skip_whitespace(&p);
if (*p == '}') {
p++;
break;
} else if (*p == ',') {
p++;
} else {
ok = false;
break;
}
}
} else if (*p == '[' || *p == '(') {
char open_bracket = *p;
p++;
ut64 val1, val2;
if (!parse_value(&p, &val1)) {
ok = false;
break;
}
skip_whitespace(&p);
if (*p != ',') {
ok = false;
break;
}
p++;
if (!parse_value(&p, &val2)) {
ok = false;
break;
}
skip_whitespace(&p);
char close_bracket = *p;
if (close_bracket != ']' && close_bracket != ')') {
ok = false;
break;
}
p++;
RzTypeConstraint c1 = { .cond = open_bracket == '[' ? RZ_TYPE_COND_GE : RZ_TYPE_COND_GT, .val = val1 };
RzTypeConstraint c2 = { .cond = close_bracket == ']' ? RZ_TYPE_COND_LE : RZ_TYPE_COND_LT, .val = val2 };
rz_vector_push(constraints, &c1);
rz_vector_push(constraints, &c2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each of these ifs/else blocks can be refactored into a function

@wargio wargio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if this parsing is better than just fixing a regex

@andersendsa andersendsa requested a review from wargio June 25, 2026 15:04
@andersendsa

Copy link
Copy Markdown
Author

Hi @wargio i have done the changes pls let me know if the pr needs any other changes or if it is good to merge

Comment thread librz/type/helpers.c
RzVector /*<ut64>*/ eqs;
rz_vector_init(&eqs, sizeof(ut64), NULL, NULL);

#define FLUSH_EQS() \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you read CONTRIBUTING.md?

Comment thread librz/type/helpers.c
}
}

static bool parse_value(const char **p, ut64 *val) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the regex instead.

@Rot127 Rot127 added the Requirements not met The PR doesn't meet the minimum contribution requirements. See CONTRIBUTING.md for details. label Jun 27, 2026
@Rot127 Rot127 marked this pull request as draft June 27, 2026 16:54
@Rot127 Rot127 added AI/LLM Partially or fully AI generated. Critical thinking is advised! and removed AI/LLM Partially or fully AI generated. Critical thinking is advised! labels Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI/LLM Partially or fully AI generated. Critical thinking is advised! Requirements not met The PR doesn't meet the minimum contribution requirements. See CONTRIBUTING.md for details. rz-test RzType

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants