diff --git a/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt b/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt index 2ae2e8cf1..21cf9394b 100644 --- a/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt +++ b/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt @@ -798,35 +798,34 @@ (for ([k (in-hash-keys requires)]) (hash-set! new-hash k #t))) - (for ([(level binders) (in-hash phase-to-binders)]) - (for ([(_ binder+modss) (in-dict binders)]) - (for ([binder+mods (in-list binder+modss)]) - (define var (binder+mods-binder binder+mods)) - (define varset (lookup-phase-to-mapping phase-to-varsets level)) - (color-variable var level varset) - (document-variable var level)))) + (for* ([(level binders) (in-hash phase-to-binders)] + [(_ binder+modss) (in-dict binders)] + [binder+mods (in-list binder+modss)]) + (define var (binder+mods-binder binder+mods)) + (define varset (lookup-phase-to-mapping phase-to-varsets level)) + (color-variable var level varset) + (document-variable var level)) (for ([(level+mods varrefs) (in-hash phase-to-varrefs)]) - (define level (list-ref level+mods 0)) - (define mods (list-ref level+mods 1)) + (match-define (list level mods) level+mods) (define binders (lookup-phase-to-mapping phase-to-binders level)) (define varsets (lookup-phase-to-mapping phase-to-varsets level)) (initialize-binder-connections binders connections) - (for ([vars (in-list (get-idss varrefs))]) - (for ([var (in-list vars)]) - (color-variable var level varsets) - (document-variable var level) - (connect-identifier var - mods - binders - unused/phases - phase-to-requires - level - user-namespace - user-directory - #t - connections - module-lang-requires)))) + (for* ([vars (in-list (get-idss varrefs))] + [var (in-list vars)]) + (color-variable var level varsets) + (document-variable var level) + (connect-identifier var + mods + binders + unused/phases + phase-to-requires + level + user-namespace + user-directory + #t + connections + module-lang-requires))) ;; build a set of all of the known phases @@ -835,8 +834,7 @@ (for ([phase (in-hash-keys phase-to-binders)]) (set! phases (set-add phases phase))) (for ([(phase+mod _) (in-hash phase-to-requires)]) - (define phase (list-ref phase+mod 0)) - (define mod (list-ref phase+mod 1)) + (match-define (list phase mod) phase+mod) (set! phases (set-add phases phase)) (set! all-mods (set-add all-mods mod))) @@ -862,10 +860,9 @@ (for ([(level tops) (in-hash phase-to-tops)]) (define binders (lookup-phase-to-mapping phase-to-binders level)) - (for ([vars (in-list (get-idss tops))]) - (for ([var (in-list vars)]) - (color/connect-top user-namespace user-directory binders var connections - module-lang-requires)))) + (for* ([vars (in-list (get-idss tops))] + [var (in-list vars)]) + (color/connect-top user-namespace user-directory binders var connections module-lang-requires))) (for ([(phase+mods require-hash) (in-hash phase-to-requires)]) ;; don't mark for-label requires as unused until we can properly handle them @@ -874,8 +871,7 @@ (color-unused require-hash unused-hash module-lang-requires))) (for ([(level+mods directives) (in-hash sub-identifier-binding-directives)]) - (define phase-level (list-ref level+mods 0)) - (define mods (list-ref level+mods 1)) + (match-define (list phase-level mods) level+mods) (for ([directive (in-list directives)]) (match-define (vector binding-id to-start to-span to-dx to-dy new-binding-id from-start from-span from-dx from-dy) @@ -948,8 +944,8 @@ (color-range source start end unused-require-style-name)) (define (self-module? mpi) - (let-values ([(a b) (module-path-index-split mpi)]) - (and (not a) (not b)))) + (define-values (a b) (module-path-index-split mpi)) + (and (not a) (not b))) ;; connect-identifier : syntax ;; (or/c #f (listof symbol)) -- name of enclosing sub-modules @@ -1116,7 +1112,7 @@ (define phase-shift (if (pair? phase+space-shift) (car phase+space-shift) phase+space-shift)) (define phase+space (list-ref binding 6)) (define phase (if (pair? phase+space) (car phase+space) phase+space)) - (define space (if (pair? phase+space) (cdr phase+space) #f)) + (define space (and (pair? phase+space) (cdr phase+space))) (when (and (number? phase-level) (not (= phase-level (+ phase-shift @@ -1138,22 +1134,29 @@ [else #f]))) ;; color/connect-top : namespace directory id-set syntax connections[see defn for ctc] -> void -(define (color/connect-top user-namespace user-directory binders var connections - module-lang-requires) - (let ([top-bound? - (or (get-ids binders var) - (parameterize ([current-namespace user-namespace]) - (let/ec k - (namespace-variable-value (syntax-e var) #t (λ () (k #f))) - #t)))]) - (cond - [top-bound? - (color var lexically-bound-variable-style-name)] - [else - (add-mouse-over var (format "~s is a free variable" (syntax-e var))) - (color var free-variable-style-name)]) - (connect-identifier var #f binders #f #f 0 user-namespace user-directory #t connections - module-lang-requires))) +(define (color/connect-top user-namespace user-directory binders var connections module-lang-requires) + (define top-bound? + (or (get-ids binders var) + (parameterize ([current-namespace user-namespace]) + (let/ec k + (namespace-variable-value (syntax-e var) #t (λ () (k #f))) + #t)))) + (cond + [top-bound? (color var lexically-bound-variable-style-name)] + [else + (add-mouse-over var (format "~s is a free variable" (syntax-e var))) + (color var free-variable-style-name)]) + (connect-identifier var + #f + binders + #f + #f + 0 + user-namespace + user-directory + #t + connections + module-lang-requires)) ;; annotate-counts : connections[see defn] -> void ;; this function doesn't try to show the number of uses at @@ -1171,39 +1174,39 @@ ;; records the src locs of each 'end' position of each arrow) ;; to do this, but maybe lets leave that for another day. (define (annotate-counts connections) - (for ([(key val) (in-hash connections)]) - (when (list? val) - (define start (first val)) - (define end (second val)) - (define color? (third val)) - (define (show-starts) - (when (zero? start) - (define defs-text (current-annotations)) - (when defs-text - (send defs-text syncheck:unused-binder - (list-ref key 0) (list-ref key 1) (list-ref key 2)))) - (add-mouse-over/loc (list-ref key 0) (list-ref key 1) (list-ref key 2) - (cond - [(zero? start) - (string-constant cs-zero-varrefs)] - [(= 1 start) - (string-constant cs-one-varref)] - [else - (format (string-constant cs-n-varrefs) start)]))) - (define (show-ends) - (unless (= 1 end) - (add-mouse-over/loc (list-ref key 0) (list-ref key 1) (list-ref key 2) - (format (string-constant cs-binder-count) end)))) - (cond - [(zero? end) ;; assume this is a binder, show uses - #;(when (and color? (zero? start)) - (color-unused-binder (list-ref key 0) (list-ref key 1) (list-ref key 2))) - (show-starts)] - [(zero? start) ;; assume this is a use, show bindings (usually just one, so do nothing) - (show-ends)] - [else ;; crazyness, show both - (show-starts) - (show-ends)])))) + (for ([(key val) (in-hash connections)] + #:when (list? val)) + (define start (first val)) + (define end (second val)) + (define color? (third val)) + (define (show-starts) + (when (zero? start) + (define defs-text (current-annotations)) + (when defs-text + (send defs-text syncheck:unused-binder (list-ref key 0) (list-ref key 1) (list-ref key 2)))) + (add-mouse-over/loc (list-ref key 0) + (list-ref key 1) + (list-ref key 2) + (cond + [(zero? start) (string-constant cs-zero-varrefs)] + [(= 1 start) (string-constant cs-one-varref)] + [else (format (string-constant cs-n-varrefs) start)]))) + (define (show-ends) + (unless (= 1 end) + (add-mouse-over/loc (list-ref key 0) + (list-ref key 1) + (list-ref key 2) + (format (string-constant cs-binder-count) end)))) + (cond + ;; assume this is a binder, show uses + #;(when (and color? (zero? start)) + (color-unused-binder (list-ref key 0) (list-ref key 1) (list-ref key 2))) + [(zero? end) (show-starts)] + ;; assume this is a use, show bindings (usually just one, so do nothing) + [(zero? start) (show-ends)] + [else ;; crazyness, show both + (show-starts) + (show-ends)]))) ;; color-variable : syntax phase-level identifier-mapping -> void (define (color-variable var phase-level varsets) @@ -1219,10 +1222,11 @@ (define (is-lexical? b) (or (not b) (eq? b 'lexical) - (and (pair? b) - (let ([path (caddr b)]) - (and (module-path-index? path) - (self-module? path)))))) + (cond + [(pair? b) + (define path (caddr b)) + (and (module-path-index? path) (self-module? path))] + [else #f]))) ;; initialize-binder-connections : id-set connections -> void (define (initialize-binder-connections binders connections) @@ -1317,22 +1321,19 @@ ;; popup menu in this area allows the programmer to jump ;; to the definition of the id. (define (add-jump-to-definition stx id filename submods phase-level+space) - (let ([source (find-source-editor stx)] - [defs-text (current-annotations)]) - (when (and source - defs-text - (syntax-position stx) - (syntax-span stx)) - (let* ([pos-left (- (syntax-position stx) 1)] - [pos-right (+ pos-left (syntax-span stx))]) - (send defs-text syncheck:add-jump-to-definition/phase-level+space - source - pos-left - pos-right - id - filename - submods - phase-level+space))))) + (define source (find-source-editor stx)) + (define defs-text (current-annotations)) + (when (and source defs-text (syntax-position stx) (syntax-span stx)) + (let* ([pos-left (- (syntax-position stx) 1)] + [pos-right (+ pos-left (syntax-span stx))]) + (send defs-text syncheck:add-jump-to-definition/phase-level+space + source + pos-left + pos-right + id + filename + submods + phase-level+space)))) ;; annotate-require-open : namespace string -> (stx -> void) ;; relies on current-module-name-resolver, which in turn depends on diff --git a/drracket/gui-debugger/debug-tool.rkt b/drracket/gui-debugger/debug-tool.rkt index 722ddee82..54aea5098 100644 --- a/drracket/gui-debugger/debug-tool.rkt +++ b/drracket/gui-debugger/debug-tool.rkt @@ -156,10 +156,12 @@ (send (group:get-the-frame-group) for-each-frame (lambda (frame) - (and (is-a? frame drscheme:unit:frame<%>) - (let* ([defss (map (lambda (t) (send t get-defs)) (send frame get-tabs))] - [defs (findf (lambda (d) (send d port-name-matches? source)) defss)]) - (and defs (k defs)))))) + (cond + [(is-a? frame drscheme:unit:frame<%>) + (define defss (map (lambda (t) (send t get-defs)) (send frame get-tabs))) + (define defs (findf (lambda (d) (send d port-name-matches? source)) defss)) + (and defs (k defs))] + [else #f]))) default]))) (define (debug-definitions-text-mixin super%) @@ -486,26 +488,26 @@ (when (and (send (get-tab) debug?) (not before)) ;; render breakpoints (let ([breakpoints (send (get-tab) get-breakpoints)]) - (for ([(pos enabled?) (in-hash breakpoints)]) - (when (and (>= pos 0) (or enabled? (and mouse-over-pos (= mouse-over-pos pos)))) - (define-values (xl yl xr yr) (find-char-box this pos)) - (define diameter (- xr xl)) - (define yoff (/ (- yr yl diameter) 2)) - (define op (send dc get-pen)) - (define ob (send dc get-brush)) - (case enabled? - [(#t) - (send dc set-pen bp-pen) - (send dc set-brush bp-brush)] - [(#f) - (send dc set-pen bp-mo-pen) - (send dc set-brush bp-mo-brush)] - [else - (send dc set-pen bp-tmp-pen) - (send dc set-brush bp-tmp-brush)]) - (send dc draw-ellipse (+ xl dx) (+ yl dy yoff) diameter diameter) - (send dc set-pen op) - (send dc set-brush ob)))) + (for ([(pos enabled?) (in-hash breakpoints)] + #:when (and (>= pos 0) (or enabled? (and mouse-over-pos (= mouse-over-pos pos))))) + (define-values (xl yl xr yr) (find-char-box this pos)) + (define diameter (- xr xl)) + (define yoff (/ (- yr yl diameter) 2)) + (define op (send dc get-pen)) + (define ob (send dc get-brush)) + (case enabled? + [(#t) + (send dc set-pen bp-pen) + (send dc set-brush bp-brush)] + [(#f) + (send dc set-pen bp-mo-pen) + (send dc set-brush bp-mo-brush)] + [else + (send dc set-pen bp-tmp-pen) + (send dc set-brush bp-tmp-brush)]) + (send dc draw-ellipse (+ xl dx) (+ yl dy yoff) diameter diameter) + (send dc set-pen op) + (send dc set-brush ob))) ;; mark the boundaries of the current stack frame ;; unless we're at the end of the expression and looking at the top frame, ;; in which case just mark the current location @@ -636,10 +638,11 @@ (namespace-syntax-introduce (datum->syntax #f orig-exp)))) (define top-e (expand-syntax-to-top-form exp)) - (define fn (and (syntax? orig-exp) - (let ([src (syntax-source orig-exp)]) - (and (path? src) - src)))) + (define fn (cond + [(syntax? orig-exp) + (define src (syntax-source orig-exp)) + (and (path? src) src)] + [else #f])) (define annotating-tabs (make-hasheq)) (cond [(or (eq? (filename->defs (and (syntax? orig-exp) @@ -909,39 +912,45 @@ (define/public (defs-containing-pc) (let ([stack-frames (get-stack-frames)]) - (and (cons? stack-frames) - (let* ([src-stx (mark-source (first stack-frames))] - [source (syntax-source src-stx)]) - (if source - (filename->defs source) - (get-defs)))))) + (cond + [(cons? stack-frames) + (define src-stx (mark-source (first stack-frames))) + (define source (syntax-source src-stx)) + (if source + (filename->defs source) + (get-defs))] + [else #f]))) (define/public (defs-containing-current-frame) (let ([stack-frames (get-stack-frames)]) - (and (cons? stack-frames) - (let* ([src-stx (mark-source (list-ref stack-frames (get-frame-num)))] - [source (syntax-source src-stx)]) - (if source - (filename->defs source) - (get-defs)))))) + (cond + [(cons? stack-frames) + (define src-stx (mark-source (list-ref stack-frames (get-frame-num)))) + (define source (syntax-source src-stx)) + (if source + (filename->defs source) + (get-defs))] + [else #f]))) (define/public (get-pc) (let ([stack-frames (get-stack-frames)]) - (and (cons? stack-frames) - (let* ([src-stx (mark-source (first stack-frames))] - [start (syntax-position src-stx)] - [end (and start (+ start (syntax-span src-stx) -1))]) - (if (cons? (get-break-status)) - end - start))))) + (cond + [(cons? stack-frames) + (define src-stx (mark-source (first stack-frames))) + (define start (syntax-position src-stx)) + (define end (and start (+ start (syntax-span src-stx) -1))) + (if (cons? (get-break-status)) end start)] + [else #f]))) (define/public (get-frame-endpoints frame-num) (let ([stack-frames (get-stack-frames)]) - (and (cons? stack-frames) - (let* ([src-stx (mark-source (list-ref stack-frames frame-num))] - [start (syntax-position src-stx)] - [end (and start (+ start (syntax-span src-stx) -1))]) - (list start end))))) + (cond + [(cons? stack-frames) + (define src-stx (mark-source (list-ref stack-frames frame-num))) + (define start (syntax-position src-stx)) + (define end (and start (+ start (syntax-span src-stx) -1))) + (list start end)] + [else #f]))) (define/public (get-current-frame-endpoints) (get-frame-endpoints (get-frame-num))) @@ -1234,21 +1243,20 @@ (define/public (register-stack-frames frames already-stopped?) (define trimmed-exprs - (map (lambda (frame) - (let ([expr (mark-source frame)]) - (cond - ; should succeed unless the user closes a secondary tab during debugging - [(and expr (filename->defs (syntax-source expr))) - => - (lambda (defs) - (trim-expr-str (if (syntax-position expr) - (send defs get-text - (sub1 (syntax-position expr)) - (+ -1 (syntax-position expr) (syntax-span expr))) - "??") - 15))] - ["??"]))) - frames)) + (for/list ([frame (in-list frames)]) + (define expr (mark-source frame)) + (cond + ; should succeed unless the user closes a secondary tab during debugging + [(and expr (filename->defs (syntax-source expr))) + => + (lambda (defs) + (trim-expr-str (if (syntax-position expr) + (send defs get-text + (sub1 (syntax-position expr)) + (+ -1 (syntax-position expr) (syntax-span expr))) + "??") + 15))] + ["??"]))) (send stack-frames begin-edit-sequence) (send stack-frames lock #f) (unless already-stopped?