From: Joe Marshall Date: Tue, 9 Feb 2010 18:01:25 +0000 (-0800) Subject: Add IGNORABLE declaration for variables. Issue warning if variable is IGNORE, but... X-Git-Tag: 20100708-Gtk~168^2~18 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3d7fa885768575f03bbd661cd266ccaf346eaf42;p=mit-scheme.git Add IGNORABLE declaration for variables. Issue warning if variable is IGNORE, but used anyway. --- diff --git a/src/sf/cgen.scm b/src/sf/cgen.scm index 7cb7fb8a5..f81e6f3ce 100644 --- a/src/sf/cgen.scm +++ b/src/sf/cgen.scm @@ -217,6 +217,9 @@ USA. (define-method/cgen 'REFERENCE (lambda (interns expression) + (if (variable/must-ignore? (reference/variable expression)) + (warn "Variable declared IGNORE, but was used: " + (variable/name (reference/variable expression)))) (cgen/variable interns (reference/variable expression)))) (define-method/cgen 'SEQUENCE diff --git a/src/sf/object.scm b/src/sf/object.scm index 79fbc1120..4b86532cc 100644 --- a/src/sf/object.scm +++ b/src/sf/object.scm @@ -196,7 +196,8 @@ USA. (define-flag SIDE-EFFECTED variable/side-effected variable/side-effect!) (define-flag REFERENCED variable/referenced variable/reference!) (define-flag INTEGRATED variable/integrated variable/integrated!) -(define-flag CAN-IGNORE variable/can-ignore? variable/can-ignore!) +(define-flag MAY-IGNORE variable/may-ignore? variable/may-ignore!) +(define-flag MUST-IGNORE variable/must-ignore? variable/must-ignore!) (define open-block/value-marker ;; This must be an interned object because we will fasdump it and diff --git a/src/sf/pardec.scm b/src/sf/pardec.scm index c4451d75d..5b2694b8f 100644 --- a/src/sf/pardec.scm +++ b/src/sf/pardec.scm @@ -306,11 +306,25 @@ USA. ;;;; Flag Declarations +;; IGNORABLE suppresses warnings about the variable not being used. +;; This is useful in macros that bind variables that the body may +;; not actually use. Mentioning the variable in a sequence will +;; have the effect of marking it ignorable. +(define-declaration 'IGNORABLE + (lambda (block names) + (for-each (lambda (variable) + (if variable + (variable/may-ignore! variable))) + (block/lookup-names block names #f)) + '())) + +;; IGNORE causes warnings if an ignored variable actually ends +;; up being used. (define-declaration 'IGNORE (lambda (block names) (for-each (lambda (variable) (if variable - (variable/can-ignore! variable))) + (variable/must-ignore! variable))) (block/lookup-names block names #f)) '())) diff --git a/src/sf/subst.scm b/src/sf/subst.scm index 5fb5f3421..dfac87893 100644 --- a/src/sf/subst.scm +++ b/src/sf/subst.scm @@ -219,7 +219,8 @@ USA. (define (variable/unreferenced? variable) (and (not (variable/integrated variable)) (not (variable/referenced variable)) - (not (variable/can-ignore? variable)))) + (not (variable/may-ignore? variable)) + (not (variable/must-ignore? variable)))) (define-method/integrate 'PROCEDURE (lambda (operations environment procedure) @@ -588,7 +589,7 @@ USA. (cons (cond ((reference? action) ;; This clause lets you ignore a variable by ;; mentioning it in a sequence. - (variable/can-ignore! (reference/variable action)) + (variable/may-ignore! (reference/variable action)) action) ((eq? action open-block/value-marker) action)