Add IGNORABLE declaration for variables. Issue warning if variable is IGNORE, but...
authorJoe Marshall <jmarshall@alum.mit.edu>
Tue, 9 Feb 2010 18:01:25 +0000 (10:01 -0800)
committerJoe Marshall <jmarshall@alum.mit.edu>
Tue, 9 Feb 2010 18:01:25 +0000 (10:01 -0800)
src/sf/cgen.scm
src/sf/object.scm
src/sf/pardec.scm
src/sf/subst.scm

index 7cb7fb8a5c51281884a90e6dc2356b51c21d1a30..f81e6f3ce1cf21bbc7d79df0812accfee03d2b95 100644 (file)
@@ -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
index 79fbc11208ad7bc44e66d38fe865ccf090bb0d8a..4b86532cc7fddeb7bf98c525da28c1ac1cd6ee13 100644 (file)
@@ -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
index c4451d75de79feefc14a09479fcb4cbe37745222..5b2694b8f4363d0c58a857b7c682b802b77a556a 100644 (file)
@@ -306,11 +306,25 @@ USA.
 \f
 ;;;; 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))
     '()))
 \f
index 5fb5f3421f0afd7927dd58c7b7437b3e83822af8..dfac87893a98fe6bc4c135b5947b17b03a4294a2 100644 (file)
@@ -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)