Package: PatternAssistantIR

PatternAssistantIR

nameinstructionbranchcomplexitylinemethod
PatternAssistantIR(AssistantManager)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
consIdPattern(String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getTupleType(AUnionTypeIR, ATuplePatternIR)
M: 0 C: 88
100%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 0 C: 17
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.codegen.assistant;
2:
3: import java.util.LinkedList;
4: import java.util.List;
5:
6: import org.overture.codegen.ir.STypeIR;
7: import org.overture.codegen.ir.patterns.AIdentifierPatternIR;
8: import org.overture.codegen.ir.patterns.ATuplePatternIR;
9: import org.overture.codegen.ir.types.ATupleTypeIR;
10: import org.overture.codegen.ir.types.AUnionTypeIR;
11:
12: public class PatternAssistantIR extends AssistantBase
13: {
14:         public PatternAssistantIR(AssistantManager assistantManager)
15:         {
16:                 super(assistantManager);
17:         }
18:
19:         public AIdentifierPatternIR consIdPattern(String name)
20:         {
21:                 AIdentifierPatternIR idPattern = new AIdentifierPatternIR();
22:                 idPattern.setName(name);
23:
24:                 return idPattern;
25:         }
26:
27:         public ATupleTypeIR getTupleType(AUnionTypeIR unionType,
28:                         ATuplePatternIR tuplePattern)
29:         {
30:                 List<ATupleTypeIR> tupleTypes = new LinkedList<ATupleTypeIR>();
31:
32:•                for (STypeIR nextType : unionType.getTypes())
33:                 {
34:•                        if (nextType instanceof ATupleTypeIR)
35:                         {
36:                                 ATupleTypeIR nextTupleType = (ATupleTypeIR) nextType;
37:
38:•                                if (nextTupleType.getTypes().size() == tuplePattern.getPatterns().size())
39:                                 {
40:                                         tupleTypes.add(nextTupleType);
41:                                 }
42:                         }
43:                 }
44:
45:                 ATupleTypeIR resTupleType = new ATupleTypeIR();
46:
47:•                if (tupleTypes.size() == 1)
48:                 {
49:                         resTupleType = tupleTypes.get(0);
50:                 } else
51:                 {
52:•                        for (int i = 0; i < tuplePattern.getPatterns().size(); i++)
53:                         {
54:                                 AUnionTypeIR fieldType = new AUnionTypeIR();
55:
56:•                                for (ATupleTypeIR t : tupleTypes)
57:                                 {
58:                                         fieldType.getTypes().add(t.getTypes().get(i).clone());
59:                                 }
60:
61:                                 resTupleType.getTypes().add(fieldType);
62:                         }
63:                 }
64:                 return resTupleType;
65:         }
66: }