summaryrefslogtreecommitdiff
path: root/sources/scalac/Unit.java
blob: 97058d73d8389feaa025dd0bcd46cc1036959a1d (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
84
85
86
87
88
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**                                                                      **
** $Id$
\*                                                                      */

package scalac;

import ch.epfl.lamp.util.SourceFile;
import ch.epfl.lamp.util.Position;

import scalac.symtab.NameMangler;
import scalac.ast.Tree;
import scalac.atree.ARepository;
import java.util.HashMap;


/** A representation for a compilation unit in scala
 *
 *  @author     Matthias Zenger
 *  @version    1.0
 */
public class Unit {

    /** the global compilation environment
     */
    public final Global global;

    /** the associated source code file
     */
    public final SourceFile source;

    /** does this unit come from the interpreter console
     */
    public final boolean console;

    /** is this unit only there for mixin expansion?
     */
    public final boolean mixinOnly;

    /** the content of the compilation unit in tree form
     */
    public Tree[] body;
    public ARepository repository;

    /** the name mangler
     */
    public NameMangler mangler = new NameMangler();

    public Unit(Global global, SourceFile source,
		boolean console, boolean mixinOnly) {
        this.global = global;
        this.source = source;
        this.console = console;
	this.mixinOnly = mixinOnly;
    }

    public Unit(Global global, SourceFile source, boolean console) {
	this(global, source, console, false);
    }

    /** return the position representing the given encoded position
     */
    public Position position(int pos) {
        return new Position(source, pos);
    }

    /** issue an error in this compilation unit at a specific location
     */
    public void error(int pos, String message) {
        global.reporter.error(position(pos), message);
    }

    /** issue a warning in this compilation unit at a specific location
     */
    public void warning(int pos, String message) {
        global.reporter.warning(position(pos), message);
    }

    /** return a string representation
     */
    public String toString() {
        return source.toString();
    }

}