Build, and adjust if needed, a cast expression.
(dimb-make/adjust-expr-cast type inc/dec arg) → expr
This is used to build or adjust a cast expression during disambiguation.
When dimb-expr encounters a cast expression,
it recursively disambiguates
the type name
Note that
The same kind of adjustment may be needed, besides dimb-expr,
also in functions like dimb-cast/and-to-cast,
which turns ambiguous expressions of the form
This function takes
The
In summary, this function builds and adjusts the expression so that the sub-expressions have priorities greater than or equal to the ones expected by the super-expressions at those place. Another way to express this condition on priorities is that the expression prints without any added parentheses. But this is not a function to adjust all kinds of priority mismatches: it only works on the ones that may arise during disambiguation.
Function:
(defun dimb-make/adjust-expr-cast (type inc/dec arg) (declare (xargs :guard (and (tynamep type) (inc/dec-op-listp inc/dec) (exprp arg)))) (declare (xargs :guard (and (tyname-unambp type) (expr-unambp arg)))) (let ((__function__ 'dimb-make/adjust-expr-cast)) (declare (ignorable __function__)) (cond ((expr-case arg :binary) (make-expr-binary :op (expr-binary->op arg) :arg1 (dimb-make/adjust-expr-cast type inc/dec (expr-binary->arg1 arg)) :arg2 (expr-binary->arg2 arg) :info nil)) ((expr-priority-< (expr->priority arg) (expr-priority-logand)) (prog2$ (raise "Internal error: ~x0 has lower priority than &&." arg) (expr-fix arg))) ((and (consp inc/dec) (expr-case arg :cast)) (prog2$ (raise "Internal error: ~x0 applied to ~x1." inc/dec arg) (expr-fix arg))) (t (make-expr-cast :type type :arg (apply-pre-inc/dec-ops inc/dec arg))))))
Theorem:
(defthm exprp-of-dimb-make/adjust-expr-cast (b* ((expr (dimb-make/adjust-expr-cast type inc/dec arg))) (exprp expr)) :rule-classes :rewrite)
Theorem:
(defthm expr-unambp-of-dimb-make/adjust-expr-cast (implies (and (tyname-unambp type) (expr-unambp arg)) (b* ((?expr (dimb-make/adjust-expr-cast type inc/dec arg))) (expr-unambp expr))))
Theorem:
(defthm dimb-make/adjust-expr-cast-of-tyname-fix-type (equal (dimb-make/adjust-expr-cast (tyname-fix type) inc/dec arg) (dimb-make/adjust-expr-cast type inc/dec arg)))
Theorem:
(defthm dimb-make/adjust-expr-cast-tyname-equiv-congruence-on-type (implies (tyname-equiv type type-equiv) (equal (dimb-make/adjust-expr-cast type inc/dec arg) (dimb-make/adjust-expr-cast type-equiv inc/dec arg))) :rule-classes :congruence)
Theorem:
(defthm dimb-make/adjust-expr-cast-of-inc/dec-op-list-fix-inc/dec (equal (dimb-make/adjust-expr-cast type (inc/dec-op-list-fix inc/dec) arg) (dimb-make/adjust-expr-cast type inc/dec arg)))
Theorem:
(defthm dimb-make/adjust-expr-cast-inc/dec-op-list-equiv-congruence-on-inc/dec (implies (inc/dec-op-list-equiv inc/dec inc/dec-equiv) (equal (dimb-make/adjust-expr-cast type inc/dec arg) (dimb-make/adjust-expr-cast type inc/dec-equiv arg))) :rule-classes :congruence)
Theorem:
(defthm dimb-make/adjust-expr-cast-of-expr-fix-arg (equal (dimb-make/adjust-expr-cast type inc/dec (expr-fix arg)) (dimb-make/adjust-expr-cast type inc/dec arg)))
Theorem:
(defthm dimb-make/adjust-expr-cast-expr-equiv-congruence-on-arg (implies (expr-equiv arg arg-equiv) (equal (dimb-make/adjust-expr-cast type inc/dec arg) (dimb-make/adjust-expr-cast type inc/dec arg-equiv))) :rule-classes :congruence)