-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathWurstChecker.java
More file actions
75 lines (58 loc) · 2.2 KB
/
WurstChecker.java
File metadata and controls
75 lines (58 loc) · 2.2 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
package de.peeeq.wurstscript;
import com.google.common.base.Preconditions;
import de.peeeq.wurstscript.ast.CompilationUnit;
import de.peeeq.wurstscript.ast.WurstModel;
import de.peeeq.wurstscript.attributes.ErrorHandler;
import de.peeeq.wurstscript.attributes.names.DesugarArrayLength;
import de.peeeq.wurstscript.gui.WurstGui;
import de.peeeq.wurstscript.validation.GlobalCaches;
import de.peeeq.wurstscript.validation.TRVEHelper;
import de.peeeq.wurstscript.validation.WurstValidator;
import java.util.Collection;
public class WurstChecker {
private final WurstGui gui;
private final ErrorHandler errorHandler;
public WurstChecker(WurstGui gui, ErrorHandler errorHandler) {
this.gui = gui;
this.errorHandler = errorHandler;
}
public void checkProg(WurstModel root, Collection<CompilationUnit> toCheck) {
Preconditions.checkNotNull(root);
Preconditions.checkNotNull(toCheck);
if (root.isEmpty()) {
return;
}
TRVEHelper.protectedVariables.clear();
new DesugarArrayLength().run(root);
gui.sendProgress("Checking Files");
if (errorHandler.getErrorCount() > 0) return;
attachErrorHandler(root);
clearGlobalCaches(root, toCheck);
expandModules(root);
if (errorHandler.getErrorCount() > 0) return;
// compute the flow attributes
for (CompilationUnit cu : toCheck) {
WurstValidator.computeFlowAttributes(cu);
}
// validate the resource:
WurstValidator validator = new WurstValidator(root);
validator.validate(toCheck);
}
private void clearGlobalCaches(WurstModel root, Collection<CompilationUnit> toCheck) {
if (toCheck == root || toCheck.size() >= root.size()) {
GlobalCaches.clearAll();
} else {
GlobalCaches.clearLookupCacheFor(toCheck);
}
}
private void attachErrorHandler(WurstModel root) {
for (CompilationUnit cu : root) {
cu.getCuInfo().setCuErrorHandler(errorHandler);
}
}
private void expandModules(WurstModel root) {
for (CompilationUnit cu : root) {
ModuleExpander.expandModules(cu);
}
}
}