Some tweaks in inferences - more support for "known selectors", like ,#==, #+ or: #class.
There are more known selectors to add...
--- a/SmallSense__SmalltalkInferencer.st Fri Jul 25 21:15:22 2014 +0100
+++ b/SmallSense__SmalltalkInferencer.st Tue Aug 05 14:10:28 2014 +0100
@@ -41,6 +41,13 @@
privateIn:SmalltalkInferencer
!
+SmalltalkParseNodeVisitor subclass:#Phase3
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:SmalltalkInferencer
+!
+
!SmalltalkInferencer class methodsFor:'documentation'!
copyright
@@ -207,12 +214,14 @@
Phase1 process: tree in: class.
+ Phase2 process: tree in: class.
"
(SmallSenseParseNodeInspector new node: tree source: source) open
"
"Created: / 26-11-2011 / 12:51:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 05-08-2014 / 14:04:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
parse
@@ -266,6 +275,7 @@
"Modified: / 21-03-2014 / 19:00:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+
!SmalltalkInferencer::Phase1 methodsFor:'initialization'!
initialize
@@ -499,6 +509,45 @@
"Modified: / 18-09-2013 / 01:26:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+visitVariableNode:anObject
+
+ | t |
+
+ "Following code ensures, that all variable nodes refering same
+ variable shares the inferred type"
+ t := types at: anObject name ifAbsentPut:[Type unknown].
+ anObject inferedType: t.
+
+ anObject isGlobalVariable ifTrue:[
+ | global class |
+
+ global := Smalltalk at: anObject name asSymbol.
+ "/ Special hack for JAVA - its actually a JavaPackage...
+
+ global == (Smalltalk at: #JAVA) ifTrue:[
+ global := JavaPackage
+ ].
+ class := global class.
+
+ global notNil ifTrue:[
+ t addClass: class.
+ t trustfullness: 100.
+ ].
+ ^self.
+ ].
+ anObject isClassVariable ifTrue:[
+ t addClass: (class theNonMetaclass classVarAt: anObject name asSymbol) class.
+ t trustfullness: 100.
+ ^self.
+ ].
+
+ "Created: / 26-11-2011 / 13:31:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 26-10-2013 / 10:08:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+
+!SmalltalkInferencer::Phase2 methodsFor:'visiting'!
+
visitUnaryNode:anObject
| type sel rec classes |
@@ -507,11 +556,14 @@
sel := anObject selector.
+ "/ #class should always return a class of the receiver...
sel == #class ifTrue:[
type := anObject receiver inferedType classSide.
anObject inferedType: type.
^self.
].
+
+ "/ #new / #basicNew: conventionally returns an instance of the class, if receiver is a class.
(sel == #new or:[sel == #basicNew]) ifTrue:[
rec := anObject receiver.
(rec isSelf and:[class isMetaclass]) ifTrue:[
@@ -556,60 +608,26 @@
"Created: / 27-11-2011 / 15:49:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 08-10-2013 / 11:07:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-visitVariableNode:anObject
-
- | t |
-
- "Following code ensures, that all variable nodes refering same
- variable shares the inferred type"
- t := types at: anObject name ifAbsentPut:[Type unknown].
- anObject inferedType: t.
-
- anObject isGlobalVariable ifTrue:[
- | global class |
-
- global := Smalltalk at: anObject name asSymbol.
- "/ Special hack for JAVA - its actually a JavaPackage...
-
- global == (Smalltalk at: #JAVA) ifTrue:[
- global := JavaPackage
- ].
- class := global class.
-
- global notNil ifTrue:[
- t addClass: class.
- t trustfullness: 100.
- ].
- ^self.
- ].
- anObject isClassVariable ifTrue:[
- t addClass: (class theNonMetaclass classVarAt: anObject name asSymbol) class.
- t trustfullness: 100.
- ^self.
- ].
-
- "Created: / 26-11-2011 / 13:31:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 26-10-2013 / 10:08:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 05-08-2014 / 13:56:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!SmalltalkInferencer::Phase2 methodsFor:'processing'!
+!SmalltalkInferencer::Phase3 class methodsFor:'documentation'!
-process: tree in: cls
-
- self process: tree in: cls info: (Manager instance infoForClass: cls)
+documentation
+"
+ Phase 3: guess types based on naming conventions. This is mainly to process
+ parameters in form of aString or aStringOrBoolean...
- "Created: / 26-11-2011 / 13:48:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+ [author:]
+ Jan Vrany <jan.vrany@fit.cvut.cz>
-process: tree in: cls info: clsInfo
+ [instance variables:]
- class := cls.
- classInfo := clsInfo.
- self visit: tree.
+ [class variables:]
- "Created: / 27-11-2011 / 16:22:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ [see also:]
+
+"
! !
!SmalltalkInferencer class methodsFor:'documentation'!