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); if(node.getInvType() != null && !_visitedNodes.contains(node.getInvType())) node.getInvType().apply(this, question); if(node.getInvPattern() != null && !_visitedNodes.contains(node.getInvPattern())) node.getInvPattern().apply(this, question); if(node.getInvExpression() != null && !_visitedNodes.contains(node.getInvExpression())) node.getInvExpression().apply(this, question); if(node.getInvdef() != null && !_visitedNodes.contains(node.getInvdef()))
@Override public List<PDefinition> caseATypeDefinition(ATypeDefinition node) throws AnalysisException { List<PDefinition> defs = new Vector<PDefinition>(); defs.add(node); defs.addAll(node.getComposeDefinitions()); if (node.getInvdef() != null) { defs.add(node.getInvdef()); } return defs; }
throws AnalysisException if (node.getInvPattern() != null) node.setInvdef(getInvDefinition(node)); node.getInvType().setInvDef(node.getInvdef()); } else node.setInvdef(null); if (node.getOrdRelation() != null) { node.getOrdRelation().setRelDef(getRelDef(node.getOrdRelation(),node,node.getName().getOrdName(node.getLocation().clone()))); node.getInvType().setOrdDef(node.getOrdRelation().getRelDef()); setMinMax(node.getOrdRelation(),node); if (node.getEqRelation() != null) { node.getEqRelation().setRelDef(getRelDef(node.getEqRelation(),node,node.getName().getEqName(node.getLocation().clone()))); node.getInvType().setEqDef(node.getEqRelation().getRelDef()); if (node.getInvType() instanceof ANamedInvariantType) ANamedInvariantType ntype = (ANamedInvariantType) node.getInvType(); node.getComposeDefinitions().clear(); node.getComposeDefinitions().add(AstFactory.newATypeDefinition(rtype.getName(), rtype, null, null));
node.setInfinite(false); node.setInvType((SInvariantType) af.createPTypeAssistant().typeResolve((SInvariantType) node.getInvType(), node, question.rootVisitor, question.question)); if (node.getInfinite()) TypeCheckerErrors.report(3050, "Type '" + node.getName() + "' is infinite", node.getLocation(), node); node.setType(node.getInvType()); if (node.getInvdef() != null) node.getInvdef().apply(this, question); af.createPPatternAssistant().typeResolve(node.getInvPattern(), question.rootVisitor, question.question); if (node.getEqRelation() != null) node.getEqRelation().getRelDef().apply(this, question); af.createPPatternAssistant().typeResolve(node.getEqRelation().getLhsPattern(), question.rootVisitor, question.question); af.createPPatternAssistant().typeResolve(node.getEqRelation().getRhsPattern(), question.rootVisitor, question.question); if (node.getOrdRelation() != null) node.getOrdRelation().getRelDef().apply(this, question); af.createPPatternAssistant().typeResolve(node.getOrdRelation().getLhsPattern(), question.rootVisitor, question.question); af.createPPatternAssistant().typeResolve(node.getOrdRelation().getRhsPattern(), question.rootVisitor, question.question); if (node.getOrdRelation().getMinDef() != null)
if (node.getInvdef() != null) node.getInvdef().apply(THIS, question); if (node.getEqRelation() != null) node.getEqRelation().apply(THIS,question); if (node.getOrdRelation() != null) node.getOrdRelation().apply(THIS,question); node.setType(type); node.getComposeDefinitions().clear(); cdef.setAccess(node.getAccess().clone()); node.getComposeDefinitions().add(cdef); rtype.getDefinitions().get(0).setAccess(node.getAccess().clone()); if (question.assistantFactory.createPTypeAssistant().narrowerThan(ntype.getType(), node.getAccess())) TypeCheckerErrors.report(3321, "Type component visibility less than type's definition", node.getLocation(), node); if (question.assistantFactory.createPTypeAssistant().narrowerThan(field.getType(), node.getAccess())) return node.getType();
public AExplicitFunctionDefinition getInvDefinition(ATypeDefinition 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(); if (d.getInvType() instanceof ARecordInvariantType) { // Records are inv_R: R +> bool ptypes.add(AstFactory.newAUnresolvedType(d.getName().clone())); } else { // Named types are inv_T: x +> bool, for T = x ANamedInvariantType nt = (ANamedInvariantType) d.getInvType(); ptypes.add(nt.getType().clone()); } AFunctionType ftype = AstFactory.newAFunctionType(loc, false, ptypes, AstFactory.newABooleanBasicType(loc)); AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(d.getName().getInvName(loc), NameScope.GLOBAL, null, ftype, parameters, d.getInvExpression(), null, null, true, null); def.setAccess(d.getAccess().clone()); // Same as type's def.setClassDefinition(d.getClassDefinition()); return def; }
Newquestion question) throws AnalysisException PDefinition invdef = node.getInvdef(); PDefinition eqdef = node.getEqRelation() == null ? null : node.getEqRelation().getRelDef(); PDefinition orddef = node.getOrdRelation() == null ? null : node.getOrdRelation().getRelDef(); PDefinition mindef = node.getOrdRelation() == null ? null : node.getOrdRelation().getMinDef(); PDefinition maxdef = node.getOrdRelation() == null ? null : node.getOrdRelation().getMaxDef();
@Override public String caseATypeDefinition(ATypeDefinition node, PrettyPrinterEnv question) throws AnalysisException { StringBuilder sb = new StringBuilder(question.getIdent()); sb.append(node.getAccess().getAccess() + " "); sb.append(node.getName()); if (node.getType() instanceof ARecordInvariantType) { ARecordInvariantType record = (ARecordInvariantType) node.getType(); sb.append(" :: "); for (Iterator<AFieldField> itr = record.getFields().iterator(); itr.hasNext();) { if (itr.hasNext()) { sb.append("\n" + question.getIdent()); } sb.append(itr.next().apply(this, question)); } } else { sb.append(" = " + node.getType().apply(typePrinter, question)); } // + (node.getType() instanceof ARecordInvariantType ? " :: " // : " = ") + node.getType().apply(typePrinter, question)); return sb.toString() + ";"; }
@Override public SDeclIR caseATypeDefinition(ATypeDefinition node, IRInfo question) throws AnalysisException { String access = node.getAccess().getAccess().toString(); PType type = node.getType(); SDeclIR declCg = type.apply(question.getDeclVisitor(), question); SDeclIR invCg = question.getSettings().generateInvariants() && node.getInvdef() != null ? node.getInvdef().apply(question.getDeclVisitor(), question) : null; ATypeDeclIR typeDecl = new ATypeDeclIR(); typeDecl.setAccess(access); typeDecl.setDecl(declCg); typeDecl.setInv(invCg); return typeDecl; }
AFunctionType ftype = AstFactory.newAFunctionType(loc.clone(), false, ptypes, typeDef.getInvType().clone()); AExplicitFunctionDefinition maxD = AstFactory.newAExplicitFunctionDefinition(typeDef.getName().getMaxName(loc), NameScope.GLOBAL, null, ftype, parameters, maxBody, null, null, true, null); maxD.setAccess(typeDef.getAccess().clone()); // Same as type's maxD.setClassDefinition(typeDef.getClassDefinition()); ordRelation.setMaxDef(maxD); ftype = AstFactory.newAFunctionType(loc.clone(), false, ptypes, typeDef.getInvType().clone()); AExplicitFunctionDefinition minD = AstFactory.newAExplicitFunctionDefinition(typeDef.getName().getMinName(loc), NameScope.GLOBAL, null, ftype, parameters2, minBody, null, null, true, null); minD.setAccess(typeDef.getAccess().clone()); // Same as type's minD.setClassDefinition(typeDef.getClassDefinition()); ordRelation.setMinDef(minD);
public static ATypeDefinition newATypeDefinition(ILexNameToken name, SInvariantType type, PPattern invPattern, PExp invExpression, AEqRelation eqRelation, AOrdRelation ordRelation) { ATypeDefinition result = new ATypeDefinition(); initDefinition(result, Pass.TYPES, name.getLocation(), name, NameScope.TYPENAME); // Force all type defs (invs) to be static. There is no guarantee that // this will say here but is should result.getAccess().setStatic(new TStatic()); result.setInvType(type); result.setInvPattern(invPattern); result.setInvExpression(invExpression); result.setEqRelation(eqRelation); result.setOrdRelation(ordRelation); result.setType(type); if (type != null) { if (type.getDefinitions() == null) { type.setDefinitions(new LinkedList<PDefinition>()); } type.getDefinitions().add(result); } return result; }
public SatisfiabilityObligation(ATypeDefinition node, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(node, POType.TYPE_INV_SAT, ctxt, node.getLocation(), af); AExistsExp exists_exp = new AExistsExp(); exists_exp.setType(new ABooleanBasicType()); ATypeMultipleBind tmb = new ATypeMultipleBind(); List<PPattern> pats = new LinkedList<PPattern>(); pats.add(node.getInvPattern().clone()); tmb.setPlist(pats); tmb.setType(node.getInvType().clone()); List<PMultipleBind> binds = new LinkedList<PMultipleBind>(); binds.add(tmb); exists_exp.setBindList(binds); exists_exp.setPredicate(node.getInvExpression().clone()); stitch = exists_exp; valuetree.setPredicate(ctxt.getPredWithContext(exists_exp)); }
@Override public LexNameSet caseATypeDefinition(ATypeDefinition node, FreeVarInfo info) throws AnalysisException { LexNameSet names = new LexNameSet(); if (node.getType() instanceof ANamedInvariantType) { ANamedInvariantType nt = (ANamedInvariantType)node.getType(); names.addAll(nt.getType().apply(this, info)); } if (node.getInvdef() != null) { names.addAll(node.getInvdef().apply(this, info)); } return names; }
/** * Create the context (forall x,y,z...) for a Proof Obligation for * eq and ord relations. */ protected AForAllExp makeRelContext(ATypeDefinition node, AVariableExp... exps){ AForAllExp forall_exp = new AForAllExp(); forall_exp.setType(new ABooleanBasicType()); ATypeMultipleBind tmb = new ATypeMultipleBind(); List<PPattern> pats = new LinkedList<>(); for (AVariableExp exp : exps) { pats.add(AstFactory.newAIdentifierPattern(exp.getName().clone())); } tmb.setPlist(pats); tmb.setType(node.getType().clone()); List<PMultipleBind> binds = new LinkedList<>(); binds.add(tmb); forall_exp.setBindList(binds); return forall_exp; }
private AExplicitFunctionDefinition getRelDef(PRelation node, ATypeDefinition typedef, ILexNameToken fname) { ILexLocation loc = node.getLhsPattern().getLocation(); List<PPattern> params = new Vector<PPattern>(); params.add(node.getLhsPattern().clone()); params.add(node.getRhsPattern().clone()); List<List<PPattern>> parameters = new Vector<List<PPattern>>(); parameters.add(params); PTypeList ptypes = getPTypes(typedef); AFunctionType ftype = AstFactory.newAFunctionType(loc, false, ptypes, AstFactory.newABooleanBasicType(loc)); AExplicitFunctionDefinition def = AstFactory.newAExplicitFunctionDefinition(fname, NameScope.GLOBAL, null, ftype, parameters, node.getRelExp(), null, null, false, null); def.setAccess(typedef.getAccess().clone()); // Same as type's def.setClassDefinition(typedef.getClassDefinition()); return def; }
private PTypeList getPTypes(ATypeDefinition typedef) { PTypeList ptypes = new PTypeList(); if (typedef.getInvType() instanceof ARecordInvariantType) { // Records are inv_R: R +> bool AUnresolvedType uType= AstFactory.newAUnresolvedType(typedef.getName().clone()); ptypes.add(uType.clone()); ptypes.add(uType.clone()); } else { // Named types are inv_T: x +> bool, for T = x ANamedInvariantType nt = (ANamedInvariantType) typedef.getInvType(); ptypes.add(nt.getType().clone()); ptypes.add(nt.getType().clone()); } return ptypes; }
private PExp makeEqWithApply(PExp l, PExp r, ATypeDefinition node){ List<PExp> args = new Vector<>(); args.add(l.clone()); args.add(r.clone()); PExp root = AstFactory.newAVariableExp(node.getName().getEqName(node.getLocation()).clone()); return AstFactory.newAApplyExp(root,args); } }
@Override public SImportIR caseATypeImport(ATypeImport node, IRInfo question) throws AnalysisException { ATypeImportIR typeImportCg = new ATypeImportIR(); initImport(node, typeImportCg); SDeclIR typeDeclCg = node.getDef() != null ? node.getDef().apply(question.getDeclVisitor(), question) : null; if (typeDeclCg instanceof ATypeDeclIR) { typeImportCg.setDecl((ATypeDeclIR) typeDeclCg); } return typeImportCg; }
@Override public LexNameList caseATypeDefinition(ATypeDefinition node) throws AnalysisException { return new LexNameList(node.getName()); }
@Override public PType caseATypeDefinition(ATypeDefinition node) throws AnalysisException { return ((ATypeDefinition) node).getInvType(); }