10020
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libtool' }"
|
|
13 |
|
|
14 |
RBProgramNodeVisitor subclass:#CodeGenerator
|
|
15 |
instanceVariableNames:'class protocol source change replacements'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Browsers'
|
|
19 |
!
|
|
20 |
|
|
21 |
!CodeGenerator class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
! !
|
|
36 |
|
|
37 |
!CodeGenerator methodsFor:'accessing'!
|
|
38 |
|
|
39 |
category:aString
|
|
40 |
|
|
41 |
self protocol: aString
|
|
42 |
|
|
43 |
"Created: / 30-12-2008 / 17:41:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
44 |
"Modified: / 07-07-2009 / 18:46:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
45 |
!
|
|
46 |
|
|
47 |
change
|
|
48 |
|
|
49 |
change ifNil:[self createChange].
|
|
50 |
^change
|
|
51 |
|
|
52 |
"Created: / 30-12-2008 / 17:14:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
53 |
"Modified: / 07-07-2009 / 18:45:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
54 |
!
|
|
55 |
|
|
56 |
class:aClass
|
|
57 |
|
|
58 |
class := aClass
|
|
59 |
|
|
60 |
"Created: / 30-12-2008 / 15:38:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
61 |
"Modified: / 07-07-2009 / 18:46:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
62 |
!
|
|
63 |
|
|
64 |
protocol
|
|
65 |
^ protocol
|
|
66 |
!
|
|
67 |
|
|
68 |
protocol:aString
|
|
69 |
protocol := aString.
|
|
70 |
!
|
|
71 |
|
|
72 |
replace: placeholder with: code
|
|
73 |
|
|
74 |
replacements
|
|
75 |
at: placeholder
|
|
76 |
put: (code isSymbol
|
|
77 |
ifTrue:[code]
|
|
78 |
ifFalse:[RBParser parseRewriteExpression: code])
|
|
79 |
|
|
80 |
"Created: / 07-07-2009 / 18:48:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
81 |
"Modified: / 07-07-2009 / 19:58:51 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
82 |
!
|
|
83 |
|
|
84 |
replacementFor: placeholder
|
|
85 |
|
|
86 |
^replacements
|
|
87 |
at: placeholder
|
|
88 |
ifAbsent:[self error:'No replacement for ', placeholder]
|
|
89 |
|
|
90 |
"Created: / 07-07-2009 / 19:13:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
91 |
!
|
|
92 |
|
|
93 |
source:aString
|
|
94 |
source := aString.
|
|
95 |
|
|
96 |
"Created: / 30-12-2008 / 17:04:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
97 |
! !
|
|
98 |
|
|
99 |
!CodeGenerator methodsFor:'compiling'!
|
|
100 |
|
|
101 |
compile
|
|
102 |
|
|
103 |
^self change apply
|
|
104 |
|
|
105 |
"Created: / 07-07-2009 / 18:47:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
106 |
! !
|
|
107 |
|
|
108 |
!CodeGenerator methodsFor:'initialization'!
|
|
109 |
|
|
110 |
initialize
|
|
111 |
"Invoked when a new instance is created."
|
|
112 |
|
|
113 |
super initialize.
|
|
114 |
replacements := Dictionary new.
|
|
115 |
|
|
116 |
"Created: / 30-12-2008 / 15:29:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
117 |
"Modified: / 07-07-2009 / 18:45:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
118 |
! !
|
|
119 |
|
|
120 |
!CodeGenerator methodsFor:'private'!
|
|
121 |
|
|
122 |
createChange
|
|
123 |
|
|
124 |
| method |
|
|
125 |
method := RBParser parseRewriteMethod: source.
|
|
126 |
method source: nil.
|
|
127 |
method acceptVisitor: self.
|
|
128 |
(change := InteractiveAddMethodChange new)
|
|
129 |
class: class
|
|
130 |
protocol: protocol
|
|
131 |
source: method formattedCode.
|
|
132 |
|
|
133 |
"Created: / 07-07-2009 / 18:44:42 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
134 |
!
|
|
135 |
|
|
136 |
replacePlaceholdersInSelectorPartsOf:aMessageNode
|
|
137 |
aMessageNode selectorParts do:[:part |
|
|
138 |
part isPatternVariable ifTrue:[
|
|
139 |
|replacement|
|
|
140 |
|
|
141 |
replacement := self replacementFor:part value.
|
|
142 |
(replacement isSymbol or:[ replacement isVariable ]) ifFalse:[
|
|
143 |
self error:'Replacement for selector parts must be a single selector'
|
|
144 |
].
|
|
145 |
part value:replacement formattedCode
|
|
146 |
]
|
|
147 |
]
|
|
148 |
! !
|
|
149 |
|
|
150 |
!CodeGenerator methodsFor:'visitor-double dispatching'!
|
|
151 |
|
|
152 |
acceptMessageNode:aMessageNode
|
|
153 |
self replacePlaceholdersInSelectorPartsOf:aMessageNode.
|
|
154 |
super acceptMessageNode:aMessageNode.
|
|
155 |
|
|
156 |
"Created: / 07-07-2009 / 19:23:08 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
157 |
!
|
|
158 |
|
|
159 |
acceptMethodNode: aMethodNode
|
|
160 |
|
|
161 |
self replacePlaceholdersInSelectorPartsOf: aMethodNode.
|
|
162 |
super acceptMethodNode: aMethodNode.
|
|
163 |
|
|
164 |
"Created: / 07-07-2009 / 19:09:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
165 |
!
|
|
166 |
|
|
167 |
acceptVariableNode: aVariableNode
|
|
168 |
|
|
169 |
aVariableNode isPatternNode ifTrue:
|
|
170 |
[aVariableNode replaceWith:
|
|
171 |
(self replacementFor:aVariableNode name)]
|
|
172 |
|
|
173 |
"Created: / 30-12-2008 / 17:13:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
174 |
"Modified: / 07-07-2009 / 19:13:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
175 |
! !
|
|
176 |
|
|
177 |
!CodeGenerator class methodsFor:'documentation'!
|
|
178 |
|
|
179 |
version_CVS
|
|
180 |
^ '$Header: /cvs/stx/stx/libtool/CodeGenerator.st,v 1.1 2011-07-01 14:18:53 cg Exp $'
|
|
181 |
!
|
|
182 |
|
|
183 |
version_SVN
|
|
184 |
^ '§Id: CodeGenerator.st 7567 2010-04-17 10:59:53Z vranyj1 §'
|
|
185 |
! !
|