Scopes.java
2.71 KB
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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.forms.formcalc.support;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
public class Scopes {
public static final Frame FUNCTION_DECLARATION = new Frame("FUNCTION_DECLARATION");
public static final Frame LAST_EXPRESSION_IN_BLOCK = new Frame("LAST_STATEMENT_IN_BLOCK");
public static final Frame ASSIGNMENT_EXPRESSION = new Frame("ASSIGNMENT_STATEMENT");
public static final Frame FRAGMENT = new Frame("ASSIGNMENT_STATEMENT");
private Stack<Frame> frameStack = new Stack();
public Scopes() {
this.enter("GLOBAL");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void runInScope(Object block, Action action) {
try {
this.enter(block);
action.call();
}
finally {
this.exit(block);
}
}
public boolean generateReturnStatement() {
boolean lastStatement = false;
for (int i = this.frameStack.size() - 1; i >= 0; --i) {
Frame f = this.frameStack.get(i);
if (f != LAST_EXPRESSION_IN_BLOCK) {
if (f != FUNCTION_DECLARATION) break;
return lastStatement;
}
lastStatement = true;
}
return false;
}
void enter(Object block) {
if (block instanceof Frame) {
this.frameStack.push((Frame)block);
} else {
this.frameStack.push(new ScopeFrame(block));
}
}
void exit(Object block) {
this.frameStack.pop();
}
public String lookupFunction(String var) {
return null;
}
static class ScopeFrame
extends Frame {
private Map<String, String> variables = new HashMap<String, String>();
private Map<String, String> functions = new HashMap<String, String>();
public ScopeFrame(Object block) {
super(block);
}
public void defineVariable(String name) {
this.variables.put(name.toLowerCase(), name);
}
public void defineFunction(String name) {
this.functions.put(name.toLowerCase(), name);
}
public String lookupVariable(String name) {
return this.variables.get(name.toLowerCase());
}
public String lookupFunction(String name) {
return this.functions.get(name.toLowerCase());
}
public Object getBlock() {
return this.block;
}
}
public static class Frame {
protected Object block;
public Frame(Object block) {
this.block = block;
}
}
public static interface Action {
public void call();
}
}