added:
authorClaus Gittinger <cg@exept.de>
Fri, 06 Nov 2009 19:15:32 +0100
changeset 2268 adf79f6f4e06
parent 2267 3baaf3fc3e8a
child 2269 2f7433bdf66f
added: #withConstantValueDo: constant value evaluation (for true ifTrue:)
MessageNode.st
--- a/MessageNode.st	Fri Nov 06 19:15:29 2009 +0100
+++ b/MessageNode.st	Fri Nov 06 19:15:32 2009 +0100
@@ -2934,10 +2934,46 @@
     ^ receiver
 
     "Modified: / 17.7.1998 / 02:09:05 / cg"
+!
+
+withConstantValueDo:aBlock
+    "return true, if this evaluates to a constant value
+     and evaluate aBlock with it"
+
+    |recVal argValues allArgsConstant|
+
+    (receiver withConstantValueDo:[:val | recVal := val]) ifTrue:[
+        argValues := Array new:argArray size.
+        allArgsConstant := true.
+        argArray doWithIndex:[:arg :index |
+            allArgsConstant := allArgsConstant
+                                and:[ arg withConstantValueDo:[:val | argValues at:index put:val] ]
+        ].
+        allArgsConstant ifTrue:[
+            "/ only a few messages are checked:
+            recVal isNumber ifTrue:[
+                (#(positive negative abs negated + - * == = ~= ~~) includes:selector) ifFalse:[
+                    ^ false
+                ].
+            ].
+            recVal isBoolean ifTrue:[
+                (#(not && || ) includes:selector) ifFalse:[
+                    ^ false
+                ].
+            ].
+            aBlock value:(recVal perform:selector withArguments:argValues).
+            ^ true
+        ].
+    ].
+    ^ false
 ! !
 
 !MessageNode class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.165 2009-09-22 14:25:53 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.166 2009-11-06 18:15:32 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.166 2009-11-06 18:15:32 cg Exp $'
 ! !