@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() + ";"; }
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; }
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 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; }
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); minD.setAccess(typeDef.getAccess().clone()); // Same as type's minD.setClassDefinition(typeDef.getClassDefinition()); ordRelation.setMinDef(minD);
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())) if (question.assistantFactory.createPTypeAssistant().narrowerThan(field.getType(), node.getAccess()))
@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; }