StatementNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 28 Jun 2011 22:06:14 +0200
changeset 2503 791583d321c8
parent 2387 6614ed53a9d1
child 2598 2f08bc888c24
permissions -rw-r--r--
Jan's changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
52
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    12
"{ Package: 'stx:libcomp' }"
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    13
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    14
ParseNode subclass:#StatementNode
2503
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    15
	instanceVariableNames:'expression nextStatement lineNr'
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    16
	classVariableNames:''
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
	poolDictionaries:''
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    18
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    19
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    21
!StatementNode class methodsFor:'documentation'!
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    22
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    23
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    24
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
52
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
    26
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    27
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    28
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    29
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    31
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    32
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    33
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    34
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    35
!
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    36
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    37
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    38
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    39
    node for parse-trees, representing statements
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    40
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    41
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    42
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    43
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    44
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    45
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    46
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    47
!StatementNode class methodsFor:'instance creation'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    48
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
expression:e
7ad01559b262 Initial revision
claus
parents:
diff changeset
    50
    ^ (self basicNew) expression:e
7ad01559b262 Initial revision
claus
parents:
diff changeset
    51
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    52
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    53
!StatementNode methodsFor:'accessing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    54
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    55
expression
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    56
    ^ expression
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    57
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    58
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    59
expression:e
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    60
    expression := e
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    61
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    62
2503
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    63
isStatement
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    64
^true.
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    65
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    66
    "Created: / 22-02-2011 / 15:04:36 / Jakub <zelenja7@fel.cvut.cz>"
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    67
!
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
    68
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    69
last
7ad01559b262 Initial revision
claus
parents:
diff changeset
    70
    "return the last statement in a list"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    71
7ad01559b262 Initial revision
claus
parents:
diff changeset
    72
    |last this|
7ad01559b262 Initial revision
claus
parents:
diff changeset
    73
7ad01559b262 Initial revision
claus
parents:
diff changeset
    74
    "this could be done more elegant - but with lots of recursion"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    75
    last := self.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    76
    this := self.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    77
    [this notNil] whileTrue:[
52
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
    78
	last := this.
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
    79
	this := this nextStatement
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    80
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    81
    ^ last
7ad01559b262 Initial revision
claus
parents:
diff changeset
    82
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    83
711
25b9a501b97d lineNr -> lineNumber
Claus Gittinger <cg@exept.de>
parents: 542
diff changeset
    84
lineNumber
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    85
    "return lineNr"
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    86
1504
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
    87
    lineNr notNil ifTrue:[^ lineNr].
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
    88
    expression notNil ifTrue:[ ^ expression lineNumber ].
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
    89
    nextStatement notNil ifTrue:[^ nextStatement lineNumber].
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
    90
    ^ nil
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    91
711
25b9a501b97d lineNr -> lineNumber
Claus Gittinger <cg@exept.de>
parents: 542
diff changeset
    92
    "Created: / 14.5.1998 / 19:31:06 / cg"
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    93
!
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    94
711
25b9a501b97d lineNr -> lineNumber
Claus Gittinger <cg@exept.de>
parents: 542
diff changeset
    95
lineNumber:something
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    96
    "set lineNr"
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    97
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    98
    lineNr := something.
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
    99
711
25b9a501b97d lineNr -> lineNumber
Claus Gittinger <cg@exept.de>
parents: 542
diff changeset
   100
    "Created: / 14.5.1998 / 19:31:11 / cg"
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   101
!
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   102
1504
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   103
lineNumberOfFirstMessage
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   104
    |lno|
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   105
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   106
    lno := self lineNumber.
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   107
    self messagesDo:[:m | lno := lno min:(m lineNumber)].
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   108
    ^ lno
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   109
!
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   110
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   111
nextStatement
7ad01559b262 Initial revision
claus
parents:
diff changeset
   112
    ^ nextStatement
7ad01559b262 Initial revision
claus
parents:
diff changeset
   113
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   114
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   115
nextStatement:s
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   116
    nextStatement := s
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   117
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   118
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   119
!StatementNode methodsFor:'code generation'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   120
1379
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   121
codeAllForSideEffectOn:aStream inBlock:b for:aCompiler
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   122
    |thisStatement|
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   123
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   124
    thisStatement := self.
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   125
    [thisStatement notNil] whileTrue:[
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   126
        thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler.
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   127
        thisStatement := thisStatement nextStatement
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   128
    ].
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   129
!
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   130
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
    "generate code for this statement - value not needed"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   133
985
082a5f214443 care for empty statements
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   134
    expression notNil ifTrue:[
082a5f214443 care for empty statements
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   135
        expression codeForSideEffectOn:aStream inBlock:b for:aCompiler
082a5f214443 care for empty statements
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   136
    ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   137
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   138
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
codeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
    "generate code for this statement"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
1313
9ecf8d3ea043 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1209
diff changeset
   142
    expression notNil ifTrue:[
9ecf8d3ea043 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1209
diff changeset
   143
        expression codeOn:aStream inBlock:b for:aCompiler
9ecf8d3ea043 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1209
diff changeset
   144
    ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   145
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   146
1209
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   147
!StatementNode methodsFor:'converting'!
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   148
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   149
asCollectionOfStatements
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   150
    "returns a orderedCollection of statements,
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   151
     representing the list of which the receiver is the head"
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   152
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   153
    |coll stat|
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   154
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   155
    coll := OrderedCollection new.
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   156
    stat := self.
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   157
    [stat notNil] whileTrue:[
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   158
        coll add:stat.
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   159
        stat := stat nextStatement.
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   160
    ].
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   161
    ^ coll
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   162
! !
4646067249e8 asCollectionOfStatements
james
parents: 1080
diff changeset
   163
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 985
diff changeset
   164
!StatementNode methodsFor:'enumerating'!
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   165
1504
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   166
messagesDo:aBlock
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   167
    |s e|
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   168
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   169
    s := self.
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   170
    [s notNil] whileTrue:[
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   171
        e := s expression.
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   172
        e notNil ifTrue:[e messagesDo:aBlock].
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   173
        s := s nextStatement
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   174
    ].
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   175
!
eb26e6d08d71 +messagesDo: enumerator
Claus Gittinger <cg@exept.de>
parents: 1384
diff changeset
   176
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   177
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   178
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   179
1585
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
   180
    |stats this expr|
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   181
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   182
    "/ too stupid: ST/X statements are linked as a list ...
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   183
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   184
    stats := OrderedCollection new.
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   185
    this := self.
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   186
    [this notNil] whileTrue:[
1592
413a9144fc03 enumeration of return-nodes
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   187
        this isReturnNode ifTrue:[
413a9144fc03 enumeration of return-nodes
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   188
            stats add:this
413a9144fc03 enumeration of return-nodes
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   189
        ] ifFalse:[
413a9144fc03 enumeration of return-nodes
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   190
            expr := this expression.
413a9144fc03 enumeration of return-nodes
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   191
            stats add:(expr ? this).
413a9144fc03 enumeration of return-nodes
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   192
        ].
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   193
        this := this nextStatement
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   194
    ].
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   195
    ^ anEnumerator doSequence:self temporaries:#() statements:stats
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   196
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   197
    "Created: 19.6.1997 / 16:45:34 / cg"
542
728300bd8861 more ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   198
    "Modified: 19.6.1997 / 17:06:47 / cg"
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   199
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
   200
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 985
diff changeset
   201
!StatementNode methodsFor:'evaluation'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   202
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   203
evaluateAllIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   204
    |lastValue thisStatement|
52
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
   205
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   206
    "this could be done more elegant - but with lots of recursion"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   207
    thisStatement := self.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   208
    [thisStatement notNil] whileTrue:[
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   209
        lastValue := thisStatement evaluateExpressionIn:anEnvironment.
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   210
        thisStatement := thisStatement nextStatement
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   211
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   212
    ^ lastValue
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   213
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   214
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   215
evaluateExpressionIn:anEnvironment
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   216
    ^ expression evaluateIn:anEnvironment
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   217
!
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   218
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   219
evaluateIn:anEnvironment
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1379
diff changeset
   220
    ^ self evaluateAllIn:anEnvironment.
52
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
   221
! !
d80ec10c3321 *** empty log message ***
claus
parents: 33
diff changeset
   222
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   223
!StatementNode methodsFor:'printing & storing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   224
7ad01559b262 Initial revision
claus
parents:
diff changeset
   225
printAllOn:aStream 
7ad01559b262 Initial revision
claus
parents:
diff changeset
   226
    self printAllOn:aStream indent:4
7ad01559b262 Initial revision
claus
parents:
diff changeset
   227
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   228
7ad01559b262 Initial revision
claus
parents:
diff changeset
   229
printAllOn:aStream indent:i
7ad01559b262 Initial revision
claus
parents:
diff changeset
   230
    |thisStatement|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   231
7ad01559b262 Initial revision
claus
parents:
diff changeset
   232
    thisStatement := self.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   233
    [thisStatement notNil] whileTrue:[
1379
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   234
        aStream spaces:i.
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   235
        thisStatement printOn:aStream indent:i.
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   236
        thisStatement nextStatement notNil ifTrue:[
1633
5522145dfbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1592
diff changeset
   237
            aStream nextPut:$..
1379
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   238
            aStream cr.
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   239
        ].
7cbcca310b75 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   240
        thisStatement := thisStatement nextStatement
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   241
    ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   242
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   243
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   244
printOn:aStream indent:i
2168
be3e52955e96 care for nil expression when printing
Claus Gittinger <cg@exept.de>
parents: 2103
diff changeset
   245
    expression notNil ifTrue:[ expression printOn:aStream indent:i ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   246
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   247
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   248
!StatementNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   249
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   250
collectBlocksInto:aCollection
511
c144804051db handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents: 392
diff changeset
   251
    |this ex|
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   252
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   253
    this := self.
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   254
    [this notNil] whileTrue:[
511
c144804051db handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents: 392
diff changeset
   255
        ex := this expression.
c144804051db handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents: 392
diff changeset
   256
        ex notNil ifTrue:[
c144804051db handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents: 392
diff changeset
   257
            ex collectBlocksInto:aCollection.
c144804051db handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents: 392
diff changeset
   258
        ].
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   259
        this := this nextStatement
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   260
    ].
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   261
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   262
    "Created: 23.10.1996 / 15:44:13 / cg"
511
c144804051db handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents: 392
diff changeset
   263
    "Modified: 20.4.1997 / 12:10:18 / cg"
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   264
!
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   265
2385
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   266
containsReturn
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   267
    ^ self expression containsReturn
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   268
!
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   269
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   270
containsReturnInAnyStatement
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   271
    |s|
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   272
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   273
    s := self.
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   274
    [s notNil] whileTrue:[
2387
6614ed53a9d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2385
diff changeset
   275
        s isReturnNode ifTrue:[^ true].
2385
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   276
        s containsReturn ifTrue:[^ true].
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   277
        s := s nextStatement.
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   278
    ].
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   279
    ^ false
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   280
!
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   281
2065
974a231dff97 sharedPool access in doIts
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
   282
isSimpleConstant
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   283
    nextStatement notNil ifTrue:[^ false].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   284
    ^ expression isConstant
332
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   285
!
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   286
2103
7eab888fb15a obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2065
diff changeset
   287
isSimpleExpression
7eab888fb15a obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2065
diff changeset
   288
    nextStatement notNil ifTrue:[^ false].
7eab888fb15a obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2065
diff changeset
   289
    ^ expression notNil
7eab888fb15a obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2065
diff changeset
   290
!
7eab888fb15a obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2065
diff changeset
   291
2065
974a231dff97 sharedPool access in doIts
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
   292
isSimpleVariable
974a231dff97 sharedPool access in doIts
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
   293
    nextStatement notNil ifTrue:[^ false].
974a231dff97 sharedPool access in doIts
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
   294
    ^ expression isVariable
974a231dff97 sharedPool access in doIts
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
   295
!
974a231dff97 sharedPool access in doIts
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
   296
332
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   297
listEndsWithReturn
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   298
    |thisStatement lastStatement|
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   299
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   300
    thisStatement := self.
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   301
    [thisStatement notNil] whileTrue:[
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   302
        lastStatement := thisStatement.
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   303
        thisStatement := thisStatement nextStatement
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   304
    ].
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   305
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   306
    ^ lastStatement isReturnNode
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   307
7ffd2016cf73 added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   308
    "Created: 19.8.1996 / 14:32:47 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   309
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   310
2503
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   311
!StatementNode methodsFor:'testing'!
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   312
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   313
isStatementNode
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   314
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   315
    ^ true
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   316
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   317
    "Created: / 13-06-2011 / 11:26:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   318
    "Modified: / 13-06-2011 / 14:05:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   319
! !
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   320
392
cce48e2f0778 moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents: 332
diff changeset
   321
!StatementNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   322
2503
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   323
version_CVS
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   324
    ^ '$Header: /cvs/stx/stx/libcomp/StatementNode.st,v 1.39 2011-06-28 20:06:14 vrany Exp $'
2385
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   325
!
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
   326
2503
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   327
version_SVN
791583d321c8 Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2387
diff changeset
   328
    ^ ' Id '
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   329
! !