# HG changeset patch # User Claus Gittinger # Date 1482490615 -3600 # Node ID 193f12bef212fca2a0c1d12746dc9e1038fe1e1d # Parent 487ba1856c8e239086c3a72349613fc5d6e8fb65 #FEATURE by cg class: SmallSense::SmalltalkInferencer diff -r 487ba1856c8e -r 193f12bef212 SmallSense__SmalltalkInferencer.st --- a/SmallSense__SmalltalkInferencer.st Fri Dec 23 11:56:37 2016 +0100 +++ b/SmallSense__SmalltalkInferencer.st Fri Dec 23 11:56:55 2016 +0100 @@ -74,8 +74,8 @@ documentation " A heart of SmallSense - a type inferencer. For given class - and method source, instance of inferences walks the parse tree - and annotate each node with inferred type. + and method source, instance of inferencer walks the parse tree + and annotates each node with inferred type. [author:] @@ -610,15 +610,31 @@ ^ self. ]. - "/ Some selectors are known / expected to return some numerical values + "/ Some selectors are known / expected to return integer + (#( #indexOf: #lastIndexOf: #indexOf:startingAt: #lastIndexOf:startingAt: + #indexOf:ifAbsent: #lastIndexOf:ifAbsent: + #indexOf:startingAt:ifAbsent: #lastIndexOf:startingAt:ifAbsent: + #findFirst: #findFirst:ifNone: #findFirst:startingAt: + ) includes: selector) ifTrue:[ + aMessageNode inferedType: (Type withClass: Integer). + ^ self. + ]. + + "/ Some selectors are known / expected to return some numerical values (#( #+ #- #* #/ #// #\\ ) includes: selector) ifTrue:[ - "/ cg: is this true ? I thnk we should return Magnitude here (think of Charcters...) + "/ cg: is this true ? I think we should return Magnitude here (think of Characters...) aMessageNode inferedType: (Type withClass: Number). ^ self. ]. + "/ Some selectors are known / expected to return a value holder + (#( asValue ) includes: selector) ifTrue:[ + aMessageNode inferedType: (Type withClass: ValueHolder). + ^ self. + ]. + "/ #new / #basicNew: conventionally returns an instance of the class, if receiver is a class. - (#(#new: #basicNew:) includes: selector) ifTrue:[ + (#(#new #basicNew #new: #basicNew:) includes: selector) ifTrue:[ | rec type | rec := aMessageNode receiver. (rec isSelf and:[class isMetaclass]) ifTrue:[