equal
deleted
inserted
replaced
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
2 |
4 |
3 Object subclass:#PPCNode |
5 Object subclass:#PPCNode |
4 instanceVariableNames:'contextFree name firstFollowCache firstCharSet properties' |
6 instanceVariableNames:'contextFree name firstFollowCache firstCharSet properties' |
5 classVariableNames:'' |
7 classVariableNames:'' |
6 poolDictionaries:'' |
8 poolDictionaries:'' |
367 |
369 |
368 ^ parameters |
370 ^ parameters |
369 ! |
371 ! |
370 |
372 |
371 doOptimizationLoop: params status: changeStatus |
373 doOptimizationLoop: params status: changeStatus |
372 | mapping optimized root | |
374 | mapping optimized root | |
373 mapping := IdentityDictionary new. |
375 mapping := IdentityDictionary new. |
374 self allNodes do: [ :node | |
376 self allNodes do: [ :node | |
375 optimized := (node optimize: params status: changeStatus). |
377 optimized := (node optimize: params status: changeStatus). |
376 (optimized ~= node) ifTrue: [ |
378 (optimized ~= node) ifTrue: [ |
377 mapping at: node put: optimized. |
379 mapping at: node put: optimized. |
378 ]. |
380 ]. |
379 ]. |
381 ]. |
380 |
382 |
381 root := mapping at: self ifAbsent: [ self ]. |
383 root := mapping at: self ifAbsent: [ self ]. |
382 [ | changed | |
384 [ | changed | |
383 changed := false. |
385 changed := false. |
384 root allNodes do: [ :node | |
386 root allNodes do: [ :node | |
385 node children do: [ :child | |
387 node children do: [ :child | |
386 mapping at: child ifPresent: [:newChild | |
388 mapping at: child ifPresent: [:newChild | |
387 node replace: child with: newChild. |
389 node replace: child with: newChild. |
388 changed := true. |
390 changed := true ] |
389 changeStatus change] |
391 ]]. |
390 ]]. |
392 changed |
391 changed |
393 ] whileTrue. |
392 ] whileTrue. |
394 ^ root |
393 ^ root |
|
394 |
|
395 "Modified: / 26-10-2014 / 01:14:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
396 ! |
395 ! |
397 |
396 |
398 inline: changeStatus |
397 inline: changeStatus |
399 "nothing to do" |
398 "nothing to do" |
400 ! |
399 ! |
475 ifTrue: [ ^ self ]. |
474 ifTrue: [ ^ self ]. |
476 aSet add: self. |
475 aSet add: self. |
477 aBlock value: self. |
476 aBlock value: self. |
478 self children |
477 self children |
479 do: [ :each | each allParsersDo: aBlock seen: aSet ] |
478 do: [ :each | each allParsersDo: aBlock seen: aSet ] |
480 ! |
|
481 |
|
482 firstSets: aFirstDictionary into: aSet |
|
483 self children do: [ :child | aSet addAll: (aFirstDictionary at: child) ] |
|
484 ! ! |
479 ! ! |
485 |
480 |
486 !PPCNode methodsFor:'transformation'! |
481 !PPCNode methodsFor:'transformation'! |
487 |
482 |
488 asCompilerNode |
483 asCompilerNode |