Skip to content

Commit a8ed435

Browse files
committed
Rewrite compiler to indent
1 parent fa84fe7 commit a8ed435

File tree

455 files changed

+11909
-22357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

455 files changed

+11909
-22357
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ case class CompileSettings(
4040
compiler: Boolean = false,
4141
quiet: Boolean = false,
4242
colors: Boolean = false,
43-
) {
43+
):
4444
def withCompileMode(em: CompileMode): CompileSettings = this.compileMode match
4545
case CompileMode.Guess =>
4646
this.copy(compileMode = em)
@@ -83,9 +83,8 @@ case class CompileSettings(
8383

8484
def withNoColors: CompileSettings =
8585
this.copy(colors = false)
86-
}
8786

88-
object MainGenericCompiler {
87+
object MainGenericCompiler:
8988

9089
val classpathSeparator = File.pathSeparator
9190

@@ -185,4 +184,3 @@ object MainGenericCompiler {
185184

186185
run(settings)
187186
end main
188-
}

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ case class Settings(
4242
modeShouldBePossibleRun: Boolean = false,
4343
modeShouldBeRun: Boolean = false,
4444
compiler: Boolean = false,
45-
) {
45+
):
4646
def withExecuteMode(em: ExecuteMode): Settings = this.executeMode match
4747
case ExecuteMode.Guess | ExecuteMode.PossibleRun =>
4848
this.copy(executeMode = em)
@@ -94,9 +94,8 @@ case class Settings(
9494

9595
def withCompiler: Settings =
9696
this.copy(compiler = true)
97-
}
9897

99-
object MainGenericRunner {
98+
object MainGenericRunner:
10099

101100
val classpathSeparator = File.pathSeparator
102101

@@ -212,7 +211,7 @@ object MainGenericRunner {
212211
case ExecuteMode.Run =>
213212
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
214213
val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
215-
ObjectRunner.runAndCatch(newClasspath, settings.targetToRun, settings.residualArgs).flatMap {
214+
ObjectRunner.runAndCatch(newClasspath, settings.targetToRun, settings.residualArgs).flatMap:
216215
case ex: ClassNotFoundException if ex.getMessage == settings.targetToRun =>
217216
val file = settings.targetToRun
218217
Jar(file).mainClass match
@@ -221,7 +220,6 @@ object MainGenericRunner {
221220
case None =>
222221
Some(IllegalArgumentException(s"No main class defined in manifest in jar: $file"))
223222
case ex => Some(ex)
224-
}
225223

226224
case ExecuteMode.Script =>
227225
val targetScript = Paths.get(settings.targetScript).toFile
@@ -250,10 +248,9 @@ object MainGenericRunner {
250248
scripting.Main.process(properArgs.toArray)
251249

252250
case ExecuteMode.Expression =>
253-
val cp = settings.classPath match {
251+
val cp = settings.classPath match
254252
case Nil => ""
255253
case list => list.mkString(classpathSeparator)
256-
}
257254
val cpArgs = if cp.isEmpty then Nil else List("-classpath", cp)
258255
val properArgs = cpArgs ++ settings.residualArgs ++ settings.scalaArgs
259256
val driver = StringDriver(properArgs.toArray, settings.targetExpression)
@@ -280,4 +277,3 @@ object MainGenericRunner {
280277
def main(args: Array[String]): Unit =
281278
if (!process(args)) System.exit(1)
282279

283-
}

compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package backend
33

44
object ScalaPrimitivesOps extends ScalaPrimitivesOps
55

6-
class ScalaPrimitivesOps {
6+
class ScalaPrimitivesOps:
77
// Arithmetic unary operations
88
inline val POS = 1 // +x
99
inline val NEG = 2 // -x
@@ -165,68 +165,58 @@ class ScalaPrimitivesOps {
165165
def isArrayOp(code: Int): Boolean =
166166
isArrayNew(code) | isArrayLength(code) | isArrayGet(code) | isArraySet(code)
167167

168-
def isArrayNew(code: Int): Boolean = code match {
168+
def isArrayNew(code: Int): Boolean = code match
169169
case NEW_ZARRAY | NEW_BARRAY | NEW_SARRAY | NEW_CARRAY |
170170
NEW_IARRAY | NEW_LARRAY | NEW_FARRAY | NEW_DARRAY |
171171
NEW_OARRAY => true
172172
case _ => false
173-
}
174173

175-
def isArrayLength(code: Int): Boolean = code match {
174+
def isArrayLength(code: Int): Boolean = code match
176175
case ZARRAY_LENGTH | BARRAY_LENGTH | SARRAY_LENGTH | CARRAY_LENGTH |
177176
IARRAY_LENGTH | LARRAY_LENGTH | FARRAY_LENGTH | DARRAY_LENGTH |
178177
OARRAY_LENGTH | LENGTH => true
179178
case _ => false
180-
}
181179

182-
def isArrayGet(code: Int): Boolean = code match {
180+
def isArrayGet(code: Int): Boolean = code match
183181
case ZARRAY_GET | BARRAY_GET | SARRAY_GET | CARRAY_GET |
184182
IARRAY_GET | LARRAY_GET | FARRAY_GET | DARRAY_GET |
185183
OARRAY_GET | APPLY => true
186184
case _ => false
187-
}
188185

189-
def isArraySet(code: Int): Boolean = code match {
186+
def isArraySet(code: Int): Boolean = code match
190187
case ZARRAY_SET | BARRAY_SET | SARRAY_SET | CARRAY_SET |
191188
IARRAY_SET | LARRAY_SET | FARRAY_SET | DARRAY_SET |
192189
OARRAY_SET | UPDATE => true
193190
case _ => false
194-
}
195191

196192
/** Check whether the given code is a comparison operator */
197-
def isComparisonOp(code: Int): Boolean = code match {
193+
def isComparisonOp(code: Int): Boolean = code match
198194
case ID | NI | EQ | NE |
199195
LT | LE | GT | GE => true
200196

201197
case _ => false
202-
}
203198
def isUniversalEqualityOp(code: Int): Boolean = (code == EQ) || (code == NE)
204199
def isReferenceEqualityOp(code: Int): Boolean = (code == ID) || (code == NI)
205200

206-
def isArithmeticOp(code: Int): Boolean = code match {
201+
def isArithmeticOp(code: Int): Boolean = code match
207202
case POS | NEG | NOT => true; // unary
208203
case ADD | SUB | MUL |
209204
DIV | MOD => true; // binary
210205
case OR | XOR | AND |
211206
LSL | LSR | ASR => true; // bitwise
212207
case _ => false
213-
}
214208

215-
def isLogicalOp(code: Int): Boolean = code match {
209+
def isLogicalOp(code: Int): Boolean = code match
216210
case ZNOT | ZAND | ZOR => true
217211
case _ => false
218-
}
219212

220-
def isShiftOp(code: Int): Boolean = code match {
213+
def isShiftOp(code: Int): Boolean = code match
221214
case LSL | LSR | ASR => true
222215
case _ => false
223-
}
224216

225-
def isBitwiseOp(code: Int): Boolean = code match {
217+
def isBitwiseOp(code: Int): Boolean = code match
226218
case OR | XOR | AND => true
227219
case _ => false
228-
}
229220

230221
def isCoercion(code: Int): Boolean = (code >= B2B) && (code <= D2D)
231222

232-
}

compiler/src/dotty/tools/backend/WorklistAlgorithm.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ package backend
1414
* @version 1.0
1515
* @see [[scala.tools.nsc.backend.icode.Linearizers]]
1616
*/
17-
trait WorklistAlgorithm {
17+
trait WorklistAlgorithm:
1818
type Elem
19-
class WList {
19+
class WList:
2020
private var list: List[Elem] = Nil
2121
def isEmpty = list.isEmpty
2222
def nonEmpty = !isEmpty
2323
def push(e: Elem): Unit = { list = e :: list }
24-
def pop(): Elem = {
24+
def pop(): Elem =
2525
val head = list.head
2626
list = list.tail
2727
head
28-
}
2928
def pushAll(xs: Iterable[Elem]): Unit = xs.foreach(push)
3029
def clear(): Unit = list = Nil
3130

32-
}
3331

3432
val worklist: WList
3533

@@ -38,12 +36,11 @@ trait WorklistAlgorithm {
3836
* The initializer is run once before the loop starts and should
3937
* initialize the worklist.
4038
*/
41-
def run(initWorklist: => Unit) = {
39+
def run(initWorklist: => Unit) =
4240
initWorklist
4341

4442
while (worklist.nonEmpty)
4543
processElement(dequeue)
46-
}
4744

4845
/**
4946
* Process the current element from the worklist.
@@ -54,4 +51,3 @@ trait WorklistAlgorithm {
5451
* Remove and return the first element to be processed from the worklist.
5552
*/
5653
def dequeue: Elem
57-
}

compiler/src/dotty/tools/backend/jvm/AsmUtils.scala

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.io.PrintWriter
99
import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier}
1010
import scala.tools.asm.ClassReader
1111

12-
object AsmUtils {
12+
object AsmUtils:
1313

1414
/**
1515
* Print the bytecode of methods generated by GenBCode to the standard output. Only methods
@@ -33,33 +33,28 @@ object AsmUtils {
3333
inline val traceSerializedClassEnabled = false
3434
inline val traceSerializedClassPattern = ""
3535

36-
def traceMethod(mnode: MethodNode1): Unit = {
36+
def traceMethod(mnode: MethodNode1): Unit =
3737
println(s"Bytecode for method ${mnode.name}")
3838
val p = new Textifier
3939
val tracer = new TraceMethodVisitor(p)
4040
mnode.accept(tracer)
4141
val w = new PrintWriter(System.out)
4242
p.print(w)
4343
w.flush()
44-
}
4544

46-
def traceClass(cnode: ClassNode1): Unit = {
45+
def traceClass(cnode: ClassNode1): Unit =
4746
println(s"Bytecode for class ${cnode.name}")
4847
val w = new PrintWriter(System.out)
4948
cnode.accept(new TraceClassVisitor(w))
5049
w.flush()
51-
}
5250

5351
def traceClass(bytes: Array[Byte]): Unit = traceClass(readClass(bytes))
5452

55-
def readClass(bytes: Array[Byte]): ClassNode1 = {
53+
def readClass(bytes: Array[Byte]): ClassNode1 =
5654
val node = new ClassNode1()
5755
new ClassReader(bytes).accept(node, 0)
5856
node
59-
}
6057

61-
def instructionString(instruction: AbstractInsnNode): String = instruction.getOpcode match {
58+
def instructionString(instruction: AbstractInsnNode): String = instruction.getOpcode match
6259
case -1 => instruction.toString
6360
case op => scala.tools.asm.util.Printer.OPCODES(op)
64-
}
65-
}

0 commit comments

Comments
 (0)