tell an array's bound by the shape of its type
Whether a trailing name was the bound hinged on the word before it being a typedef Sex had seen, which a header's pthread_t never is, and a grouped (* T) never is either: [pthread-t N] became a two-word type. Fixes #56, #60.
This commit is contained in:
30
types.scm
30
types.scm
@@ -388,22 +388,15 @@
|
||||
(pair? (cdr arg)) ; 1 element args are always type
|
||||
(not (type-head? arg))))
|
||||
|
||||
;;; A typedef and a `define' share +type-db+; only the typedef is part
|
||||
;;; of a type:
|
||||
;;; The last element is a bound unless what precedes it is still
|
||||
;;; waiting for a type name -- a `*', a qualifier, a tag's keyword. C
|
||||
;;; spells a type with one name at most, so a name after a name, or
|
||||
;;; after a grouped type, can only be the bound:
|
||||
;;;
|
||||
;;; (typedef small int) -> (¤ small N) is N of small
|
||||
;;; (define CAP 4) -> (¤ int CAP) is CAP of int
|
||||
(define (typedef-name? name)
|
||||
(let ((info (and (symbol? name) (get-type-info name))))
|
||||
(and info (memq (car info) '(typedef struct union enum)) #t)))
|
||||
|
||||
;;; The last element is a bound only where what precedes it already
|
||||
;;; spells a whole type -- a specifier, a tag after its keyword, or a
|
||||
;;; typedef we have seen declared:
|
||||
;;;
|
||||
;;; (¤ int 4) four of int (¤ unsigned int) unsized
|
||||
;;; (¤ mytype CAP) CAP of mytype (¤ struct point) unsized
|
||||
;;; (¤ const mytype) unsized (¤ * size-t) unsized
|
||||
;;; (¤ int 4) four of int (¤ unsigned int) unsized
|
||||
;;; (¤ pthread-t CAP) CAP of pthread-t (¤ struct point) unsized
|
||||
;;; (¤ (* T) CAP) CAP of (* T) (¤ const mytype) unsized
|
||||
;;; (¤ * size-t) unsized
|
||||
;;;
|
||||
;;; TYPE is the whole `(¤ ...)' form.
|
||||
(define (array-bound? type)
|
||||
@@ -413,11 +406,8 @@
|
||||
(cond
|
||||
((not (symbol? bound)) #t)
|
||||
((or (memq bound +c-specifiers+) (memq bound +c-qualifiers+)) #f)
|
||||
((memq preceding +c-specifiers+) #t)
|
||||
;; a tag always follows its keyword, so `(¤ * struct tt)' ends
|
||||
;; in a name belonging to the type
|
||||
((memq preceding '(struct union enum)) #f)
|
||||
(else (typedef-name? preceding))))))
|
||||
(else (not (or (memq preceding '(* struct union enum))
|
||||
(memq preceding +c-qualifiers+))))))))
|
||||
|
||||
;;; What one element of a written array type is:
|
||||
;;; (¤ struct point 2) -> (struct point), (¤ * const char 2) -> (* const char)
|
||||
|
||||
Reference in New Issue
Block a user