if(node.getName() != null ) node.getName().apply(this, question); if(node.getClassDefinition() != null && !_visitedNodes.contains(node.getClassDefinition())) node.getClassDefinition().apply(this, question); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) node.getAccess().apply(this, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this, question); List<ILexNameToken> copy = new ArrayList<ILexNameToken>(node.getTypeParams()); for( ILexNameToken e : copy) if(node.getBody() != null && !_visitedNodes.contains(node.getBody())) node.getBody().apply(this, question); if(node.getPrecondition() != null && !_visitedNodes.contains(node.getPrecondition())) node.getPrecondition().apply(this, question); if(node.getPostcondition() != null && !_visitedNodes.contains(node.getPostcondition()))
public POFunctionResultContext(AImplicitFunctionDefinition definition) { this.name = definition.getName(); this.deftype = (AFunctionType) definition.getType(); this.precondition = definition.getPrecondition(); this.body = definition.getBody(); this.implicit = true; this.result = definition.getResult(); this.function = definition; }
public static String getImplicitFunctionString(AImplicitFunctionDefinition d) { return d.getAccess() + " " + d.getName().getName() + (d.getTypeParams().isEmpty() ? "" : "[" + getTypeListString(d.getTypeParams()) + "]") + Utils.listToString("(", getString(d.getParamPatterns()), ", ", ")") + d.getResult() + (d.getBody() == null ? "" : " ==\n\t" + d.getBody()) + (d.getPrecondition() == null ? "" : "\n\tpre " + d.getPrecondition()) + (d.getPostcondition() == null ? "" : "\n\tpost " + d.getPostcondition()); }
private PExp buildMeasureLeft(AImplicitFunctionDefinition def, AApplyExp apply) throws AnalysisException { List<PPattern> paramPatterns = new LinkedList<PPattern>(); for (APatternListTypePair pair : def.getParamPatterns()) { paramPatterns.addAll(pair.getPatterns()); } return buildMeasureLeftParams(apply, def.getTypeParams(), def.getActualResult(), def.getMeasureName(), paramPatterns); }
question.assistantFactory.getTypeComparator().checkComposeTypes(node.getType(), question.env, false); List<PDefinition> defs = new Vector<PDefinition>(); if (node.getTypeParams() != null) for (APatternListTypePair pltp : node.getParamPatterns()) local.setStatic(question.assistantFactory.createPAccessSpecifierAssistant().isStatic(node.getAccess())); local.setEnclosingDefinition(node); local.setFunctional(true); if (node.getPredef() != null) PType b = node.getPredef().getBody().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); ABooleanBasicType expected = AstFactory.newABooleanBasicType(node.getLocation()); TypeCheckerErrors.report(3018, "Precondition returns unexpected type", node.getLocation(), node); TypeCheckerErrors.detail2("Actual", b, "Expected", expected); qualified = node.getPredef().getBody().apply(question.assistantFactory.getQualificationVisitor(), new TypeCheckInfo(question.assistantFactory, local, question.scope)); if (node.getBody() != null) if (node.getClassDefinition() != null && !question.assistantFactory.createPAccessSpecifierAssistant().isStatic(node.getAccess())) node.setActualResult(node.getBody().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, question.qualifiers, node.getResult().getType(), null))); if (!question.assistantFactory.getTypeComparator().compatible(node.getResult().getType(), node.getActualResult()))
if (node.getTypeParams().size() > 0) node.setType(af.createPTypeAssistant().typeResolve(af.createPDefinitionAssistant().getType(node), null, question.rootVisitor, new TypeCheckInfo(question.question.assistantFactory, params, question.question.scope, question.question.qualifiers))); } else node.setType(af.createPTypeAssistant().typeResolve(af.createPDefinitionAssistant().getType(node), null, question.rootVisitor, question.question)); if (node.getResult() != null) af.createAPatternTypePairAssistant().typeResolve(node.getResult(), question.rootVisitor, question.question); node.getName().setTypeQualifier(fType.getParameters()); if (node.getBody() instanceof ASubclassResponsibilityExp || node.getBody() instanceof ANotYetSpecifiedExp) node.setIsUndefined(true); if (node.getPrecondition() != null) node.getPredef().apply(this, question); if (node.getPostcondition() != null) node.getPostdef().apply(this, question); for (APatternListTypePair pltp : node.getParamPatterns())
public FunctionValue(AImplicitFunctionDefinition def, FunctionValue precondition, FunctionValue postcondition, Context freeVariables) { this.location = def.getLocation(); this.name = def.getName().getName(); this.typeValues = null; this.type = (AFunctionType) def.getType(); this.paramPatternList = new Vector<List<PPattern>>(); PatternListTC plist = Interpreter.getInstance().getAssistantFactory().createPatternList(); for (APatternListTypePair ptp : def.getParamPatterns()) { plist.addAll(ptp.getPatterns()); } this.paramPatternList.add(plist); this.body = def.getBody(); this.result = def.getResult(); this.precondition = precondition; this.postcondition = postcondition; this.freeVariables = freeVariables; this.checkInvariants = true; this.classdef = def.getClassDefinition(); if (Settings.measureChecks && def.getMeasureName() != null) { measureName = def.getMeasureName(); measureValues = Collections.synchronizedMap(new HashMap<Long, Stack<Value>>()); } }
throws AnalysisException String accessCg = node.getAccess().getAccess().toString(); String funcNameCg = node.getName().getName(); STypeIR typeCg = node.getType().apply(question.getTypeVisitor(), question); AExplicitFunctionDefinition preCond = node.getPredef(); SDeclIR preCondCg = preCond != null ? preCond.apply(question.getDeclVisitor(), question) : null; func.setPreCond(preCondCg); AExplicitFunctionDefinition postCond = node.getPostdef(); SDeclIR postCondCg = postCond != null ? postCond.apply(question.getDeclVisitor(), question) : null; List<ILexNameToken> typeParams = node.getTypeParams(); for (int i = 0; i < typeParams.size(); i++) func.setImplicit(true); if(node.getBody() == null) func.setBody(node.getBody().apply(question.getExpVisitor(), question)); func.setFormalParams(question.getDeclAssistant().consFormalParams(node.getParamPatterns(), question)); func.setMethodType((AMethodTypeIR) typeCg); func.setName(funcNameCg);
throws AnalysisException super(func, POType.FUNC_POST_CONDITION, ctxt, func.getLocation(), assistantFactory); if (func.getBody() == null) body = patternToExp(func.getResult().getPattern()); } else if (func.getBody() instanceof ANotYetSpecifiedExp || func.getBody() instanceof ASubclassResponsibilityExp) AVariableExp varExp = getVarExp(func.getName().clone(), func.clone(), func.getType().clone()); applyExp.setRoot(varExp); body = applyExp; } else body = func.getBody().clone(); PExp pred = generatePredicate(func.getPredef(), func.getPostdef(), cloneListPExp(params), body); stitch = pred; valuetree.setPredicate(ctxt.getPredWithContext(pred));
public AExplicitFunctionDefinition getPostDefinition( AImplicitFunctionDefinition d) { List<List<PPattern>> parameters = getParamPatternList(d); parameters.get(0).add(d.getResult().getPattern().clone()); @SuppressWarnings("unchecked") 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); def.setAccess(d.getAccess().clone()); def.setClassDefinition(d.getClassDefinition()); return def; }
Context free = initialContext.getVisibleVariables(); FunctionValue prefunc = def.getPredef() == null ? null : new FunctionValue(def.getPredef(), null, null, free); FunctionValue postfunc = def.getPostdef() == null ? null : new FunctionValue(def.getPostdef(), null, null, free); func.isStatic = af.createPAccessSpecifierAssistant().isStatic(def.getAccess()); func.uninstantiated = !def.getTypeParams().isEmpty(); nvl.add(new NameValuePair(def.getName(), func)); if (def.getPredef() != null) nvl.add(new NameValuePair(def.getPredef().getName(), prefunc)); prefunc.uninstantiated = !def.getTypeParams().isEmpty(); if (def.getPostdef() != null) nvl.add(new NameValuePair(def.getPostdef().getName(), postfunc)); postfunc.uninstantiated = !def.getTypeParams().isEmpty(); if (def.getMeasureDef() != null && def.getMeasureName().toString().startsWith("measure_")) nvl.add(new NameValuePair(def.getMeasureName(), new FunctionValue(def.getMeasureDef(), null, null, null)));
AFunctionType ftype = (AFunctionType) node.getType(); Iterator<PType> typeIter = ftype.getParameters().iterator(); for (APatternListTypePair pltp : node.getParamPatterns()) if (node.getPrecondition() != null) obligations.addAll(node.getPrecondition().apply(rootVisitor, question)); if (node.getPostcondition() != null) if (node.getBody() != null) // else satisfiability, below obligations.addAll(node.getPostcondition().apply(rootVisitor, question)); question.pop(); if (node.getMeasureDef() != null && node.getMeasureName() != null && node.getMeasureName().getName().startsWith("measure_")) question.push(new PONameContext(new LexNameList(node.getMeasureName()))); obligations.addAll(node.getMeasureDef().apply(rootVisitor, question)); question.pop(); if (node.getBody() == null) if (node.getPostcondition() != null) obligations.addAll(node.getBody().apply(rootVisitor, question)); if (node.getIsUndefined()
public AExplicitFunctionDefinition getPreDefinition( AImplicitFunctionDefinition d) { @SuppressWarnings("unchecked") 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); def.setAccess(d.getAccess().clone()); def.setClassDefinition(d.getClassDefinition()); return def; }
throws AnalysisException super(func, POType.FUNC_SATISFIABILITY, ctxt, func.getLocation(), af); for (APatternListTypePair pltp : func.getParamPatterns()) if (func.getPredef() != null) preApply = getApplyExp(getVarExp(func.getPredef().getName().clone(), func.getPredef().clone()), arglist); preApply.setType(new ABooleanBasicType()); preApply.getRoot().setType(func.getPredef().getType().clone()); List<PExp> postArglist = new Vector<PExp>(arglist); if (func.getResult().getPattern() instanceof AIdentifierPattern) AIdentifierPattern ip = (AIdentifierPattern) func.getResult().getPattern().clone(); postArglist.add(patternToExp(func.getResult().getPattern())); existsExp.setBindList(getMultipleTypeBindList(func.getResult().getType().clone(), ip.getName())); } else AApplyExp postApply = getApplyExp(getVarExp(func.getPostdef().getName(), func.getPostdef()), postArglist); postApply.setType(new ABooleanBasicType()); postApply.getRoot().setType(func.getPostdef().getType().clone()); existsExp.setPredicate(postApply);
for (APatternListTypePair pltp : node.getParamPatterns()) 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));
@Override public List<PDefinition> caseAImplicitFunctionDefinition( AImplicitFunctionDefinition node) throws AnalysisException { List<PDefinition> defs = new Vector<PDefinition>(); defs.add(node); if (node.getPredef() != null) { defs.add(node.getPredef()); } if (node.getPostdef() != null) { defs.add(node.getPostdef()); } if (node.getMeasureDef() != null && node.getMeasureName().getName().startsWith("measure_")) { defs.add(node.getMeasureDef()); } return defs; }
private TypeCompatibilityObligation(AImplicitFunctionDefinition func, PType etype, PType atype, IPOContextStack ctxt, IPogAssistantFactory assistantFactory) throws AnalysisException { super(func, POType.TYPE_COMP, ctxt, func.getLocation(), assistantFactory); this.assistantFactory = assistantFactory; PExp body = null; if (func.getBody() instanceof ANotYetSpecifiedExp || func.getBody() instanceof ASubclassResponsibilityExp) { // We have to say "f(a)" because we have no body PExp root = AstFactory.newAVariableExp(func.getName()); List<PExp> args = new ArrayList<PExp>(); for (APatternListTypePair pltp : func.getParamPatterns()) { for (PPattern p : pltp.getPatterns()) { args.add(patternToExp(p)); } } body = AstFactory.newAApplyExp(root, args); } else { body = func.getBody().clone(); } stitch = oneType(false, body, etype.clone(), atype.clone()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
@Override public void caseAImplicitFunctionDefinition( AImplicitFunctionDefinition node, Environment question) throws AnalysisException { if (node.getPrecondition() != null) { node.setPredef(af.createAImplicitFunctionDefinitionAssistant().getPreDefinition(node)); af.createPDefinitionAssistant().markUsed(node.getPredef()); // af.createPDefinitionAssistant().markUsed(node.getPredef()); } else { node.setPredef(null); } if (node.getPostcondition() != null) { node.setPostdef(af.createAImplicitFunctionDefinitionAssistant().getPostDefinition(node)); af.createPDefinitionAssistant().markUsed(node.getPostdef()); } else { node.setPostdef(null); } }
@Override public PExp caseAImplicitFunctionDefinition( AImplicitFunctionDefinition def, Integer lineno) throws AnalysisException { if (def.getPredef() != null) { PExp found = def.getPredef().apply(THIS, lineno); if (found != null) { return found; } } if (def.getPostdef() != null) { PExp found = def.getPostdef().apply(THIS, lineno); if (found != null) { return found; } } return def.getBody() == null ? null : af.createPExpAssistant().findExpression(def.getBody(), lineno); }
public POFunctionDefinitionContext(AImplicitFunctionDefinition definition, boolean precond, IPogAssistantFactory assistantFactory) { this.name = definition.getName(); this.deftype = (AFunctionType) definition.getType(); this.addPrecond = precond; this.paramPatternList = assistantFactory .createAImplicitFunctionDefinitionAssistant() .getParamPatternList(definition); this.precondition = definition.getPrecondition(); this.argtypes = calculateTypes(deftype, false); }