From 906a7a7dfa38e53bfdffa2e94ddbf5eb23587592 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sun, 20 Dec 2015 11:44:08 +0100 Subject: Linker Specific: allow phases to get to TASTY section. Makes all classes and fields on the way to TASTY section accessible. Example of usage can be found here: https://gist.github.com/DarkDimius/0f9dc769b0dd7a3c7365 --- src/dotty/tools/dotc/core/Types.scala | 8 ++++++ .../tools/dotc/core/tasty/DottyUnpickler.scala | 33 +++++++++++----------- 2 files changed, 25 insertions(+), 16 deletions(-) (limited to 'src/dotty/tools/dotc') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 21b74e07b..28bd7ffed 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -995,6 +995,14 @@ object Types { case _ => Nil } + /** The parameter types of a PolyType or MethodType, Empty list for others */ + final def paramNamess(implicit ctx: Context): List[List[TermName]] = this match { + case mt: MethodType => mt.paramNames :: mt.resultType.paramNamess + case pt: PolyType => pt.resultType.paramNamess + case _ => Nil + } + + /** The parameter types in the first parameter section of a PolyType or MethodType, Empty list for others */ final def firstParamTypes(implicit ctx: Context): List[Type] = this match { case mt: MethodType => mt.paramTypes diff --git a/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala b/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala index ccd3f78e8..d62762571 100644 --- a/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala @@ -6,6 +6,7 @@ package tasty import Contexts._, SymDenotations._ import dotty.tools.dotc.ast.tpd import TastyUnpickler._, TastyBuffer._ +import dotty.tools.dotc.core.tasty.DottyUnpickler.{SourceFileUnpickler, TreeSectionUnpickler, PositionsSectionUnpickler} import util.Positions._ import util.{SourceFile, NoSource} import PositionUnpickler._ @@ -15,6 +16,21 @@ object DottyUnpickler { /** Exception thrown if classfile is corrupted */ class BadSignature(msg: String) extends RuntimeException(msg) + + class SourceFileUnpickler extends SectionUnpickler[SourceFile]("Sourcefile") { + def unpickle(reader: TastyReader, tastyName: TastyName.Table) = + new SourceFile(tastyName(reader.readNameRef()).toString, Seq()) + } + + class TreeSectionUnpickler extends SectionUnpickler[TreeUnpickler]("ASTs") { + def unpickle(reader: TastyReader, tastyName: TastyName.Table) = + new TreeUnpickler(reader, tastyName) + } + + class PositionsSectionUnpickler extends SectionUnpickler[(Position, AddrToPosition)]("Positions") { + def unpickle(reader: TastyReader, tastyName: TastyName.Table) = + new PositionUnpickler(reader).unpickle() + } } /** A class for unpickling Tasty trees and symbols. @@ -23,7 +39,7 @@ object DottyUnpickler { class DottyUnpickler(bytes: Array[Byte]) extends ClassfileParser.Embedded { import tpd._ - private val unpickler = new TastyUnpickler(bytes) + val unpickler = new TastyUnpickler(bytes) private val treeUnpickler = unpickler.unpickle(new TreeSectionUnpickler).get /** Enter all toplevel classes and objects into their scopes @@ -42,19 +58,4 @@ class DottyUnpickler(bytes: Array[Byte]) extends ClassfileParser.Embedded { treeUnpickler.usePositions(totalRange, positions) (treeUnpickler.unpickle(), source) } - - private class SourceFileUnpickler extends SectionUnpickler[SourceFile]("Sourcefile") { - def unpickle(reader: TastyReader, tastyName: TastyName.Table) = - new SourceFile(tastyName(reader.readNameRef()).toString, Seq()) - } - - private class TreeSectionUnpickler extends SectionUnpickler[TreeUnpickler]("ASTs") { - def unpickle(reader: TastyReader, tastyName: TastyName.Table) = - new TreeUnpickler(reader, tastyName) - } - - private class PositionsSectionUnpickler extends SectionUnpickler[(Position, AddrToPosition)]("Positions") { - def unpickle(reader: TastyReader, tastyName: TastyName.Table) = - new PositionUnpickler(reader).unpickle() - } } -- cgit v1.2.3