Type: Improve type constraints formatting and parsing#6561
Draft
andersendsa wants to merge 4 commits into
Draft
Conversation
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.
wargio
reviewed
Jun 25, 2026
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 }; |
wargio
reviewed
Jun 25, 2026
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); |
Member
There was a problem hiding this comment.
each of these ifs/else blocks can be refactored into a function
wargio
reviewed
Jun 25, 2026
wargio
left a comment
Member
There was a problem hiding this comment.
i'm not sure if this parsing is better than just fixing a regex
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 |
Rot127
requested changes
Jun 27, 2026
| RzVector /*<ut64>*/ eqs; | ||
| rz_vector_init(&eqs, sizeof(ut64), NULL, NULL); | ||
|
|
||
| #define FLUSH_EQS() \ |
| } | ||
| } | ||
|
|
||
| static bool parse_value(const char **p, ut64 *val) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Your checklist for this pull request
RZ_APIfunction and struct this PR changes.RZ_API).Detailed description
This Pr enhances type constraints formatting and parsing by:
{a, b, c}for exact values.[a, b],(a, b],[a, b), and(a, b).||.test/db/cmd/cmd_afvto reflect these changes.Closes:#6498
Test plan
...
Closing issues
...