ProgramNodeBuilder.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 27 Oct 2022 14:53:59 +0100
branchjv
changeset 4735 3b11fb3ede98
parent 4207 546b3e3e3df9
permissions -rw-r--r--
Allow single underscore as method / block argument and temporaries This commit is a follow up for 38b221e.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
98
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
     3
	      All Rights Reserved
claus
parents:
diff changeset
     4
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    10
 hereby transferred.
claus
parents:
diff changeset
    11
"
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    12
"{ Package: 'stx:libcomp' }"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    13
4207
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    14
"{ NameSpace: Smalltalk }"
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    15
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    16
Object subclass:#ProgramNodeBuilder
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    17
	instanceVariableNames:''
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    18
	classVariableNames:''
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    19
	poolDictionaries:''
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    20
	category:'System-Compiler ST-80-compatibility'
98
claus
parents:
diff changeset
    21
!
claus
parents:
diff changeset
    22
claus
parents:
diff changeset
    23
!ProgramNodeBuilder class methodsFor:'documentation'!
claus
parents:
diff changeset
    24
claus
parents:
diff changeset
    25
copyright
claus
parents:
diff changeset
    26
"
claus
parents:
diff changeset
    27
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
    28
	      All Rights Reserved
claus
parents:
diff changeset
    29
claus
parents:
diff changeset
    30
 This software is furnished under a license and may be used
claus
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    35
 hereby transferred.
claus
parents:
diff changeset
    36
"
claus
parents:
diff changeset
    37
!
claus
parents:
diff changeset
    38
claus
parents:
diff changeset
    39
documentation
claus
parents:
diff changeset
    40
"
claus
parents:
diff changeset
    41
    This is a pure mimicri class.
claus
parents:
diff changeset
    42
    It is not used by ST/X, but provided to support limited
claus
parents:
diff changeset
    43
    compatibility for applications which build up codetrees,
claus
parents:
diff changeset
    44
    knowing internals of ST-80's compiler class hierarchy.
claus
parents:
diff changeset
    45
    This classes protocol is not (not meant to be) fully covering
claus
parents:
diff changeset
    46
    the corresponding ST-80's classes protocol. It maps ST-80 messages
claus
parents:
diff changeset
    47
    to corresponding ST/X messages (as far as possible).
claus
parents:
diff changeset
    48
claus
parents:
diff changeset
    49
    NO WARRANTY and GUARANTEE; this class may be removed without notice.
claus
parents:
diff changeset
    50
"
claus
parents:
diff changeset
    51
! !
claus
parents:
diff changeset
    52
4207
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    53
!ProgramNodeBuilder class methodsFor:'tree building'!
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    54
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    55
newMessageReceiver: receiverNode selector: selector arguments: arguments
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    56
    selector isUnarySelector ifTrue:[
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    57
        self assert:(arguments isEmptyOrNil).
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    58
        ^ UnaryNode receiver:receiverNode selector: selector args: arguments
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    59
    ].
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    60
    selector isBinarySelector ifTrue:[
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    61
        self assert:(arguments size == 1).
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    62
        ^ BinaryNode receiver:receiverNode selector: selector args: arguments
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    63
    ].
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    64
    self assert:(arguments notEmptyOrNil).
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    65
    ^ MessageNode receiver:receiverNode selector: selector args: arguments
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    66
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    67
    "Created: / 06-08-2006 / 03:02:33 / cg"
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    68
    "Modified: / 06-08-2006 / 14:00:47 / cg"
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    69
! !
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
    70
98
claus
parents:
diff changeset
    71
!ProgramNodeBuilder methodsFor:'tree building'!
claus
parents:
diff changeset
    72
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    73
newBlockBody:statements
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    74
    ^ (BlockNode arguments:#() home:nil variables:#()) statements:statements
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    75
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    76
    "Created: / 06-08-2006 / 23:25:36 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    77
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    78
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    79
newGlobal:name
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    80
    "return a treeNode for a global variable"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    81
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    82
    ^ VariableNode globalNamed:name
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    83
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    84
    "Created: / 06-08-2006 / 01:37:56 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    85
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    86
98
claus
parents:
diff changeset
    87
newLiteralValue:aConstantValue
claus
parents:
diff changeset
    88
    "return a treeNode for a literal constant"
claus
parents:
diff changeset
    89
2900
a1349983b2e7 Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents: 2117
diff changeset
    90
    aConstantValue isAssociation ifTrue:[
2117
eb138ea841a8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
    91
        "/ happens when I am used by ST/80 or VW code, which assumes that a
eb138ea841a8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
    92
        "/ global is stored as association (which it is not in ST/X)
eb138ea841a8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
    93
        "/ check the caller and rewrite there.
eb138ea841a8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
    94
        self halt:'incompatibility warning'
eb138ea841a8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
    95
    ].
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    96
98
claus
parents:
diff changeset
    97
    ^ ConstantNode value:aConstantValue
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    98
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    99
    "Modified: / 06-08-2006 / 15:16:04 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   100
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   101
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   102
newMessageReceiver: receiverNode selector: selector
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   103
    ^ self newMessageReceiver: receiverNode selector: selector arguments: #()
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   104
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   105
    "Created: / 06-08-2006 / 02:59:55 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   106
    "Modified: / 06-08-2006 / 13:29:33 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   107
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   108
4207
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
   109
newMessageReceiver:arg1 selector:arg2 arguments:arg3
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
   110
    ^ self class newMessageReceiver:arg1 selector:arg2 arguments:arg3
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   111
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   112
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   113
newMethodArgument:name
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   114
    "return a treeNode for a method arg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   115
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   116
    ^ VariableNode methodArgumentNamed:name
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   117
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   118
    "Created: / 06-08-2006 / 01:15:33 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   119
    "Modified: / 06-08-2006 / 13:29:42 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   120
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   121
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   122
newMethodLocal:name
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   123
    "return a treeNode for a method local"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   124
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   125
    ^ VariableNode methodLocalNamed:name
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
    "Created: / 06-08-2006 / 02:10:52 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   128
    "Modified: / 06-08-2006 / 13:29:46 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   130
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
newMethodSelector:sel
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
    ^ MethodNode new selector:sel
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   133
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   134
    "Created: / 06-08-2006 / 01:17:16 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
    "Modified: / 06-08-2006 / 13:29:56 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   137
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
newMethodSelector:sel arguments:argVars temporaries:localVars statements:statementNodes
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
    ^ MethodNode new
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
        selector:sel 
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
        arguments:argVars
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
        locals:localVars 
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
        statements:statementNodes.
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
    "Modified: / 06-08-2006 / 13:30:01 / cg"
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
newParameterVariable:aNode
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   149
    ^ Variable name:(aNode name)
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   150
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   151
    "Created: / 06-08-2006 / 14:23:25 / cg"
98
claus
parents:
diff changeset
   152
!
claus
parents:
diff changeset
   153
claus
parents:
diff changeset
   154
newReturnValue:anExpressionNode
claus
parents:
diff changeset
   155
    "return a treeNode for a method-return"
claus
parents:
diff changeset
   156
claus
parents:
diff changeset
   157
    ^ ReturnNode expression:anExpressionNode
claus
parents:
diff changeset
   158
!
claus
parents:
diff changeset
   159
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   160
newSelf
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   161
    ^ SelfNode new
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   162
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   163
    "Created: / 06-08-2006 / 13:51:17 / cg"
98
claus
parents:
diff changeset
   164
! !
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   165
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   166
!ProgramNodeBuilder class methodsFor:'documentation'!
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   167
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   168
version
4207
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
   169
    ^ '$Header$'
1785
1994a5b86791 more compatibility
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   170
! !
4207
546b3e3e3df9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2900
diff changeset
   171