type an operator's result without qualifiers

The spelling was the first operand's, so (+ k 1) with k const was a
const int and (+ 1 k) was not; a value has no qualifiers either way.
This commit is contained in:
2026-10-16 17:04:20 +03:00
parent b68b91b119
commit c617fb9a33
3 changed files with 27 additions and 2 deletions

View File

@@ -55,6 +55,7 @@
type-quals
free-tvars
decay
unqualified
;; The boundary
parse-type
@@ -209,6 +210,16 @@
((fn-type? t) (make-ptr t (list)))
(else (resolve type)))))
;;; TYPE as a value has it: qualifiers belong to an object, not to what
;;; is read out of one. `(const int)' -> `int', `(* const char)' as is.
(define (unqualified type)
(let ((t (resolve type)))
(cond ((prim-type? t) (make-prim (prim-name t) (list)))
((ptr-type? t) (make-ptr (ptr-target t) (list)))
((agg-type? t) (make-agg (agg-kind t) (agg-name t) (agg-spelling t) (list)))
((alias-type? t) (make-alias (alias-name t) (alias-expansion t) (list)))
(else t))))
(define (free-tvars type)
(let collect ((t type) (acc (list)))
(let ((t (resolve t)))