public String hackResultName(AFuncDeclIR func) throws AnalysisException { SourceNode x = func.getSourceNode(); if (x.getVdmNode() instanceof AImplicitFunctionDefinition) { AImplicitFunctionDefinition iFunc = (AImplicitFunctionDefinition) x.getVdmNode(); return iFunc.getResult().getPattern().toString(); } throw new AnalysisException("Expected AFuncDeclIR in implicit function source. Got: " + x.getVdmNode().getClass().toString()); }
@Override public A defaultINode(org.overture.ast.node.INode node, IRInfo question) throws AnalysisException { A irNode = node.apply(irBuilder, question); if (irNode != null) { irNode.setSourceNode(new SourceNode(node)); } return irNode; }
public static org.overture.ast.node.INode getVdmNode(PIR irNode) { if (irNode != null && irNode.getSourceNode() != null) { return irNode.getSourceNode().getVdmNode(); } else { return null; } }
public AVarDeclIR consLocalVarDecl(INode node, STypeIR type, SPatternIR pattern, SExpIR exp) { AVarDeclIR localVarDecl = new AVarDeclIR(); localVarDecl.setType(type); localVarDecl.setFinal(false); localVarDecl.setSourceNode(node != null ? new SourceNode(node) : null); localVarDecl.setPattern(pattern); localVarDecl.setExp(exp); return localVarDecl; }
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(); }
public STypeIR constructSeqType(SSeqTypeBase node, IRInfo question) throws AnalysisException { STypeIR seqOfCg = node.getSeqof().apply(question.getTypeVisitor(), question); boolean emptyCg = node.getEmpty(); boolean isSeq1 = node instanceof ASeq1SeqType; // This is a special case since sequence of characters are strings if (seqOfCg instanceof ACharBasicTypeIR && question.getSettings().getCharSeqAsString()) { AStringTypeIR stringTypeCg = new AStringTypeIR(); stringTypeCg.setSourceNode(new SourceNode(node)); return stringTypeCg; } ASeqSeqTypeIR seqType = new ASeqSeqTypeIR(); seqType.setSeqOf(seqOfCg); seqType.setEmpty(emptyCg); seqType.setSeq1(isSeq1); return seqType; }
private String getInitName(AMethodDeclIR node) { if (node.getSourceNode() != null && node.getSourceNode().getVdmNode() != null) { INode vdmNode = node.getSourceNode().getVdmNode(); if (vdmNode instanceof AExplicitOperationDefinition) { AExplicitOperationDefinition op = (AExplicitOperationDefinition) vdmNode; return getObjectInitializerCall(op); } } return null; } }
defaultContructor.setSourceNode(new SourceNode(node)); classCg.getMethods().add(defaultContructor);
public AVarDeclIR consLocalVarDecl(STypeIR type, SPatternIR pattern, SExpIR exp) { return consLocalVarDecl(exp.getSourceNode() != null ? exp.getSourceNode().getVdmNode() : null, type, pattern, exp); }
@Override public SExpIR caseANarrowExp(ANarrowExp node, IRInfo question) throws AnalysisException { PExp exp = node.getTest(); PType type = null; if (node.getBasicType() != null) { type = node.getBasicType(); } else if (node.getTypedef() != null) { type = question.getTcFactory().createPDefinitionAssistant().getType(node.getTypedef()); } SExpIR expCg = exp.apply(question.getExpVisitor(), question); STypeIR typeCg; if (type != null) { typeCg = type.apply(question.getTypeVisitor(), question); } else { log.error("Could not find type of narrow expression"); typeCg = new AUnknownTypeIR(); typeCg.setSourceNode(new SourceNode(node)); } ACastUnaryExpIR cast = new ACastUnaryExpIR(); cast.setExp(expCg); cast.setType(typeCg); return cast; }
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; }
@Override public void caseADivideNumericBinaryExpIR(ADivideNumericBinaryExpIR node) throws AnalysisException { SExpIR leftExp = node.getLeft(); leftExp.apply(this); SExpIR rightExp = node.getRight(); rightExp.apply(this); if (info.getExpAssistant().isIntegerType(leftExp) && info.getExpAssistant().isIntegerType(rightExp)) { ARealLiteralExpIR one = new ARealLiteralExpIR(); ARealNumericBasicTypeIR realTypeCg = new ARealNumericBasicTypeIR(); realTypeCg.setSourceNode(new SourceNode(new ARealNumericBasicType())); one.setType(realTypeCg); one.setValue(1.0); ATimesNumericBinaryExpIR neutralMul = new ATimesNumericBinaryExpIR(); neutralMul.setType(realTypeCg.clone()); neutralMul.setLeft(one); neutralMul.setRight(leftExp); node.setLeft(info.getExpAssistant().isolateExpression(neutralMul)); } } }
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 INode getVdmNode(IrNodeInfo info) { if (info == null) { return null; } if (info.getNode() == null || !(info.getNode() instanceof PIR)) { return null; } SourceNode sourceNode = ((PIR) info.getNode()).getSourceNode(); if (sourceNode == null) { return null; } return sourceNode.getVdmNode(); }
/** * Given an IR status this method determines if it represents a test case or not. * * @param status * The IR status. * @return True if the <code>status</code> represents a test case - false otherwise. */ protected boolean isTestCase(IRStatus<? extends PIR> status) { return getInfo().getDeclAssistant().isTestCase(status.getIrNode().getSourceNode().getVdmNode()); }
private String getInitName(APlainCallStmIR node) { if (node.getSourceNode() != null && node.getSourceNode().getVdmNode() != null) { INode vdmNode = node.getSourceNode().getVdmNode(); if (vdmNode instanceof ACallStm) { ACallStm c = (ACallStm) vdmNode; PDefinition rootDef = c.getRootdef(); while (rootDef instanceof AInheritedDefinition) { rootDef = ((AInheritedDefinition) rootDef).getSuperdef(); } if (rootDef instanceof AExplicitOperationDefinition) { AExplicitOperationDefinition op = (AExplicitOperationDefinition) rootDef; if (op.getIsConstructor()) { return getObjectInitializerCall(op); } } } } return null; }
INode vdmNode = sourceNode.getVdmNode();
public SSeqTypeIR getSeqTypeCloned(STypeIR typeCg) throws AnalysisException { if (typeCg instanceof SSeqTypeIR) { SSeqTypeIR seqTypeCg = (SSeqTypeIR) typeCg; return seqTypeCg.clone(); } else { SourceNode sourceNode = typeCg.getSourceNode(); if (sourceNode != null && sourceNode.getVdmNode() instanceof PType) { PType vdmType = (PType) sourceNode.getVdmNode(); SSeqType seqType = info.getTcFactory().createPTypeAssistant().getSeq(vdmType); try { typeCg = seqType.apply(info.getTypeVisitor(), info); return (SSeqTypeIR) typeCg; } catch (org.overture.ast.analysis.AnalysisException e) { } } throw new AnalysisException("Exptected sequence type. Got: " + typeCg); } }
public <T extends STypeIR> T searchType(SExpIR exp, TypeFinder<T> typeFinder) { if (exp == null || exp.getType() == null) { return null; } SourceNode sourceNode = exp.getType().getSourceNode(); if (sourceNode == null) { return null; } org.overture.ast.node.INode vdmTypeNode = sourceNode.getVdmNode(); if (vdmTypeNode instanceof PType) { try { PType vdmType = (PType) vdmTypeNode; return typeFinder.findType(vdmType); } catch (org.overture.ast.analysis.AnalysisException e) { } } return null; }
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 ""; } }