• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 228

29 Nov 2023 05:00PM UTC coverage: 62.48% (-0.09%) from 62.574%
228

push

circleci

web-flow
Show dialog for choosing game path, cleanup (#1083)

* show dialog for choosing game path

* cleanup code

* remove logs and refactor

* remove confusing mpq error, make some mpq loads readonly

17295 of 27681 relevant lines covered (62.48%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/validation/ValidateLocalUsage.java
1
package de.peeeq.wurstscript.validation;
2

3
import de.peeeq.wurstscript.ast.*;
4
import de.peeeq.wurstscript.attributes.names.NameLink;
5

6
import java.util.Collection;
7
import java.util.HashSet;
8

9
/**
10
 *
11
 */
12
public class ValidateLocalUsage {
×
13
    public static void checkLocalsUsage(Collection<CompilationUnit> toCheck) {
14
        for (CompilationUnit cu : toCheck) {
1✔
15
            for (WPackage p : cu.getPackages()) {
1✔
16
                checkLocalsUsage(p);
1✔
17
            }
1✔
18
        }
1✔
19
    }
1✔
20

21
    private static void checkLocalsUsage(WPackage p) {
22
        HashSet<NameDef> locals = new HashSet<>();
1✔
23

24
        p.accept(new WPackage.DefaultVisitor() {
1✔
25

26
            @Override
27
            public void visit(LocalVarDef varDef) {
28
                super.visit(varDef);
1✔
29
                if (!varDef.attrIsConstant() && !(varDef.getParent() instanceof LoopStatement)) {
1✔
30
                    if (!(varDef.getInitialExpr() instanceof ExprClosure)) {
1✔
31
                        locals.add(varDef);
1✔
32
                    }
33
                }
34
            }
1✔
35
        });
36

37
        p.accept(new WPackage.DefaultVisitor() {
1✔
38

39
            @Override
40
            public void visit(StmtSet set) {
41
                super.visit(set);
1✔
42
                LExpr updatedExpr = set.getUpdatedExpr();
1✔
43
                if (updatedExpr != null) {
1✔
44
                    NameLink nameLink = updatedExpr.attrNameLink();
1✔
45
                    if (nameLink != null) {
1✔
46
                        locals.remove(nameLink.getDef());
1✔
47
                    }
48

49
                    if (updatedExpr instanceof ExprMemberVar) {
1✔
50
                        checkLeftExpr((ExprMemberVar) updatedExpr);
1✔
51
                    }
52
                }
53
            }
1✔
54

55
            private void checkLeftExpr(ExprMemberVar updatedExpr) {
56
                if (updatedExpr.getLeft() != null) {
1✔
57
                    if (updatedExpr.getLeft() instanceof ExprMemberVar) {
1✔
58
                        checkLeftExpr((ExprMemberVar) updatedExpr.getLeft());
1✔
59
                    } else {
60
                        locals.remove(updatedExpr.getLeft().tryGetNameDef());
1✔
61
                    }
62
                }
63
            }
1✔
64
        });
65

66
        locals.forEach(local -> local.addWarning("Constant local variables should be defined using 'let'."));
1✔
67

68
    }
1✔
69

70

71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc