# HG changeset patch # User Claus Gittinger # Date 1257531332 -3600 # Node ID adf79f6f4e069a0f1d20b41fa01a658732f1cc58 # Parent 3baaf3fc3e8a5b8acf655d930a9c53cd5dcd1764 added: #withConstantValueDo: constant value evaluation (for true ifTrue:) diff -r 3baaf3fc3e8a -r adf79f6f4e06 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 $' ! !