-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename tasty-consumer to tasty-inspector
Also rework TastyInspector API to simplify use.
- Loading branch information
1 parent
b4c1d50
commit 83fc85a
Showing
23 changed files
with
128 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
tasty-consumer/src/scala/tasty/file/TastyConsumerPhase.scala
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package scala.tasty.inspector | ||
|
||
import scala.tasty.Reflection | ||
|
||
import dotty.tools.dotc.Compiler | ||
import dotty.tools.dotc.Driver | ||
import dotty.tools.dotc.Run | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.Mode | ||
import dotty.tools.dotc.core.Phases.Phase | ||
import dotty.tools.dotc.fromtasty._ | ||
import dotty.tools.dotc.tastyreflect.ReflectionImpl | ||
import dotty.tools.dotc.util.ClasspathFromClassloader | ||
|
||
import java.io.File.pathSeparator | ||
|
||
trait TastyInspector { self => | ||
|
||
/** Process a TASTy file using TASTy reflect */ | ||
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit | ||
|
||
/** Load and process TASTy files using TASTy reflect | ||
* | ||
* @param classpath Classpath where the classes are located | ||
* @param classes classes to be inspected | ||
*/ | ||
def inspect(classpath: String, classes: List[String]): Unit = { | ||
if (classes.isEmpty) | ||
throw new IllegalArgumentException("Parameter classes should no be empty") | ||
|
||
class InspectorDriver extends Driver { | ||
override protected def newCompiler(implicit ctx: Context): Compiler = new TastyFromClass | ||
} | ||
|
||
class TastyFromClass extends TASTYCompiler { | ||
override protected def frontendPhases: List[List[Phase]] = | ||
List(new ReadTasty) :: // Load classes from tasty | ||
Nil | ||
|
||
override protected def picklerPhases: List[List[Phase]] = Nil | ||
override protected def transformPhases: List[List[Phase]] = Nil | ||
|
||
override protected def backendPhases: List[List[Phase]] = | ||
List(new TastyInspectorPhase) :: // Print all loaded classes | ||
Nil | ||
|
||
override def newRun(implicit ctx: Context): Run = { | ||
reset() | ||
new TASTYRun(this, ctx.fresh.addMode(Mode.ReadPositions).addMode(Mode.ReadComments)) | ||
} | ||
} | ||
|
||
class TastyInspectorPhase extends Phase { | ||
override def phaseName: String = "tastyInspector" | ||
|
||
override def run(implicit ctx: Context): Unit = { | ||
val reflect = ReflectionImpl(ctx) | ||
self.processCompilationUnit(reflect)(ctx.compilationUnit.tpdTree.asInstanceOf[reflect.Tree]) | ||
} | ||
} | ||
|
||
val currentClasspath = ClasspathFromClassloader(getClass.getClassLoader) | ||
val args = "-from-tasty" :: "-Yretain-trees" :: "-classpath" :: s"$classpath$pathSeparator$currentClasspath" :: classes | ||
(new InspectorDriver).process(args.toArray) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.