@Override public PType defaultSSeqType(SSeqType type, Newquestion question) throws AnalysisException { if (type.getResolved()) { return type; } else { type.setResolved(true); } try { type.setSeqof(af.createPTypeAssistant().typeResolve(type.getSeqof(), 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 defaultSSeqType(SSeqType type, Context ctxt) throws AnalysisException { return AstFactory.newASeqSeqType(type.getLocation(), type.getSeqof().apply(this, ctxt)); }
@Override public void defaultSSeqType(SSeqType type) throws AnalysisException { if (!type.getResolved()) { return; } else { type.setResolved(false); } type.getSeqof().apply(THIS); }
@Override public SSeqTypeIR findType(PType type) throws org.overture.ast.analysis.AnalysisException { SSeqType seqType = transAssistant.getInfo().getTcFactory().createPTypeAssistant().getSeq(type); return seqType != null ? (SSeqTypeIR) seqType.apply(transAssistant.getInfo().getTypeVisitor(), transAssistant.getInfo()) : null; } });
@Override public Boolean defaultSSeqType(SSeqType type, AAccessSpecifierAccessSpecifier accessSpecifier) throws AnalysisException { return type.getSeqof().apply(this, accessSpecifier); }
@Override public ILexLocation defaultSSeqType(SSeqType node) throws AnalysisException { return node.getLocation(); }
@Override public PType caseAIndicesUnaryExp(AIndicesUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); boolean empty = false; if (!question.assistantFactory.createPTypeAssistant().isSeq(etype)) { TypeCheckerErrors.report(3109, "Argument to 'inds' is not a sequence", node.getLocation(), node); TypeCheckerErrors.detail("Actual type", etype); } else { empty = question.assistantFactory.createPTypeAssistant().getSeq(etype).getEmpty(); } node.setType(AstFactory.newASetSetType(node.getLocation(), AstFactory.newANatOneNumericBasicType(node.getLocation()))); ((ASetSetType)node.getType()).setEmpty(empty); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
/** * Sets the {@code _seqType} child of this {@link AForPatternBindStm} node. * @param value the new {@code _seqType} child of this {@link AForPatternBindStm} node */ public void setSeqType(SSeqType value) { if( value != null && value.parent() == null) { value.parent(this); } this._seqType = value; }
/** * Called by the {@link AForPatternBindStm} node from {@link AForPatternBindStm#apply(IAnalysis)}. * @param node the calling {@link AForPatternBindStm} node */ public void caseAForPatternBindStm(AForPatternBindStm node) throws AnalysisException { _visitedNodes.add(node); inAForPatternBindStm(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getPatternBind() != null && !_visitedNodes.contains(node.getPatternBind())) { node.getPatternBind().apply(this); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } if(node.getStatement() != null && !_visitedNodes.contains(node.getStatement())) { node.getStatement().apply(this); } if(node.getSeqType() != null && !_visitedNodes.contains(node.getSeqType())) { node.getSeqType().apply(this); } outAForPatternBindStm(node); }
@Override public List<PDefinition> caseASeqPattern(ASeqPattern pattern, NewQuestion question) throws AnalysisException { List<PDefinition> defs = new Vector<PDefinition>(); if (!af.createPTypeAssistant().isSeq(question.ptype)) { TypeCheckerErrors.report(3203, "Sequence pattern is matched against " + question.ptype, pattern.getLocation(), pattern); } else { PType elem = af.createPTypeAssistant().getSeq(question.ptype).getSeqof(); for (PPattern p : pattern.getPlist()) { defs.addAll(af.createPPatternAssistant().getDefinitions(p, elem, question.scope)); } } return defs; }
/** * Called by the {@link AForPatternBindStm} node from {@link AForPatternBindStm#apply(IPOFAnalysis)}. * @param node the calling {@link AForPatternBindStm} node */ public void caseAForPatternBindStm(AForPatternBindStm node) throws AnalysisException { _visitedNodes.add(node); inAForPatternBindStm(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getPatternBind() != null && !_visitedNodes.contains(node.getPatternBind())) { node.getPatternBind().apply(this); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } if(node.getStatement() != null && !_visitedNodes.contains(node.getStatement())) { node.getStatement().apply(this); } if(node.getSeqType() != null && !_visitedNodes.contains(node.getSeqType())) { node.getSeqType().apply(this); } outAForPatternBindStm(node); }
public PType seqApply(AApplyObjectDesignator node, SSeqType seq, Environment env, NameScope scope, boolean unique, IQuestionAnswer<TypeCheckInfo, PType> rootVisitor, TypeCheckInfo question) throws AnalysisException { if (node.getArgs().size() != 1) { TypeCheckerErrors.concern(unique, 3252, "Sequence application must have one argument", node.getLocation(), node); return AstFactory.newAUnknownType(node.getLocation()); } PType argtype = node.getArgs().get(0).apply(rootVisitor, new TypeCheckInfo(question.assistantFactory, env, scope)); if (!env.af.createPTypeAssistant().isNumeric(argtype)) { TypeCheckerErrors.concern(unique, 3253, "Sequence argument is not numeric", node.getLocation(), node); TypeCheckerErrors.detail(unique, "Type", argtype); } return seq.getSeqof(); }
public PType sequenceApply(AApplyExp node, boolean isSimple, SSeqType seq, TypeCheckInfo question) { if (node.getArgs().size() != 1) { TypeCheckerErrors.concern(isSimple, 3055, "Sequence selector must have one argument", node.getLocation(), node); } else if (!question.assistantFactory.createPTypeAssistant().isNumeric(node.getArgtypes().get(0))) { TypeCheckerErrors.concern(isSimple, 3056, "Sequence application argument must be numeric", node.getLocation(), node); } else if (seq.getEmpty()) { TypeCheckerErrors.concern(isSimple, 3268, "Empty sequence cannot be applied", node.getLocation(), node); } return seq.getSeqof(); }
@Override public PType defaultSSeqType(SSeqType type, Newquestion question) throws AnalysisException { return AstFactory.newASeqSeqType(type.getLocation(), af.createPTypeAssistant().polymorph(type.getSeqof(), question.pname, question.actualType)); }
/** * Sets the {@code _seqType} child of this {@link AMapSeqStateDesignator} node. * @param value the new {@code _seqType} child of this {@link AMapSeqStateDesignator} node */ public void setSeqType(SSeqType value) { if( value != null && value.parent() == null) { value.parent(this); } this._seqType = value; }
/** * Called by the {@link AMapSeqStateDesignator} node from {@link AMapSeqStateDesignator#apply(IAnalysis)}. * @param node the calling {@link AMapSeqStateDesignator} node */ public void caseAMapSeqStateDesignator(AMapSeqStateDesignator node) throws AnalysisException { _visitedNodes.add(node); inAMapSeqStateDesignator(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getMapseq() != null && !_visitedNodes.contains(node.getMapseq())) { node.getMapseq().apply(this); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } if(node.getMapType() != null && !_visitedNodes.contains(node.getMapType())) { node.getMapType().apply(this); } if(node.getSeqType() != null && !_visitedNodes.contains(node.getSeqType())) { node.getSeqType().apply(this); } outAMapSeqStateDesignator(node); }
@Override protected Value convertValueTo(PType to, Context ctxt, Set<PType> done) throws AnalysisException { // We can't use the isSeq method as it plucks out one sequence // value from a union. We need to try all union members. So we // only test for pure SeqTypes. if (to instanceof SSeqType) { if (to instanceof ASeq1SeqType && values.isEmpty()) { abort(4084, "Cannot convert empty sequence to seq1", ctxt); } SSeqType seqto = (SSeqType) to; ValueList nl = new ValueList(); for (Value v : values) { nl.add(v.convertValueTo(seqto.getSeqof(), ctxt)); } return new SeqValue(nl); } else { return super.convertValueTo(to, ctxt, done); } }
@Override public PType caseAElementsUnaryExp(AElementsUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp etype = node.getExp(); question.qualifiers = null; TypeCheckInfo argConstraint = question; if (question.constraint != null && question.assistantFactory.createPTypeAssistant().isSet(question.constraint)) { PType stype = question.assistantFactory.createPTypeAssistant().getSet(question.constraint).getSetof(); stype = AstFactory.newASeqSeqType(node.getLocation(), stype); argConstraint = question.newConstraint(stype); } PType arg = etype.apply(THIS, argConstraint); if (!question.assistantFactory.createPTypeAssistant().isSeq(arg)) { TypeCheckerErrors.report(3085, "Argument of 'elems' is not a sequence", node.getLocation(), node); node.setType(AstFactory.newASetSetType(node.getLocation(), AstFactory.newAUnknownType(node.getLocation()))); return node.getType(); } SSeqType seq = question.assistantFactory.createPTypeAssistant().getSeq(arg); node.setType(seq.getEmpty() ? AstFactory.newASetSetType(node.getLocation()) : AstFactory.newASetSetType(node.getLocation(), seq.getSeqof())); return node.getType(); }