if(node.getName() != null ) node.getName().apply(this); if(node.getClassDefinition() != null && !_visitedNodes.contains(node.getClassDefinition())) node.getClassDefinition().apply(this); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) node.getAccess().apply(this); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); List<AFieldField> copy = new ArrayList<AFieldField>(node.getFields()); for( AFieldField e : copy) if(node.getInvPattern() != null && !_visitedNodes.contains(node.getInvPattern())) node.getInvPattern().apply(this); if(node.getInvExpression() != null && !_visitedNodes.contains(node.getInvExpression())) node.getInvExpression().apply(this); if(node.getInvdef() != null && !_visitedNodes.contains(node.getInvdef()))
@Override public PType caseAStateDefinition(AStateDefinition node, TypeCheckInfo question) throws AnalysisException { Environment base = question.env; if (base.findStateDefinition() != node) { TypeCheckerErrors.report(3047, "Only one state definition allowed per module", node.getLocation(), node); return null; } for (PDefinition def : node.getStateDefs()) { if (!def.getName().getOld()) // Don't check old names { question.assistantFactory.getTypeComparator().checkComposeTypes(def.getType(), question.env, false); } } question.assistantFactory.createPDefinitionListAssistant().typeCheck(node.getStateDefs(), THIS, question); if (node.getInvdef() != null) { node.getInvdef().apply(THIS, question); question.assistantFactory.createPPatternAssistant().typeResolve(node.getInvPattern(), THIS, question); } if (node.getInitdef() != null) { node.getInitdef().apply(THIS, question); question.assistantFactory.createPPatternAssistant().typeResolve(node.getInitPattern(), THIS, question); } return null; }
public String toString() { return "" + "init "+_state.getInitPattern()+" == "+_state.getInitExpression(); }
@Override public void caseAStateDefinition(AStateDefinition node, Environment question) throws AnalysisException { if (node.getInvPattern() != null) { node.setInvdef(getInvDefinition(node)); } if (node.getInitPattern() != null) { node.setInitdef(getInitDefinition(node)); } }
@Override public void inAStateDefinition(AStateDefinition node) throws AnalysisException { if (node.getCanBeExecuted() != null && !node.getCanBeExecuted()) { info.addUnsupportedNode(node, String.format("The state definition '%s' is not executable.\n" + "Only an executable state definition can be code generated.", node.getName().getName())); } }
throws AnalysisException AAccessSpecifierAccessSpecifier access = node.getAccess(); ILexNameToken name = node.getName(); AExplicitFunctionDefinition initdef = node.getInitdef(); PExp initExp = node.getInitExpression(); PPattern initPattern = node.getInitPattern(); AExplicitFunctionDefinition invdef = node.getInvdef(); PExp invExp = node.getInvExpression(); PPattern invPattern = node.getInvPattern(); stateDeclCg.setExecutable(node.getCanBeExecuted()); for (AFieldField field : node.getFields())
@Override public void caseAStateDefinition(AStateDefinition node, NewQuestion question) throws AnalysisException { for (AFieldField f : node.getFields()) { try { f.apply(THIS, new NewQuestion(question.rootVisitor, question.question)); } catch (TypeCheckException e) { question.question.assistantFactory.createPTypeAssistant().unResolve(f.getType()); throw e; } } node.setRecordType(af.createPTypeAssistant().typeResolve(node.getRecordType(), null, question.rootVisitor, question.question)); if (node.getInvPattern() != null) { node.getInvdef().apply(this, question); ARecordInvariantType rtype = (ARecordInvariantType) node.getRecordType(); rtype.setInvDef(node.getInvdef()); } if (node.getInitPattern() != null) { node.getInitdef().apply(this, question); } }
if (definition.getInitPattern() != null) if (!definition.getCanBeExecuted() || !(definition.getInitExpression() instanceof AEqualsBinaryExp)) AEqualsBinaryExp ee = (AEqualsBinaryExp) definition.getInitExpression(); ee.getLocation().hit(); ee.getLeft().getLocation().hit(); for (AFieldField f : definition.getFields()) VdmRuntimeError.abort(definition.getLocation(), (ValueException) e);
public void initState(AStateDefinition sdef, StateContext initialContext) { StateDefinitionRuntimeState state = new StateDefinitionRuntimeState(); VdmRuntime.setNodeState(sdef, state); if (sdef.getInvdef() != null) { state.invfunc = new FunctionValue(sdef.getInvdef(), null, null, initialContext); initialContext.put(sdef.getName().getInvName(sdef.getLocation()), state.invfunc); } if (sdef.getInitdef() != null) { state.initfunc = new FunctionValue(sdef.getInitdef(), null, null, initialContext); initialContext.put(sdef.getName().getInitName(sdef.getLocation()), state.initfunc); } state.moduleState = new State(sdef); state.moduleState.initialize(initialContext); }
public State(AStateDefinition definition) { this.definition = definition; NameValuePairList fieldvalues = new NameValuePairList(); for (AFieldField f : definition.getFields()) { fieldvalues.add(new NameValuePair(f.getTagname(), UpdatableValue.factory(new ValueListenerList(this)))); } ARecordInvariantType rt = (ARecordInvariantType) definition.getRecordType(); this.context = new Context(Interpreter.getInstance().getAssistantFactory(), definition.getLocation(), "module state", null); this.recordValue = UpdatableValue.factory(new RecordValue(rt, fieldvalues, context), new ValueListenerList(this)); this.context.put(definition.getName(), recordValue); this.context.putList(fieldvalues); }
letExp.setType(def.getInvExpression().getType().clone()); List<PDefinition> invDefs = new Vector<PDefinition>(); AEqualsDefinition local = new AEqualsDefinition(); local.setExpType(def.getRecordType().clone()); local.setPattern(def.getInvPattern().clone()); local.setName(def.getName().clone()); AVariableExp varExp = getVarExp(def.getName(), def.clone()); varExp.setType(def.getRecordType().clone()); local.setTest(varExp); invDefs.add(local); letExp.setLocalDefs(invDefs); letExp.setExpression(def.getInvExpression().clone());
AStateDefinition result = new AStateDefinition(); result.setFields(fields); result.setInvPattern(invPattern); result.setInvExpression(invExpression); result.setInitPattern(initPattern); result.setInitExpression(initExpression); result.setRecordType(AstFactory.newARecordInvariantType(name.clone(), fields)); recordDefinition = AstFactory.newALocalDefinition(result.getLocation(), name, NameScope.STATE, result.getRecordType()); recordDefinition.setUsed(true); // Can't be exported anyway stateDefs.add(recordDefinition); recordDefinition = AstFactory.newALocalDefinition(result.getLocation(), name.getOldName(), NameScope.OLDSTATE, result.getRecordType()); recordDefinition.setUsed(true); // Can't be exported anyway stateDefs.add(recordDefinition); result.setStateDefs(stateDefs);
PPattern pattern = node.getState().getInitPattern(); PExp exp = node.getState().getInitExpression(); boolean canBeExecuted = false; canBeExecuted = rt.getName().getName().equals(node.getState().getName().getName()); "p == p = mk_" + node.getState().getName().getName() + "(...)"); node.getState().setCanBeExecuted(canBeExecuted); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return node.getType();
public AExplicitFunctionDefinition getInvDefinition(AStateDefinition d) { ILexLocation loc = d.getInvPattern().getLocation(); List<PPattern> params = new Vector<PPattern>(); params.add(d.getInvPattern().clone()); List<List<PPattern>> parameters = new Vector<List<PPattern>>(); parameters.add(params); PTypeList ptypes = new PTypeList(); ptypes.add(AstFactory.newAUnresolvedType(d.getName())); AFunctionType ftype = AstFactory.newAFunctionType(loc, false, ptypes, AstFactory.newABooleanBasicType(loc)); return AstFactory.newAExplicitFunctionDefinition(d.getName().getInvName(loc), NameScope.GLOBAL, null, ftype, parameters, d.getInvExpression(), null, null, true, null); }
private PExp makeInvApplyExp(AAtomicStm atom) { AStateDefinition stateDef = atom.getAssignments().get(0).getStateDefinition(); if (stateDef == null) { return extractInv(atom); } String stateName = getStateName(stateDef); List<PExp> arglist = new Vector<PExp>(); for (AFieldField f : stateDef.getFields()) { arglist.add(getVarExp(f.getTagname().clone(), stateDef.clone(),f.getType())); } PExp mkExp = AstExpressionFactory.newAMkTypeExp(new LexNameToken("", stateName, null), stateDef.getRecordType().clone(), arglist); AApplyExp invApplyExp = getApplyExp(getVarExp(stateDef.getInvdef().getName().clone(), stateDef.getInvdef().clone(), stateDef.getInvdef().getType().clone()), new ABooleanBasicType(), mkExp); invApplyExp.getRoot().setType(stateDef.getInvdef().getType().clone()); return invApplyExp; }
private void appendStatePatterns(StringBuilder sb) { if (stateDefinition == null) { return; } else if (stateDefinition instanceof AStateDefinition) { AStateDefinition def = (AStateDefinition) stateDefinition; sb.append(", oldstate:"); sb.append(def.getName().getName()); } else { SClassDefinition def = (SClassDefinition) stateDefinition; sb.append(", oldself:"); sb.append(def.getName().getName()); } }
PDefinition invdef = node.getInvdef(); PDefinition initdef = node.getInitdef(); if (initdef != null && initdef.apply(this, question) != null)// PDefinitionAssistantTC.findName(initdef, for (PDefinition d : node.getStateDefs())
public AExplicitFunctionDefinition getInitDefinition(AStateDefinition d) { ILexLocation loc = d.getInitPattern().getLocation(); List<PPattern> params = new Vector<PPattern>(); params.add(d.getInitPattern().clone()); List<List<PPattern>> parameters = new Vector<List<PPattern>>(); parameters.add(params); PTypeList ptypes = new PTypeList(); ptypes.add(AstFactory.newAUnresolvedType(d.getName())); AFunctionType ftype = AstFactory.newAFunctionType(loc, false, ptypes, AstFactory.newABooleanBasicType(loc)); PExp body = AstFactory.newAStateInitExp(d); AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getInitName(loc), NameScope.GLOBAL, null, ftype, parameters, body, null, null, false, null); return def; }
@Override public PExp caseAStateDefinition(AStateDefinition def, Integer lineno) throws AnalysisException { if (def.getInvExpression() != null) { PExp found = af.createPExpAssistant().findExpression(def.getInvExpression(), lineno); if (found != null) { return found; } } if (def.getInitExpression() != null) { if (def.getInitExpression() instanceof AEqualsBinaryExp) { AEqualsBinaryExp ee = (AEqualsBinaryExp) def.getInitExpression(); PExp found = af.createPExpAssistant().findExpression(ee.getRight(), lineno); if (found != null) { return found; } } } return null; }