-
Notifications
You must be signed in to change notification settings - Fork 284
Define and use an expr_skeletont class #4841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,49 @@ class byte_extract_exprt; | |
| class ssa_exprt; | ||
| struct symex_configt; | ||
|
|
||
| /// Expression in which some part is missing and can be substituted for another | ||
| /// expression. | ||
| /// | ||
| /// For instance, a skeleton `☐[index]` where `☐` is the missing part, can be | ||
| /// applied to an expression `x` to get `x[index]` (see | ||
| /// \ref expr_skeletont::apply). It can also be composed with another skeleton, | ||
| /// let say `☐.some_field` which would give the skeleton `☐.some_field[index]` | ||
| /// (see \ref expr_skeletont::compose). | ||
| class expr_skeletont final | ||
| { | ||
| public: | ||
| /// Empty skeleton. Applying it to an expression would give the same | ||
| /// expression unchanged | ||
| expr_skeletont() : skeleton(nil_exprt{}) | ||
| { | ||
| } | ||
|
|
||
| /// Replace the missing part of the current skeleton by another skeleton, | ||
| /// ending in a bigger skeleton corresponding to the two combined. | ||
| expr_skeletont compose(expr_skeletont other) const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this would be very easy and worthwhile to unit test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add them in another pull request #4843 because it takes a lot of tries to get CI to pass these days. |
||
|
|
||
| /// Replace the missing part by the given expression, to end-up with a | ||
| /// complete expression | ||
| exprt apply(exprt expr) const; | ||
|
|
||
| /// Create a skeleton by removing the first operand of \p e. For instance, | ||
| /// remove_op0 on `array[index]` would give a skeleton in which `array` is | ||
| /// missing, and applying that skeleton to `array2` would give | ||
| /// `array2[index]`. | ||
| static expr_skeletont remove_op0(exprt e); | ||
|
|
||
| private: | ||
| /// In \c skeleton, nil_exprt is used to mark the sub expression to be | ||
| /// substituted. The nil_exprt always appears recursively following the first | ||
| /// operands because the only way to get a skeleton is by removing the first | ||
| /// operand. | ||
| exprt skeleton; | ||
|
|
||
| explicit expr_skeletont(exprt e) : skeleton(std::move(e)) | ||
| { | ||
| } | ||
| }; | ||
|
|
||
| /// Functor for symex assignment | ||
| class symex_assignt | ||
| { | ||
|
|
@@ -44,13 +87,13 @@ class symex_assignt | |
| /// respectively. | ||
| void assign_symbol( | ||
| const ssa_exprt &lhs, // L1 | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| const exprt::operandst &guard); | ||
|
|
||
| void assign_rec( | ||
| const exprt &lhs, | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| exprt::operandst &guard); | ||
|
|
||
|
|
@@ -63,13 +106,13 @@ class symex_assignt | |
|
|
||
| void assign_from_struct( | ||
| const ssa_exprt &lhs, // L1 | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const struct_exprt &rhs, | ||
| const exprt::operandst &guard); | ||
|
|
||
| void assign_non_struct_symbol( | ||
| const ssa_exprt &lhs, // L1 | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| const exprt::operandst &guard); | ||
|
|
||
|
|
@@ -78,7 +121,7 @@ class symex_assignt | |
| template <bool use_update> | ||
| void assign_array( | ||
| const index_exprt &lhs, | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| exprt::operandst &guard); | ||
|
|
||
|
|
@@ -87,25 +130,25 @@ class symex_assignt | |
| template <bool use_update> | ||
| void assign_struct_member( | ||
| const member_exprt &lhs, | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| exprt::operandst &guard); | ||
|
|
||
| void assign_if( | ||
| const if_exprt &lhs, | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| exprt::operandst &guard); | ||
|
|
||
| void assign_typecast( | ||
| const typecast_exprt &lhs, | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| exprt::operandst &guard); | ||
|
|
||
| void assign_byte_extract( | ||
| const byte_extract_exprt &lhs, | ||
| const exprt &full_lhs, | ||
| const expr_skeletont &full_lhs, | ||
| const exprt &rhs, | ||
| exprt::operandst &guard); | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 I wouldn't have guessed the behaviour of this expression from the name. Perhaps
algebraic_expr,partial_exprexpr_template?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I couldn't find a very good name, but
algebraic_exprcould be mistaken for a special type ofexprt(like expr containing symbols),expr_templatewould be expected to be a template,partial_expris as good asexpr_skeletonI think.