author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 04 Sep 2013 11:33:19 +0100 | |
branch | jv |
changeset 13491 | b3afe831ff0a |
parent 12431 | 9f0c59c742d5 |
child 15566 | 184cea584be5 |
permissions | -rw-r--r-- |
10020 | 1 |
" |
10047 | 2 |
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague |
3 |
Copyright (c) 2009-2010 eXept Software AG |
|
10020 | 4 |
|
10047 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
10020 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
27 |
||
28 |
RBProgramNodeVisitor subclass:#CodeGenerator |
|
29 |
instanceVariableNames:'class protocol source change replacements' |
|
30 |
classVariableNames:'' |
|
31 |
poolDictionaries:'' |
|
32 |
category:'Interface-Browsers' |
|
33 |
! |
|
34 |
||
35 |
!CodeGenerator class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
10047 | 39 |
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague |
40 |
Copyright (c) 2009-2010 eXept Software AG |
|
41 |
||
42 |
Permission is hereby granted, free of charge, to any person |
|
43 |
obtaining a copy of this software and associated documentation |
|
44 |
files (the 'Software'), to deal in the Software without |
|
45 |
restriction, including without limitation the rights to use, |
|
46 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
47 |
copies of the Software, and to permit persons to whom the |
|
48 |
Software is furnished to do so, subject to the following |
|
49 |
conditions: |
|
10020 | 50 |
|
10047 | 51 |
The above copyright notice and this permission notice shall be |
52 |
included in all copies or substantial portions of the Software. |
|
53 |
||
54 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
55 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
56 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
57 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
58 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
59 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
60 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
61 |
OTHER DEALINGS IN THE SOFTWARE. |
|
10020 | 62 |
" |
63 |
! ! |
|
64 |
||
65 |
!CodeGenerator methodsFor:'accessing'! |
|
66 |
||
67 |
category:aString |
|
68 |
||
69 |
self protocol: aString |
|
70 |
||
71 |
"Created: / 30-12-2008 / 17:41:44 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
72 |
"Modified: / 07-07-2009 / 18:46:20 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
73 |
! |
|
74 |
||
75 |
change |
|
76 |
||
77 |
change ifNil:[self createChange]. |
|
78 |
^change |
|
79 |
||
80 |
"Created: / 30-12-2008 / 17:14:14 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
81 |
"Modified: / 07-07-2009 / 18:45:07 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
82 |
! |
|
83 |
||
84 |
class:aClass |
|
85 |
||
86 |
class := aClass |
|
87 |
||
88 |
"Created: / 30-12-2008 / 15:38:00 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
89 |
"Modified: / 07-07-2009 / 18:46:34 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
90 |
! |
|
91 |
||
92 |
protocol |
|
93 |
^ protocol |
|
94 |
! |
|
95 |
||
96 |
protocol:aString |
|
97 |
protocol := aString. |
|
98 |
! |
|
99 |
||
100 |
replace: placeholder with: code |
|
101 |
||
102 |
replacements |
|
103 |
at: placeholder |
|
104 |
put: (code isSymbol |
|
105 |
ifTrue:[code] |
|
106 |
ifFalse:[RBParser parseRewriteExpression: code]) |
|
107 |
||
108 |
"Created: / 07-07-2009 / 18:48:21 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
109 |
"Modified: / 07-07-2009 / 19:58:51 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
110 |
! |
|
111 |
||
112 |
replacementFor: placeholder |
|
113 |
||
114 |
^replacements |
|
115 |
at: placeholder |
|
116 |
ifAbsent:[self error:'No replacement for ', placeholder] |
|
117 |
||
118 |
"Created: / 07-07-2009 / 19:13:18 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
119 |
! |
|
120 |
||
121 |
source:aString |
|
122 |
source := aString. |
|
123 |
||
124 |
"Created: / 30-12-2008 / 17:04:14 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
125 |
! ! |
|
126 |
||
127 |
!CodeGenerator methodsFor:'compiling'! |
|
128 |
||
129 |
compile |
|
130 |
||
131 |
^self change apply |
|
132 |
||
133 |
"Created: / 07-07-2009 / 18:47:52 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
134 |
! ! |
|
135 |
||
136 |
!CodeGenerator methodsFor:'initialization'! |
|
137 |
||
138 |
initialize |
|
139 |
"Invoked when a new instance is created." |
|
140 |
||
141 |
super initialize. |
|
142 |
replacements := Dictionary new. |
|
143 |
||
144 |
"Created: / 30-12-2008 / 15:29:17 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
145 |
"Modified: / 07-07-2009 / 18:45:17 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
146 |
! ! |
|
147 |
||
148 |
!CodeGenerator methodsFor:'private'! |
|
149 |
||
150 |
createChange |
|
151 |
||
152 |
| method | |
|
153 |
method := RBParser parseRewriteMethod: source. |
|
154 |
method source: nil. |
|
155 |
method acceptVisitor: self. |
|
156 |
(change := InteractiveAddMethodChange new) |
|
157 |
class: class |
|
158 |
protocol: protocol |
|
159 |
source: method formattedCode. |
|
160 |
||
161 |
"Created: / 07-07-2009 / 18:44:42 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
162 |
! |
|
163 |
||
164 |
replacePlaceholdersInSelectorPartsOf:aMessageNode |
|
165 |
aMessageNode selectorParts do:[:part | |
|
166 |
part isPatternVariable ifTrue:[ |
|
167 |
|replacement| |
|
168 |
||
169 |
replacement := self replacementFor:part value. |
|
170 |
(replacement isSymbol or:[ replacement isVariable ]) ifFalse:[ |
|
171 |
self error:'Replacement for selector parts must be a single selector' |
|
172 |
]. |
|
173 |
part value:replacement formattedCode |
|
174 |
] |
|
175 |
] |
|
176 |
! ! |
|
177 |
||
178 |
!CodeGenerator methodsFor:'visitor-double dispatching'! |
|
179 |
||
180 |
acceptMessageNode:aMessageNode |
|
181 |
self replacePlaceholdersInSelectorPartsOf:aMessageNode. |
|
182 |
super acceptMessageNode:aMessageNode. |
|
183 |
||
184 |
"Created: / 07-07-2009 / 19:23:08 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
185 |
! |
|
186 |
||
187 |
acceptMethodNode: aMethodNode |
|
188 |
||
189 |
self replacePlaceholdersInSelectorPartsOf: aMethodNode. |
|
190 |
super acceptMethodNode: aMethodNode. |
|
191 |
||
192 |
"Created: / 07-07-2009 / 19:09:11 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
193 |
! |
|
194 |
||
195 |
acceptVariableNode: aVariableNode |
|
196 |
||
197 |
aVariableNode isPatternNode ifTrue: |
|
198 |
[aVariableNode replaceWith: |
|
199 |
(self replacementFor:aVariableNode name)] |
|
200 |
||
201 |
"Created: / 30-12-2008 / 17:13:16 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
202 |
"Modified: / 07-07-2009 / 19:13:55 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
203 |
! ! |
|
204 |
||
205 |
!CodeGenerator class methodsFor:'documentation'! |
|
206 |
||
207 |
version_CVS |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10047
diff
changeset
|
208 |
^ '§Header: /cvs/stx/stx/libtool/CodeGenerator.st,v 1.2 2011/07/03 13:41:45 cg Exp §' |
10020 | 209 |
! |
210 |
||
12431
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
211 |
version_HG |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
212 |
|
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
213 |
^ '$Changeset: <not expanded> $' |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
214 |
! |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
215 |
|
10020 | 216 |
version_SVN |
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12123
diff
changeset
|
217 |
^ '$Id: CodeGenerator.st 7854 2012-01-30 17:49:41Z vranyj1 $' |
12431
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
218 |
! ! |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
219 |