@Override public Boolean defaultSSetType(SSetType type, AAccessSpecifierAccessSpecifier accessSpecifier) throws AnalysisException { return type.getSetof().apply(this, accessSpecifier); }
@Override public String defaultSSetType(SSetType type) throws AnalysisException { return type.getEmpty() ? "{}" : "set of (" + type.getSetof() + ")"; }
@Override public PTypeList defaultSSetType(SSetType node) throws AnalysisException { return node.getSetof().apply(THIS); }
@Override public String defaultSSetType(SSetType node, PrettyPrinterEnv question) throws AnalysisException { return "" + "" + (node.getEmpty() ? "{}" : "set of (" + node.getSetof().apply(this, question) + ")"); }
@Override public Integer defaultSSetType(SSetType type) throws AnalysisException { return type.getEmpty() ? 0 : type.getSetof().apply(THIS); }
@Override public void defaultSSetType(SSetType type) throws AnalysisException { if (!type.getResolved()) { return; } else { type.setResolved(false); } type.getSetof().apply(THIS); }
@Override public STypeIR defaultSSetType(SSetType node, IRInfo question) throws AnalysisException { PType setOf = node.getSetof(); STypeIR typeCg = setOf.apply(question.getTypeVisitor(), question); boolean empty = node.getEmpty(); ASetSetTypeIR setType = new ASetSetTypeIR(); setType.setSetOf(typeCg); setType.setEmpty(empty); return setType; }
@Override public PType caseADistIntersectUnaryExp( ADistIntersectUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType arg = exp.apply(THIS, question.newConstraint(null)); if (question.assistantFactory.createPTypeAssistant().isSet(arg)) { SSetType set = question.assistantFactory.createPTypeAssistant().getSet(arg); if (set.getEmpty() || question.assistantFactory.createPTypeAssistant().isSet(set.getSetof())) { node.setType(set.getSetof()); return set.getSetof(); } } TypeCheckerErrors.report(3076, "Argument of 'dinter' is not a set of sets", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); }
@Override public PType caseADistMergeUnaryExp(ADistMergeUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; TypeCheckInfo expConstraint = question; if (question.constraint != null) { PType stype = AstFactory.newASetSetType(node.getLocation(), question.constraint); expConstraint = question.newConstraint(stype); } PType arg = exp.apply(THIS, expConstraint); if (question.assistantFactory.createPTypeAssistant().isSet(arg)) { SSetType set = question.assistantFactory.createPTypeAssistant().getSet(arg); if (!set.getEmpty() && question.assistantFactory.createPTypeAssistant().isMap(set.getSetof())) { node.setType(set.getSetof()); return set.getSetof(); } } TypeCheckerErrors.report(3077, "Merge argument is not a set of maps", node.getLocation(), node); return AstFactory.newAMapMapType(node.getLocation()); // Unknown types }
@Override public List<PDefinition> caseASetPattern(ASetPattern pattern, NewQuestion question) throws AnalysisException { // return ASetPatternAssistantTC.getAllDefinitions(pattern, question.ptype, question.scope); List<PDefinition> defs = new Vector<PDefinition>(); if (!af.createPTypeAssistant().isSet(question.ptype)) { TypeCheckerErrors.report(3204, "Set pattern is not matched against set type", pattern.getLocation(), pattern); TypeCheckerErrors.detail("Actual type", question.ptype); } else { SSetType set = af.createPTypeAssistant().getSet(question.ptype); if (!set.getEmpty()) { for (PPattern p : pattern.getPlist()) { defs.addAll(af.createPPatternAssistant().getDefinitions(p, set.getSetof(), question.scope)); } } } return defs; }
@Override public ValueList defaultSSetType(SSetType type, Context ctxt) throws AnalysisException { ValueList list = type.getSetof().apply(THIS, ctxt); ValueSet set = new ValueSet(list.size()); set.addAll(list); List<ValueSet> psets = set.powerSet(); list.clear(); for (ValueSet v : psets) { list.add(new SetValue(v)); } return list; }
@Override protected Value convertValueTo(PType to, Context ctxt, Set<PType> done) throws AnalysisException { if (to instanceof SSetType) { if (to instanceof ASet1SetType && values.isEmpty()) { abort(4170, "Cannot convert empty set to set1", ctxt); } SSetType setto = (SSetType) to; ValueSet ns = new ValueSet(); for (Value v : values) { ns.add(v.convertValueTo(setto.getSetof(), ctxt)); } return new SetValue(ns); } else { return super.convertValueTo(to, ctxt, done); } }
@Override public PType caseADistUnionUnaryExp(ADistUnionUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; TypeCheckInfo expConstraint = question; if (question.constraint != null) { PType stype = AstFactory.newASetSetType(node.getLocation(), question.constraint); expConstraint = question.newConstraint(stype); } PType type = exp.apply(THIS, expConstraint); if (question.assistantFactory.createPTypeAssistant().isSet(type)) { SSetType set = question.assistantFactory.createPTypeAssistant().getSet(type); if (question.assistantFactory.createPTypeAssistant().isSet(set.getSetof())) { node.setType(set.getSetof()); return set.getSetof(); } } TypeCheckerErrors.report(3078, "dunion argument is not a set of sets", node.getLocation(), node); node.setType(AstFactory.newASetSetType(node.getLocation(), AstFactory.newAUnknownType(node.getLocation()))); return node.getType(); }
@Override public PType defaultSSetType(SSetType type, Newquestion question) throws AnalysisException { if (type.getResolved()) { return type; } else { type.setResolved(true); } try { type.setSetof(af.createPTypeAssistant().typeResolve(type.getSetof(), question.root, question.rootVisitor, question.question)); if (question.root != null) { question.root.setInfinite(false); // Could be empty } return type; } catch (TypeCheckException e) { type.apply(af.getTypeUnresolver()); throw e; } }
@Override public PType caseAPowerSetUnaryExp(APowerSetUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; TypeCheckInfo argConstraint = question.newConstraint(null); if (question.constraint != null && question.assistantFactory.createPTypeAssistant().isSet(question.constraint)) { PType stype = question.assistantFactory.createPTypeAssistant().getSet(question.constraint).getSetof(); argConstraint = question.newConstraint(stype); } PType etype = exp.apply(THIS, argConstraint); if (!question.assistantFactory.createPTypeAssistant().isSet(etype)) { TypeCheckerErrors.report(3145, "Argument to 'power' is not a set", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } SSetType eset = question.assistantFactory.createPTypeAssistant().getSet(etype); node.setType(AstFactory.newASetSetType(node.getLocation(), AstFactory.newASetSetType(node.getLocation(), eset.getSetof()))); return node.getType(); }
@Override public PType caseASetEnumSetExp(ASetEnumSetExp node, TypeCheckInfo question) throws AnalysisException { PTypeSet ts = new PTypeSet(question.assistantFactory); node.setTypes(new LinkedList<PType>()); List<PType> types = node.getTypes(); TypeCheckInfo elemConstraint = question; if (question.constraint != null && question.assistantFactory.createPTypeAssistant().isSet(question.constraint)) { PType setType = question.assistantFactory.createPTypeAssistant().getSet(question.constraint).getSetof(); elemConstraint = question.newConstraint(setType); } for (PExp ex : node.getMembers()) { question.qualifiers = null; PType mt = ex.apply(THIS, elemConstraint); ts.add(mt); types.add(mt); } node.setType(ts.isEmpty() ? AstFactory.newASetSetType(node.getLocation()) : AstFactory.newASet1SetType(node.getLocation(), ts.getType(node.getLocation()))); return question.assistantFactory.createPTypeAssistant().possibleConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public SSetType caseAUnionType(AUnionType type) throws AnalysisException { ILexLocation location = type.getLocation(); if (!type.getSetDone()) { type.setSetDone(true); // Mark early to avoid recursion. // type.setSetType(PTypeAssistantTC.getSet(AstFactory.newAUnknownType(location))); type.setSetType(af.createPTypeAssistant().getSet(AstFactory.newAUnknownType(location))); PTypeSet set = new PTypeSet(af); for (PType t : type.getTypes()) { if (af.createPTypeAssistant().isSet(t)) { // set.add(PTypeAssistantTC.getSet(t).getSetof()); set.add(t.apply(THIS).getSetof()); } } type.setSetType(set.isEmpty() ? null : AstFactory.newASetSetType(location, set.getType(location))); } return type.getSetType(); }
@Override public PType caseAInSetBinaryExp(AInSetBinaryExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo noConstraint = question.newConstraint(null); PType ltype = node.getLeft().apply(THIS, noConstraint); PType rtype = node.getRight().apply(THIS, noConstraint); if (!question.assistantFactory.createPTypeAssistant().isSet(node.getRight().getType())) { TypeCheckerErrors.report(3110, "Argument of 'in set' is not a set", node.getLocation(), node); TypeCheckerErrors.detail("Actual", rtype); } else { SSetType stype = question.assistantFactory.createPTypeAssistant().getSet(rtype); if (!question.assistantFactory.getTypeComparator().compatible(stype.getSetof(), ltype)) { TypeCheckerErrors.report(3319, "'in set' expression is always false", node.getLocation(), node); TypeCheckerErrors.detail2("Element", ltype, "Set", stype); } } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAForAllStm(AForAllStm node, TypeCheckInfo question) throws AnalysisException { node.setType(node.getSet().apply(THIS, question)); question.assistantFactory.createPPatternAssistant().typeResolve(node.getPattern(), THIS, question); if (question.assistantFactory.createPTypeAssistant().isSet(node.getType())) { SSetType st = question.assistantFactory.createPTypeAssistant().getSet(node.getType()); List<PDefinition> defs = question.assistantFactory.createPPatternAssistant().getDefinitions(node.getPattern(), st.getSetof(), NameScope.LOCAL); Environment local = new FlatCheckedEnvironment(question.assistantFactory, defs, question.env, question.scope); PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); local.unusedCheck(); node.setType(rt); return rt; } else { TypeCheckerErrors.report(3219, "For all statement does not contain a set type", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } }
@Override public PType caseANotInSetBinaryExp(ANotInSetBinaryExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo noConstraint = question.newConstraint(null); PType ltype = node.getLeft().apply(THIS, noConstraint); PType rtype = node.getRight().apply(THIS, noConstraint); if (!question.assistantFactory.createPTypeAssistant().isSet(node.getRight().getType())) { TypeCheckerErrors.report(3138, "Argument of 'not in set' is not a set", node.getLocation(), node); TypeCheckerErrors.detail("Actual", node.getRight().getType()); } else { SSetType stype = question.assistantFactory.createPTypeAssistant().getSet(rtype); if (!question.assistantFactory.getTypeComparator().compatible(stype.getSetof(), ltype)) { TypeCheckerErrors.report(3320, "'not in set' expression is always true", node.getLocation(), node); TypeCheckerErrors.detail2("Element", ltype, "Set", stype); } } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }