public static String getImplicitOperationString( AImplicitOperationDefinition d) { return d.getName() + Utils.listToString("(", d.getParameterPatterns(), ", ", ")") + (d.getResult() == null ? "" : " " + d.getResult()) + (d.getExternals().isEmpty() ? "" : "\n\text " + d.getExternals()) + (d.getPrecondition() == null ? "" : "\n\tpre " + d.getPrecondition()) + (d.getPostcondition() == null ? "" : "\n\tpost " + d.getPostcondition()) + (d.getErrors().isEmpty() ? "" : "\n\terrs " + d.getErrors()); }
public POOperationDefinitionContext( AImplicitOperationDefinition definition, boolean precond, PDefinition stateDefinition, IPogAssistantFactory assistantFactory) { this.name = definition.getName(); this.deftype = (AOperationType) definition.getType(); this.addPrecond = precond; this.paramPatternList = assistantFactory.createAImplicitOperationDefinitionAssistant().getParamPatternList(definition); this.precondition = definition.getPrecondition(); this.stateDefinition = stateDefinition; this.opDef = definition; }
throws AnalysisException if (def.getPredef() != null) PExp found = def.getPredef().apply(THIS, lineno); if (found != null) if (def.getPostdef() != null) PExp found = def.getPostdef().apply(THIS, lineno); if (found != null) if (def.getErrors() != null) for (AErrorCase err : def.getErrors()) return def.getBody() == null ? null : af.createPStmAssistant().findExpression(def.getBody(), lineno);
@Override public List<PDefinition> caseAImplicitOperationDefinition( AImplicitOperationDefinition node) throws AnalysisException { List<PDefinition> defs = new Vector<PDefinition>(); defs.add(node); if (Settings.dialect == Dialect.VDM_SL || Settings.release == Release.CLASSIC) { if (node.getPredef() != null) { defs.add(node.getPredef()); } if (node.getPostdef() != null) { defs.add(node.getPostdef()); } } return defs; }
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); if(node.getBody() != null && !_visitedNodes.contains(node.getBody())) node.getBody().apply(this); if(node.getPrecondition() != null && !_visitedNodes.contains(node.getPrecondition())) node.getPrecondition().apply(this); if(node.getPostcondition() != null && !_visitedNodes.contains(node.getPostcondition())) node.getPostcondition().apply(this); if(node.getPredef() != null && !_visitedNodes.contains(node.getPredef()))
question.assistantFactory.getTypeComparator().checkComposeTypes(node.getType(), question.env, false); question = new TypeCheckInfo(question.assistantFactory, question.env, NameScope.NAMESANDSTATE, question.qualifiers); List<PDefinition> defs = new Vector<PDefinition>(); node.setStateDefinition(question.env.findClassDefinition()); } else node.setStateDefinition(question.env.findStateDefinition()); for (APatternListTypePair ptp : node.getParameterPatterns()) if (node.getResult() != null) defs.addAll(question.assistantFactory.createPPatternAssistant().getDefinitions(node.getResult().getPattern(), ((AOperationType) node.getType()).getResult(), NameScope.STATE)); if (node.getExternals().size() != 0) for (AExternalClause clause : node.getExternals()) + exname + " is not this type", node.getLocation(), node); TypeCheckerErrors.detail2("Declared", sdef.getType(), "ext type", clause.getType()); } else && node.getName().getName().equals(node.getClassDefinition().getName().getName())) local.setStatic(question.assistantFactory.createPAccessSpecifierAssistant().isStatic(node.getAccess())); local.setEnclosingDefinition(node); local.setFunctional(false);
@SuppressWarnings("unchecked") public AExplicitFunctionDefinition getPreDefinition( AImplicitOperationDefinition d, Environment base) { List<List<PPattern>> parameters = new Vector<List<PPattern>>(); List<PPattern> plist = new Vector<PPattern>(); for (APatternListTypePair pl : (LinkedList<APatternListTypePair>) d.getParameterPatterns()) { plist.addAll((Collection<PPattern>) pl.getPatterns().clone()); } AStateDefinition state = d.getState(); if (state != null) { plist.add(AstFactory.newAIdentifierPattern(state.getName().clone())); } else if (base.isVDMPP() && !af.createPAccessSpecifierAssistant().isStatic(d.getAccess())) { plist.add(AstFactory.newAIdentifierPattern(d.getName().getSelfName())); } parameters.add(plist); PExp preop = AstFactory.newAPreOpExp(d.getName().clone(), d.getPrecondition(), d.getErrors(), d.getState()); AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getPreName(d.getPrecondition().getLocation()), NameScope.GLOBAL, null, af.createAOperationTypeAssistant().getPreType((AOperationType) d.getType(), state, d.getClassDefinition(), af.createPAccessSpecifierAssistant().isStatic(d.getAccess())), parameters, preop, null, null, false, null); // Operation precondition functions are effectively not static as // their expression can directly refer to instance variables, even // though at runtime these are passed via a "self" parameter. def.setAccess(af.createPAccessSpecifierAssistant().getStatic(d, false)); def.setClassDefinition(d.getClassDefinition()); return def; }
throws AnalysisException node.setType(af.createPTypeAssistant().typeResolve(node.getType(), null, question.rootVisitor, question.question)); if (node.getResult() != null) af.createAPatternTypePairAssistant().typeResolve(node.getResult(), question.rootVisitor, question.question); node.getName().setTypeQualifier(((AOperationType) node.getType()).getParameters()); if (node.getName().getName().equals(node.getClassDefinition().getName().getName())) node.setIsConstructor(true); node.getClassDefinition().setHasContructors(true); if (node.getPrecondition() != null) node.getPredef().apply(this, question); if (node.getPostcondition() != null) node.getPostdef().apply(this, question); for (APatternListTypePair ptp : node.getParameterPatterns())
AOperationType otype = (AOperationType) node.getType(); Iterator<PType> typeIter = otype.getParameters().iterator(); boolean alwaysMatches = true; PatternAlwaysMatchesVisitor amVisitor = new PatternAlwaysMatchesVisitor(); for (APatternListTypePair tp : node.getParameterPatterns()) if (node.getPrecondition() != null) obligations.addAll(node.getPrecondition().apply(rootVisitor, question)); if (node.getPostcondition() != null) if (node.getPrecondition() != null) question.push(new POImpliesContext(node.getPrecondition())); obligations.addAll(node.getPostcondition().apply(rootVisitor, question)); question.pop(); } else obligations.addAll(node.getPostcondition().apply(rootVisitor, question)); if (node.getBody() != null) obligations.addAll(node.getBody().apply(rootVisitor, question)); if (node.getIsConstructor() && node.getClassDefinition() != null && node.getClassDefinition().getInvariant() != null)
@Override public NameValuePairList caseAImplicitOperationDefinition( AImplicitOperationDefinition def, Context initialContext) throws AnalysisException { NameValuePairList nvl = new NameValuePairList(); FunctionValue prefunc = def.getPredef() == null ? null : new FunctionValue(def.getPredef(), null, null, null); FunctionValue postfunc = def.getPostdef() == null ? null : new FunctionValue(def.getPostdef(), null, null, null); // Note, body may be null if it is really implicit. This is caught // when the function is invoked. The value is needed to implement // the pre_() expression for implicit functions. OperationValue op = new OperationValue(def, prefunc, postfunc, def.getState(), af); op.isConstructor = def.getIsConstructor(); op.isStatic = af.createPAccessSpecifierAssistant().isStatic(def.getAccess()); nvl.add(new NameValuePair(def.getName(), op)); if (def.getPredef() != null) { prefunc.isStatic = af.createPAccessSpecifierAssistant().isStatic(def.getAccess()); nvl.add(new NameValuePair(def.getPredef().getName(), prefunc)); } if (def.getPostdef() != null) { postfunc.isStatic = af.createPAccessSpecifierAssistant().isStatic(def.getAccess()); nvl.add(new NameValuePair(def.getPostdef().getName(), postfunc)); } return nvl; }
private OperationValue(AImplicitOperationDefinition def, FunctionValue precondition, FunctionValue postcondition, AStateDefinition state, boolean async) { this.impldef = def; this.expldef = null; this.name = def.getName(); this.type = (AOperationType) def.getType(); this.paramPatterns = new Vector<PPattern>(); for (APatternListTypePair ptp : def.getParameterPatterns()) { paramPatterns.addAll(ptp.getPatterns()); } this.body = def.getBody(); this.precondition = precondition; this.postcondition = postcondition; this.state = state; this.classdef = def.getClassDefinition(); this.isAsync = async; traceRT = Settings.dialect == Dialect.VDM_RT && classdef != null && !(classdef instanceof ASystemClassDefinition) && !classdef.getName().getName().equals("CPU") && !classdef.getName().getName().equals("BUS") && !name.getName().equals("thread"); }
@Override public void caseAImplicitOperationDefinition( AImplicitOperationDefinition node, Environment question) throws AnalysisException { node.setState(findStateDefinition(question, node)); if (node.getPrecondition() != null) { node.setPredef(af.createAImplicitOperationDefinitionAssistant().getPreDefinition(node, question)); af.createPDefinitionAssistant().markUsed(node.getPredef()); } if (node.getPostcondition() != null) { node.setPostdef(af.createAImplicitOperationDefinitionAssistant().getPostDefinition(node, question)); af.createPDefinitionAssistant().markUsed(node.getPostdef()); } }
@Override public LexNameSet caseAImplicitOperationDefinition(AImplicitOperationDefinition node, FreeVarInfo info) throws AnalysisException { List<PDefinition> defs = new Vector<PDefinition>(); for (APatternListTypePair pltp : node.getParameterPatterns()) { defs.addAll(getDefinitions(pltp, NameScope.LOCAL)); } FreeVarInfo local = info.set(new FlatEnvironment(af, defs, info.env)); LexNameSet names = new LexNameSet(); if (node.getBody() != null) { names.addAll(node.getBody().apply(this, local)); } if (node.getPredef() != null) { names.addAll(node.getPredef().apply(this, local)); } if (node.getPostdef() != null) { names.addAll(node.getPostdef().apply(this, local)); } return names; }
public OperationPostConditionObligation(AImplicitOperationDefinition op, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(op, POType.OP_POST_CONDITION, ctxt, op.getLocation(), af); stitch = buildExp(op.getPrecondition(), op.getPostcondition().clone(), op.clone().getErrors()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
for (APatternListTypePair pltp : op.getParameterPatterns()) if (op.getPredef() != null) preApply = getApplyExp(getVarExp(op.getPredef().getName().clone(), op.getPredef()), arglist); preApply.getRoot().setType(op.getPredef().getType().clone()); preApply.setType(new ABooleanBasicType()); if (op.getResult() != null) if (op.getResult().getPattern() instanceof AIdentifierPattern) AIdentifierPattern ip = (AIdentifierPattern) op.getResult().getPattern(); postArglist.add(patternToExp(op.getResult().getPattern().clone())); existsExp.setBindList(getMultipleTypeBindList(op.getResult().getType().clone(), ip.getName().clone())); } else AApplyExp postApply = getApplyExp(getVarExp(op.getPostdef().getName(),op.getPostdef().clone()), postArglist); postApply.getRoot().setType(op.getPostdef().getType().clone()); postApply.setType(new ABooleanBasicType()); existsExp.setPredicate(postApply); AApplyExp postApply = getApplyExp(getVarExp(op.getPostdef().getName(),op.getPostdef().clone()), new Vector<PExp>(postArglist)); postApply.setType(new ABooleanBasicType()); postApply.getRoot().setType(op.getPostdef().getType().clone()); exists_exp.setPredicate(postApply); mainExp = exists_exp;
public ParameterPatternObligation(AImplicitOperationDefinition def, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(def, POType.OPERATION_PATTERNS, ctxt, def.getLocation(), af); this.assistantFactory = af; stitch = generate(def.getPredef(), cloneListPatternList(assistantFactory.createAImplicitOperationDefinitionAssistant().getListParamPatternList(def)), cloneListType(((AOperationType) def.getType()).getParameters()), ((AOperationType) def.getType()).getResult().clone()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
private TypeCompatibilityObligation(AImplicitOperationDefinition def, PType actualResult, IPOContextStack ctxt, IPogAssistantFactory assistantFactory) throws AnalysisException { super(def, POType.TYPE_COMP, ctxt, def.getLocation(), assistantFactory); this.assistantFactory = assistantFactory; PExp result = null; if (def.getResult().getPattern() instanceof AIdentifierPattern) { AIdentifierPattern ip = (AIdentifierPattern) def.getResult().getPattern(); result = AstFactory.newAVariableExp(ip.getName()); } else { ATuplePattern tp = (ATuplePattern) def.getResult().getPattern(); List<PExp> args = new ArrayList<PExp>(); for (PPattern p : tp.getPlist()) { AIdentifierPattern ip = (AIdentifierPattern) p; args.add(AstFactory.newAVariableExp(ip.getName())); } result = AstFactory.newATupleExp(def.getLocation(), args); } stitch = oneType(false, result, ((AOperationType) def.getType()).getResult().clone(), actualResult.clone()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
public StateInvariantObligation(AImplicitOperationDefinition def, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(def, POType.STATE_INV, ctxt, def.getLocation(), af); assistantFactory = af; if (def.getClassDefinition() == null) { stitch = invDefs(def.getClassDefinition()); } else { stitch = invDefs(def.getStateDefinition()); } valuetree.setPredicate(ctxt.getPredWithContext(stitch)); // valuetree.setContext(ctxt.getContextNodeList()); }
@Override public SDeclIR caseAImplicitOperationDefinition( AImplicitOperationDefinition node, IRInfo question) throws AnalysisException { AMethodDeclIR method = question.getDeclAssistant().initMethod(node, question); if (method == null) { question.addUnsupportedNode(node, "Expected method type for explicit operation. Got: " + node.getType()); return null; } // The curent IR construction does not include: // // Name of result and its type: // APatternTypePair res = node.getResult(); // Ext clauses (read and write): // LinkedList<AExternalClause> externals = node.getExternals(); // Exceptions thrown: // LinkedList<AErrorCase> errors = node.getErrors(); if(method.getBody() == null) { method.setBody(new ANotImplementedStmIR()); } method.setFormalParams(question.getDeclAssistant().consFormalParams(node.getParameterPatterns(), question)); return method; }