2010-04-23 16:08:01 +02:00
|
|
|
|
;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
2009-04-04 11:59:57 +02:00
|
|
|
|
;;;;
|
2009-03-17 23:11:56 +01:00
|
|
|
|
;;;; This library is free software; you can redistribute it and/or
|
|
|
|
|
|
;;;; modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License as published by the Free Software Foundation; either
|
|
|
|
|
|
;;;; version 2.1 of the License, or (at your option) any later version.
|
2009-04-04 11:59:57 +02:00
|
|
|
|
;;;;
|
2009-03-17 23:11:56 +01:00
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
2009-04-04 11:59:57 +02:00
|
|
|
|
;;;;
|
2009-03-17 23:11:56 +01:00
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License along with this library; if not, write to the Free Software
|
|
|
|
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-04-04 11:59:57 +02:00
|
|
|
|
;;;;
|
2009-03-17 23:11:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (system xref)
|
|
|
|
|
|
#:use-module (system base pmatch)
|
|
|
|
|
|
#:use-module (system base compile)
|
|
|
|
|
|
#:use-module (system vm program)
|
2009-03-28 21:57:26 -07:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2009-03-18 01:49:28 +01:00
|
|
|
|
#:export (*xref-ignored-modules*
|
|
|
|
|
|
procedure-callees
|
2010-09-10 13:29:56 +02:00
|
|
|
|
procedure-callers
|
|
|
|
|
|
source-procedures))
|
2009-03-17 23:11:56 +01:00
|
|
|
|
|
2010-09-10 12:55:09 +02:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; The cross-reference database: who calls whom.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(define (program-callee-rev-vars prog)
|
2009-03-28 21:57:26 -07:00
|
|
|
|
(define (cons-uniq x y)
|
|
|
|
|
|
(if (memq x y) y (cons x y)))
|
2009-03-17 23:11:56 +01:00
|
|
|
|
(cond
|
|
|
|
|
|
((program-objects prog)
|
|
|
|
|
|
=> (lambda (objects)
|
|
|
|
|
|
(let ((n (vector-length objects))
|
|
|
|
|
|
(progv (make-vector (vector-length objects) #f))
|
|
|
|
|
|
(asm (decompile (program-objcode prog) #:to 'assembly)))
|
|
|
|
|
|
(pmatch asm
|
de-nargs struct scm_objcode; procedure-property refactor
* libguile/objcodes.h (struct scm_objcode): Remove nargs, nrest, and
nlocs, as they are no longer needed. Also obviates the need for a
padding word.
* libguile/procs.c (scm_thunk_p): Use scm_i_program_arity for programs.
* libguile/procprop.c (scm_i_procedure_arity): Use scm_i_program_arity
for programs.
(scm_procedure_properties, scm_set_procedure_properties_x)
(scm_procedure_property, scm_set_procedure_property_x): Rework so that
non-closure properties are stored directly in a weak hash, instead of
needing a weak hash of "stand-in" closures to hold the properties. Fix
docstrings also.
* libguile/root.h (scm_stand_in_procs): Remove from the scm_sys_protects
set. Actually with libGC, we should be able to store the elements of
scm_sys_protects directly as global variables.
* libguile/gc.c (scm_init_storage): Remove scm_stand_in_procs
initialization.
* libguile/programs.c (scm_i_program_arity): New private accessor, tries
to determine the "minimum arity" of a program.
* libguile/vm.c (really_make_boot_program): Adapt to changes in
struct scm_objcode.
* module/language/assembly.scm (*program-header-len*, byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
Adapt to changes in objcode.
* module/system/xref.scm (program-callee-rev-vars): Adapt to changes in
assembly.
* module/language/glil.scm: Remove nargs, nrest, and nlocs from
glil-program.
* module/language/glil/compile-assembly.scm (make-meta, glil->assembly):
* module/language/glil/decompile-assembly.scm (decompile-toplevel):
(decompile-load-program): Adapt to changes in GLIL and assembly.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Adapt to
changes in GLIL.
* test-suite/tests/asm-to-bytecode.test: Adapt to assembly and bytecode
changes.
* test-suite/tests/tree-il.test: Adapt to GLIL changes.
2009-10-13 23:45:22 +02:00
|
|
|
|
((load-program ,labels ,len . ,body)
|
2009-03-17 23:11:56 +01:00
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(pmatch x
|
|
|
|
|
|
((toplevel-ref ,n) (vector-set! progv n #t))
|
|
|
|
|
|
((toplevel-set ,n) (vector-set! progv n #t))))
|
|
|
|
|
|
body)))
|
|
|
|
|
|
(let lp ((i 0) (out '()))
|
|
|
|
|
|
(cond
|
2009-03-18 01:49:28 +01:00
|
|
|
|
((= i n) out)
|
2009-03-17 23:11:56 +01:00
|
|
|
|
((program? (vector-ref objects i))
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(lp (1+ i)
|
2009-03-28 21:57:26 -07:00
|
|
|
|
(fold cons-uniq out
|
|
|
|
|
|
(program-callee-rev-vars (vector-ref objects i)))))
|
2009-03-17 23:11:56 +01:00
|
|
|
|
((vector-ref progv i)
|
|
|
|
|
|
(let ((obj (vector-ref objects i)))
|
|
|
|
|
|
(if (variable? obj)
|
2009-03-28 21:57:26 -07:00
|
|
|
|
(lp (1+ i) (cons-uniq obj out))
|
2009-03-17 23:11:56 +01:00
|
|
|
|
;; otherwise it's an unmemoized binding
|
|
|
|
|
|
(pmatch obj
|
|
|
|
|
|
(,sym (guard (symbol? sym))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
(let ((v (module-variable (or (program-module prog)
|
|
|
|
|
|
the-root-module)
|
|
|
|
|
|
sym)))
|
2009-03-28 21:57:26 -07:00
|
|
|
|
(lp (1+ i) (if v (cons-uniq v out) out))))
|
2009-03-17 23:11:56 +01:00
|
|
|
|
((,mod ,sym ,public?)
|
|
|
|
|
|
;; hm, hacky.
|
2010-04-23 16:08:01 +02:00
|
|
|
|
(let* ((m (nested-ref-module (resolve-module '() #f)
|
|
|
|
|
|
mod))
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(v (and m
|
|
|
|
|
|
(module-variable
|
|
|
|
|
|
(if public?
|
|
|
|
|
|
(module-public-interface m)
|
|
|
|
|
|
m)
|
|
|
|
|
|
sym))))
|
|
|
|
|
|
(lp (1+ i)
|
2009-03-28 21:57:26 -07:00
|
|
|
|
(if v (cons-uniq v out) out))))))))
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(else (lp (1+ i) out)))))))
|
2009-03-17 23:11:56 +01:00
|
|
|
|
(else '())))
|
|
|
|
|
|
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(define (procedure-callee-rev-vars proc)
|
2009-03-17 23:11:56 +01:00
|
|
|
|
(cond
|
2009-03-18 01:49:28 +01:00
|
|
|
|
((program? proc) (program-callee-rev-vars proc))
|
2009-03-17 23:16:35 +01:00
|
|
|
|
(else '())))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(define (procedure-callees prog)
|
2009-04-04 11:59:57 +02:00
|
|
|
|
"Evaluates to a list of the given program callees."
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(let lp ((in (procedure-callee-rev-vars prog)) (out '()))
|
|
|
|
|
|
(cond ((null? in) out)
|
|
|
|
|
|
((variable-bound? (car in))
|
|
|
|
|
|
(lp (cdr in) (cons (variable-ref (car in)) out)))
|
|
|
|
|
|
(else (lp (cdr in) out)))))
|
|
|
|
|
|
|
2009-04-04 11:59:57 +02:00
|
|
|
|
;; var -> ((module-name caller ...) ...)
|
2009-03-18 00:44:26 +01:00
|
|
|
|
(define *callers-db* #f)
|
2009-04-04 11:59:57 +02:00
|
|
|
|
;; module-name -> (callee ...)
|
|
|
|
|
|
(define *module-callees-db* (make-hash-table))
|
|
|
|
|
|
;; (module-name ...)
|
|
|
|
|
|
(define *tainted-modules* '())
|
2009-03-18 00:44:26 +01:00
|
|
|
|
|
|
|
|
|
|
(define *xref-ignored-modules* '((value-history)))
|
|
|
|
|
|
(define (on-module-modified m)
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(let ((name (module-name m)))
|
|
|
|
|
|
(if (and (not (member name *xref-ignored-modules*))
|
|
|
|
|
|
(not (member name *tainted-modules*))
|
|
|
|
|
|
(pair? name))
|
|
|
|
|
|
(set! *tainted-modules* (cons name *tainted-modules*)))))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(define (add-caller callee caller mod-name)
|
|
|
|
|
|
(let ((all-callers (hashq-ref *callers-db* callee)))
|
|
|
|
|
|
(if (not all-callers)
|
|
|
|
|
|
(hashq-set! *callers-db* callee `((,mod-name ,caller)))
|
|
|
|
|
|
(let ((callers (assoc mod-name all-callers)))
|
|
|
|
|
|
(if callers
|
|
|
|
|
|
(if (not (member caller callers))
|
|
|
|
|
|
(set-cdr! callers (cons caller (cdr callers))))
|
|
|
|
|
|
(hashq-set! *callers-db* callee
|
|
|
|
|
|
(cons `(,mod-name ,caller) all-callers)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (forget-callers callee mod-name)
|
|
|
|
|
|
(hashq-set! *callers-db* callee
|
|
|
|
|
|
(assoc-remove! (hashq-ref *callers-db* callee '()) mod-name)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (add-callees callees mod-name)
|
|
|
|
|
|
(hash-set! *module-callees-db* mod-name
|
|
|
|
|
|
(append callees (hash-ref *module-callees-db* mod-name '()))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (untaint-modules)
|
|
|
|
|
|
(define (untaint m)
|
|
|
|
|
|
(for-each (lambda (callee) (forget-callers callee m))
|
|
|
|
|
|
(hash-ref *module-callees-db* m '()))
|
|
|
|
|
|
(ensure-callers-db m))
|
|
|
|
|
|
(ensure-callers-db #f)
|
|
|
|
|
|
(for-each untaint *tainted-modules*)
|
|
|
|
|
|
(set! *tainted-modules* '()))
|
|
|
|
|
|
|
|
|
|
|
|
(define (ensure-callers-db mod-name)
|
|
|
|
|
|
(let ((mod (and mod-name (resolve-module mod-name)))
|
|
|
|
|
|
(visited #f))
|
2010-09-10 12:55:09 +02:00
|
|
|
|
(define (visit-variable var mod-name)
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(if (variable-bound? var)
|
|
|
|
|
|
(let ((x (variable-ref var)))
|
|
|
|
|
|
(cond
|
2009-04-04 11:59:57 +02:00
|
|
|
|
((and visited (hashq-ref visited x)))
|
2009-03-18 01:49:28 +01:00
|
|
|
|
((procedure? x)
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(if visited (hashq-set! visited x #t))
|
|
|
|
|
|
(let ((callees (filter variable-bound?
|
|
|
|
|
|
(procedure-callee-rev-vars x))))
|
|
|
|
|
|
(for-each (lambda (callee)
|
|
|
|
|
|
(add-caller callee x mod-name))
|
|
|
|
|
|
callees)
|
2010-09-10 12:55:09 +02:00
|
|
|
|
(add-callees callees mod-name)))))))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
|
2010-09-10 12:55:09 +02:00
|
|
|
|
(define (visit-module mod)
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(if visited (hashq-set! visited mod #t))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
(if (not (memq on-module-modified (module-observers mod)))
|
|
|
|
|
|
(module-observe mod on-module-modified))
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(let ((name (module-name mod)))
|
|
|
|
|
|
(module-for-each (lambda (sym var)
|
2010-09-10 12:55:09 +02:00
|
|
|
|
(visit-variable var name))
|
2009-04-04 11:59:57 +02:00
|
|
|
|
mod)))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
|
2010-09-10 12:55:09 +02:00
|
|
|
|
(define (visit-submodules mod)
|
|
|
|
|
|
(hash-for-each
|
|
|
|
|
|
(lambda (name sub)
|
|
|
|
|
|
(if (not (and visited (hashq-ref visited sub)))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(visit-module sub)
|
|
|
|
|
|
(visit-submodules sub))))
|
|
|
|
|
|
(module-submodules mod)))
|
|
|
|
|
|
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(cond ((and (not mod-name) (not *callers-db*))
|
|
|
|
|
|
(set! *callers-db* (make-hash-table 1000))
|
|
|
|
|
|
(set! visited (make-hash-table 1000))
|
2010-09-10 12:55:09 +02:00
|
|
|
|
(visit-submodules (resolve-module '() #f)))
|
|
|
|
|
|
(mod-name (visit-module mod)))))
|
2009-03-18 00:44:26 +01:00
|
|
|
|
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(define (procedure-callers var)
|
2009-04-04 11:59:57 +02:00
|
|
|
|
"Returns an association list, keyed by module name, of known callers
|
|
|
|
|
|
of the given procedure. The latter can specified directly as a
|
|
|
|
|
|
variable, a symbol (which gets resolved in the current module) or a
|
|
|
|
|
|
pair of the form (module-name . variable-name), "
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(let ((v (cond ((variable? var) var)
|
|
|
|
|
|
((symbol? var) (module-variable (current-module) var))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(pmatch var
|
|
|
|
|
|
((,modname . ,sym)
|
|
|
|
|
|
(module-variable (resolve-module modname) sym))
|
|
|
|
|
|
(else
|
2009-03-28 21:57:26 -07:00
|
|
|
|
(error "expected a variable, symbol, or (modname . sym)" var)))))))
|
2009-04-04 11:59:57 +02:00
|
|
|
|
(untaint-modules)
|
2009-03-18 01:49:28 +01:00
|
|
|
|
(hashq-ref *callers-db* v '())))
|
2010-09-10 13:29:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The source database: procedures defined at a given source location.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; FIXME: refactor to share code with the xref database.
|
|
|
|
|
|
|
|
|
|
|
|
;; ((ip file line . col) ...)
|
|
|
|
|
|
(define (procedure-sources proc)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((program? proc) (program-sources proc))
|
|
|
|
|
|
(else '())))
|
|
|
|
|
|
|
|
|
|
|
|
;; file -> line -> (proc ...)
|
|
|
|
|
|
(define *sources-db* #f)
|
|
|
|
|
|
;; module-name -> proc -> sources
|
|
|
|
|
|
(define *module-sources-db* (make-hash-table))
|
|
|
|
|
|
;; (module-name ...)
|
|
|
|
|
|
(define *tainted-sources* '())
|
|
|
|
|
|
|
|
|
|
|
|
(define (on-source-modified m)
|
|
|
|
|
|
(let ((name (module-name m)))
|
|
|
|
|
|
(if (and (not (member name *xref-ignored-modules*))
|
|
|
|
|
|
(not (member name *tainted-sources*))
|
|
|
|
|
|
(pair? name))
|
|
|
|
|
|
(set! *tainted-sources* (cons name *tainted-sources*)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (add-source proc file line)
|
|
|
|
|
|
(let ((file-table (or (hash-ref *sources-db* file)
|
|
|
|
|
|
(let ((table (make-hash-table)))
|
|
|
|
|
|
(hash-set! *sources-db* file table)
|
|
|
|
|
|
table))))
|
|
|
|
|
|
(hashv-set! file-table
|
|
|
|
|
|
line
|
|
|
|
|
|
(cons proc (hashv-ref file-table line '())))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (forget-source proc file line)
|
|
|
|
|
|
(let ((file-table (hash-ref *sources-db* file)))
|
|
|
|
|
|
(if file-table
|
|
|
|
|
|
(let ((procs (delq proc (hashv-ref file-table line '()))))
|
|
|
|
|
|
(if (pair? procs)
|
|
|
|
|
|
(hashv-set! file-table line procs)
|
|
|
|
|
|
(hashv-remove! file-table line))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (add-sources proc mod-name)
|
|
|
|
|
|
(let ((sources (procedure-sources proc)))
|
|
|
|
|
|
(if (pair? sources)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
;; Add proc to *module-sources-db*, for book-keeping.
|
|
|
|
|
|
(hashq-set! (or (hash-ref *module-sources-db* mod-name)
|
|
|
|
|
|
(let ((table (make-hash-table)))
|
|
|
|
|
|
(hash-set! *module-sources-db* mod-name table)
|
|
|
|
|
|
table))
|
|
|
|
|
|
proc
|
|
|
|
|
|
sources)
|
|
|
|
|
|
;; Actually add the source entries.
|
|
|
|
|
|
(for-each (lambda (source)
|
|
|
|
|
|
(pmatch source
|
|
|
|
|
|
((,ip ,file ,line . ,col)
|
|
|
|
|
|
(add-source proc file line))
|
|
|
|
|
|
(else (error "unexpected source format" source))))
|
|
|
|
|
|
sources)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (forget-sources proc mod-name)
|
|
|
|
|
|
(let ((mod-table (hash-ref *module-sources-db* mod-name)))
|
|
|
|
|
|
(if mod-table
|
|
|
|
|
|
(begin
|
|
|
|
|
|
;; Forget source entries.
|
|
|
|
|
|
(for-each (lambda (source)
|
|
|
|
|
|
(pmatch source
|
|
|
|
|
|
((,ip ,file ,line . ,col)
|
|
|
|
|
|
(forget-source proc file line))
|
|
|
|
|
|
(else (error "unexpected source format" source))))
|
|
|
|
|
|
(hashq-ref mod-table proc '()))
|
|
|
|
|
|
;; Forget the proc.
|
|
|
|
|
|
(hashq-remove! mod-table proc)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (untaint-sources)
|
|
|
|
|
|
(define (untaint m)
|
|
|
|
|
|
(for-each (lambda (proc) (forget-sources proc m))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((hash-ref *module-sources-db* m)
|
|
|
|
|
|
=> (lambda (table)
|
|
|
|
|
|
(hash-for-each (lambda (proc sources) proc) table)))
|
|
|
|
|
|
(else '())))
|
|
|
|
|
|
(ensure-sources-db m))
|
|
|
|
|
|
(ensure-sources-db #f)
|
|
|
|
|
|
(for-each untaint *tainted-sources*)
|
|
|
|
|
|
(set! *tainted-sources* '()))
|
|
|
|
|
|
|
|
|
|
|
|
(define (ensure-sources-db mod-name)
|
|
|
|
|
|
(define (visit-module mod)
|
|
|
|
|
|
(if (not (memq on-source-modified (module-observers mod)))
|
|
|
|
|
|
(module-observe mod on-source-modified))
|
|
|
|
|
|
(let ((name (module-name mod)))
|
|
|
|
|
|
(module-for-each
|
|
|
|
|
|
(lambda (sym var)
|
|
|
|
|
|
(if (variable-bound? var)
|
|
|
|
|
|
(let ((x (variable-ref var)))
|
|
|
|
|
|
(if (procedure? x)
|
|
|
|
|
|
(add-sources x name)))))
|
|
|
|
|
|
mod)))
|
|
|
|
|
|
|
|
|
|
|
|
(define visit-submodules
|
|
|
|
|
|
(let ((visited #f))
|
|
|
|
|
|
(lambda (mod)
|
|
|
|
|
|
(if (not visited)
|
|
|
|
|
|
(set! visited (make-hash-table)))
|
|
|
|
|
|
(hash-for-each
|
|
|
|
|
|
(lambda (name sub)
|
|
|
|
|
|
(if (not (hashq-ref visited sub))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(hashq-set! visited sub #t)
|
|
|
|
|
|
(visit-module sub)
|
|
|
|
|
|
(visit-submodules sub))))
|
|
|
|
|
|
(module-submodules mod)))))
|
|
|
|
|
|
|
|
|
|
|
|
(cond ((and (not mod-name) (not *sources-db*))
|
|
|
|
|
|
(set! *sources-db* (make-hash-table 1000))
|
|
|
|
|
|
(visit-submodules (resolve-module '() #f)))
|
|
|
|
|
|
(mod-name (visit-module (resolve-module mod-name)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (lines->ranges file-table)
|
|
|
|
|
|
(let ((ranges (make-hash-table)))
|
|
|
|
|
|
(hash-for-each
|
|
|
|
|
|
(lambda (line procs)
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (proc)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((hashq-ref ranges proc)
|
|
|
|
|
|
=> (lambda (pair)
|
|
|
|
|
|
(if (< line (car pair))
|
|
|
|
|
|
(set-car! pair line))
|
|
|
|
|
|
(if (> line (cdr pair))
|
|
|
|
|
|
(set-cdr! pair line))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(hashq-set! ranges proc (cons line line)))))
|
|
|
|
|
|
procs))
|
|
|
|
|
|
file-table)
|
|
|
|
|
|
(sort! (hash-map->list cons ranges)
|
|
|
|
|
|
(lambda (x y) (< (cadr x) (cadr y))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define* (source-procedures file line #:key (canonicalization 'relative))
|
|
|
|
|
|
(ensure-sources-db #f)
|
|
|
|
|
|
(let* ((port (with-fluids ((%file-port-name-canonicalization canonicalization))
|
|
|
|
|
|
(false-if-exception (open-input-file file))))
|
|
|
|
|
|
(file (if port (port-filename port) file))
|
|
|
|
|
|
(file-table (hash-ref *sources-db* file)))
|
|
|
|
|
|
(if file-table
|
|
|
|
|
|
(let lp ((ranges (lines->ranges file-table))
|
|
|
|
|
|
(procs '()))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? ranges) (reverse procs))
|
|
|
|
|
|
((<= (cadar ranges) line (cddar ranges))
|
|
|
|
|
|
(lp (cdr ranges) (cons (caar ranges) procs)))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(lp (cdr ranges) procs)))))))
|