Commit 3fca9094 authored by Pascal Costanza's avatar Pascal Costanza
Browse files

Turned warnings about missing generic functions for defmethod forms into style...

Turned warnings about missing generic functions for defmethod forms into style warnings, and provided a way to selectively disable/enable them.

Ignore-this: 7a6a9b4cf7a97523943207c0020c2ebb

darcs-hash:c505d79b84192052c5f02c0daf72bd1a09481838
parent e1c9cb01
......@@ -203,4 +203,6 @@
#:standard-instance-access
#:update-dependent
#:validate-superclass
#:writer-method-class))
#:writer-method-class
#:warn-on-defmethod-without-generic-function))
......@@ -388,12 +388,19 @@
(add-method gf method)
method))
(define-condition defmethod-without-generic-function (style-warning)
((name :initarg :name :reader dwg-name))
(:report (lambda (c s) (format s "No generic function present when encountering a defmethod for ~S. Assuming it will be an instance of standard-generic-function." (dwg-name c)))))
(define-symbol-macro warn-on-defmethod-without-generic-function t)
(defmacro defmethod (&whole form name &body body &environment env)
(loop with generic-function = (when (fboundp name) (fdefinition name))
initially
(unless generic-function
(warn "No generic function ~S present when encountering macroexpansion of defmethod. Assuming it will be an instance of standard-generic-function." name))
(when (macroexpand 'warn-on-defmethod-without-generic-function env)
(unless generic-function
(warn 'defmethod-without-generic-function :name name)))
(unless (typep generic-function 'standard-generic-function)
(return-from defmethod `(cl:defmethod ,@(cdr form))))
(when (only-standard-methods generic-function)
......
......@@ -209,4 +209,6 @@
#:standard-instance-access
#:update-dependent
#:validate-superclass
#-lispworks4.3 #:writer-method-class))
#-lispworks4.3 #:writer-method-class
#:warn-on-defmethod-without-generic-function))
......@@ -786,12 +786,19 @@
(add-method gf method)
method))
(define-condition defmethod-without-generic-function (style-warning)
((name :initarg :name :reader dwg-name))
(:report (lambda (c s) (format s "No generic function present when encountering a defmethod for ~S. Assuming it will be an instance of standard-generic-function." (dwg-name c)))))
(define-symbol-macro warn-on-defmethod-without-generic-function t)
(defmacro defmethod (&whole form name &body body &environment env)
(loop with generic-function = (when (fboundp name) (fdefinition name))
initially
(unless generic-function
(warn "No generic function ~S present when encountering macroexpansion of defmethod. Assuming it will be an instance of standard-generic-function." name))
(when (macroexpand 'warn-on-defmethod-without-generic-function env)
(unless generic-function
(warn 'defmethod-without-generic-function :name name)))
(unless (typep generic-function 'standard-generic-function)
(return-from defmethod `(cl:defmethod ,@(cdr form))))
(when (only-standard-methods generic-function)
......
......@@ -212,4 +212,6 @@
#-ccl #:typep
#:update-dependent
#:validate-superclass
#:writer-method-class))
#:writer-method-class
#+ccl #:warn-on-defmethod-without-generic-function))
......@@ -640,12 +640,19 @@
(add-method gf method)
method))
(define-condition defmethod-without-generic-function (style-warning)
((name :initarg :name :reader dwg-name))
(:report (lambda (c s) (format s "No generic function present when encountering a defmethod for ~S. Assuming it will be an instance of standard-generic-function." (dwg-name c)))))
(define-symbol-macro warn-on-defmethod-without-generic-function t)
(defmacro defmethod (&whole form name &body body &environment env)
(loop with generic-function = (when (fboundp name) (fdefinition name))
initially
(unless generic-function
(warn "No generic function ~S present when encountering macroexpansion of defmethod. Assuming it will be an instance of standard-generic-function." name))
(when (macroexpand 'warn-on-defmethod-without-generic-function env)
(unless generic-function
(warn 'defmethod-without-generic-function :name name)))
(unless (typep generic-function 'standard-generic-function)
(return-from defmethod `(cl:defmethod ,@(cdr form))))
(when (only-standard-methods generic-function)
......
......@@ -216,4 +216,6 @@
#:typep
#:update-dependent
#:validate-superclass
#:writer-method-class))
#:writer-method-class
#+sbcl warn-on-defmethod-without-generic-function))
......@@ -399,11 +399,18 @@
(eval-when (:load-toplevel :execute)
(cl:defgeneric ,name ,args ,@options)))))
(defmacro defmethod (&whole form name &body body)
(define-condition defmethod-without-generic-function (style-warning)
((name :initarg :name :reader dwg-name))
(:report (lambda (c s) (format s "No generic function present when encountering a defmethod for ~S. Assuming it will be an instance of standard-generic-function." (dwg-name c)))))
(define-symbol-macro warn-on-defmethod-without-generic-function nil)
(defmacro defmethod (&whole form name &body body &environment env)
(declare (ignore body))
(let ((generic-function (when (fboundp name) (fdefinition name))))
(unless generic-function
(warn "No generic function ~S present when encountering macroexpansion of defmethod. Assuming it will be an instance of standard-generic-function." name))
(when (macroexpand 'warn-on-defmethod-without-generic-function env)
(unless generic-function
(warn 'defmethod-without-generic-function :name name)))
`(cl:defmethod ,@(cdr form)))))
#+sbcl
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment