Tools__CodeGenerator.st
author Jan Vrany <jan.vrany@labware.com>
Wed, 07 Sep 2022 15:27:34 +0100
branchjv
changeset 19640 9001c87bacbe
parent 19607 f9108fde4972
permissions -rw-r--r--
Use `allTestSelectors includes:` instead of `isTestSelector:` ...as the latter is Smalltalk/X specific so overriding it won't work with portable code. Indeed, this is much slower for large classes. Will see.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     2
 Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     3
 Copyright (c) 2009-2010 eXept Software AG
19607
f9108fde4972 Move `CodeGenerator` and `CodeGeneratorTests` to namespace `Tools`
Jan Vrany <jan.vrany@labware.com>
parents: 15566
diff changeset
     4
 Copyright (c) 2021 LabWare
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     6
 Permission is hereby granted, free of charge, to any person
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     7
 obtaining a copy of this software and associated documentation
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     8
 files (the 'Software'), to deal in the Software without
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     9
 restriction, including without limitation the rights to use,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    10
 copy, modify, merge, publish, distribute, sublicense, and/or sell
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    11
 copies of the Software, and to permit persons to whom the
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    12
 Software is furnished to do so, subject to the following
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    13
 conditions:
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    14
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    15
 The above copyright notice and this permission notice shall be
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    16
 included in all copies or substantial portions of the Software.
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    17
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    18
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    19
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    20
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    21
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    22
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    23
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    24
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    25
 OTHER DEALINGS IN THE SOFTWARE.
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
"{ Package: 'stx:libtool' }"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
19607
f9108fde4972 Move `CodeGenerator` and `CodeGeneratorTests` to namespace `Tools`
Jan Vrany <jan.vrany@labware.com>
parents: 15566
diff changeset
    29
"{ NameSpace: Tools }"
f9108fde4972 Move `CodeGenerator` and `CodeGeneratorTests` to namespace `Tools`
Jan Vrany <jan.vrany@labware.com>
parents: 15566
diff changeset
    30
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
RBProgramNodeVisitor subclass:#CodeGenerator
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
    32
	instanceVariableNames:'class protocol source change replacements
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
    33
		recordedReplacementsInSource'
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	classVariableNames:''
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
	poolDictionaries:''
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
	category:'Interface-Browsers'
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!CodeGenerator class methodsFor:'documentation'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
copyright
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    43
 Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    44
 Copyright (c) 2009-2010 eXept Software AG
19607
f9108fde4972 Move `CodeGenerator` and `CodeGeneratorTests` to namespace `Tools`
Jan Vrany <jan.vrany@labware.com>
parents: 15566
diff changeset
    45
 Copyright (c) 2021 LabWare
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    46
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    47
 Permission is hereby granted, free of charge, to any person
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    48
 obtaining a copy of this software and associated documentation
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    49
 files (the 'Software'), to deal in the Software without
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    50
 restriction, including without limitation the rights to use,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    51
 copy, modify, merge, publish, distribute, sublicense, and/or sell
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    52
 copies of the Software, and to permit persons to whom the
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    53
 Software is furnished to do so, subject to the following
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    54
 conditions:
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    56
 The above copyright notice and this permission notice shall be
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    57
 included in all copies or substantial portions of the Software.
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    58
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    59
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    60
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    61
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    62
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    63
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    64
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    65
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    66
 OTHER DEALINGS IN THE SOFTWARE.
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
!CodeGenerator methodsFor:'accessing'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
category:aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    self protocol: aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    "Created: / 30-12-2008 / 17:41:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    "Modified: / 07-07-2009 / 18:46:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
change
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
   change ifNil:[self createChange].
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
   ^change
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    "Created: / 30-12-2008 / 17:14:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    "Modified: / 07-07-2009 / 18:45:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
class:aClass
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    class := aClass
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    "Created: / 30-12-2008 / 15:38:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    "Modified: / 07-07-2009 / 18:46:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
protocol
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    ^ protocol
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
protocol:aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    protocol := aString.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
replace: placeholder with: code
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    replacements 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
        at: placeholder
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
        put: (code isSymbol 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
                ifTrue:[code]
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
                ifFalse:[RBParser parseRewriteExpression: code])
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "Created: / 07-07-2009 / 18:48:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "Modified: / 07-07-2009 / 19:58:51 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
replacementFor: placeholder
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    ^replacements 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
        at: placeholder
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
        ifAbsent:[self error:'No replacement for ', placeholder]
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    "Created: / 07-07-2009 / 19:13:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
source:aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    source := aString.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "Created: / 30-12-2008 / 17:04:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
!CodeGenerator methodsFor:'compiling'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
compile
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    ^self change apply
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    "Created: / 07-07-2009 / 18:47:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
!CodeGenerator methodsFor:'initialization'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
initialize
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    "Invoked when a new instance is created."
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    super initialize.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    replacements := Dictionary new.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    "Created: / 30-12-2008 / 15:29:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    "Modified: / 07-07-2009 / 18:45:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!CodeGenerator methodsFor:'private'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
createChange
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
14423
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   157
    | parser method |
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   158
    parser := RBParser new.
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   159
    recordedReplacementsInSource := OrderedCollection new.
14423
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   160
    parser errorBlock:[ :str :pos | self error: ('Error: %1: %2' bindWith: pos with: str). ^ self ].
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   161
    parser initializeParserWith: source type: #rewriteSavingCommentsOn:errorBlock:.
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   162
    method := parser parseMethod: source.    
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   163
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
    method source: nil.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    method acceptVisitor: self.
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   166
    self replaceInSourceCode.
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    (change := InteractiveAddMethodChange new)
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
        class: class
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
        protocol: protocol
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   170
        source: (source notNil ifTrue:[source] ifFalse:[method formattedCode]).
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    "Created: / 07-07-2009 / 18:44:42 / Jan Vrany <vranyj1@fel.cvut.cz>"
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   173
    "Modified: / 26-08-2014 / 23:51:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   174
!
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   175
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   176
recordReplaceInSourceFrom:start to:stop by:code
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   177
    recordedReplacementsInSource add: { start. stop . code }.
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   178
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   179
    "Modified: / 26-08-2014 / 23:50:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   180
!
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   181
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   182
replaceInSourceCode
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   183
    "Perform recorded replacements in source"
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   184
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   185
    recordedReplacementsInSource sort: [ :a :b | a second < b first ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   186
    recordedReplacementsInSource reverseDo:[ :replacement |
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   187
        source := 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   188
            (source copyTo: replacement first - 1) , replacement third , (source copyFrom: replacement second + 1)  
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   189
    ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   190
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   191
    "Created: / 26-08-2014 / 23:51:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
replacePlaceholdersInSelectorPartsOf:aMessageNode 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    aMessageNode selectorParts do:[:part | 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
        part isPatternVariable ifTrue:[
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
            |replacement|
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
            replacement := self replacementFor:part value.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
            (replacement isSymbol or:[ replacement isVariable ]) ifFalse:[
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
                self error:'Replacement for selector parts must be a single selector'
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
            ].
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   203
            source notNil ifTrue:[
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   204
                self 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   205
                      recordReplaceInSourceFrom:part start
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   206
                      to:part stop
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   207
                      by:replacement formattedCode.
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   208
            ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   209
            part value:replacement formattedCode.                 
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
        ]
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    ]
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   212
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   213
    "Modified: / 26-08-2014 / 23:37:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
!CodeGenerator methodsFor:'visitor-double dispatching'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
acceptMessageNode:aMessageNode 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    self replacePlaceholdersInSelectorPartsOf:aMessageNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    super acceptMessageNode:aMessageNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    "Created: / 07-07-2009 / 19:23:08 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
acceptMethodNode: aMethodNode
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    self replacePlaceholdersInSelectorPartsOf: aMethodNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    super acceptMethodNode: aMethodNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    "Created: / 07-07-2009 / 19:09:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
acceptVariableNode: aVariableNode
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   235
    aVariableNode isPatternNode ifTrue:[            
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   236
        source notNil ifTrue:[ 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   237
            self 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   238
                  recordReplaceInSourceFrom:aVariableNode start
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   239
                  to:aVariableNode stop
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   240
                  by:(self replacementFor:aVariableNode name) formattedCode
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   241
        ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   242
        aVariableNode replaceWith: (self replacementFor:aVariableNode name).
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   243
    ]
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    "Created: / 30-12-2008 / 17:13:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    "Modified: / 07-07-2009 / 19:13:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   247
    "Modified: / 26-08-2014 / 23:37:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
!CodeGenerator class methodsFor:'documentation'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
version_CVS
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   253
    ^ '$Header: /cvs/stx/stx/libtool/CodeGenerator.st,v 1.4 2014-08-26 22:58:13 vrany Exp $'
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
version_SVN
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   257
    ^ '$Id: CodeGenerator.st,v 1.4 2014-08-26 22:58:13 vrany Exp $'
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
! !
14423
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   259