CodeGenerator.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 14 Jun 2018 22:19:39 +0100
branchjv
changeset 18227 d25a407ba86d
parent 15566 184cea584be5
permissions -rw-r--r--
Mini testrunner: show "green" if there's at least one pass and rest is pass or skip This is more meaningfull result then showing "gray" if there's at least one skip.
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
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     5
 Permission is hereby granted, free of charge, to any person
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     6
 obtaining a copy of this software and associated documentation
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     7
 files (the 'Software'), to deal in the Software without
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     8
 restriction, including without limitation the rights to use,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
     9
 copy, modify, merge, publish, distribute, sublicense, and/or sell
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    10
 copies of the Software, and to permit persons to whom the
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    11
 Software is furnished to do so, subject to the following
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    12
 conditions:
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    13
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    14
 The above copyright notice and this permission notice shall be
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    15
 included in all copies or substantial portions of the Software.
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    16
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    17
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    18
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    19
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    20
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    21
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    22
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    23
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    24
 OTHER DEALINGS IN THE SOFTWARE.
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"{ Package: 'stx:libtool' }"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
RBProgramNodeVisitor subclass:#CodeGenerator
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
    29
	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
    30
		recordedReplacementsInSource'
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	classVariableNames:''
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	poolDictionaries:''
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	category:'Interface-Browsers'
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!CodeGenerator class methodsFor:'documentation'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
copyright
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    40
 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
    41
 Copyright (c) 2009-2010 eXept Software AG
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    42
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    43
 Permission is hereby granted, free of charge, to any person
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    44
 obtaining a copy of this software and associated documentation
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    45
 files (the 'Software'), to deal in the Software without
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    46
 restriction, including without limitation the rights to use,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    47
 copy, modify, merge, publish, distribute, sublicense, and/or sell
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    48
 copies of the Software, and to permit persons to whom the
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    49
 Software is furnished to do so, subject to the following
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    50
 conditions:
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
10047
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    52
 The above copyright notice and this permission notice shall be
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    53
 included in all copies or substantial portions of the Software.
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    54
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    55
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    56
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    57
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    58
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    59
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    60
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    61
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
5962c20bb7d8 copyright
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
    62
 OTHER DEALINGS IN THE SOFTWARE.
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
!CodeGenerator methodsFor:'accessing'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
category:aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    self protocol: aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "Created: / 30-12-2008 / 17:41:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    "Modified: / 07-07-2009 / 18:46:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
change
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
   change ifNil:[self createChange].
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
   ^change
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    "Created: / 30-12-2008 / 17:14:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    "Modified: / 07-07-2009 / 18:45:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
class:aClass
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    class := aClass
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    "Created: / 30-12-2008 / 15:38:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    "Modified: / 07-07-2009 / 18:46:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
protocol
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    ^ protocol
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:aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    protocol := aString.
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
replace: placeholder with: code
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    replacements 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
        at: placeholder
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
        put: (code isSymbol 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                ifTrue:[code]
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
                ifFalse:[RBParser parseRewriteExpression: code])
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "Created: / 07-07-2009 / 18:48:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "Modified: / 07-07-2009 / 19:58:51 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
replacementFor: placeholder
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    ^replacements 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        at: placeholder
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
        ifAbsent:[self error:'No replacement for ', 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
    "Created: / 07-07-2009 / 19:13:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
source:aString
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    source := aString.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    "Created: / 30-12-2008 / 17:04:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
!CodeGenerator methodsFor:'compiling'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
compile
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    ^self change apply
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    "Created: / 07-07-2009 / 18:47:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
!CodeGenerator methodsFor:'initialization'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
initialize
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    "Invoked when a new instance is created."
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    super initialize.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    replacements := Dictionary new.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    "Created: / 30-12-2008 / 15:29:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    "Modified: / 07-07-2009 / 18:45:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
!CodeGenerator methodsFor:'private'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
createChange
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
14423
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   153
    | parser method |
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   154
    parser := RBParser new.
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   155
    recordedReplacementsInSource := OrderedCollection new.
14423
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   156
    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
   157
    parser initializeParserWith: source type: #rewriteSavingCommentsOn:errorBlock:.
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   158
    method := parser parseMethod: source.    
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   159
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    method source: nil.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    method acceptVisitor: self.
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   162
    self replaceInSourceCode.
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    (change := InteractiveAddMethodChange new)
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
        class: class
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
        protocol: protocol
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   166
        source: (source notNil ifTrue:[source] ifFalse:[method formattedCode]).
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    "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
   169
    "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
   170
!
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   171
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   172
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
   173
    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
   174
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   175
    "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
   176
!
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   177
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   178
replaceInSourceCode
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   179
    "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
   180
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   181
    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
   182
    recordedReplacementsInSource reverseDo:[ :replacement |
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   183
        source := 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   184
            (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
   185
    ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   186
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   187
    "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
   188
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
replacePlaceholdersInSelectorPartsOf:aMessageNode 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    aMessageNode selectorParts do:[:part | 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
        part isPatternVariable ifTrue:[
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
            |replacement|
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
            replacement := self replacementFor:part value.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
            (replacement isSymbol or:[ replacement isVariable ]) ifFalse:[
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
                self error:'Replacement for selector parts must be a single selector'
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
            ].
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   199
            source notNil ifTrue:[
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   200
                self 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   201
                      recordReplaceInSourceFrom:part start
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   202
                      to:part stop
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   203
                      by:replacement formattedCode.
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   204
            ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   205
            part value:replacement formattedCode.                 
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
        ]
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    ]
14717
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
    "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
   210
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
!CodeGenerator methodsFor:'visitor-double dispatching'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
acceptMessageNode:aMessageNode 
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    self replacePlaceholdersInSelectorPartsOf:aMessageNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    super acceptMessageNode:aMessageNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    "Created: / 07-07-2009 / 19:23:08 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
acceptMethodNode: aMethodNode
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    self replacePlaceholdersInSelectorPartsOf: aMethodNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    super acceptMethodNode: aMethodNode.
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    "Created: / 07-07-2009 / 19:09:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
acceptVariableNode: aVariableNode
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   231
    aVariableNode isPatternNode ifTrue:[            
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   232
        source notNil ifTrue:[ 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   233
            self 
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   234
                  recordReplaceInSourceFrom:aVariableNode start
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   235
                  to:aVariableNode stop
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   236
                  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
   237
        ].
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   238
        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
   239
    ]
10020
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    "Created: / 30-12-2008 / 17:13:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    "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
   243
    "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
   244
! !
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
!CodeGenerator class methodsFor:'documentation'!
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
8a61b43817e1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
version_CVS
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   249
    ^ '$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
   250
!
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_SVN
14717
7fd0faf76e90 Fixed CodeGenerator to preserve original source code formatting.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 14423
diff changeset
   253
    ^ '$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
   254
! !
14423
ce279b3422b2 Fix to preserve comment.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10047
diff changeset
   255