Build, and adjust if needed, a unary expression.
This is similar to dimb-make/adjust-expr-cast and dimb-make/adjust-expr-binary: see those functions' documentation first. Since some of the unary operators expect a cast expression as argument (as well as an expression with priority higher than a cast), the argument of a unary operators, as produced by the parser, may be an ambiguous cast expression that becomes a binary expression, which has therefore lower priority than a cast expression. This makes it necessary to adjust the expression so that the actual priorities match the expected priorities (where `matching' includes being higher, besides being equal).
For instance,
So this function builds, and adjusts if needed,
a unary expression out of the operator
Note that
Function:
(defun dimb-make/adjust-expr-unary (op arg) (declare (xargs :guard (and (unopp op) (exprp arg)))) (declare (xargs :guard (expr-unambp arg))) (let ((__function__ 'dimb-make/adjust-expr-unary)) (declare (ignorable __function__)) (b* ((arg-expected (if (member-eq (unop-kind op) '(:predec :preinc :postdec :postinc :sizeof :alignof)) (expr-priority-unary) (expr-priority-cast))) (arg-actual (expr->priority arg)) ((when (expr-priority->= arg-actual arg-expected)) (make-expr-unary :op op :arg arg :info nil)) ((unless (expr-case arg :binary)) (raise "Internal error: ~ non-binary expression ~x0 ~ used as argument of unary operator ~x1." (expr-fix arg) (unop-fix op)) (expr-unary op arg nil))) (make-expr-binary :op (expr-binary->op arg) :arg1 (dimb-make/adjust-expr-unary op (expr-binary->arg1 arg)) :arg2 (expr-binary->arg2 arg) :info nil))))
Theorem:
(defthm exprp-of-dimb-make/adjust-expr-unary (b* ((expr (dimb-make/adjust-expr-unary op arg))) (exprp expr)) :rule-classes :rewrite)
Theorem:
(defthm expr-unambp-of-dimb-make/adjust-expr-unary (implies (expr-unambp arg) (b* ((?expr (dimb-make/adjust-expr-unary op arg))) (expr-unambp expr))))
Theorem:
(defthm dimb-make/adjust-expr-unary-of-unop-fix-op (equal (dimb-make/adjust-expr-unary (unop-fix op) arg) (dimb-make/adjust-expr-unary op arg)))
Theorem:
(defthm dimb-make/adjust-expr-unary-unop-equiv-congruence-on-op (implies (unop-equiv op op-equiv) (equal (dimb-make/adjust-expr-unary op arg) (dimb-make/adjust-expr-unary op-equiv arg))) :rule-classes :congruence)
Theorem:
(defthm dimb-make/adjust-expr-unary-of-expr-fix-arg (equal (dimb-make/adjust-expr-unary op (expr-fix arg)) (dimb-make/adjust-expr-unary op arg)))
Theorem:
(defthm dimb-make/adjust-expr-unary-expr-equiv-congruence-on-arg (implies (expr-equiv arg arg-equiv) (equal (dimb-make/adjust-expr-unary op arg) (dimb-make/adjust-expr-unary op arg-equiv))) :rule-classes :congruence)