--- a/NamespaceAwareLookup.st Mon May 18 01:57:27 2015 +0200
+++ b/NamespaceAwareLookup.st Mon May 18 02:05:38 2015 +0200
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
- All Rights Reserved
+ All Rights Reserved
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
@@ -37,7 +37,7 @@
copyright
"
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
- All Rights Reserved
+ All Rights Reserved
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
@@ -83,119 +83,122 @@
!NamespaceAwareLookup class methodsFor:'lookup'!
-lookupMethodForSelector: selector directedTo: initialSearchClass for: receiver withArguments: argArrayOrNil from: sendingContext
+lookupMethodForSelector: selector directedTo: initialSearchClass for: receiver withArguments: argArrayOrNil from: sendingContext
"JV @ 2010-07-24
Following C code is just a performance optimization.
It is not neccessary, however it speeds things in most
cases. Such optimization significantly speeds up the IDE
since class browser involves dozens of super-polymorphic
- sends (> 1000 receiver classes per send-site).
+ sends (> 1000 receiver classes per send-site).
"
-%{
+%{
OBJ sendingMthd = __ContextInstPtr(sendingContext)->c_method;
- if (__Class(sendingMthd) == Method &&
- __MethodInstPtr(sendingMthd)->m_annotation == nil) {
- OBJ m = __lookup(initialSearchClass, selector);
- if (m != nil) RETURN ( m );
- }
+ if (__Class(sendingMthd) == Method &&
+ __MethodInstPtr(sendingMthd)->m_annotation == nil) {
+ OBJ m = __lookup(initialSearchClass, selector);
+ if (m != nil) RETURN ( m );
+ }
%}.
^Instance lookupMethodForSelector: selector directedTo: initialSearchClass
- for: receiver withArguments: argArrayOrNil
- from: sendingContext
+ for: receiver withArguments: argArrayOrNil
+ from: sendingContext
! !
!NamespaceAwareLookup methodsFor:'lookup'!
-lookupMethodForSelector: selector directedTo: initialSearchClass for: receiver withArguments: argArrayOrNil from: sendingContext ilc: ilcCache
+lookupMethodForSelector: selector directedTo: initialSearchClass for: receiver withArguments: argArrayOrNil from: sendingContext ilc: ilcCache
"Invoked by the VM to ask me for a method to fire.
For details, see comment inLookup>>lookupMethodForSelector:directedTo:for:withArguments:from:"
- | sendingNs sendingMthd queue seen namespaces methods imports |
+ | sendingNs sendingMthd queue seen namespaces methods imports numMethods|
"JV @ 2010-07-24
Following C code is just a performance optimization.
It is not neccessary, however it speeds things in most
cases. Such optimization significantly speeds up the IDE
since class browser involves dozens of super-polymorphic
- sends (> 1000 receiver classes per send-site).
- "
-%{
+ sends (> 1000 receiver classes per send-site).
+ "
+%{
sendingMthd = __ContextInstPtr(sendingContext)->c_method;
- if (__Class(sendingMthd) == Method &&
- __MethodInstPtr(sendingMthd)->m_annotation == nil) {
- OBJ m = __lookup(initialSearchClass, selector);
- if (m != nil) {
- if (ilcCache != nil) __ilcBind(ilcCache, initialSearchClass, m, selector);
- RETURN ( m );
- }
- }
+ if (__Class(sendingMthd) == Method &&
+ __MethodInstPtr(sendingMthd)->m_annotation == nil) {
+ OBJ m = __lookup(initialSearchClass, selector);
+ if (m != nil) {
+ if (ilcCache != nil) __ilcBind(ilcCache, initialSearchClass, m, selector);
+ RETURN ( m );
+ }
+ }
%}.
"If you remove C code above, uncomment the line below."
"sendingMthd := sendingContext method."
sendingNs := sendingMthd isNil
- ifTrue:[nil]
- ifFalse:[sendingMthd nameSpace].
+ ifTrue:[nil]
+ ifFalse:[sendingMthd nameSpace].
- "Second chance to speed up things (in case sending method
- has resource or so)"
+ "Second chance to speed up things (in case sending method
+ has resource or so)"
%{
if (sendingNs == nil) {
- OBJ m = __lookup(initialSearchClass, selector);
- if (m != nil) {
- if (ilcCache != nil) __ilcBind(ilcCache, initialSearchClass, m, selector);
- RETURN ( m );
- }
+ OBJ m = __lookup(initialSearchClass, selector);
+ if (m != nil) {
+ if (ilcCache != nil) __ilcBind(ilcCache, initialSearchClass, m, selector);
+ RETURN ( m );
+ }
}
%}.
"
Stderr
- show: 'sel='; show: selector; show: ' ns='; show: sendingNs printString;
- show: ' method=', sendingMthd printString; cr.
- "
-
+ show: 'sel='; show: selector; show: ' ns='; show: sendingNs printString;
+ show: ' method=', sendingMthd printString; cr.
+ "
+
sendingNs notNil ifTrue: [
-
- seen := Set new.
- namespaces := Array with: sendingNs.
+ seen := Set new.
+ namespaces := Array with: sendingNs.
- [namespaces notEmpty] whileTrue:
- [
- methods := self
- lookupMethodsForSelector: selector
- directedTo: initialSearchClass
- inNamespaces: namespaces.
- methods size == 1 ifTrue:
- [^methods anyOne].
- methods size > 1 ifTrue:
- [^self ambiguousMessageSend: selector
- withArgs: argArrayOrNil].
- "No method found"
- seen addAll: namespaces.
- imports := Set new.
- namespaces do:
- [:namespace|
- namespace notNil ifTrue:
- [namespace imports do:
- [:import|
- (seen includes: import) ifFalse:
- [imports add: import]]]].
- namespaces := imports].
- ].
-
- methods := self lookupMethodsForSelector: selector
- directedTo: initialSearchClass.
+ [namespaces notEmpty] whileTrue:[
+ methods := self
+ lookupMethodsForSelector: selector
+ directedTo: initialSearchClass
+ inNamespaces: namespaces.
+ numMethods := methods size.
+ numMethods == 1 ifTrue:[
+ ^ methods anyOne
+ ].
+ numMethods > 1 ifTrue:[
+ ^self ambiguousMessageSend: selector withArgs: argArrayOrNil
+ ].
+ "No method found"
+ seen addAll: namespaces.
+ imports := Set new.
+ namespaces do:[:namespace|
+ namespace notNil ifTrue:[
+ namespace imports do:[:import|
+ (seen includes: import) ifFalse: [
+ imports add: import
+ ]
+ ]
+ ]
+ ].
+ namespaces := imports
+ ].
+ ].
+
+ methods := self lookupMethodsForSelector: selector
+ directedTo: initialSearchClass.
methods size == 1 ifTrue:[
- | m |
+ | m |
- m := methods anyOne.
- ilcCache notNil ifTrue:[ ilcCache bindTo: m forClass: initialSearchClass ].
- ^ m
+ m := methods anyOne.
+ ilcCache notNil ifTrue:[ ilcCache bindTo: m forClass: initialSearchClass ].
+ ^ m
].
-
+
^nil
"Created: / 19-02-2014 / 21:49:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -203,31 +206,31 @@
!NamespaceAwareLookup methodsFor:'lookup - helpers'!
-lookupMethodsForSelector: selector directedTo: initialSearchClass
-
+lookupMethodsForSelector: selector directedTo: initialSearchClass
"Searches initialSearchClass for a methods with in any namespace"
- ^self
- lookupMethodsForSelector: selector
- directedTo: initialSearchClass
- suchThat:[:sel :mthd|true].
+
+ ^self
+ lookupMethodsForSelector: selector
+ directedTo: initialSearchClass
+ suchThat:[:sel :mthd|true].
"Created: / 19-07-2010 / 15:37:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
lookupMethodsForSelector: selector directedTo: initialSearchClass inNamespaces: namespaces
+ "Searches initialSearchClass for a methods with given selector in given namespaces."
- "Searches initialSearchClass for a methods with given selector in given namespaces."
- ^self
- lookupMethodsForSelector: selector
- directedTo: initialSearchClass
- suchThat:[:sel :mthd|namespaces includes: mthd nameSpace].
+ ^self
+ lookupMethodsForSelector: selector
+ directedTo: initialSearchClass
+ suchThat:[:sel :mthd|namespaces includes: mthd nameSpace].
"Created: / 19-07-2010 / 15:13:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
lookupMethodsForSelector: selector directedTo: initialSearchClass suchThat: block
+ "Searches initialSearchClass for a method with given selector in given nameSpace.
- "Searches initialSearchClass for a method with given selector in given nameSpace.
if no method in given namespace is found, returns nil"
| searchClass methods seen |
@@ -235,15 +238,18 @@
searchClass := initialSearchClass.
methods := Set new.
seen := OrderedCollection new.
- [ searchClass notNil ] whileTrue:
- [searchClass selectorsAndMethodsDo:
- [:sel :mthd|
- (sel selector = selector
- and:[(seen includes: mthd nameSpace) not
- and:[block value: sel value: mthd]]) ifTrue:
- [methods add: mthd.
- seen add: mthd nameSpace]].
- searchClass := searchClass superclass].
+ [ searchClass notNil ] whileTrue:[
+ searchClass selectorsAndMethodsDo:[:sel :mthd|
+ (sel selector = selector
+ and:[ (seen includes: mthd nameSpace) not
+ and:[ block value: sel value: mthd]]
+ ) ifTrue:[
+ methods add: mthd.
+ seen add: mthd nameSpace
+ ]
+ ].
+ searchClass := searchClass superclass
+ ].
^methods
"Created: / 19-07-2010 / 15:34:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -255,10 +261,10 @@
ambiguousMessageSend
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: #()
- )
+ (Message
+ selector: #__placeholder__
+ arguments: #()
+ )
"Created: / 19-08-2010 / 22:05:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
@@ -268,22 +274,23 @@
| trampoline |
trampoline := self class methodDictionary at:
- (#(" 0"ambiguousMessageSend
- " 1"ambiguousMessageSendWith:
- " 2"ambiguousMessageSendWith:with:
- " 3"ambiguousMessageSendWith:with:with:
- " 4"ambiguousMessageSendWith:with:with:with:
- " 5"ambiguousMessageSendWith:with:with:with:with:
- " 6"ambiguousMessageSendWith:with:with:with:with:with:
- " 7"ambiguousMessageSendWith:with:with:with:with:with:with:
- " 8"ambiguousMessageSendWith:with:with:with:with:with:with:with:
- )
- at: argArrayOrNil size + 1).
+ (#(" 0"ambiguousMessageSend
+ " 1"ambiguousMessageSendWith:
+ " 2"ambiguousMessageSendWith:with:
+ " 3"ambiguousMessageSendWith:with:with:
+ " 4"ambiguousMessageSendWith:with:with:with:
+ " 5"ambiguousMessageSendWith:with:with:with:with:
+ " 6"ambiguousMessageSendWith:with:with:with:with:with:
+ " 7"ambiguousMessageSendWith:with:with:with:with:with:with:
+ " 8"ambiguousMessageSendWith:with:with:with:with:with:with:with:
+ )
+ at: argArrayOrNil size + 1).
trampoline := trampoline asByteCodeMethod.
- 1 to: trampoline numLiterals do:
- [:litNr|
- (trampoline literalAt: litNr) == #__placeholder__
- ifTrue:[(trampoline literalAt: litNr put: selector)]].
+ 1 to: trampoline numLiterals do: [:litNr|
+ (trampoline literalAt: litNr) == #__placeholder__ ifTrue:[
+ (trampoline literalAt: litNr put: selector)
+ ]
+ ].
^trampoline
"Created: / 19-08-2010 / 22:09:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -292,10 +299,10 @@
ambiguousMessageSendWith: a1
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1)
+ )
"Created: / 19-08-2010 / 22:06:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
@@ -303,10 +310,10 @@
ambiguousMessageSendWith: a1 with: a2
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2)
+ )
"Created: / 19-08-2010 / 22:06:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
@@ -314,10 +321,10 @@
ambiguousMessageSendWith: a1 with: a2 with: a3
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2 with: a3)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2 with: a3)
+ )
"Created: / 19-08-2010 / 22:06:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
@@ -325,62 +332,62 @@
ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2 with: a3 with: a4)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2 with: a3 with: a4)
+ )
"Created: / 19-08-2010 / 22:06:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
- with: a5
+ with: a5
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2 with: a3 with: a4
- with: a5)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5)
+ )
"Created: / 19-08-2010 / 22:07:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
- with: a5 with: a6
+ with: a5 with: a6
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2 with: a3 with: a4
- with: a5 with: a6)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6)
+ )
"Created: / 19-08-2010 / 22:07:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
- with: a5 with: a6 with: a7
+ with: a5 with: a6 with: a7
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2 with: a3 with: a4
- with: a5 with: a6 with: a7)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6 with: a7)
+ )
"Created: / 19-08-2010 / 22:07:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
- with: a5 with: a6 with: a7 with: a8
+ with: a5 with: a6 with: a7 with: a8
^self ambiguousMessage:
- (Message
- selector: #__placeholder__
- arguments: (Array with: a1 with: a2 with: a3 with: a4
- with: a5 with: a6 with: a7 with: a8)
- )
+ (Message
+ selector: #__placeholder__
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6 with: a7 with: a8)
+ )
"Created: / 19-08-2010 / 22:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
@@ -388,11 +395,11 @@
!NamespaceAwareLookup class methodsFor:'documentation'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/NamespaceAwareLookup.st,v 1.3 2014-02-19 21:51:45 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/NamespaceAwareLookup.st,v 1.4 2015-05-18 00:05:38 cg Exp $'
!
version_SVN
- ^ '$Id: NamespaceAwareLookup.st,v 1.3 2014-02-19 21:51:45 vrany Exp $'
+ ^ '$Id: NamespaceAwareLookup.st,v 1.4 2015-05-18 00:05:38 cg Exp $'
! !