aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/dotty/tools/dotc/parsing/parsePackage.scala
blob: df5368ffe337bd7fabcb43dbca24ea530e7352e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package dotty.tools
package dotc
package parsing

import dotty.tools.dotc._
import core._, ast._
import Trees._
import Contexts.Context

object parsePackage extends ParserTest {

  import ast.untpd._

  var nodes = 0

  val transformer = new UntypedTreeMap {
    override def transform(tree: Tree)(implicit ctx: Context): Tree = {
      nodes += 1
      tree match {
        case Ident(name) =>
          Ident(name)
        case This(name) =>
          This(name)
        case TypedSplice(t) =>
          TypedSplice(t)
        case SymbolLit(str) =>
          tree
        case InterpolatedString(id, segments) =>
          InterpolatedString(id, segments map transform)
        case mdef @ ModuleDef(name, impl) =>
          ModuleDef(name, transformSub(impl)).withMods(mdef.mods)
        case Function(params, body) =>
          Function(params map transform, body)
        case InfixOp(l, o, r) =>
          InfixOp(transform(l), o, transform(r))
        case PostfixOp(l, o) =>
          PostfixOp(transform(l), o)
        case PrefixOp(o, t) =>
          PrefixOp(o, transform(t))
        case Parens(t) =>
          Parens(transform(t))
        case Tuple(ts) =>
          Tuple(ts map transform)
        case WhileDo(cond, body) =>
          WhileDo(transform(cond), transform(body))
        case DoWhile(body, cond) =>
          DoWhile(transform(body), transform(cond))
        case ForYield(enums, expr) =>
          ForYield(enums map transform, transform(expr))
        case ForDo(enums, expr) =>
          ForDo(enums map transform, transform(expr))
        case GenFrom(pat, expr) =>
          GenFrom(transform(pat), transform(expr))
        case GenAlias(pat, expr) =>
          GenAlias(transform(pat), transform(expr))
        case PatDef(mods, pats, tpt, expr) =>
          PatDef(mods, pats map transform, transform(tpt), transform(expr))
        case ContextBounds(bounds, cxBounds) =>
          ContextBounds(transformSub(bounds), cxBounds map transform)
        case _ =>
          super.transform(tree)
      }
    }
  }

  def test() = {
    reset()
    nodes = 0
    val start = System.nanoTime()
    parseDir("./src")
    parseDir("./scala-scala/src")
    val ms1 = (System.nanoTime() - start)/1000000
    val buf = parsedTrees map transformer.transform
    val ms2 = (System.nanoTime() - start)/1000000
    println(s"$parsed files parsed in ${ms1}ms, $nodes nodes transformed in ${ms2-ms1}ms, total trees created = ${Trees.ntrees}")
    ctx.reporter.printSummary(ctx)
  }

  def main(args: Array[String]): Unit = {
//    parse("/Users/odersky/workspace/scala/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala")
    for (i <- 0 until 10) test()
  }
}