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
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
\* */
// $OldId: ExpressionContext.java,v 1.2 2002/06/05 09:05:56 paltherr Exp $
// $Id$
package scala.tools.scalai;
import java.util.Map;
import java.util.HashMap;
import ch.epfl.lamp.util.SourceFile;
import scalac.symtab.Symbol;
import scalac.symtab.Type;
import scalac.util.Debug;
public class ExpressionContext {
//########################################################################
// Private Fields
private final Environment environment;
private final Map functions;
private final Map variables;
private final SourceFile source;
private final Symbol owner;
private int current;
private int maximum;
//########################################################################
// Public Constructors
public ExpressionContext(
Environment environment, SourceFile source, Symbol owner)
{
this.environment = environment;
this.functions = new HashMap();
this.variables = new HashMap();
this.source = source;
this.owner = owner;
this.current = 0;
this.maximum = 0;
}
//########################################################################
// Public Methods - translate
public Class getClass(Symbol symbol) {
return environment.getClass(symbol);
}
public Class getClass(Type type) {
return environment.getClass(type);
}
//########################################################################
// Public Methods - insert
public Function insertLabel(Symbol symbol) {
Function function = Function.Label(symbol);
assert Debug.log("insert label : ", symbol);
assert !functions.containsKey(symbol) : Debug.show(symbol);
functions.put(symbol, function);
return function;
}
public Variable insertVariable(Symbol symbol, Variable variable) {
assert Debug.log("insert variable: ", symbol);
assert !variables.containsKey(symbol) : Debug.show(symbol);
variables.put(symbol, variable);
return variable;
}
//########################################################################
// Public Methods - lookup
public Template lookupTemplate(Symbol symbol) {
return environment.lookupTemplate(symbol);
}
public Function lookupFunction(Symbol symbol) {
Object value = functions.get(symbol);
if (value != null) return (Function)value;
return environment.lookupFunction(symbol);
}
public Variable lookupVariable(Symbol symbol) {
Object value = variables.get(symbol);
if (value != null) return (Variable)value;
return environment.lookupVariable(symbol);
}
//########################################################################
// Public Methods - origin
public SourceFile source() {
return source;
}
public Symbol owner() {
return owner;
}
//########################################################################
// Public Methods - stack
public void stacksize(int size) {
assert size >= 0 : size;
maximum = Math.max(current, maximum);
current = size;
}
public int stacksize() {
return current;
}
public int stackmax() {
return maximum = Math.max(current, maximum);
}
public int push() {
return current++;
}
public int pop() {
maximum = Math.max(current, maximum);
return --current;
}
//########################################################################
}
|