Expand uses of defines like
(vl-expand-define name defines echars config loc) → (mv successp new-echars)
Note that variables in `define are lazy, e.g., if you do:
`define foo 3 `define bar `foo `define foo 4
Then from here on
Subtle. If we simply inserted the echars stored in the defines table,
then locations on these characters would refer to their original position in
the file. This might lead to confusing error messages, telling you that
something is wrong and showing you line numbers for a
Function:
(defun vl-expand-define (name defines echars config loc) (declare (xargs :guard (and (stringp name) (vl-defines-p defines) (vl-echarlist-p echars) (vl-loadconfig-p config) (vl-location-p loc)))) (let ((__function__ 'vl-expand-define)) (declare (ignorable __function__)) (b* ((lookup (vl-find-define name defines)) ((unless lookup) (mv (cw "Preprocessor error (~s0): `~s1 is not defined.~%" (vl-location-string loc) name) echars)) ((vl-define lookup)) ((when (atom lookup.formals)) (b* ((body-str lookup.body) (body-echars (vl-echarlist-from-str body-str)) (body-fixed (vl-change-echarlist-locations body-echars loc))) (mv t (append body-fixed echars)))) ((mv ?ws echars) (vl-read-while-whitespace echars)) ((unless (and (consp echars) (eql (vl-echar->char (car echars)) #\())) (mv (cw "Preprocessor error (~s0): `~s1 requires arguments.~%" (vl-location-string loc) name) echars)) (echars (cdr echars)) ((mv successp actuals echars) (vl-parse-define-actuals name echars config loc)) ((unless successp) (mv nil echars)) ((mv successp subst) (vl-line-up-define-formals-and-actuals lookup.formals actuals name loc)) ((unless successp) (mv nil echars)) ((mv okp rev-replacement-body) (vl-substitute-into-macro-text (vl-echarlist-from-str lookup.body) subst name loc config nil)) ((unless okp) (mv nil echars)) (replacement-body (rev rev-replacement-body)) (echars (append replacement-body echars))) (mv t echars))))
Theorem:
(defthm booleanp-of-vl-expand-define.successp (b* (((mv ?successp ?new-echars) (vl-expand-define name defines echars config loc))) (booleanp successp)) :rule-classes :type-prescription)
Theorem:
(defthm vl-echarlist-p-of-vl-expand-define.new-echars (implies (force (vl-echarlist-p echars)) (b* (((mv ?successp ?new-echars) (vl-expand-define name defines echars config loc))) (vl-echarlist-p new-echars))) :rule-classes :rewrite)