AssignmentNode.st
author claus
Fri, 11 Aug 1995 22:28:40 +0200
changeset 104 2016bfa4cd45
parent 103 f4a69d7dd387
child 117 3736a828cb50
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.
"

ParseNode subclass:#AssignmentNode
       instanceVariableNames:'variable expression'
       classVariableNames:''
       poolDictionaries:''
       category:'System-Compiler-Support'
!

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

$Header: /cvs/stx/stx/libcomp/AssignmentNode.st,v 1.11 1995-08-11 20:27:30 claus Exp $
'!

!AssignmentNode 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/AssignmentNode.st,v 1.11 1995-08-11 20:27:30 claus Exp $
"
!

documentation
"
    node for parse-trees, representing assignments
"
! !

!AssignmentNode class methodsFor:'instance creation'!

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

!AssignmentNode methodsFor:'evaluating'!

evaluate
    |value|
    value := expression evaluate.
    variable store:value.
    ^ value
! !

!AssignmentNode methodsFor:'queries'!

isAssignment
    "return true, if this is a node for an assignment"

    ^ true
! !

!AssignmentNode methodsFor:'accessing'!

variable:v expression:e
    variable := v.
    expression := e
!

expression
    ^ expression
! !

!AssignmentNode methodsFor:'code generation'!

codeForSideEffectOn:aStream inBlock:b for:aCompiler
    |sel arg|

    (variable type == #MethodVariable) ifTrue:[
	expression isBinaryMessage ifTrue:[
	    sel := expression selector.
	    ((sel == #+) or:[sel == #-]) ifTrue:[
		(expression receiver type == #MethodVariable) ifTrue:[
		    (expression receiver index == variable index) ifTrue:[
			arg := expression arg1.
			arg isConstant ifTrue:[
			    (arg value == 1) ifTrue:[
				(sel == #+) ifTrue:[
				    aStream nextPut:#incMethodVar
				] ifFalse:[
				    aStream nextPut:#decMethodVar
				].
				aStream nextPut:(expression lineNumber).
				aStream nextPut:(variable index).
				^ self
			    ]
			]
		    ]
		]
	    ]
	]
    ].
    expression codeOn:aStream inBlock:b for:aCompiler.
    variable codeStoreOn:aStream inBlock:b valueNeeded:false for:aCompiler
!

codeOn:aStream inBlock:b for:aCompiler
    expression codeOn:aStream inBlock:b for:aCompiler.
    variable codeStoreOn:aStream inBlock:b valueNeeded:true for:aCompiler
! !

!AssignmentNode methodsFor:'printing'!

printOn:aStream indent:i
    variable printOn:aStream.
    aStream nextPutAll:' := '.
    expression printOn:aStream
! !