@Override public LexNameList caseATypeDefinition(ATypeDefinition node) throws AnalysisException { return new LexNameList(node.getName()); }
@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 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); } }
private PExp makeLessWithApply(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().getOrdName(node.getLocation()).clone()); return AstFactory.newAApplyExp(root,args); }
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); 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);
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; }
node.getOrdRelation().setRelDef(getRelDef(node.getOrdRelation(),node,node.getName().getOrdName(node.getLocation().clone()))); node.getInvType().setOrdDef(node.getOrdRelation().getRelDef()); setMinMax(node.getOrdRelation(),node); node.getEqRelation().setRelDef(getRelDef(node.getEqRelation(),node,node.getName().getEqName(node.getLocation().clone()))); node.getInvType().setEqDef(node.getEqRelation().getRelDef());
TypeCheckerErrors.report(3050, "Type '" + node.getName() + "' is infinite", node.getLocation(), node);