private SExpIR consFieldValueToMatch(AIdentifierVarExpIR patternVar, int fieldNumber, STypeIR currentType, boolean cast) { if (patternVar.getType() instanceof ATupleTypeIR) { return consTupleFieldExp(patternVar, fieldNumber, currentType, cast); } else if (patternVar.getType() instanceof ARecordTypeIR) { return consRecFieldExp(patternVar, fieldNumber, currentType, cast); } return null; }
/** * Called by the {@link AIdentifierVarExpIR} node from {@link AIdentifierVarExpIR#apply(IAnalysis)}. * @param node the calling {@link AIdentifierVarExpIR} node */ public void caseAIdentifierVarExpIR(AIdentifierVarExpIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inAIdentifierVarExpIR(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this, question); } outAIdentifierVarExpIR(node, question); }
/** * Called by the {@link AIdentifierVarExpIR} node from {@link AIdentifierVarExpIR#apply(IAnalysis)}. * @param node the calling {@link AIdentifierVarExpIR} node */ public void caseAIdentifierVarExpIR(AIdentifierVarExpIR node) throws AnalysisException { _visitedNodes.add(node); inAIdentifierVarExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outAIdentifierVarExpIR(node); }
/** * Called by the {@link AIdentifierVarExpIR} node from {@link AIdentifierVarExpIR#apply(IIsaAnalysis)}. * @param node the calling {@link AIdentifierVarExpIR} node */ public void caseAIdentifierVarExpIR(AIdentifierVarExpIR node) throws AnalysisException { _visitedNodes.add(node); inAIdentifierVarExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outAIdentifierVarExpIR(node); }
/** * Called by the {@link AIdentifierVarExpIR} node from {@link AIdentifierVarExpIR#apply(IAnalysis)}. * @param node the calling {@link AIdentifierVarExpIR} node */ public A caseAIdentifierVarExpIR(AIdentifierVarExpIR node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAIdentifierVarExpIR(node)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this)); } mergeReturns(retVal,outAIdentifierVarExpIR(node)); return retVal; }
/** * Called by the {@link AIdentifierVarExpIR} node from {@link AIdentifierVarExpIR#apply(IAnalysis)}. * @param node the calling {@link AIdentifierVarExpIR} node */ public A caseAIdentifierVarExpIR(AIdentifierVarExpIR node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAIdentifierVarExpIR(node, question)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this, question)); } mergeReturns(retVal,outAIdentifierVarExpIR(node, question)); return retVal; }
@Override public ALocalPatternAssignmentStmIR getNextElementAssigned( AIdentifierVarExpIR setVar, List<SPatternIR> patterns, SPatternIR pattern, AVarDeclIR successVarDecl, AVarDeclIR nextElementDecl) throws AnalysisException { STypeIR elementType = transAssistant.getElementType(setVar.getType()); return transAssistant.consNextElementAssignment(transAssistant.consClassType(ITERATOR_TYPE), elementType, pattern, iteratorName, NEXT_ELEMENT_ITERATOR, nextElementDecl); }
@Override public AVarDeclIR getNextElementDeclared(AIdentifierVarExpIR setVar, List<SPatternIR> patterns, SPatternIR pattern) throws AnalysisException { STypeIR elementType = transAssistant.getElementType(setVar.getType()); return transAssistant.consNextElementDeclared(transAssistant.consClassType(ITERATOR_TYPE), elementType, pattern, iteratorName, NEXT_ELEMENT_ITERATOR); }
public SExpIR consStoreLookup(AIdentifierVarExpIR node, boolean noCast) { AClassTypeIR storeType = transAssistant.consClassType(tracePrefixes.storeClassName()); AIdentifierVarExpIR idArg = transAssistant.getInfo().getExpAssistant().consIdVar(idConstNameMap.get(node.getName()), new ANatNumericBasicTypeIR()); SExpIR call = transAssistant.consInstanceCall(storeType, tracePrefixes.storeVarName(), node.getType(), tracePrefixes.storeGetValueMethodName(), idArg); if (noCast || node.getType() instanceof AUnionTypeIR || node.getType() instanceof AUnknownTypeIR || node.getType() instanceof AObjectTypeIR) { return call; } else { ACastUnaryExpIR cast = new ACastUnaryExpIR(); cast.setType(node.getType().clone()); cast.setExp(call); return cast; } } }
public AMetaStmIR consAssert(AIdentifierVarExpIR var) { if (util.assertRec(var)) { ARecordTypeIR recType = (ARecordTypeIR) var.getType(); return invTrans.consMetaStm(util.consValidRecCheck(var, var.getName(), recType)); } else { return null; } } }
@Override public List<AVarDeclIR> getOuterBlockDecls(AIdentifierVarExpIR setVar, List<SPatternIR> patterns) throws AnalysisException { if (firstBind) { IRInfo info = transAssist.getInfo(); AIdentifierPatternIR resId = new AIdentifierPatternIR(); resId.setName(resultVarName); List<AVarDeclIR> decls = new LinkedList<>(); STypeIR elemType = transAssist.getElementType(setVar.getType()); AUndefinedExpIR initExp = info.getExpAssistant().consUndefinedExp(); decls.add(info.getDeclAssistant().consLocalVarDecl(elemType, resId, initExp)); AIdentifierPatternIR countId = new AIdentifierPatternIR(); countId.setName(counterName); decls.add(consCounterDecl(info, countId)); return decls; } else { return null; } }
public List<AMetaStmIR> consAsserts(AIdentifierVarExpIR var) { AbstractTypeInfo typeInfo = util.findTypeInfo(var.getType()); if (!proceed(typeInfo)) { return null; } ADefaultClassDeclIR encClass = decorator.getStateDesInfo().getEnclosingClass(var); if (encClass == null) { return null; } /** * Normalisation of state designators will never occur inside record classes so really there is no need to check * if invariant checks are enabled */ return util.consAssertStm(typeInfo, encClass, var, var, decorator.getRecInfo()); }
@Override public SExpIR caseAIdentifierVarExpIR(AIdentifierVarExpIR node) throws AnalysisException { if (node instanceof SVarExpIR) { SVarExpIR varExp = (SVarExpIR) node; if (BooleanUtils.isFalse(varExp.getIsLocal())) { ACastUnaryExpIR objId = consObjId(); AFieldExpIR fieldObj = new AFieldExpIR(); fieldObj.setType(node.getType().clone()); fieldObj.setMemberName(varExp.getName()); fieldObj.setObject(objId); assist.replaceNodeWith(node, fieldObj); return objId; } return node; } log.error("Expected variable expression at this point. Got: " + node); return null; }
public ACallObjectExpStmIR consAddTraceVarCall(AIdentifierVarExpIR subject, AIdentifierVarExpIR t) { ANewExpIR newVar = new ANewExpIR(); newVar.setName(getTransAssist().consTypeNameForClass(traceTrans.getTracePrefixes().traceVarClassName())); newVar.setType(getTransAssist().consClassType(traceTrans.getTracePrefixes().traceVarClassName())); newVar.getArgs().add(getInfo().getExpAssistant().consStringLiteral(t.getName(), false)); newVar.getArgs().add(getInfo().getExpAssistant().consStringLiteral("" + getTransAssist().getInfo().getTypeAssistant().getVdmType(t.getType()), false)); newVar.getArgs().add(traceTrans.getToStringBuilder().toStringOf(t.clone())); return getTransAssist().consInstanceCallStm(subject.getType(), subject.getName(), traceTrans.getTracePrefixes().addVarFirstMethodName(), newVar); }
private AFieldNumberExpIR consTupleFieldExp( AIdentifierVarExpIR tuplePatternVar, int i, STypeIR currentType, boolean cast) { AFieldNumberExpIR fieldNumberExp = new AFieldNumberExpIR(); fieldNumberExp.setType(currentType.clone()); if (!cast) { fieldNumberExp.setTuple(tuplePatternVar.clone()); } else { ACastUnaryExpIR castedExp = new ACastUnaryExpIR(); castedExp.setType(tuplePatternVar.getType().clone()); castedExp.setExp(tuplePatternVar.clone()); fieldNumberExp.setTuple(castedExp); } fieldNumberExp.setField(new Long(1 + i)); return fieldNumberExp; }
public AAddrNotEqualsBinaryExpIR consParamNotNullComp( AIdentifierVarExpIR param) { AAddrNotEqualsBinaryExpIR fieldComparison = new AAddrNotEqualsBinaryExpIR(); fieldComparison.setType(new ABoolBasicTypeIR()); AIdentifierVarExpIR instanceField = new AIdentifierVarExpIR(); instanceField.setType(param.getType().clone()); instanceField.setIsLocal(true); instanceField.setName(param.getName()); fieldComparison.setLeft(instanceField); fieldComparison.setRight(info.getExpAssistant().consNullExp()); return fieldComparison; }
@Override public AVarDeclIR getForLoopInit(AIdentifierVarExpIR setVar, List<SPatternIR> patterns, SPatternIR pattern) { iteratorName = transAssistant.getInfo().getTempVarNameGen().nextVarName(iteVarPrefixes.iterator()); String setName = setVar.getName(); AClassTypeIR iteratorType = transAssistant.consClassType(ITERATOR_TYPE); STypeIR setType = setVar.getType().clone(); SExpIR getIteratorCall = transAssistant.consInstanceCall(setType, setName, iteratorType.clone(), GET_ITERATOR); return transAssistant.getInfo().getDeclAssistant().consLocalVarDecl(iteratorType, transAssistant.getInfo().getPatternAssistant().consIdPattern(iteratorName), getIteratorCall); }
private ABlockStmIR consUnionTypedTuplePatternCheck( boolean declarePatternVar, AUnionTypeIR unionType, PatternBlockData patternData, SExpIR actualValue, ATuplePatternIR tuplePattern) { ATupleTypeIR resTupleType = transAssistant.getInfo().getPatternAssistant().getTupleType(unionType, tuplePattern); ABlockStmIR tuplePatternCheck = consTuplePatternCheck(declarePatternVar, tuplePattern, resTupleType, patternData, actualValue, true); AIsOfClassExpIR instanceCheck = new AIsOfClassExpIR(); instanceCheck.setType(new ABoolBasicTypeIR()); instanceCheck.setCheckedType(patternData.getRootPatternVar().getType().clone()); instanceCheck.setExp(patternData.getRootPatternVar().clone()); AIfStmIR typeCheck = new AIfStmIR(); typeCheck.setIfExp(instanceCheck); typeCheck.setThenStm(tuplePatternCheck); ABlockStmIR block = new ABlockStmIR(); block.getStatements().add(typeCheck); return block; }
private SExpIR consRecFieldExp(AIdentifierVarExpIR patternVar, int i, STypeIR currentType, boolean cast) { ARecordTypeIR recordType = (ARecordTypeIR) patternVar.getType(); AFieldDeclIR recordField = transAssistant.getInfo().getAssistantManager().getDeclAssistant().getFieldDecl(transAssistant.getInfo().getClasses(), recordType, i); String fieldName = recordField.getName(); AFieldExpIR fieldExp = consRecFieldExp(patternVar, currentType, fieldName); if (cast) { ACastUnaryExpIR casted = new ACastUnaryExpIR(); casted.setType(recordType.clone()); casted.setExp(fieldExp.getObject()); fieldExp.setObject(casted); } return fieldExp; }
@Override public void caseAIdentifierVarExpIR(AIdentifierVarExpIR node) throws AnalysisException { INode var = AssistantBase.getVdmNode(node); if(var instanceof AVariableExp) { PDefinition def = ((AVariableExp) var).getVardef(); if(def instanceof ARenamedDefinition) { ARenamedDefinition renamedDef = (ARenamedDefinition) def; AClassTypeIR definingClass = new AClassTypeIR(); definingClass.setName(renamedDef.getDef().getName().getModule()); definingClass.setSourceNode(node.getSourceNode()); AExplicitVarExpIR expVar = new AExplicitVarExpIR(); expVar.setName(renamedDef.getDef().getName().getName()); expVar.setType(node.getType().clone()); expVar.setIsLambda(node.getIsLambda()); expVar.setIsLocal(node.getIsLocal()); expVar.setMetaData(node.getMetaData()); expVar.setTag(node.getTag()); expVar.setSourceNode(node.getSourceNode()); expVar.setClassType(definingClass); assist.replaceNodeWith(node, expVar); } } }