AssignmentNode.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 03:15:59 +0100
changeset 140 1ef1d1395146
parent 135 aa4f7b8f121e
child 148 ef0e604209ec
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:#AssignmentNode
	 instanceVariableNames:'variable expression'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'System-Compiler-Support'
!

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

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

version
    ^ '$Header: /cvs/stx/stx/libcomp/AssignmentNode.st,v 1.14 1995-11-23 02:12:04 cg Exp $'
! !

!AssignmentNode class methodsFor:'instance creation'!

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

!AssignmentNode methodsFor:'accessing'!

expression
    ^ expression
!

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

!AssignmentNode methodsFor:'code generation'!

checkIncDecOn:aStream
    |sel erec arg code|

    (variable type == #MethodVariable) ifTrue:[
	expression isBinaryMessage ifTrue:[
	    sel := expression selector.
	    erec := expression receiver.
	    ((sel == #+) or:[sel == #-]) ifTrue:[
		(erec type == #MethodVariable) ifTrue:[
		    (erec index == variable index) ifTrue:[
			arg := expression arg1.
			arg isConstant ifTrue:[
			    (arg value == 1) ifTrue:[
				(sel == #+) ifTrue:[
				    code := #incMethodVar
				] ifFalse:[
				    code := #decMethodVar
				].
				aStream nextPut:code; nextPut:(expression lineNumber); nextPut:(variable index).
				^ true
			    ]
			]
		    ]
		]
	    ]
	]
    ].
    ^ false
!

codeForSideEffectOn:aStream inBlock:b for:aCompiler
    (self checkIncDecOn:aStream) ifTrue:[^ self].
    expression codeOn:aStream inBlock:b for:aCompiler.
    variable codeStoreOn:aStream inBlock:b valueNeeded:false for:aCompiler

    "Modified: 4.9.1995 / 14:38:10 / claus"
!

codeOn:aStream inBlock:b for:aCompiler
    (self checkIncDecOn:aStream) ifTrue:[
	expression receiver codeOn:aStream inBlock:b for:aCompiler.
	^ self
    ].
    expression codeOn:aStream inBlock:b for:aCompiler.
    variable codeStoreOn:aStream inBlock:b valueNeeded:true for:aCompiler
! !

!AssignmentNode methodsFor:'evaluating'!

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

!AssignmentNode methodsFor:'printing'!

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

!AssignmentNode methodsFor:'queries'!

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

    ^ true
! !