-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow tasty files to be the input of -from-tasty #5325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolasstucki
merged 6 commits into
scala:master
from
dotty-staging:add-tasty-file-input
Nov 23, 2018
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff48634
Allow tasty files to be the input of -from-tasty
nicolasstucki 15b912a
Use File.pathSeparator
nicolasstucki 4e6adcf
Fix handling of empty package and ASTs name
nicolasstucki 830cdb1
Get name by reading the TASTy tree
nicolasstucki c034eaf
Rename variables
nicolasstucki 0bf8b17
Move tasty setup logic and invert classpath order
nicolasstucki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
58 changes: 58 additions & 0 deletions
58
compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala
This file contains hidden or 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,58 @@ | ||
package dotty.tools.dotc | ||
package core | ||
package tasty | ||
|
||
import Contexts._, Decorators._ | ||
import Names.{Name, TermName} | ||
import StdNames.nme | ||
import TastyUnpickler._ | ||
import TastyBuffer.NameRef | ||
import util.Positions.offsetToInt | ||
import printing.Highlighting._ | ||
|
||
/** Reads the package and class name of the class contained in this TASTy */ | ||
class TastyClassName(bytes: Array[Byte]) { | ||
|
||
val unpickler: TastyUnpickler = new TastyUnpickler(bytes) | ||
import unpickler.{nameAtRef, unpickle} | ||
|
||
/** Returns a tuple with the package and class names */ | ||
def readName(): Option[(TermName, TermName)] = unpickle(new TreeSectionUnpickler) | ||
|
||
class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](TreePickler.sectionName) { | ||
import TastyFormat._ | ||
def unpickle(reader: TastyReader, tastyName: NameTable): (TermName, TermName) = { | ||
import reader._ | ||
def readName() = { | ||
val idx = readNat() | ||
nameAtRef(NameRef(idx)) | ||
} | ||
def readNames(pack: TermName): (TermName, TermName) = { | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val tag = readByte() | ||
if (tag >= firstLengthTreeTag) { | ||
val len = readNat() | ||
val end = currentAddr + len | ||
tag match { | ||
case TYPEDEF => | ||
val name = readName() | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
goto(end) | ||
(pack, name) | ||
case IMPORT | VALDEF => | ||
goto(end) | ||
readNames(pack) | ||
case PACKAGE => | ||
readNames(pack) | ||
} | ||
} | ||
else tag match { | ||
case TERMREFpkg | TYPEREFpkg => | ||
val packName = readName() | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
readNames(packName) | ||
case _ => | ||
readNames(pack) | ||
} | ||
} | ||
readNames(nme.EMPTY_PACKAGE) | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala
This file contains hidden or 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,38 @@ | ||
package dotty.tools.dotc | ||
package fromtasty | ||
|
||
import java.nio.file.{Files, Path, Paths} | ||
import java.io | ||
|
||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.NameKinds | ||
import dotty.tools.dotc.core.Names.SimpleName | ||
import dotty.tools.dotc.core.StdNames.nme | ||
import dotty.tools.dotc.core.tasty.{TastyUnpickler, TreePickler} | ||
|
||
object TastyFileUtil { | ||
|
||
/** Get the class path and the class name including packages | ||
* | ||
* If | ||
* ```scala | ||
* package foo | ||
* class Foo | ||
* ``` | ||
* then `getClassName("./out/foo/Foo.tasty") returns `Some(("./out", "foo.Foo"))` | ||
*/ | ||
def getClassName(path: Path): Option[(String, String)] = { | ||
assert(path.toString.endsWith(".tasty")) | ||
assert(Files.exists(path)) | ||
val bytes = Files.readAllBytes(path) | ||
val names = new core.tasty.TastyClassName(bytes).readName() | ||
names.map { case (packName, className) => | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val fullName = s"$packName.${className.lastPart}" | ||
val classInPath = fullName.replace(".", io.File.separator) + ".tasty" | ||
val classpath = path.toString.replace(classInPath, "") | ||
(classpath, fullName) | ||
} | ||
|
||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.