From 2adedd10d43244f58e794aa9d8ad2dc4c43c80df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20D=C5=BEeri=C5=86=C5=A1?= Date: Thu, 23 May 2013 19:18:58 +0300 Subject: [PATCH] Suppress warnings for register-groups-bind with empty var-list If (for some reason) the var-list is empty, there is no code generated that uses the reg-starts and reg-ends variables, and hence they become unused. And without the bindings, the substr-fn is also not necessary. --- api.lisp | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/api.lisp b/api.lisp index 9b0d451..21550e1 100644 --- a/api.lisp +++ b/api.lisp @@ -332,28 +332,32 @@ substrings may share structure with TARGET-STRING." (with-rebinding (target-string) (with-unique-names (match-start match-end reg-starts reg-ends start-index substr-fn) - `(multiple-value-bind (,match-start ,match-end ,reg-starts ,reg-ends) - (scan ,regex ,target-string :start (or ,start 0) - :end (or ,end (length ,target-string))) - (declare (ignore ,match-end)) - (when ,match-start - (let* ,(cons - `(,substr-fn (if ,sharedp - #'nsubseq - #'subseq)) - (loop for (function var) in (normalize-var-list var-list) - for counter from 0 - when var - collect `(,var (let ((,start-index - (aref ,reg-starts ,counter))) - (if ,start-index - (funcall ,function - (funcall ,substr-fn - ,target-string - ,start-index - (aref ,reg-ends ,counter))) - nil))))) - ,@body)))))) + (let ((var-bindings + (loop for (function var) in (normalize-var-list var-list) + for counter from 0 + when var + collect `(,var (let ((,start-index + (aref ,reg-starts ,counter))) + (if ,start-index + (funcall ,function + (funcall ,substr-fn + ,target-string + ,start-index + (aref ,reg-ends ,counter))) + nil)))))) + `(multiple-value-bind (,match-start ,match-end ,reg-starts ,reg-ends) + (scan ,regex ,target-string :start (or ,start 0) + :end (or ,end (length ,target-string))) + (declare (ignore ,match-end)) + ,@(unless var-bindings + `((declare (ignore ,reg-starts ,reg-ends)))) + (when ,match-start + ,@(if var-bindings + `((let* ,(list* + `(,substr-fn (if ,sharedp #'nsubseq #'subseq)) + var-bindings) + ,@body)) + body))))))) (defmacro do-scans ((match-start match-end reg-starts reg-ends regex target-string