Skip to content

Commit 8e3bad9

Browse files
committed
Address review comments
1 parent cdfa433 commit 8e3bad9

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,12 @@ class JavaPlatform extends Platform {
2121
}
2222

2323
// The given symbol is a method with the right name and signature to be a runnable java program.
24-
def isJavaMainMethod(sym: SymDenotation)(implicit ctx: Context) =
24+
def isMainMethod(sym: SymDenotation)(implicit ctx: Context) =
2525
(sym.name == nme.main) && (sym.info match {
2626
case MethodTpe(_, defn.ArrayOf(el) :: Nil, restpe) => el =:= defn.StringType && (restpe isRef defn.UnitClass)
2727
case _ => false
2828
})
2929

30-
// The given class has a main method.
31-
def hasJavaMainMethod(sym: Symbol)(implicit ctx: Context): Boolean =
32-
(sym.info member nme.main).hasAltWith {
33-
case x: SymDenotation => isJavaMainMethod(x)
34-
case _ => false
35-
}
36-
3730
/** Update classpath with a substituted subentry */
3831
def updateClassPath(subst: Map[ClassPath, ClassPath]): Unit = currentClassPath.get match {
3932
case AggregateClassPath(entries) =>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ package config
1010
import io.{ClassPath, AbstractFile}
1111
import core.Contexts._, core.Symbols._
1212
import core.SymbolLoader
13+
import core.SymDenotations.SymDenotation
14+
import core.StdNames.nme
1315

1416
/** The platform dependent pieces of Global.
1517
*/
@@ -35,5 +37,15 @@ abstract class Platform {
3537

3638
/** Create a new class loader to load class file `bin` */
3739
def newClassLoader(bin: AbstractFile)(implicit ctx: Context): SymbolLoader
40+
41+
/** The given symbol is a method with the right name and signature to be a runnable program. */
42+
def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean
43+
44+
/** The given class has a main method. */
45+
final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean =
46+
sym.info.member(nme.main).hasAltWith {
47+
case x: SymDenotation => isMainMethod(x)
48+
case _ => false
49+
}
3850
}
3951

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,9 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
228228
name, acc, modifiers, anns, defType, api.SafeLazy.strict(selfType), api.SafeLazy.strict(structure), Constants.emptyStringArray,
229229
childrenOfSealedClass, topLevel, tparams)
230230

231-
// if (name.toString.contains("DottyPredef")) {
232-
// println("sym: " + sym)
233-
// println("name: " + name)
234-
// ctx.atPhase(ctx.flattenPhase.next) { implicit ctx =>
235-
// println("flatten: " + sym.fullName.toString)
236-
// println("flattenm: " + sym.fullName.mangledString)
237-
// }
238-
// println("flattenx: " + toDenot(sym.binaryName.toString)
239-
// }
240-
241231
allNonLocalClassesInSrc += cl
242232

243-
val javaPlatform = ctx.platform.asInstanceOf[JavaPlatform]
244-
if (sym.isStatic && defType == DefinitionType.Module && javaPlatform.hasJavaMainMethod(sym)) {
233+
if (sym.isStatic && defType == DefinitionType.Module && ctx.platform.hasMainMethod(sym)) {
245234
_mainClasses += name
246235
}
247236

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ object ExtractDependencies {
161161

162162
private case class ClassDependency(from: Symbol, to: Symbol, context: DependencyContext)
163163

164+
/** An object that maintain the set of used names from within a class */
164165
private final class UsedNamesInClass {
165166
private val _names = new mutable.HashMap[Name, EnumSet[UseScope]]
166167
def names: collection.Map[Name, EnumSet[UseScope]] = _names

compiler/src/dotty/tools/dotc/transform/CollectEntryPoints.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ class CollectEntryPoints extends MiniPhase {
7070
}
7171
def precise(implicit ctx: Context) = {
7272
val companion = sym.companionClass //sym.asClass.linkedClassOfClass
73-
val javaPlatform = ctx.platform.asInstanceOf[JavaPlatform]
74-
if (javaPlatform.hasJavaMainMethod(companion))
73+
if (ctx.platform.hasMainMethod(companion))
7574
failNoForwarder("companion contains its own main method")
7675
else if (companion.exists && companion.info.member(nme.main).exists)
7776
// this is only because forwarders aren't smart enough yet
@@ -80,7 +79,7 @@ class CollectEntryPoints extends MiniPhase {
8079
failNoForwarder("companion is a trait")
8180
// Now either succeed, or issue some additional warnings for things which look like
8281
// attempts to be java main methods.
83-
else (possibles exists (x => javaPlatform.isJavaMainMethod(x.symbol))) || {
82+
else (possibles exists (x => ctx.platform.isMainMethod(x.symbol))) || {
8483
possibles exists {
8584
m =>
8685
m.symbol.info match {
@@ -90,7 +89,7 @@ class CollectEntryPoints extends MiniPhase {
9089
if (t.resultType :: t.paramInfos exists (_.typeSymbol.isAbstractType))
9190
fail("main methods cannot refer to type parameters or abstract types.", m.symbol.pos)
9291
else
93-
javaPlatform.isJavaMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.pos)
92+
ctx.platform.isMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.pos)
9493
case tp =>
9594
fail(s"don't know what this is: $tp", m.symbol.pos)
9695
}

0 commit comments

Comments
 (0)