summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/CompilationUnits.scala
blob: e76f95d207943a6ffc9e17a1b5a6ccbca8711222 (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
/* NSC -- new Scala compiler
 * Copyright 2005-2006 LAMP/EPFL
 * @author  Martin Odersky
 */
// $Id$

package scala.tools.nsc

import scala.tools.nsc.util.{FreshNameCreator,Position,SourceFile}
import scala.tools.nsc.io.AbstractFile
import scala.collection.mutable.HashSet

trait CompilationUnits requires Global {

  /** One unit of compilation that has been submitted to the compiler.
    * It typically corresponds to a single file of source code.  It includes
    * error-reporting hooks.  */
  class CompilationUnit(val source: SourceFile) {

    /** the fresh name creator */
    var fresh = new FreshNameCreator

    /** the content of the compilation unit in tree form */
    var body: Tree = EmptyTree

    val depends = new HashSet[AbstractFile]

    def position(pos: int) = new Position(source, pos)

    /** The icode representation of classes in this compilation unit.
     *  It is empty up to phase 'icode'.
     */
    val icode: HashSet[icodes.IClass] = new HashSet

    val errorPositions = new HashSet[int]

    def error(pos: int, msg: String) =
      if (!(errorPositions contains pos)) {
        errorPositions += pos
        reporter.error(position(pos), msg)
      }

    def warning(pos: int, msg: String) =
      if (!(errorPositions contains pos)) {
        errorPositions += pos
        reporter.warning(position(pos), msg)
      }

    def deprecationWarning(pos: int, msg: String) =
      if (settings.deprecation.value) warning(pos, msg)
      else currentRun.deprecationWarnings = true

    def uncheckedWarning(pos: int, msg: String) =
      if (settings.unchecked.value) warning(pos, msg)
      else currentRun.uncheckedWarnings = true

    def incompleteInputError(pos:int, msg:String) =
      if (!(errorPositions contains pos)) {
        errorPositions += pos
        reporter.incompleteInputError(position(pos), msg)
      }

    override def toString() = source.toString()

    def clear() = {
      fresh = null
      body = null
      depends.clear
      errorPositions.clear
    }
  }
}