Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (types-in-ref-cycle tn0)
- ;; todo is (listof Type): a worklist accumulator
- ;; current-cycle is (listof Type): a context preserving accumulator
- (local [(define (fn-for-type-name tn todo current-cycle)
- (if (member? tn0 current-cycle)
- current-cycle
- (fn-for-typedef (lookup-typedef tn) todo current-cycle)))
- (define (fn-for-typedef td todo current-cycle)
- (fn-for-type (typedef-type td) todo current-cycle))
- (define (fn-for-type t todo current-cycle)
- (cond [(string? t) (fn-for-type-name t todo current-cycle)]
- [(primitive? t) (fn-for-lot todo current-cycle)]
- [(distinct? t) (fn-for-lot todo current-cycle)]
- [(oneof? t) (fn-for-lot (append (oneof-subclasses t) todo) current-cycle)]
- [(compound? t) (fn-for-lot (append (compound-types t) todo) current-cycle)]))
- (define (fn-for-lot todo current-cycle)
- (cond [(empty? todo) empty]
- [else
- (fn-for-type (first todo) (rest todo) (cond [(and (string? (first todo))
- (not (or (string=? "String" (first todo))
- (string=? "Image" (first todo))
- (string=? "Number" (first todo))))
- (local [(define c (typedef-type (lookup-typedef (first todo))))
- (define (compound-or-oneof--c? type)
- (or (compound? (typedef-type (lookup-typedef type)))
- (oneof? (typedef-type (lookup-typedef type)))))
- (define (compound-or-oneof--of? type)
- (or (compound? type)
- (oneof? type)))]
- (cond [(compound? c) (ormap compound-or-oneof--c? (compound-types c))]
- [(oneof? c) (ormap compound-or-oneof--of? (oneof-subclasses c))])))
- (cons (first todo) current-cycle)]
- [else current-cycle]))]))]
- (fn-for-type-name tn0 empty empty)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement