Skip to content

Commit 7ac7c56

Browse files
committed
Bassic support for dotp flags
1 parent 6c5c9ec commit 7ac7c56

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class ScalaSettings extends Settings.SettingGroup {
9696
val YnoPatmatOpt = BooleanSetting("-Yno-patmat-opt", "disable all pattern matching optimizations.")
9797
val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.")
9898
val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.")
99+
val YprintNoPrivate = BooleanSetting("-Y-print-no-private", "when printing trees print do not print private/protected members.")
99100
val YprintDebug = BooleanSetting("-Yprint-debug", "when printing trees, print some extra information useful for debugging.")
100101
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
101102
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
192192
}
193193

194194
def blockText[T >: Untyped](trees: List[Tree[T]]): Text =
195-
("{" ~ toText(trees, "\n") ~ "}").close
195+
("{" ~ toText(trees.filter(t => !t.symbol.isPrivate), "\n") ~ "}").close
196196

197197
override def toText[T >: Untyped](tree: Tree[T]): Text = controlled {
198198

@@ -318,6 +318,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
318318
case _ => false
319319
}
320320
params ::: rest
321+
} else if (ctx.settings.YprintNoPrivate.value) {
322+
impl.body.filter(t => !t.symbol.isPrivate && !t.symbol.is(Protected))
321323
} else impl.body
322324

323325
val bodyText = "{" ~~ selfText ~~ toTextGlobal(primaryConstrs ::: body, "\n") ~ "}"

compiler/src/dotty/tools/dotp/Main.scala

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,28 @@ object Main extends dotc.Driver {
1313
new TASTYDecompiler
1414
}
1515

16-
override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
17-
val args1 = if (args.contains("-tasty")) args else args :+ "-tasty"
18-
super.setup(args1, rootCtx)
16+
override def setup(args0: Array[String], rootCtx: Context): (List[String], Context) = {
17+
var args = args0
18+
args = if (args.contains("-tasty")) args else args :+ "-tasty"
19+
args = if (args.exists(a => a == "-private" || a == "-p")) args.filter(a => a != "-private" && a != "-p") else args :+ "-Y-print-no-private"
20+
args = if (args.exists(a => a == "-code" || a == "-c")) args.filter(a => a != "-code" && a != "-c") else args :+ "-Yprint-syms"
21+
22+
if (args.contains("-help")) {
23+
printHelp()
24+
sys.exit(0)
25+
} else super.setup(args, rootCtx)
26+
}
27+
28+
private def printHelp(): Unit = {
29+
val msg =
30+
"""dotp <option|class>*
31+
|
32+
|options:
33+
| -private | -p Print private and protected members
34+
| -code | -c Print implementations (code disassembly)
35+
| -classpath <path> Classpath where to find the classes
36+
| -help Print this message
37+
""".stripMargin
38+
println(msg)
1939
}
2040
}

project/scripts/sbtBootstrappedTests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mkdir out/scriptedtest2
3737
# check that `dotp` runs
3838
echo "testing ./bin/dotp"
3939
./bin/dotp -classpath out/scriptedtest1 dotrtest.Test > sbtdotr3.out
40-
if grep -e "def main(args: Array\[String\]): Unit =" sbtdotr3.out; then
40+
if grep -e "def main(args: Array\[String\]): Unit" sbtdotr3.out; then
4141
echo "output ok"
4242
else
4343
echo "failed output check"

project/scripts/sbtTests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fi
2929
# check that `sbt dotp` runs
3030
echo "testing sbt dotp"
3131
./project/scripts/sbt ";dotp -tasty -classpath out/scriptedtest1 dotrtest.Test" > sbtdotr3.out
32-
if grep -e "def main(args: Array\[String\]): Unit =" sbtdotr3.out; then
32+
if grep -e "def main(args: Array\[String\]): Unit" sbtdotr3.out; then
3333
echo "output ok"
3434
else
3535
echo "failed output check"

0 commit comments

Comments
 (0)