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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
** **
** $Id$
\* */
package scalac;
import scalac.util.*;
import scalac.symtab.NameMangler;
import scalac.ast.parser.Sourcefile;
import scalac.ast.Tree;
import scala.compiler.typechecker.*;
import java.io.*;
import java.util.*;
/** A representation for a compilation unit in scala
*
* @author Matthias Zenger
* @version 1.0
*/
public class Unit {
/** the global compilation environment
*/
public Global global;
/** the associated source code file
*/
public Sourcefile source;
/** the content of the compilation unit in tree form
*/
public Tree[] body;
/** the generated symbol data; Symbol -> byte[]
public SymData symdata;
*/
/** the name mangler
*/
public NameMangler mangler = new NameMangler();
/** number of errors issued for this compilation unit
*/
public int errors;
/** number of warnings issued for this compilation unit
*/
public int warnings;
/** number of notes issued for this compilation unit
*/
public int notes;
public Unit(Global global, Sourcefile source) {
this.global = global;
this.source = source;
}
/*
public void print(String message) {
print(System.out, message);
}
public void print(PrintStream out, String message) {
out.println("[[begin " + message + "]]");
new Printer(out).printCompilationUnit(this);
out.println();
out.println("[[end " + message + "]]");
}
*/
/** issue an error in this compilation unit
*/
public void error(String message) {
error(Position.NOPOS, message);
}
/** issue an error in this compilation unit at a specific location
*/
public void error(int pos, String message) {
boolean hidden = source.testAndSetLog(pos, message);
if (!hidden) errors++;
global.reporter.error(source.getMessage(pos, message), hidden);
}
/** issue a warning in this compilation unit
*/
public void warning(String message) {
warning(Position.NOPOS, message);
}
/** issue a warning in this compilation unit at a specific location
*/
public void warning(int pos, String message) {
if (global.reporter.nowarn) return;
message = "warning: " + message;
boolean hidden = source.testAndSetLog(pos, message);
if (!hidden) warnings++;
global.reporter.warning(source.getMessage(pos, message), hidden);
}
/** issue a note in this compilation unit
*/
public void note(String message) {
note(Position.NOPOS, message);
}
/** issue a note in this compilation unit at a specific location
*/
public void note(int pos, String message) {
global.reporter.note(source.getMessage(pos, message));
notes++;
}
/** return a string representation
*/
public String toString() {
return source.toString();
}
}
|