Package: AImplicitFunctionDefinitionAssistantTC

AImplicitFunctionDefinitionAssistantTC

nameinstructionbranchcomplexitylinemethod
AImplicitFunctionDefinitionAssistantTC(ITypeCheckerAssistantFactory)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getParamPatternList(AImplicitFunctionDefinition)
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
getPostDefinition(AImplicitFunctionDefinition)
M: 0 C: 51
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getPreDefinition(AImplicitFunctionDefinition)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getType(AImplicitFunctionDefinition, List)
M: 0 C: 40
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 9
100%
M: 0 C: 1
100%
getTypeParamDefinitions(AImplicitFunctionDefinition)
M: 0 C: 37
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * The VDM Type Checker
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.typechecker.assistant.definition;
23:
24: import java.util.ArrayList;
25: import java.util.Collection;
26: import java.util.Iterator;
27: import java.util.List;
28:
29: import org.overture.ast.assistant.IAstAssistant;
30: import org.overture.ast.definitions.AExplicitFunctionDefinition;
31: import org.overture.ast.definitions.AImplicitFunctionDefinition;
32: import org.overture.ast.definitions.PDefinition;
33: import org.overture.ast.factory.AstFactory;
34: import org.overture.ast.intf.lex.ILexNameToken;
35: import org.overture.ast.patterns.APatternListTypePair;
36: import org.overture.ast.patterns.PPattern;
37: import org.overture.ast.typechecker.NameScope;
38: import org.overture.ast.types.AFunctionType;
39: import org.overture.ast.types.PType;
40: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
41:
42: public class AImplicitFunctionDefinitionAssistantTC implements IAstAssistant
43: {
44:         protected ITypeCheckerAssistantFactory af;
45:
46:         public AImplicitFunctionDefinitionAssistantTC(
47:                         ITypeCheckerAssistantFactory af)
48:         {
49:                 this.af = af;
50:         }
51:
52:         public AFunctionType getType(AImplicitFunctionDefinition impdef,
53:                         List<PType> actualTypes)
54:         {
55:                 Iterator<PType> ti = actualTypes.iterator();
56:                 AFunctionType ftype = (AFunctionType) impdef.getType();
57:
58:•                if (impdef.getTypeParams() != null)
59:                 {
60:•                 for (ILexNameToken pname : impdef.getTypeParams())
61:                 {
62:                         PType ptype = ti.next();
63:                         // AFunctionTypeAssistent.
64:                         ftype = (AFunctionType) af.createPTypeAssistant().polymorph(ftype, pname, ptype);
65:                 }
66:                         
67:                         ftype.setInstantiated(true);
68:                 }
69:
70:                 return ftype;
71:         }
72:
73:         public List<PDefinition> getTypeParamDefinitions(
74:                         AImplicitFunctionDefinition node)
75:         {
76:
77:                 List<PDefinition> defs = new ArrayList<PDefinition>();
78:
79:•                for (ILexNameToken pname : node.getTypeParams())
80:                 {
81:                         PDefinition p = AstFactory.newALocalDefinition(pname.getLocation(), pname.clone(), NameScope.NAMES, AstFactory.newAParameterType(pname.clone()));
82:                         // new ALocalDefinition(
83:                         // pname.location, NameScope.NAMES,false,null, null, new
84:                         // AParameterType(null,false,null,pname.clone()),false,pname.clone());
85:
86:                         af.createPDefinitionAssistant().markUsed(p);
87:                         defs.add(p);
88:                 }
89:
90:                 return defs;
91:         }
92:
93:         public AExplicitFunctionDefinition getPostDefinition(
94:                         AImplicitFunctionDefinition d)
95:         {
96:
97:                 List<List<PPattern>> parameters = getParamPatternList(d);
98:                 parameters.get(0).add(d.getResult().getPattern().clone());
99:
100:                 @SuppressWarnings("unchecked")
101:                 AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getPostName(d.getPostcondition().getLocation()), NameScope.GLOBAL, (List<ILexNameToken>) d.getTypeParams().clone(), af.createAFunctionTypeAssistant().getPostType((AFunctionType) d.getType()), parameters, d.getPostcondition(), null, null, false, null);
102:
103:                 def.setAccess(d.getAccess().clone());
104:                 def.setClassDefinition(d.getClassDefinition());
105:                 return def;
106:         }
107:
108:         public AExplicitFunctionDefinition getPreDefinition(
109:                         AImplicitFunctionDefinition d)
110:         {
111:
112:                 @SuppressWarnings("unchecked")
113:                 AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getPreName(d.getPrecondition().getLocation()), NameScope.GLOBAL, (List<ILexNameToken>) d.getTypeParams().clone(), af.createAFunctionTypeAssistant().getPreType((AFunctionType) d.getType()), getParamPatternList(d), d.getPrecondition(), null, null, false, null);
114:
115:                 def.setAccess(d.getAccess().clone());
116:                 def.setClassDefinition(d.getClassDefinition());
117:                 return def;
118:         }
119:
120:         @SuppressWarnings("unchecked")
121:         public List<List<PPattern>> getParamPatternList(
122:                         AImplicitFunctionDefinition d)
123:         {
124:
125:                 List<List<PPattern>> parameters = new ArrayList<List<PPattern>>();
126:                 List<PPattern> plist = new ArrayList<PPattern>();
127:
128:•                for (APatternListTypePair pl : d.getParamPatterns())
129:                 {
130:                         plist.addAll((Collection<PPattern>) pl.getPatterns().clone());
131:                 }
132:
133:                 parameters.add(plist);
134:                 return parameters;
135:         }
136: }