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

68.24
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtojass/ImAttrType.java
1
package de.peeeq.wurstscript.translation.imtojass;
2

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

7
import java.util.List;
8

UNCOV
9
public class ImAttrType {
!
10

11
    public static ImType getType(ImBoolVal e) {
12
        return WurstTypeBool.instance().imTranslateType();
1×
13
    }
14

15
    public static ImType getType(ImFuncRef e) {
UNCOV
16
        return WurstTypeCode.instance().imTranslateType();
!
17
    }
18

19
    public static ImType getType(ImFunctionCall e) {
20
        ImType t = e.getFunc().getReturnType();
1×
21
        t = substituteType(t, e.getTypeArguments(), e.getFunc().getTypeVariables());
1×
22
        if (e.getTuplesEliminated()) {
1×
UNCOV
23
            if (t instanceof ImTupleType) {
!
UNCOV
24
                ImTupleType tt = (ImTupleType) t;
!
25
                return tt.getTypes().get(0);
!
26
            }
27
        }
28
        return t;
1×
29
    }
30

31
    public static ImType substituteType(ImType type, List<ImTypeArgument> generics, List<ImTypeVar> typeVars) {
32
        return type.match(new TypeRewriteMatcher() {
1×
33

34
            @Override
35
            public ImType case_ImTypeVarRef(ImTypeVarRef t) {
UNCOV
36
                int index = typeVars.indexOf(t.getTypeVariable());
!
UNCOV
37
                if (index < 0) {
!
38
                    return t;
!
39
                } else if (index >= generics.size()) {
!
40
                    throw new RuntimeException("Could not find replacement for " + t + " when replacing " + typeVars + " with " + generics);
!
41
                }
42
                return generics.get(index).getType();
!
43
            }
44

45
        });
46
    }
47

48

49
    public static ImType getType(ImIntVal e) {
50
        return WurstTypeInt.instance().imTranslateType();
1×
51
    }
52

53
    public static ImType getType(ImNull e) {
54
        return e.getType();
1×
55
    }
56

57
    public static ImType getType(ImOperatorCall e) {
58
        switch (e.getOp()) {
1×
59
            case MOD_REAL:
UNCOV
60
                return WurstTypeReal.instance().imTranslateType();
!
61
            case DIV_INT:
62
            case MOD_INT:
63
                return WurstTypeInt.instance().imTranslateType();
1×
64
            case AND:
65
            case OR:
66
            case EQ:
67
            case NOTEQ:
68
            case GREATER_EQ:
69
            case GREATER:
70
            case LESS:
71
            case LESS_EQ:
72
            case NOT:
73
                return WurstTypeBool.instance().imTranslateType();
1×
74
            case DIV_REAL:
75
            case PLUS:
76
            case MINUS:
77
            case MULT: {
78
                ImType leftType = e.getArguments().get(0).attrTyp();
1×
79
                ImType rightType = e.getArguments().get(1).attrTyp();
1×
80
                if (typeReal(leftType) || typeReal(rightType)) {
1×
81
                    return WurstTypeReal.instance().imTranslateType();
1×
82
                }
83
            }
84
            case UNARY_MINUS:
85
        }
86
        return e.getArguments().get(0).attrTyp();
1×
87
    }
88

89
    private static boolean typeReal(ImType t) {
90
        if (t instanceof ImSimpleType) {
1×
91
            ImSimpleType st = (ImSimpleType) t;
1×
92
            return st.getTypename().equals("real");
1×
93
        }
UNCOV
94
        return false;
!
95
    }
96

97
    public static ImType getType(ImRealVal e) {
98
        return WurstTypeReal.instance().imTranslateType();
1×
99
    }
100

101
    public static ImType getType(ImStatementExpr e) {
102
        return e.getExpr().attrTyp();
1×
103
    }
104

105
    public static ImType getType(ImStringVal e) {
106
        return WurstTypeString.instance().imTranslateType();
1×
107
    }
108

109
    public static ImType getType(ImTupleSelection e) {
110
        ImTupleType tt = (ImTupleType) e.getTupleExpr().attrTyp();
1×
111
        return tt.getTypes().get(e.getTupleIndex());
1×
112
    }
113

114
    public static ImType getType(ImVarAccess e) {
115
        return e.getVar().getType();
1×
116
    }
117

118
    public static ImType getType(ImVarArrayAccess e) {
119
        ImType ar = e.getVar().getType();
1×
120
        if (ar instanceof ImArrayType) {
1×
121
            ImArrayType t = (ImArrayType) ar;
1×
122
            return t.getEntryType();
1×
123
        } else if (ar instanceof ImArrayTypeMulti) {
1×
124
            ImArrayTypeMulti t = (ImArrayTypeMulti) ar;
1×
125
            return t.getEntryType();
1×
126
        }
UNCOV
127
        return ar;
!
128
    }
129

130
    public static ImType getType(ImTupleExpr imTupleExpr) {
131
        List<ImType> types = Lists.newArrayList();
1×
132
        List<String> names = Lists.newArrayList();
1×
133
        int i = 1;
1×
134
        for (ImExpr e : imTupleExpr.getExprs()) {
1×
135
            types.add(e.attrTyp());
1×
136
            names.add("" + i++);
1×
137
        }
1×
138
        return JassIm.ImTupleType(types, names);
1×
139
    }
140

141

142
    public static ImType getType(ImMethodCall mc) {
143
        return mc.getMethod().getImplementation().getReturnType();
1×
144
    }
145

146
    public static ImType getType(ImMemberAccess e) {
147
        ImType t = e.getVar().getType();
1×
148
        ImType receiverType1 = e.getReceiver().attrTyp();
1×
149
        if (receiverType1 instanceof ImClassType) {
1×
150
            ImClassType receiverType = (ImClassType) receiverType1;
1×
151
            ImTypeArguments typeArgs = e.getTypeArguments();
1×
152
            try {
153
                if (typeArgs.isEmpty()) {
1×
154
                    typeArgs = receiverType.getTypeArguments();
1×
155
                }
156
                t = substituteType(t, typeArgs, receiverType.getClassDef().getTypeVariables());
1×
157

158
                if (!e.getIndexes().isEmpty()) {
1×
159
                    if (t instanceof ImArrayType) {
1×
160
                        ImArrayType at = (ImArrayType) t;
!
161
                        t = at.getEntryType();
!
162
                    } else if (t instanceof ImArrayTypeMulti) {
1×
163
                        ImArrayTypeMulti at = (ImArrayTypeMulti) t;
1×
164
                        t = at.getEntryType();
1×
165
                    } else {
1×
UNCOV
166
                        throw new RuntimeException("unhandled case: " + t);
!
167
                    }
168
                }
169
                return t;
1×
UNCOV
170
            } catch (Exception ex) {
!
UNCOV
171
                throw new RuntimeException("Could not determine type of " + e + " with receiverType " + receiverType, ex);
!
172
            }
173
        } else {
174
            return t;
1×
175
        }
176
    }
177

178
    public static ImType getType(ImAlloc imAlloc) {
UNCOV
179
        return TypesHelper.imInt();
!
180
    }
181

182
    public static ImType getType(ImDealloc imDealloc) {
UNCOV
183
        return TypesHelper.imVoid();
!
184
    }
185

186
    public static ImType getType(ImInstanceof imInstanceof) {
UNCOV
187
        return TypesHelper.imBool();
!
188
    }
189

190
    public static ImType getType(ImTypeIdOfClass imTypeIdOfClass) {
UNCOV
191
        return TypesHelper.imInt();
!
192
    }
193

194
    public static ImType getType(ImTypeIdOfObj imTypeIdOfObj) {
UNCOV
195
        return TypesHelper.imInt();
!
196
    }
197

198

199
    public static ImType getType(ImGetStackTrace imGetStackTrace) {
UNCOV
200
        return TypesHelper.imString();
!
201
    }
202

203
    public static ImType getType(ImCompiletimeExpr e) {
UNCOV
204
        return e.getExpr().attrTyp();
!
205
    }
206

207
    public static ImType getType(ImTypeVarDispatch e) {
UNCOV
208
        return e.getTypeClassFunc().getReturnType();
!
209
    }
210

211
    public static ImType getType(ImCast imCast) {
212
        return imCast.getToType();
1×
213
    }
214
}
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