@Override public PType caseAAssignmentDefinition(AAssignmentDefinition node) throws AnalysisException { return node.getType(); }
@Override public PType caseAAssignmentDefinition(AAssignmentDefinition node, TypeCheckInfo question) throws AnalysisException { question.qualifiers = null; node.setType(question.assistantFactory.createPTypeAssistant().typeResolve(question.assistantFactory.createPDefinitionAssistant().getType(node), null, THIS, question)); ExcludedDefinitions.setExcluded(node); node.setExpType(node.getExpression().apply(THIS, question)); ExcludedDefinitions.clearExcluded(); question.assistantFactory.getTypeComparator().checkComposeTypes(node.getType(), question.env, false); if (node.getExpType() instanceof AVoidType) { TypeCheckerErrors.report(3048, "Expression does not return a value", node.getExpression().getLocation(), node.getExpression()); } if (!question.assistantFactory.getTypeComparator().compatible(node.getType(), node.getExpType())) { TypeCheckerErrors.report(3000, "Expression does not match declared type", node.getExpression().getLocation(), node); TypeCheckerErrors.detail2("Declared", node.getType(), "Expression", node.getExpType()); } return node.getType(); }
@Override public IProofObligationList caseAAssignmentDefinition( AAssignmentDefinition node, IPOContextStack question) throws AnalysisException { try { IProofObligationList obligations = new ProofObligationList(); PExp expression = node.getExpression(); PType type = node.getType(); PType expType = node.getExpType(); obligations.addAll(expression.apply(rootVisitor, question)); if (!assistantFactory.getTypeComparator().isSubType(question.checkType(expression, expType), type)) { TypeCompatibilityObligation sto = TypeCompatibilityObligation.newInstance(expression, type, expType, question, assistantFactory); if (sto != null) { obligations.add(sto); } } return obligations; } catch (Exception e) { throw new POException(node, e.getMessage()); } }
private PDefinition readInstanceVariableDefinition() throws ParserException, LexException { LexToken token = lastToken(); if (token.is(VDMToken.INV)) { nextToken(); PExp exp = getExpressionReader().readExpression(); String str = getCurrentModule(); LexNameToken className = new LexNameToken(str, str, token.location); return AstFactory.newAClassInvariantDefinition(className.getInvName(token.location), exp); } else { AAccessSpecifierAccessSpecifier access = readAccessSpecifier(false, false); AAssignmentDefinition def = getStatementReader().readAssignmentDefinition(); AInstanceVariableDefinition ivd = AstFactory.newAInstanceVariableDefinition(def.getName(), def.getType(), def.getExpression()); def.getType().parent(ivd);// the type of ivd is graph but we trough away the assignment ivd.setAccess(access); return ivd; } }
@Override public NameValuePairList caseAAssignmentDefinition( AAssignmentDefinition def, Context initialContext) throws AnalysisException { try { Value v = def.getExpression().apply(VdmRuntime.getExpressionEvaluator(), initialContext); if (!v.isUndefined()) { v = v.convertTo(def.getType(), initialContext); } return new NameValuePairList(new NameValuePair(def.getName(), v.getUpdatable(null))); } catch (AnalysisException e) { if (e instanceof ValueException) { VdmRuntimeError.abort(def.getLocation(), (ValueException) e); } return null; } }
PType type = def.getType(); String name = def.getName().getName(); PExp exp = def.getExpression();