@Override public PTypeSet defaultPStm(PStm statement) throws AnalysisException { return new PTypeSet(af); }
@Override public String caseAUnionType(AUnionType type) throws AnalysisException { List<PType> types = type.getTypes(); if (types.size() == 1) { return types.iterator().next().toString(); } else { return Utils.setToString(new PTypeSet(types, af), " | "); } }
@Override public PTypeSet caseAAssignmentStm(AAssignmentStm statement) throws AnalysisException { // TODO We don't know what an expression call will raise return new PTypeSet(AstFactory.newAUnknownType(statement.getLocation()), af); }
public PTypeSet exitCheck(PStm statement, TypeCheckInfo question) { try { return statement.apply(question.assistantFactory.getExitTypeCollector()); } catch (AnalysisException e) { return new PTypeSet(question.assistantFactory); } }
@Override public PTypeSet caseACallObjectStm(ACallObjectStm statement) throws AnalysisException { // TODO We don't know what an operation call will raise return new PTypeSet(AstFactory.newAUnknownType(statement.getLocation()), af); }
@Override public PTypeSet caseACallStm(ACallStm statement) throws AnalysisException { // TODO We don't know what an operation call will raise return new PTypeSet(AstFactory.newAUnknownType(statement.getLocation()), af); }
@Override public PTypeSet caseACasesStm(ACasesStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); for (ACaseAlternativeStm c : statement.getCases()) { types.addAll(c.apply(THIS)); } return types; }
@Override public PTypeSet defaultSSimpleBlockStm(SSimpleBlockStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); for (PStm stmt : statement.getStatements()) { types.addAll(stmt.apply(THIS)); } return types; }
public PType getPossibleType(LinkedList<PPattern> plist, ILexLocation location) { switch (plist.size()) { case 0: return AstFactory.newAUnknownType(location); case 1: return af.createPPatternAssistant().getPossibleType(plist.get(0)); default: PTypeSet list = new PTypeSet(af); for (PPattern p : plist) { list.add(af.createPPatternAssistant().getPossibleType(p)); } return list.getType(location); // NB. a union of types } }
@Override public PTypeSet caseATixeStm(ATixeStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); types.addAll(statement.getBody().apply(THIS)); for (ATixeStmtAlternative tsa : statement.getTraps()) { types.addAll(exitCheck(tsa)); } return types; }
@Override public PTypeSet caseAAlwaysStm(AAlwaysStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); types.addAll(statement.getBody().apply(THIS)); types.addAll(statement.getAlways().apply(THIS)); return types; }
@Override public PTypeSet caseATrapStm(ATrapStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); types.addAll(statement.getBody().apply(THIS)); types.addAll(statement.getWith().apply(THIS)); return types; }
@Override public PTypeSet caseAExitStm(AExitStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); if (statement.getExpression() == null) { types.add(AstFactory.newAVoidType(statement.getLocation())); } else { types.add(statement.getExpType()); } return types; }
@Override public Boolean caseAUnionType(AUnionType type, Object other) throws AnalysisException { other = deBracket((PType) other); PTypeSet types = new PTypeSet(type.getTypes(), af); if (other instanceof AUnionType) { AUnionType uother = (AUnionType) other; for (PType t : uother.getTypes()) { if (!types.contains(t)) { return false; } } return true; } return types.contains(other); }
@Override public PType caseAUnionType(AUnionType type, Newquestion question) throws AnalysisException { // return AUnionTypeAssistantTC.polymorph(type, question.pname, question.actualType); PTypeSet polytypes = new PTypeSet(af); for (PType ptype : ((AUnionType) type).getTypes()) { polytypes.add(af.createPTypeAssistant().polymorph(ptype, question.pname, question.actualType)); } // TODO: Types in unionType should be a SET PTypeList result = new PTypeList(); result.addAll(polytypes); return AstFactory.newAUnionType(type.getLocation(), result); }
@Override public PTypeSet caseAIfStm(AIfStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); types.addAll(statement.getThenStm().apply(THIS)); for (AElseIfStm stmt : statement.getElseIf()) { types.addAll(stmt.apply(THIS)); } if (statement.getElseStm() != null) { types.addAll(statement.getElseStm().apply(THIS)); } return types; }
@Override public PType caseAUnionPattern(AUnionPattern pattern) throws AnalysisException { PTypeSet set = new PTypeSet(af); set.add(af.createPPatternAssistant().getPossibleType(pattern.getLeft())); set.add(af.createPPatternAssistant().getPossibleType(pattern.getRight())); PType s = set.getType(pattern.getLocation()); return af.createPTypeAssistant().isUnknown(s) ? AstFactory.newASetSetType(pattern.getLocation(), AstFactory.newAUnknownType(pattern.getLocation())) : s; }
@Override public PType caseAConcatenationPattern(AConcatenationPattern pattern) throws AnalysisException { PTypeSet set = new PTypeSet(af); set.add(af.createPPatternAssistant().getPossibleType(pattern.getLeft())); set.add(af.createPPatternAssistant().getPossibleType(pattern.getRight())); PType s = set.getType(pattern.getLocation()); return af.createPTypeAssistant().isUnknown(s) ? AstFactory.newASeqSeqType(pattern.getLocation(), AstFactory.newAUnknownType(pattern.getLocation())) : s; }
@Override public PType caseACasesExp(ACasesExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo noConstraint = question.newConstraint(null); question.qualifiers = null; PType expType = node.getExpression().apply(THIS, noConstraint); PTypeSet rtypes = new PTypeSet(question.assistantFactory); for (ACaseAlternative c : node.getCases()) { rtypes.add(typeCheck(c, THIS, question, expType)); } if (node.getOthers() != null) { rtypes.add(node.getOthers().apply(THIS, question)); } node.setType(rtypes.getType(node.getLocation())); return node.getType(); }