PPCConfiguration refactoring: [8/10]: Cleaned up compilation API.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 07 Sep 2015 08:03:02 +0100
changeset 536 548996aca274
parent 535 a8feb0f47574
child 537 fb212e14d1f4
PPCConfiguration refactoring: [8/10]: Cleaned up compilation API. Methods in PPCConfiguration not meant for public use have been moved to private protocol to make it clear.
compiler/PPCConfiguration.st
--- a/compiler/PPCConfiguration.st	Fri Sep 04 14:06:56 2015 +0100
+++ b/compiler/PPCConfiguration.st	Mon Sep 07 08:03:02 2015 +0100
@@ -9,6 +9,7 @@
 	category:'PetitCompiler-Core'
 !
 
+
 !PPCConfiguration class methodsFor:'as yet unclassified'!
 
 default
@@ -51,27 +52,6 @@
     ^ context
 !
 
-defaultArguments
-    ^ PPCCompilationOptions default
-
-    "Modified: / 24-08-2015 / 23:39:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-input: aPPParser
-    ir := aPPParser asCompilerTree.    
-    self remember: (self copyTree: ir) as: #input
-
-    "Modified (format): / 29-08-2015 / 07:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-ir
-    ^ ir
-!
-
-ir: whatever
-    ir := whatever
-!
-
 options
     ^ context options
 
@@ -133,8 +113,64 @@
     "Created: / 04-09-2015 / 15:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!PPCConfiguration methodsFor:'adding / removing passes'!
+
+removePass: pass
+    | index |
+
+    self initializePassesIfNotAlready.
+    [ 
+        index := passes indexOf: pass.
+        index ~~ 0
+    ] whileTrue:[ 
+        passes removeAtIndex: index
+    ].
+
+    "Created: / 04-09-2015 / 11:24:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-09-2015 / 16:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !PPCConfiguration methodsFor:'compiling'!
 
+compile: aPPParser
+    | time |
+    self input: aPPParser.
+    
+    time := [ self compile ] timeToRun.
+    ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifFalse:[ 
+        "Assume Pharo"
+        time := time asMilliSeconds.
+    ].
+    self reportTime: time.
+    
+    ^ ir
+
+    "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!PPCConfiguration methodsFor:'initialization'!
+
+initialize
+    history := OrderedCollection new.
+    context := PPCCompilationContext new.
+
+    "Modified: / 04-09-2015 / 15:56:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+initializePassesIfNotAlready
+    passes isNil ifTrue:[ 
+        context options tokenize ifTrue:[ 
+            passes := self defaultPassesForTokenizingParser
+        ] ifFalse:[ 
+            passes := self defaultPassesForUniversalParser
+        ].
+    ].
+
+    "Created: / 04-09-2015 / 16:02:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!PPCConfiguration methodsFor:'private'!
+
 buildClass: clazz
     |  builder |
     builder := PPCClassBuilder new.
@@ -147,20 +183,16 @@
     ^ builder compileClass.	
 !
 
-compile: whatever
-    | time |
-    self input: whatever.
-    
-    time := [ self invokePhases ] timeToRun.
-    ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifFalse:[ 
-        "Assume Pharo"
-        time := time asMilliSeconds.
-    ].
-    self reportTime: time.
-    
-    ^ ir
+compile
+    self runPasses.
+    self generateScanner.
+    self generateParser.
 
-    "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 07-09-2015 / 07:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+copyTree: somethingTransformable
+    ^ somethingTransformable transform: [ :e | e copy ]
 !
 
 generateParser
@@ -212,34 +244,19 @@
     "Modified: / 04-09-2015 / 15:33:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-invokePhases
-    self initializePassesIfNotAlready.
-
-    self runPasses: passes.
-
-    self generateScanner.
-    self generateParser.
+input: aPPParser
+    ir := aPPParser asCompilerTree.    
+    self remember: (self copyTree: ir) as: #input
 
-    "Modified: / 04-09-2015 / 16:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!PPCConfiguration methodsFor:'debugging'!
-
-copy: somethingTransformable
-    self deprecated: 'copy on your own, or whatever, but dont use me'.
-    ^ somethingTransformable transform: [ :e | e copy ]
+    "Modified (format): / 29-08-2015 / 07:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-copyTree: somethingTransformable
-    ^ somethingTransformable transform: [ :e | e copy ]
+ir
+    ^ ir
 !
 
-remember: key
-    self deprecated: 'use remember:as:'.
-    
-    self options debug ifTrue: [ 
-        history add: key -> (self copy: ir).
-    ]
+ir: whatever
+    ir := whatever
 !
 
 remember: value as: key
@@ -248,56 +265,25 @@
     ]
 
     "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!PPCConfiguration methodsFor:'initialization'!
-
-initialize
-    history := OrderedCollection new.
-    context := PPCCompilationContext new.
-
-    "Modified: / 04-09-2015 / 15:56:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-initializePassesIfNotAlready
-    passes isNil ifTrue:[ 
-        context options tokenize ifTrue:[ 
-            passes := self defaultPassesForTokenizingParser
-        ] ifFalse:[ 
-            passes := self defaultPassesForUniversalParser
-        ].
-    ].
-
-    "Created: / 04-09-2015 / 16:02:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!PPCConfiguration methodsFor:'reporting'!
-
 reportTime: timeInMs
     context options profile ifTrue: [ 
-        Transcript show: 'Time to compile: ', timeInMs asString, ' ms'; cr.
+        Transcript show: 'Time to compile: '; show: timeInMs asString; show: ' ms'; cr.
     ]
 
-    "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 07-09-2015 / 07:55:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+runPasses
+    self initializePassesIfNotAlready.
+    passes do:[:each | self runPass: each  ]
+
+    "Created: / 07-09-2015 / 07:53:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'running'!
 
-removePass: pass
-    | index |
-
-    self initializePassesIfNotAlready.
-    [ 
-        index := passes indexOf: pass.
-        index ~~ 0
-    ] whileTrue:[ 
-        passes removeAtIndex: index
-    ].
-
-    "Created: / 04-09-2015 / 11:24:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 04-09-2015 / 16:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 runPass: pass
     | p |
 
@@ -307,11 +293,12 @@
 
     "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-runPasses: aCollection
-    aCollection do:[:each | self runPass: each  ]
-
-    "Created: / 04-09-2015 / 11:23:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!PPCConfiguration class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+