ReturnNode.st
author Claus Gittinger <cg@exept.de>
Mon, 21 Apr 2003 16:50:34 +0200
changeset 1399 95b2eaa4e457
parent 1383 3d485eefbb36
child 1403 1bc763430b94
permissions -rw-r--r--
undefinedVariableNotification fix

"
 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.
"

"{ Package: 'stx:libcomp' }"

StatementNode subclass:#ReturnNode
	instanceVariableNames:'myHome blockHome'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Compiler-Support'
!

!ReturnNode 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.
"
!

documentation
"
    node for parse-trees, representing return expressions
    This is a helper class for the compiler.

    [author:]
        Claus Gittinger
"
! !

!ReturnNode class methodsFor:'code generation helpers'!

codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler
    "/ let expression decide how to do it efficiently.
    expression
        codeForSimpleReturnOn:aStream 
        inBlock:b 
        lineNumber:lineNrOrNil 
        for:aCompiler

    "Created: 21.10.1996 / 14:37:35 / cg"
    "Modified: 21.10.1996 / 14:43:11 / cg"
! !

!ReturnNode methodsFor:'accessing'!

expression:e
    super expression:e.

    "/ any block, which is returned cannot be inlined.
    e isBlockNode ifTrue:[
        e possiblyInlined:false
    ]

!

home:someOne blockHome:aBlockNode
    myHome := someOne.
    blockHome := aBlockNode
! !

!ReturnNode methodsFor:'code generation'!

codeForSideEffectOn:aStream inBlock:b for:aCompiler
    "redefined - drop not needed since notreached"

    ^ self codeOn:aStream inBlock:b for:aCompiler
!

codeOn:aStream inBlock:b for:aCompiler
    b isNil ifTrue:[
        expression isNil ifTrue:[
            aStream nextPut:#retNil.
        ] ifFalse:[
            self class
                codeSimpleReturnFor:expression 
                inBlock:nil 
                on:aStream 
                inLine:lineNr 
                for:aCompiler.
        ].
        ^ self.
    ].

    expression codeOn:aStream inBlock:b for:aCompiler.

    lineNr notNil ifTrue:[
        self codeLineNumber:lineNr on:aStream for:aCompiler
    ].

    aStream nextPut:#homeRetTop.

    "Modified: 21.10.1996 / 14:54:36 / cg"
! !

!ReturnNode methodsFor:'enumerating'!

nodeDo:anEnumerator
    "helper for parse tree walking"

    ^ anEnumerator doReturn:self value:expression

    "Modified: 19.6.1997 / 16:42:40 / cg"
! !

!ReturnNode methodsFor:'evaluation'!

evaluateExpressionIn:anEnvironment
    |val|

    val := expression evaluateIn:anEnvironment.
    myHome exitWith:val.
    "when we arrive here, the parser context is already gone
     - try block-return"
    blockHome notNil ifTrue:[blockHome exitWith:val].
    "well - what else can be done"
    ^ val
! !

!ReturnNode methodsFor:'printing & storing'!

printOn:aStream indent:i
    aStream nextPutAll:'^ '.
    expression printOn:aStream
! !

!ReturnNode methodsFor:'queries'!

isConstant
    ^ false
!

isReturnNode
    ^ true
! !

!ReturnNode class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.28 2003-03-28 14:39:23 cg Exp $'
! !