• 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

79.03
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/types/WurstTypeArray.java
1
package de.peeeq.wurstscript.types;
2

3
import com.google.common.collect.Lists;
4
import de.peeeq.wurstscript.ast.Element;
5
import de.peeeq.wurstscript.ast.Expr;
6
import de.peeeq.wurstscript.attributes.AttrConstantValue;
7
import de.peeeq.wurstscript.intermediatelang.ILconst;
8
import de.peeeq.wurstscript.intermediatelang.ILconstInt;
9
import de.peeeq.wurstscript.jassIm.ImExprOpt;
10
import de.peeeq.wurstscript.jassIm.ImType;
11
import de.peeeq.wurstscript.jassIm.JassIm;
12
import de.peeeq.wurstscript.translation.imtranslation.ImTranslator;
13
import org.eclipse.jdt.annotation.Nullable;
14

15
import java.util.List;
16

17

18
public class WurstTypeArray extends WurstType {
19

20
    private Expr arSize;
21
    private final WurstType baseType;
22
    private int[] sizes;
23

24

25
    public WurstTypeArray(WurstType baseType, Expr arSize) {
1✔
26
        if (baseType instanceof WurstTypeArray) {
1✔
27
            throw new Error("cannot have array of arrays...");
×
28
        }
29
        this.baseType = baseType;
1✔
30
        this.arSize = arSize;
1✔
31
    }
1✔
32

33
    public WurstTypeArray(WurstType baseType) {
1✔
34
        if (baseType instanceof WurstTypeArray) {
1✔
35
            throw new Error("cannot have array of arrays...");
×
36
        }
37
        this.baseType = baseType;
1✔
38
        this.sizes = new int[] { -1 };
1✔
39
    }
1✔
40

41
    public WurstTypeArray(WurstType baseType, int size) {
1✔
42
        if (baseType instanceof WurstTypeArray) {
1✔
43
            throw new Error("cannot have array of arrays...");
×
44
        }
45
        this.baseType = baseType;
1✔
46
        this.sizes = new int[] { size };
1✔
47
    }
1✔
48

49
    private void initSizes() {
50
        if (sizes != null) {
1✔
51
            return;
1✔
52
        }
53
        // default is to have no array sizes:
54
        int[] sizes = {};
1✔
55
        // when there is an array size given, try to evaluate it:
56
        try {
57
            ILconst i = arSize.attrConstantValue();
1✔
58
            if (i instanceof ILconstInt) {
1✔
59
                int val = ((ILconstInt) i).getVal();
1✔
60
                sizes = new int[]{val};
1✔
61
                if (val < 0) {
1✔
62
                    arSize.addError("Array size must be at least 0");
×
63
                }
64
            } else {
1✔
65
                arSize.addError("Array sizes should be integer...");
×
66
            }
67
        } catch (AttrConstantValue.ConstantValueCalculationException e) {
1✔
68
            arSize.addError("Array size is not a constant expression.");
×
69
        }
1✔
70
        this.sizes = sizes;
1✔
71
    }
1✔
72

73

74
    public WurstType getBaseType() {
75
        return baseType;
1✔
76
    }
77

78

79
    public int getDimensions() {
80
        initSizes();
1✔
81
        return sizes.length;
1✔
82
    }
83

84

85
    @Override
86
    VariableBinding matchAgainstSupertypeIntern(WurstType other, @Nullable Element location, VariableBinding mapping, VariablePosition variablePosition) {
87
        if (other instanceof WurstTypeArray) {
1✔
88
            WurstTypeArray otherArray = (WurstTypeArray) other;
1✔
89
            mapping = baseType.matchTypes(otherArray.baseType, location, mapping, VariablePosition.RIGHT);
1✔
90
            if (mapping == null) {
1✔
91
                return null;
×
92
            }
93
            if (getDimensions() != otherArray.getDimensions()) {
1✔
94
                return null;
×
95
            }
96
            return mapping;
1✔
97
        }
98
        return null;
×
99
    }
100

101
    @Override
102
    public String getName() {
103
        // TODO Auto-generated method stub
104
        return baseType.getName() + " array(dimensions = " + getDimensions() + ")";
1✔
105
    }
106

107
    @Override
108
    public String getFullName() {
109
        return getName();
×
110
    }
111

112

113
    public int getSize(int i) {
114
        initSizes();
1✔
115
        return sizes[i];
1✔
116
    }
117

118

119
    @Override
120
    public ImType imTranslateType(ImTranslator tr) {
121
        initSizes();
1✔
122
        ImType bt = baseType.imTranslateType(tr);
1✔
123
        if (sizes.length > 0) {
1✔
124
            if (sizes[0] < 0) {
1✔
125
                return JassIm.ImArrayType(bt);
1✔
126
            }
127
            List<Integer> nsizes = Lists.newArrayList();
1✔
128
            for (int size : sizes) {
1✔
129
                nsizes.add(size);
1✔
130
            }
131

132
            return JassIm.ImArrayTypeMulti(bt, nsizes);
1✔
133
        }
134
        return JassIm.ImArrayType(bt);
×
135
    }
136

137

138
    @Override
139
    public ImExprOpt getDefaultValue(ImTranslator tr) {
140
        throw new Error();
×
141
    }
142

143
    @Override
144
    protected boolean isNullable() {
145
        return false;
×
146
    }
147

148
}
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