Skip to content

Commit 635fbe6

Browse files
committed
correctness fixes
1 parent daecc28 commit 635fbe6

2 files changed

Lines changed: 5 additions & 60 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/names/NameResolution.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import java.util.*;
1313

1414
public class NameResolution {
15-
private static final String PACKAGE_NAME_LOOKUP_PREFIX = "__pkg_name__";
16-
private static final String PACKAGE_TYPE_LOOKUP_PREFIX = "__pkg_type__";
17-
1815
private static String memberFuncCacheName(String name, WurstType receiverType) {
1916
return name
2017
+ "@"
@@ -24,70 +21,13 @@ private static String memberFuncCacheName(String name, WurstType receiverType) {
2421
}
2522

2623
private static ImmutableCollection<DefLink> scopeNameLinks(WScope scope, String name) {
27-
if (scope instanceof WPackage) {
28-
return packageNameLinks((WPackage) scope, name);
29-
}
3024
return scope.attrNameLinks().get(name);
3125
}
3226

3327
private static ImmutableCollection<TypeLink> scopeTypeLinks(WScope scope, String name) {
34-
if (scope instanceof WPackage) {
35-
return packageTypeLinks((WPackage) scope, name);
36-
}
3728
return scope.attrTypeNameLinks().get(name);
3829
}
3930

40-
private static ImmutableCollection<DefLink> packageNameLinks(WPackage p, String name) {
41-
GlobalCaches.CacheKey key = new GlobalCaches.CacheKey(p, PACKAGE_NAME_LOOKUP_PREFIX + name, GlobalCaches.LookupType.PACKAGE);
42-
@SuppressWarnings("unchecked")
43-
ImmutableCollection<DefLink> cached = (ImmutableCollection<DefLink>) GlobalCaches.lookupCache.get(key);
44-
if (cached != null) {
45-
return cached;
46-
}
47-
48-
LinkedHashSet<DefLink> result = new LinkedHashSet<>();
49-
boolean repl = p.getName().equals("WurstREPL");
50-
for (WImport imp : p.getImports()) {
51-
if (imp.getPackagename().equals("NoWurst")) {
52-
continue;
53-
}
54-
WPackage importedPackage = imp.attrImportedPackage();
55-
if (importedPackage == null) {
56-
continue;
57-
}
58-
if (repl) {
59-
result.addAll(importedPackage.getElements().attrNameLinks().get(name));
60-
result.addAll(importedPackage.attrNameLinks().get(name));
61-
} else {
62-
result.addAll(importedPackage.attrExportedNameLinks().get(name));
63-
}
64-
}
65-
ImmutableCollection<DefLink> links = ImmutableList.copyOf(result);
66-
GlobalCaches.lookupCache.put(key, links);
67-
return links;
68-
}
69-
70-
private static ImmutableCollection<TypeLink> packageTypeLinks(WPackage p, String name) {
71-
GlobalCaches.CacheKey key = new GlobalCaches.CacheKey(p, PACKAGE_TYPE_LOOKUP_PREFIX + name, GlobalCaches.LookupType.PACKAGE);
72-
@SuppressWarnings("unchecked")
73-
ImmutableCollection<TypeLink> cached = (ImmutableCollection<TypeLink>) GlobalCaches.lookupCache.get(key);
74-
if (cached != null) {
75-
return cached;
76-
}
77-
78-
LinkedHashSet<TypeLink> result = new LinkedHashSet<>();
79-
for (WImport imp : p.getImports()) {
80-
WPackage importedPackage = imp.attrImportedPackage();
81-
if (importedPackage == null) {
82-
continue;
83-
}
84-
result.addAll(importedPackage.attrExportedTypeNameLinks().get(name));
85-
}
86-
ImmutableCollection<TypeLink> links = ImmutableList.copyOf(result);
87-
GlobalCaches.lookupCache.put(key, links);
88-
return links;
89-
}
90-
9131
public static ImmutableCollection<FuncLink> lookupFuncsNoConfig(Element node, String name, boolean showErrors) {
9232
if (!showErrors) {
9333
GlobalCaches.CacheKey key = new GlobalCaches.CacheKey(node, name, GlobalCaches.LookupType.FUNC);

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/CyclicFunctionRemover.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ private void removeCycle(List<ImFunction> funcs, Set<ImFunction> funcSet) {
9898
// Rewrite only affected roots:
9999
// - merged cycle body (contains moved bodies from all old funcs)
100100
// - callers that directly call any removed function
101+
// - global inits / other program-level roots that may contain ImFuncRef
101102
Set<Element> rewriteRoots = new LinkedHashSet<>();
102103
rewriteRoots.add(newFunc.getBody());
104+
rewriteRoots.add(prog);
105+
for (List<ImSet> initStmts : prog.getGlobalInits().values()) {
106+
rewriteRoots.addAll(initStmts);
107+
}
103108
for (ImFunction caller : new ArrayList<>(tr.getCalledFunctions().keySet())) {
104109
Collection<ImFunction> called = tr.getCalledFunctions().get(caller);
105110
for (ImFunction removed : funcSet) {

0 commit comments

Comments
 (0)