Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

wurstscript / WurstScript / 1005

21 Mar 2019 - 22:31 coverage decreased (-0.09%) to 61.245%
1005

Pull #822

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
more new bug fixes
Pull Request #822: WIP: support for persisting objects in compiletime expressions

14931 of 24379 relevant lines covered (61.25%)

0.61 hits per line

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

61.9
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtojass/DefaultValue.java
1
package de.peeeq.wurstscript.translation.imtojass;
2

3
import com.google.common.collect.Lists;
4
import de.peeeq.wurstscript.WLogger;
5
import de.peeeq.wurstscript.intermediatelang.*;
6
import de.peeeq.wurstscript.jassIm.*;
7

8
import java.util.List;
9
import java.util.function.Supplier;
10

11
public class DefaultValue {
!
12

13
    public static ILconst get(ImArrayType t) {
14
        return t.getEntryType().defaultValue();
1×
15
    }
16

17
    public static ILconst get(ImSimpleType t) {
18
        String typename = t.getTypename();
1×
19
        if (typename.equals("string")) return ILconstNull.instance();
1×
20
        if (typename.equals("integer")) return new ILconstInt(0);
1×
21
        if (typename.equals("real")) return new ILconstReal(0);
1×
22
        if (typename.equals("boolean")) return ILconstBool.FALSE;
1×
23
        WLogger.info("could not get default value for " + typename);
1×
24
        return ILconstNull.instance();
1×
25
    }
26

27
    public static ILconst get(ImTupleType tt) {
28
        List<ILconst> values = Lists.newArrayList();
1×
29
        for (ImType t : tt.getTypes()) {
1×
30
            values.add(t.defaultValue());
1×
31
        }
1×
32
        return new ILconstTuple(values.toArray(new ILconst[0]));
1×
33
    }
34

35
    public static ILconst get(ImVoid t) {
36
        throw new Error("Could not get default value for void variable.");
!
37
    }
38

39
    public static ILconst get(ImArrayTypeMulti t) {
UNCOV
40
        return new ILconstArray(makeSupplier(t.getArraySize().size() - 1, t.getEntryType()));
!
41
    }
42

43
    private static Supplier<ILconst> makeSupplier(int depth, ImType entryType) {
UNCOV
44
        if (depth <= 1) {
!
UNCOV
45
            return entryType::defaultValue;
!
46
        }
47
        return () -> new ILconstArray(makeSupplier(depth - 1, entryType));
!
48
    }
49

50
    public static ILconst get(ImTypeVarRef e) {
51
        return new ILconstUnsafeDefault(e.getTypeVariable());
!
52
    }
53

54
    public static ILconst get(ImClassType ct) {
55
        return new ILconstInt(0);
!
56
    }
57
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc