;;; -*- Mode: Common-Lisp; Package: TICLOS; Base: 10.; Patch-File: T -*-

;;; Reason: Compute-applicable-methods fix to not include NILs in the list [SPR 10199]  and add check for wrong number of arguments. [SPR 10330].

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 01/18/90 12:45:16 by BERGER,
;;; while running on ARIES from band LOD1
;;; With SYSTEM 6.28, VIRTUAL-MEMORY 6.3, EH 6.5, MAKE-SYSTEM 6.2, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.2, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.7, NETWORK-NAMESPACE 6.1,
;;;  DISK-IO 6.2, DISK-LABEL 6.0, BASIC-FILE 6.7, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.14, TV 6.22, DATALINK 6.0, CHAOSNET 6.5, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.2,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.5, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.12,
;;;  DEBUG-TOOLS 6.4, NETWORK-SUPPORT 6.1, NETWORK-SERVICE 6.2, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.4, MAIL-READER 6.6, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.4, PROFILE 6.2, VISIDOC 6.7, Inconsistent TI-CLOS 6.30, CLEH 6.5,
;;;  IP 3.57, Experimental CLX 6.8, CLUE 6.46, X11M 6.20, Experimental BUG 11.17,
;;;   microcode 431, Band Name: REl 6.0 SLE 12/28

#!C
; From file GENERIC.LISP#> CLOS; SYS:
#10R TICLOS#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TICLOS"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: CLOS; GENERIC.#"


(defun compute-applicable-methods (generic-function  args)
  "Return the list of methods that are applicable for the given generic function
and list of argument values.  The result is sorted by precedence order."
  ;;note that reorder-parameter-specializer will throw away non
  ;;required arguments.
  ;;The result is sorted by precedence order.
  (let ((gfunc (generic-function-named generic-function)))
    (check-type args list)
    (unless (= (length args) (length (generic-function-argument-precedence-order gfunc)))
      (error "Wrong number of arguments for ~S." gfunc))
    (labels ((cam (alist args)
		  (if (null args)
		      (collect-body
			(dolist (m alist)
			  (let ((method (method-spec-object-method m)))
			    (cond ((null method) nil) ; DAB 01-18-90
				  ((typep method 'standard-accessor-method)
				   (collect method))
				  ((combined-method-p method)
				   nil)
				  (t 
				   (collect method))))))
		      (let ((sublist (get-sorted-alists-by-value (car args) alist)))
			(and sublist
			     (collect-body 
			       (dolist (ael sublist)
				 (join (cam (cdr ael) (cdr args))))))))))
      (cam (generic-function-method-list gfunc)
	   (reorder-parameter-specializers gfunc args)))))
))
