Lookup.st
author Claus Gittinger <cg@exept.de>
Tue, 07 May 2013 15:58:24 +0200
changeset 15221 4d047c57a287
parent 13405 13dea24362ff
child 15957 b8ad4b672f8a
child 18011 deb0c3355881
permissions -rw-r--r--
class: ProjectDefinition changed: #productName

"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libbasic' }"

Object subclass:#Lookup
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Extensions'
!

!Lookup class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
! !

!Lookup class methodsFor:'initialization'!

initialize

    self lookupObject: Lookup builtin

    "Created: / 26-04-2010 / 21:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Lookup class methodsFor:'accessing'!

builtin

    ^BuiltinLookup instance

    "Created: / 26-04-2010 / 19:26:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Lookup methodsFor:'lookup'!

lookupMethodForSelector: selector directedTo: initialSearchClass

     |cls md method|

	"Following C code is just a performance optimization.
	 It is not neccessary, however it speeds up UI code,
	 since it heavily uses perform:"
%{
	RETURN (  __lookup(initialSearchClass, selector) );
%}.

     cls := initialSearchClass.
     [ cls notNil ] whileTrue:[
        md := cls methodDictionary.
        method := md at:selector ifAbsent:nil.
        method notNil ifTrue:[^ method ].
        cls := cls superclass.
     ].
     ^ nil

    "Created: / 27-04-2010 / 15:30:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext
    "invoked by the VM to ask me for a method to call.
     The arguments are: the selector, receiver and arguments,
     the class to start the search in (for here-, super and directed sends)
     the sending context.

     The returned method object will be put into the inline- and polyCache
     at the call site; it might therefore be called more than once for the
     same receiver-class/selector combination (once for each call site).
     If I return nil, a doesNotUnderstand will be invoked."

     |cls md method|

	"Following C code is just a performance optimization.
	 It is not neccessary, however it speeds up UI code,
	 since it heavily uses perform:"
%{
	RETURN (  __lookup(initialSearchClass, selector) );
%}.
    ^ self lookupMethodForSelector: selector 
		   directedTo: initialSearchClass


! !

!Lookup class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic/Lookup.st,v 1.2 2011-06-28 11:04:17 cg Exp $'
!

version_SVN
    ^ '§Id: Lookup.st,v 1.1 2011/06/28 10:51:38 vrany Exp §'
! !

Lookup initialize!