Package: VdmPpRuntimeUtil

VdmPpRuntimeUtil

nameinstructionbranchcomplexitylinemethod
VdmPpRuntimeUtil()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
parseExpression(String, String, String, Dialect)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
typeCheck(ClassList, String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
typeCheck(ClassList, String, Dialect)
M: 79 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.vdmpp.debug
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.ide.vdmpp.debug.utils;
23:
24: import org.overture.ast.definitions.SClassDefinition;
25: import org.overture.ast.expressions.PExp;
26: import org.overture.ast.factory.AstFactory;
27: import org.overture.ast.lex.Dialect;
28: import org.overture.ast.lex.LexLocation;
29: import org.overture.ast.lex.LexNameToken;
30: import org.overture.ast.typechecker.NameScope;
31: import org.overture.ast.util.definitions.ClassList;
32: import org.overture.parser.lex.LexException;
33: import org.overture.parser.lex.LexTokenReader;
34: import org.overture.parser.messages.Console;
35: import org.overture.parser.messages.VDMErrorsException;
36: import org.overture.parser.syntax.ExpressionReader;
37: import org.overture.parser.syntax.ParserException;
38: import org.overture.typechecker.Environment;
39: import org.overture.typechecker.PublicClassEnvironment;
40: import org.overture.typechecker.TypeCheckInfo;
41: import org.overture.typechecker.TypeChecker;
42: import org.overture.typechecker.assistant.TypeCheckerAssistantFactory;
43: import org.overture.typechecker.visitor.TypeCheckVisitor;
44:
45: public class VdmPpRuntimeUtil
46: {
47:         public static boolean typeCheck(ClassList classes, String expression)
48:                         throws VDMErrorsException, ParserException, LexException
49:         {
50:                 return typeCheck(classes, expression,Dialect.VDM_PP);
51:         }
52:         public static boolean typeCheck(ClassList classes, String expression, Dialect dialect)
53:                         throws VDMErrorsException, ParserException, LexException
54:         {
55:                 String defaultModuleName = null;
56: //                if (expression.contains(STATIC_CALL_SEPERATOR))
57: //                {
58: //                        defaultModuleName = expression.substring(0, expression.indexOf(STATIC_CALL_SEPERATOR)); // needed for static
59: //                                                                                                                                                                                                        // fn/op check
60: //                }
61:
62:                 SClassDefinition defaultModule = null;
63:
64:•                if (defaultModuleName == null || (classes.isEmpty()))
65:                 {
66:                         LexNameToken name =new LexNameToken("CLASS", "DEFAULT", new LexLocation());
67:                         defaultModule = AstFactory.newAClassClassDefinition(name, null, null);
68:                         defaultModule.setUsed(true);
69:                                 
70:                                         
71:                                 //        new AClassClassDefinition(name.getLocation(),name,NameScope.CLASSNAME,true,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null, null);
72: //                        classes.add(defaultModule);
73:                 }
74: //                else
75: //                {
76: //                        for (SClassDefinition m : classes)
77: //                        {
78: //                                if (m.getName().name.equals(defaultModuleName))
79: //                                {
80: //                                        defaultModule = m;
81: //                                }
82: //                        }
83: //                }
84:
85:                 TypeCheckVisitor tc = new TypeCheckVisitor();
86:                 TypeChecker.clearErrors();
87:                 Environment env = new PublicClassEnvironment(new TypeCheckerAssistantFactory(),classes,null);
88:                 PExp expr;
89:
90:                 expr = parseExpression(expression, defaultModule.getName().getName(), defaultModule.getName().getName(),dialect);
91:
92:                 try
93:                 {
94:                         expr.apply(tc, new TypeCheckInfo(new TypeCheckerAssistantFactory(),env, NameScope.NAMESANDSTATE));
95:                 } catch (Throwable e)
96:                 {
97:                         throw new VDMErrorsException(TypeChecker.getErrors());//FIXME: this might not has any errors if it goes wrong
98:                 }
99:
100:•                if (TypeChecker.getErrorCount() > 0)
101:                 {
102:                         throw new VDMErrorsException(TypeChecker.getErrors());
103:                         // return false;
104:                 }
105:
106:                 return true;
107:         }
108:
109:         protected static PExp parseExpression(String expression, String name,
110:                         String defaultModuleName, Dialect dialect) throws ParserException, LexException
111:         {
112:                 LexTokenReader ltr = new LexTokenReader(expression, dialect, Console.charset);
113:                 ExpressionReader reader = new ExpressionReader(ltr);
114:                 reader.setCurrentModule(defaultModuleName);
115:                 return reader.readExpression();
116:         }
117: }