-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFunctionSymbol.java
206 lines (165 loc) · 5.73 KB
/
FunctionSymbol.java
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import javax.swing.*;
import java.util.ArrayList;
import java.util.HashMap;
public class FunctionSymbol extends Symbol implements Scope, Data {
public HashMap<Integer, Arity> arity = new HashMap<>();
Integer currentArityNumber = 0;
Arity currentArity;
Boolean inDeclaration = true;
Scope enclosingScope;
ClojureParser.AuxformsContext ctx;
Integer currentArgument = 0;
JPanel fPanel;
JTextArea fIntel;
public Boolean isDefault;
public static Integer scopesNumber = 0;
public FunctionSymbol(String name, Scope enclosingScope) {
this(name, enclosingScope, true);
}
public FunctionSymbol(String name, Scope enclosingScope, Boolean flag) {
super(name);
isDefault = flag;
this.enclosingScope = enclosingScope;
if(isDefault) {
fIntel = new JTextArea(15, 40);
fIntel.setLineWrap(true);
fIntel.setWrapStyleWord(true);
fIntel.setEditable(false);
JScrollPane scroller = new JScrollPane(fIntel);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
fPanel = new JPanel();
fPanel.add(scroller);
fIntel.append(toString());
}
value = new Cadena(name);
}
public Integer getParametersNumber(){ return currentArity.getParametersNumber(); }
public void setArity(Arity a){
currentArity = a;
}
public String getParameter(Integer i){
return currentArity.parameters.get(i);
}
public void addArgument(String name, Symbol s){
currentArity.arguments.put(name, s);
}
public Integer getCurrentArityNumber() {
return currentArityNumber;
}
public void setCurrentArityNumber(Integer currentArityNumber) {
this.currentArityNumber = currentArityNumber;
}
public void establishCurrentArity(){
currentArity = arity.get(currentArityNumber);
}
public Integer getCurrentArgument() {
return currentArity.getCurrentArgument();
}
public void setCurrentArgument(Integer currentArgument) {
for(Arity a : arity.values())
a.currentArgument = currentArgument;
this.currentArgument = currentArgument;
}
public void addParameter(String name){ currentArity.parameters.put(currentArity.getCurrentParameter(),name); }
public void setHasRest(Boolean hasRest) { currentArity.setHasRest(hasRest); }
public Integer getCurrentParameter() { return currentArity.getCurrentParameter(); }
public Integer getDestructors() {
return currentArity.getDestructors();
}
public void setDestructors(Integer destructors) {
currentArity.setDestructors(destructors);
}
public void setCurrentParameter(Integer currentParameter) { currentArity.currentParameter = currentParameter; }
public String toString2(){
return "Funcion " + name + " con Arity igual a " + arity.size();
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Scope: " + "Funcion " + name + " con Arity igual a " + arity.size() + "\n");
if(enclosingScope != null)
builder.append("Enclosing scope: " + enclosingScope.getScopeName() + "\n\n");
builder.append("Variables en memoria:\n\n");
if(currentArity != null)
for(Symbol s : currentArity.arguments.values()) {
if(!(s instanceof BlockScope))
builder.append(s.toString() + "\n");
else
builder.append(((BlockScope) s).toString2());
}
return builder.toString();
}
public Boolean getHasRecur() {
return currentArity.getHasRecur();
}
public void setHasRecur(Boolean hasRecur) {
currentArity.setHasRecur(hasRecur);
}
public Boolean getInDeclaration() {
return inDeclaration;
}
public void setInDeclaration(Boolean inDeclaration) {
this.inDeclaration = inDeclaration;
}
public Symbol resolve(String name) {
Symbol s = currentArity.arguments.get(name);
if ( s!=null )
return s;
if ( getEnclosingScope() != null ) {
return getEnclosingScope().resolve(name);
}
return null;
}
public void define(Symbol sym) {
currentArity.arguments.put(sym.name, sym);
sym.scope = this;
}
public Scope getEnclosingScope() {
return enclosingScope;
}
public String getScopeName() {
return name;
}
public ClojureParser.AuxformsContext getCtx() {
return ctx;
}
public void setCtx(ClojureParser.AuxformsContext ctx) {
this.ctx = ctx;
}
public ClojureParser.ArityContext getArityCtx() {
return currentArity.getArityCtx();
}
public void setArityCtx(ClojureParser.ArityContext arityCtx) {
currentArity.setArityCtx(arityCtx);
}
public void updateFrame(){
fIntel.setText(toString());
if(enclosingScope != null)
enclosingScope.updateFrame();
}
public void addFrame(){
scopesNumber++;
Visitor.scopesTabs.add("Function " + name, fPanel);
Visitor.scopesTabs.setSelectedIndex(scopesNumber);
}
public void deleteFrame(){
scopesNumber--;
Visitor.scopesTabs.remove(fPanel);
}
@Override
public Object getData() {
return value;
}
@Override
public void setData(Object data) {
value = (Cadena)(data);
}
@Override
public Object clone() {
try {
return super.clone();
} catch (Exception e){
return null;
}
}
}