Package: ObjectDesignatorToExpIR

ObjectDesignatorToExpIR

nameinstructionbranchcomplexitylinemethod
ObjectDesignatorToExpIR(IRInfo)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseAApplyObjectDesignatorIR(AApplyObjectDesignatorIR)
M: 0 C: 65
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 19
100%
M: 0 C: 1
100%
caseAFieldObjectDesignatorIR(AFieldObjectDesignatorIR)
M: 16 C: 52
76%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 15
83%
M: 0 C: 1
100%
caseAIdentifierObjectDesignatorIR(AIdentifierObjectDesignatorIR)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseANewObjectDesignatorIR(ANewObjectDesignatorIR)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseASelfObjectDesignatorIR(ASelfObjectDesignatorIR)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
createNewReturnValue(INode)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * VDM Code Generator
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.codegen.trans.conv;
23:
24: import java.util.LinkedList;
25: import java.util.List;
26:
27: import org.apache.log4j.Logger;
28: import org.overture.codegen.ir.INode;
29: import org.overture.codegen.ir.IRInfo;
30: import org.overture.codegen.ir.SExpIR;
31: import org.overture.codegen.ir.SObjectDesignatorIR;
32: import org.overture.codegen.ir.STypeIR;
33: import org.overture.codegen.ir.SourceNode;
34: import org.overture.codegen.ir.analysis.AnalysisException;
35: import org.overture.codegen.ir.analysis.AnswerAdaptor;
36: import org.overture.codegen.ir.declarations.ADefaultClassDeclIR;
37: import org.overture.codegen.ir.expressions.AApplyExpIR;
38: import org.overture.codegen.ir.expressions.AFieldExpIR;
39: import org.overture.codegen.ir.expressions.ASelfExpIR;
40: import org.overture.codegen.ir.statements.AApplyObjectDesignatorIR;
41: import org.overture.codegen.ir.statements.AFieldObjectDesignatorIR;
42: import org.overture.codegen.ir.statements.AIdentifierObjectDesignatorIR;
43: import org.overture.codegen.ir.statements.ANewObjectDesignatorIR;
44: import org.overture.codegen.ir.statements.ASelfObjectDesignatorIR;
45: import org.overture.codegen.ir.types.AClassTypeIR;
46: import org.overture.codegen.ir.types.AMethodTypeIR;
47: import org.overture.codegen.ir.types.AUnknownTypeIR;
48: import org.overture.codegen.ir.types.SMapTypeIR;
49: import org.overture.codegen.ir.types.SSeqTypeIR;
50:
51:•public class ObjectDesignatorToExpIR extends AnswerAdaptor<SExpIR>
52: {
53:         private IRInfo info;
54:
55:         private Logger log = Logger.getLogger(this.getClass().getName());
56:
57:         public ObjectDesignatorToExpIR(IRInfo info)
58:         {
59:                 this.info = info;
60:         }
61:
62:         @SuppressWarnings("unchecked")
63:         @Override
64:         public SExpIR caseAApplyObjectDesignatorIR(AApplyObjectDesignatorIR node)
65:                         throws AnalysisException
66:         {
67:                 SObjectDesignatorIR object = node.getObject();
68:                 SourceNode sourceNode = node.getSourceNode();
69:                 LinkedList<SExpIR> args = node.getArgs();
70:
71:                 SExpIR root = object.apply(this);
72:
73:                 STypeIR rootType = root.getType();
74:                 STypeIR applyType = null;
75:
76:•                if (rootType instanceof SSeqTypeIR)
77:                 {
78:                         applyType = ((SSeqTypeIR) rootType).getSeqOf();
79:•                } else if (rootType instanceof SMapTypeIR)
80:                 {
81:                         applyType = ((SMapTypeIR) rootType).getTo();
82:•                } else if (rootType instanceof AMethodTypeIR)
83:                 {
84:                         applyType = ((AMethodTypeIR) rootType).getResult();
85:                 }
86:
87:                 applyType = applyType.clone();
88:
89:                 AApplyExpIR applyExp = new AApplyExpIR();
90:                 applyExp.setArgs((List<? extends SExpIR>) args.clone());
91:                 applyExp.setRoot(root);
92:                 applyExp.setType(applyType);
93:                 applyExp.setSourceNode(sourceNode);
94:
95:                 return applyExp;
96:         }
97:
98:         @Override
99:         public SExpIR caseAFieldObjectDesignatorIR(AFieldObjectDesignatorIR node)
100:                         throws AnalysisException
101:         {
102:                 String fieldName = node.getFieldName();
103:                 String fieldModule = node.getFieldModule();
104:                 SObjectDesignatorIR obj = node.getObject();
105:                 SourceNode sourceNode = node.getSourceNode();
106:
107:                 INode parent = node.parent();
108:
109:                 STypeIR fieldExpType = null;
110:                 try
111:                 {
112:                         fieldExpType = info.getTypeAssistant().getFieldExpType(info, fieldName, fieldModule, obj, parent);
113:                 } catch (org.overture.ast.analysis.AnalysisException e)
114:                 {
115:                         log.error("Could not find field expression type of " + node);
116:                         fieldExpType = new AUnknownTypeIR();
117:                 }
118:
119:                 SExpIR objExp = obj.apply(this);
120:
121:                 AFieldExpIR fieldExp = new AFieldExpIR();
122:                 fieldExp.setMemberName(fieldName);
123:                 fieldExp.setType(fieldExpType);
124:                 fieldExp.setObject(objExp);
125:                 fieldExp.setSourceNode(sourceNode);
126:
127:                 return fieldExp;
128:         }
129:
130:         @Override
131:         public SExpIR caseAIdentifierObjectDesignatorIR(
132:                         AIdentifierObjectDesignatorIR node) throws AnalysisException
133:         {
134:                 return node.getExp().clone();
135:         }
136:
137:         @Override
138:         public SExpIR caseANewObjectDesignatorIR(ANewObjectDesignatorIR node)
139:                         throws AnalysisException
140:         {
141:                 return node.getExp().clone();
142:         }
143:
144:         @Override
145:         public SExpIR caseASelfObjectDesignatorIR(ASelfObjectDesignatorIR node)
146:                         throws AnalysisException
147:         {
148:                 ADefaultClassDeclIR enclosingClass = node.getAncestor(ADefaultClassDeclIR.class);
149:
150:                 String className = enclosingClass.getName();
151:                 SourceNode sourceNode = node.getSourceNode();
152:
153:                 AClassTypeIR classType = new AClassTypeIR();
154:                 classType.setName(className);
155:
156:                 ASelfExpIR self = new ASelfExpIR();
157:                 self.setType(classType);
158:                 self.setSourceNode(sourceNode);
159:
160:                 return self;
161:         }
162:
163:         @Override
164:         public SExpIR createNewReturnValue(INode node) throws AnalysisException
165:         {
166:•                assert false : "This should never happen";
167:                 return null;
168:         }
169:
170:         @Override
171:         public SExpIR createNewReturnValue(Object node) throws AnalysisException
172:         {
173:•                assert false : "This should never happen";
174:                 return null;
175:         }
176: }