StatNode.st
author Claus Gittinger <cg@exept.de>
Sat, 09 Dec 1995 23:10:33 +0100
changeset 163 9a7dfd547e69
parent 148 ef0e604209ec
child 261 0372e948ca2d
permissions -rw-r--r--
checkin from browser

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

ParseNode subclass:#StatementNode
	 instanceVariableNames:'expression nextStatement'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'System-Compiler-Support'
!

!StatementNode 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 statements
"
! !

!StatementNode class methodsFor:'instance creation'!

expression:e
    ^ (self basicNew) expression:e
! !

!StatementNode methodsFor:'accessing'!

expression
    ^ expression
!

expression:e
    expression := e
!

last
    "return the last statement in a list"

    |last this|

    "this could be done more elegant - but with lots of recursion"
    last := self.
    this := self.
    [this notNil] whileTrue:[
	last := this.
	this := this nextStatement
    ].
    ^ last
!

nextStatement
    ^ nextStatement
!

nextStatement:s
    nextStatement := s
! !

!StatementNode methodsFor:'code generation'!

codeForSideEffectOn:aStream inBlock:b for:aCompiler
    "generate code for this statement - value not needed"

    expression codeForSideEffectOn:aStream inBlock:b for:aCompiler
!

codeOn:aStream inBlock:b for:aCompiler
    "generate code for this statement"

    expression codeOn:aStream inBlock:b for:aCompiler
! !

!StatementNode methodsFor:'evaluating'!

evaluate
    |lastValue thisStatement|

    "this could be done more elegant - but with lots of recursion"
    thisStatement := self.
    [thisStatement notNil] whileTrue:[
	lastValue := thisStatement evaluateExpression.
	thisStatement := thisStatement nextStatement
    ].
    ^ lastValue
!

evaluateExpression
    ^ expression evaluate
! !

!StatementNode methodsFor:'printing'!

printAllOn:aStream 
    self printAllOn:aStream indent:4
!

printAllOn:aStream indent:i
    |thisStatement|

    thisStatement := self.
    [thisStatement notNil] whileTrue:[
	aStream spaces:i.
	thisStatement printOn:aStream indent:i.
	thisStatement nextStatement notNil ifTrue:[
	    aStream nextPut:$..
	    aStream cr.
	].
	thisStatement := thisStatement nextStatement
    ]
!

printOn:aStream indent:i
    expression printOn:aStream indent:i.
! !

!StatementNode methodsFor:'queries'!

isConstant
    nextStatement notNil ifTrue:[^ false].
    ^ expression isConstant
! !

!StatementNode class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libcomp/Attic/StatNode.st,v 1.13 1995-12-03 12:17:26 cg Exp $'
! !