/** * Sets the {@code _exportType} child of this {@link AValueExportIR} node. * @param value the new {@code _exportType} child of this {@link AValueExportIR} node */ public void setExportType(STypeIR value) { if( value != null && value.parent() == null) { value.parent(this); } this._exportType = value; }
public ACastUnaryExpIR consNextElementCall(STypeIR iteratorType, String iteratorName, STypeIR elementType, String nextElementMethod) { ACastUnaryExpIR cast = new ACastUnaryExpIR(); cast.setType(elementType.clone()); cast.setExp(consInstanceCall(iteratorType, iteratorName, elementType.clone(), nextElementMethod)); return cast; }
@Override public Boolean caseASeqSeqTypeIR(ASeqSeqTypeIR node) throws AnalysisException { return node.getSeqOf().apply(new IsCharTypeVisitor()); } }
public STypeIR getElementType(STypeIR t) { STypeIR elementType; if (t instanceof ASetSetTypeIR) { elementType = ((ASetSetTypeIR) t).getSetOf().clone(); } else if (t instanceof ASeqSeqTypeIR) { elementType = ((ASeqSeqTypeIR) t).getSeqOf().clone(); } else { String vdmNodeInfo = info.getLocationAssistant().consVdmNodeInfoStr(t); log.error("Expected set or sequence type. Got: " + t.getClass().getName() + "." + vdmNodeInfo); elementType = new AUnknownTypeIR(); elementType.setSourceNode(t.getSourceNode()); } return elementType; }
private SExpIR correctTypes(SExpIR exp, STypeIR castedType) throws AnalysisException { if ((exp.getType() instanceof AUnknownTypeIR || exp.getType() instanceof AUnionTypeIR || castedType instanceof ATemplateTypeIR) && !(exp instanceof ACastUnaryExpIR) && !exp.getType().equals(castedType)) { ACastUnaryExpIR casted = new ACastUnaryExpIR(); casted.setType(castedType.clone()); casted.setExp(exp.clone()); transAssistant.replaceNodeWith(exp, casted); return casted; } return exp; }
public PType getVdmType(STypeIR type) { SourceNode source = type.getSourceNode(); if (source != null) { org.overture.ast.node.INode vdmNode = source.getVdmNode(); if (vdmNode != null) { if (vdmNode instanceof PType) { return (PType) vdmNode; } } } log.error("Could not get VDM type of " + type); return new AUnknownType(); }
private String findNumberDereferenceCall(STypeIR type) { if (type == null || type.parent() instanceof AHistoryExpIR) { return ""; } final String DOUBLE_VALUE = ".doubleValue()"; final String LONG_VALUE = ".longValue()"; if (info.getAssistantManager().getTypeAssistant().isInt(type)) { return LONG_VALUE; } else if (info.getAssistantManager().getTypeAssistant().isRealOrRat(type)) { return DOUBLE_VALUE; } else { PTypeAssistantTC typeAssistant = info.getTcFactory().createPTypeAssistant(); SourceNode sourceNode = type.getSourceNode(); if (sourceNode != null && !(sourceNode.getVdmNode() instanceof PType)) { PType vdmType = (PType) sourceNode.getVdmNode(); if (typeAssistant.isNumeric(vdmType)) { return DOUBLE_VALUE; } } return ""; } }
@Override public STypeIR caseAOptionalType(AOptionalType node, IRInfo question) throws AnalysisException { STypeIR typeCg = node.getType().apply(question.getTypeVisitor(), question); if (typeCg != null) { typeCg.setOptional(true); } return typeCg; }
public STypeIR getFieldType(SClassDeclIR classDecl, String fieldName, List<SClassDeclIR> classes) { for (AFieldDeclIR field : assistantManager.getDeclAssistant().getAllFields(classDecl, classes)) { if (field.getName().equals(fieldName)) { return field.getType().clone(); } } return null; }
/** * Called by the {@link ASelfExpIR} node from {@link ASelfExpIR#apply(IAnalysis)}. * @param node the calling {@link ASelfExpIR} node */ public void caseASelfExpIR(ASelfExpIR node) throws AnalysisException { _visitedNodes.add(node); inASelfExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outASelfExpIR(node); }
private boolean handleUnaryExp(SUnaryExpIR exp) throws AnalysisException { STypeIR type = exp.getExp().getType(); if (type instanceof AUnionTypeIR) { org.overture.ast.node.INode vdmNode = type.getSourceNode().getVdmNode(); if (vdmNode instanceof PType) { return true; } } return false; }
public static STypeIR toIrType(PType type, IRInfo info) { try { STypeIR irType = type.apply(info.getTypeVisitor(), info); if (irType != null) { irType.setOptional(false); } return irType; } catch (AnalysisException e) { log.error("Problems encountered while attempting " + "to construct the IR type from a VDM type: " + e.getMessage()); e.printStackTrace(); return null; } } }
public ACastUnaryExpIR consNextElementCall(STypeIR instanceType, String instance, String member, ACompSeqExpIR seqComp) throws AnalysisException { STypeIR elementType = getSeqTypeCloned(seqComp).getSeqOf(); SExpIR nextCall = consInstanceCall(instanceType, instance, elementType.clone(), member); ACastUnaryExpIR cast = new ACastUnaryExpIR(); cast.setType(elementType.clone()); cast.setExp(nextCall); return cast; }
/** * Called by the {@link ANullExpIR} node from {@link ANullExpIR#apply(IAnalysis)}. * @param node the calling {@link ANullExpIR} node */ public void caseANullExpIR(ANullExpIR node) throws AnalysisException { _visitedNodes.add(node); inANullExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outANullExpIR(node); }
/** * Sets the {@code _exportType} child of this {@link AOperationExportIR} node. * @param value the new {@code _exportType} child of this {@link AOperationExportIR} node */ public void setExportType(STypeIR value) { if( value != null && value.parent() == null) { value.parent(this); } this._exportType = value; }
public String toString() { return (_classType!=null?_classType.toString():this.getClass().getSimpleName()); }
public boolean compatible(IRInfo info, STypeIR left, STypeIR right) { SourceNode leftSource = left.getSourceNode(); SourceNode rightSource = right.getSourceNode(); if (leftSource == null || rightSource == null) { return false; } org.overture.ast.node.INode leftType = leftSource.getVdmNode(); org.overture.ast.node.INode rightType = rightSource.getVdmNode(); if (!(leftType instanceof PType) || !(rightType instanceof PType)) { return false; } TypeComparator typeComparator = info.getTcFactory().getTypeComparator(); if (!typeComparator.compatible((PType) leftType, (PType) rightType)) { return false; } return true; }
public STypeIR getFieldType(List<SClassDeclIR> classes, ARecordTypeIR recordType, String memberName) { AFieldDeclIR field = assistantManager.getDeclAssistant().getFieldDecl(classes, recordType, memberName); if (field != null) { return field.getType().clone(); } return null; }
/** * Called by the {@link ATimeExpIR} node from {@link ATimeExpIR#apply(IAnalysis)}. * @param node the calling {@link ATimeExpIR} node */ public void caseATimeExpIR(ATimeExpIR node) throws AnalysisException { _visitedNodes.add(node); inATimeExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outATimeExpIR(node); }