9 category:'PetitCompiler-Visitors' |
9 category:'PetitCompiler-Visitors' |
10 ! |
10 ! |
11 |
11 |
12 !PPCCodeGenerator class methodsFor:'as yet unclassified'! |
12 !PPCCodeGenerator class methodsFor:'as yet unclassified'! |
13 |
13 |
|
14 new |
|
15 ^ self basicNew |
|
16 initialize; |
|
17 yourself |
|
18 ! |
|
19 |
14 on: aPPCCompiler |
20 on: aPPCCompiler |
15 ^ self new |
21 ^ self new |
16 compiler: aPPCCompiler; |
22 compiler: aPPCCompiler; |
17 yourself |
23 yourself |
18 ! ! |
24 ! ! |
19 |
25 |
20 !PPCCodeGenerator methodsFor:'accessing'! |
26 !PPCCodeGenerator methodsFor:'accessing'! |
21 |
27 |
22 compiler: aPPCCompiler |
28 compiler: aPPCCompiler |
23 compiler := aPPCCompiler |
29 compiler := aPPCCompiler |
|
30 ! |
|
31 |
|
32 guards |
|
33 ^ arguments guards |
24 ! ! |
34 ! ! |
25 |
35 |
26 !PPCCodeGenerator methodsFor:'hooks'! |
36 !PPCCodeGenerator methodsFor:'hooks'! |
27 |
37 |
28 afterAccept: node retval: retval |
38 afterAccept: node retval: retval |
243 (self isOpen: child) ifTrue: [ |
253 (self isOpen: child) ifTrue: [ |
244 "already processing..." |
254 "already processing..." |
245 ^ nil |
255 ^ nil |
246 ]. |
256 ]. |
247 |
257 |
248 "TODO JK: this is is wrong,.. to tired now to fix this :(" |
|
249 " (self isCached: child) ifTrue: [ |
|
250 node replace: child with: (self cachedValue: child). |
|
251 ^ nil |
|
252 ]. |
|
253 " |
|
254 ^ self visit: child. |
258 ^ self visit: child. |
255 ! |
259 ! |
256 |
260 |
257 visitChoiceNode: node |
261 visitChoiceNode: node |
258 | firsts guard whitespaceConsumed elementVar | |
262 | firsts guard whitespaceConsumed elementVar | |
266 elementVar := compiler allocateTemporaryVariableNamed: 'element'. |
270 elementVar := compiler allocateTemporaryVariableNamed: 'element'. |
267 " |
271 " |
268 If we want to compile in guard and the choice starts with trimming token, |
272 If we want to compile in guard and the choice starts with trimming token, |
269 we should invoke the whitespace parser |
273 we should invoke the whitespace parser |
270 " |
274 " |
271 (arguments guards and: [ firsts allSatisfy: [ :e | e isTrimmingTokenNode ] ]) ifTrue: [ |
275 (self guards and: [ firsts allSatisfy: [ :e | e isTrimmingTokenNode ] ]) ifTrue: [ |
272 self compileTokenWhitespace: firsts anyOne. |
276 self compileTokenWhitespace: firsts anyOne. |
273 whitespaceConsumed := true. |
277 whitespaceConsumed := true. |
274 ]. |
278 ]. |
275 |
279 |
276 1 to: node children size do: [ :idx | |child allowGuard | |
280 1 to: node children size do: [ :idx | |child allowGuard | |
277 child := node children at: idx. |
281 child := node children at: idx. |
278 allowGuard := whitespaceConsumed. |
282 allowGuard := whitespaceConsumed. |
279 |
283 |
280 (allowGuard and: [arguments guards and: [ (guard := PPCGuard on: child) makesSense ]]) ifTrue: [ |
284 (allowGuard and: [self guards and: [ (guard := PPCGuard on: child) makesSense ]]) ifTrue: [ |
281 guard id: (compiler idFor: guard prefixed: #guard). |
285 guard id: (compiler idFor: guard prefixed: #guard). |
282 guard compileGuard: compiler. |
286 guard compileGuard: compiler. |
283 compiler add: ' ifTrue: [ '. |
287 compiler add: ' ifTrue: [ '. |
284 compiler indent. |
288 compiler indent. |
285 compiler add: 'self clearError.'. |
289 compiler add: 'self clearError.'. |