CascadeNode.st
author claus
Thu, 10 Aug 1995 20:13:01 +0200
changeset 102 77e4d1119ff2
parent 32 094d0a06c0ed
child 103 f4a69d7dd387
permissions -rw-r--r--
.

"
 COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

MessageNode subclass:#CascadeNode
       instanceVariableNames:''
       classVariableNames:''
       poolDictionaries:''
       category:'System-Compiler-Support'
!

CascadeNode comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libcomp/CascadeNode.st,v 1.8 1995-08-10 18:11:13 claus Exp $
'!

!CascadeNode class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libcomp/CascadeNode.st,v 1.8 1995-08-10 18:11:13 claus Exp $
$Revision: 1.8 $
"
!

documentation
"
    node for parse-trees, representing cascade message sends
"
! !

!CascadeNode methodsFor: 'code generation'!

codeOn:aStream inBlock:b valueNeeded:valueNeeded
    receiver codeForCascadeOn:aStream inBlock:b.
    self codeSendOn:aStream inBlock:b valueNeeded:valueNeeded
!

codeForCascadeOn:aStream inBlock:b
    receiver codeForCascadeOn:aStream inBlock:b.
    aStream nextPut:#dup.
    self codeSendOn:aStream inBlock:b valueNeeded:false
! !

!CascadeNode methodsFor: 'printing'!

printOn:aStream indent:i
    |needParen selectorParts index index2 arg nargs|

    index := 1.
    selectorParts := OrderedCollection new.
    [index == 0] whileFalse:[
        index2 := selector indexOf:$: startingAt:index.
        index2 ~~ 0 ifTrue:[
            selectorParts add:(selector copyFrom:index to:index2).
            index2 := index2 + 1
        ].
        index := index2
    ].

    receiver printOn:aStream indent:i.
    aStream nextPutAll:'; '.

    nargs := argArray size.
    nargs == 0 ifTrue:[
        selector printOn:aStream
    ] ifFalse:[
        1 to:nargs do:[:argIndex |
            aStream space.
            (selectorParts at:argIndex) printOn:aStream.
            aStream space.
            arg := argArray at:argIndex.
            needParen := false.
            arg isMessage ifTrue:[
                arg isBinaryMessage ifFalse:[
                    arg isUnaryMessage ifFalse:[
                        needParen := true
                    ]
                ].
            ].
            needParen ifTrue:[
                aStream nextPutAll:'('
            ].
            arg printOn:aStream indent:i.
            needParen ifTrue:[
                aStream nextPutAll:') '
            ].
        ]
    ]
! !

!CascadeNode methodsFor: 'evaluating'!

evaluate
    |t argValueArray|

    receiver isSuper ifTrue:[
        ^ super evaluate
    ].

    t := receiver evaluateForCascade.
    argArray isNil ifTrue:[
        t perform:selector.
        ^ t
    ].
    argValueArray := argArray collect:[:arg | arg evaluate].
    ^ t perform:selector withArguments:argValueArray
!

evaluateForCascade
    |t argValueArray|

    receiver isSuper ifTrue:[
        ^ super evaluateForCascade
    ].

    t := receiver evaluateForCascade.
    argArray isNil ifTrue:[
        t perform:selector.
        ^ t
    ].
    argValueArray := argArray collect:[:arg | arg evaluate]. 
    t perform:selector withArguments:argValueArray.
    ^ t
! !