private AIsOfClassExpIR consInstanceCheck(SExpIR copy, STypeIR type) { AIsOfClassExpIR check = new AIsOfClassExpIR(); check.setType(new ABoolBasicTypeIR()); check.setCheckedType(type.clone()); check.setExp(copy.clone()); return check; }
/** * Returns a deep clone of this {@link AIsOfClassExpIR} node. * @return a deep clone of this {@link AIsOfClassExpIR} node */ public AIsOfClassExpIR clone() { return new AIsOfClassExpIR( _sourceNode, _tag, _metaData, cloneNode(_type), cloneNode(_checkedType), cloneNode(_exp) ); }
/** * Essentially this.toString().equals(o.toString()). **/ @Override public boolean equals(Object o) { if (o != null && o instanceof AIsOfClassExpIR) { return toString().equals(o.toString()); } return false; }
/** * Creates a new complete constructor {@code AIsOfClassExpIR} node with the given nodes as children. * @deprecated This method should not be used, use AstFactory instead. * The basic child nodes are removed from their previous parents. * @param checkedType_ the {@link STypeIR} node for the {@code checkedType} child of this {@link AIsOfClassExpIR} node * @param exp_ the {@link SExpIR} node for the {@code exp} child of this {@link AIsOfClassExpIR} node */ public AIsOfClassExpIR(SourceNode sourceNode_, Object tag_, List<? extends ClonableString> metaData_, STypeIR type_, STypeIR checkedType_, SExpIR exp_) { super(sourceNode_,tag_,metaData_,type_); this.setCheckedType(checkedType_); this.setExp(exp_); }
/** * Called by the {@link AIsOfClassExpIR} node from {@link AIsOfClassExpIR#apply(IAnalysis)}. * @param node the calling {@link AIsOfClassExpIR} node */ public void caseAIsOfClassExpIR(AIsOfClassExpIR node) throws AnalysisException { _visitedNodes.add(node); inAIsOfClassExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getCheckedType() != null && !_visitedNodes.contains(node.getCheckedType())) { node.getCheckedType().apply(this); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } outAIsOfClassExpIR(node); }
/** * Called by the {@link AIsOfClassExpIR} node from {@link AIsOfClassExpIR#apply(IAnalysis)}. * @param node the calling {@link AIsOfClassExpIR} node */ public void caseAIsOfClassExpIR(AIsOfClassExpIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inAIsOfClassExpIR(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this, question); } if(node.getCheckedType() != null && !_visitedNodes.contains(node.getCheckedType())) { node.getCheckedType().apply(this, question); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this, question); } outAIsOfClassExpIR(node, question); }
/** * Creates a new tree field only constructor {@code AIsOfClassExpIR TAG=isOfClass} node with the given nodes as children. * @deprecated This method should not be used, use AstFactory instead. * The basic child nodes are removed from their previous parents. * @param checkedType_ the {@link STypeIR} node for the {@code checkedType} child of this {@link AIsOfClassExpIR} node * @param exp_ the {@link SExpIR} node for the {@code exp} child of this {@link AIsOfClassExpIR} node */ public AIsOfClassExpIR(STypeIR type_, STypeIR checkedType_, SExpIR exp_) { super(null,null,null,type_); this.setCheckedType(checkedType_); this.setExp(exp_); }
@Override public SExpIR caseAIsOfClassExp(AIsOfClassExp node, IRInfo question) throws AnalysisException { PType type = node.getType(); AClassType classType = node.getClassType(); PExp objRef = node.getExp(); STypeIR typeCg = type.apply(question.getTypeVisitor(), question); STypeIR classTypeCg = classType.apply(question.getTypeVisitor(), question); if (!(classTypeCg instanceof AClassTypeIR)) { log.error("Unexpected class type encountered for " + AIsOfClassExp.class.getName() + ". Expected class type: " + AClassTypeIR.class.getName() + ". Got: " + typeCg.getClass().getName() + " at " + node.getLocation()); } SExpIR objRefCg = objRef.apply(question.getExpVisitor(), question); AIsOfClassExpIR instanceOfExp = new AIsOfClassExpIR(); instanceOfExp.setType(typeCg); instanceOfExp.setCheckedType(classTypeCg); instanceOfExp.setExp(objRefCg); return instanceOfExp; }
/** * Called by the {@link AIsOfClassExpIR} node from {@link AIsOfClassExpIR#apply(IIsaAnalysis)}. * @param node the calling {@link AIsOfClassExpIR} node */ public void caseAIsOfClassExpIR(AIsOfClassExpIR node) throws AnalysisException { _visitedNodes.add(node); inAIsOfClassExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getCheckedType() != null && !_visitedNodes.contains(node.getCheckedType())) { node.getCheckedType().apply(this); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } outAIsOfClassExpIR(node); }
/** * Creates a deep clone of this {@link AIsOfClassExpIR} node while putting all * old node-new node relations in the map {@code oldToNewMap}. * @param oldToNewMap the map filled with the old node-new node relation * @return a deep clone of this {@link AIsOfClassExpIR} node */ public AIsOfClassExpIR clone(Map<INode,INode> oldToNewMap) { AIsOfClassExpIR node = new AIsOfClassExpIR( _sourceNode, _tag, _metaData, cloneNode(_type, oldToNewMap), cloneNode(_checkedType, oldToNewMap), cloneNode(_exp, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
private AMethodDeclIR consEqualsMethod(String name) { AIdentifierVarExpIR paramVar = transAssistant.getInfo().getExpAssistant().consIdVar(EQUALS_METHOD_PARAM, new AObjectTypeIR()); AClassTypeIR quoteClass = new AClassTypeIR(); quoteClass.setName(name); AIsOfClassExpIR instanceCheck = new AIsOfClassExpIR(); instanceCheck.setType(new ABoolBasicTypeIR()); instanceCheck.setExp(paramVar); instanceCheck.setCheckedType(quoteClass); AReturnStmIR checkReturned = new AReturnStmIR(); checkReturned.setExp(instanceCheck); AMethodDeclIR equalsMethod = consEqualMethodSignature(EQUALS_METHOD_PARAM); ABlockStmIR body = new ABlockStmIR(); body.getStatements().add(checkReturned); equalsMethod.setBody(body); return equalsMethod; }
/** * Called by the {@link AIsOfClassExpIR} node from {@link AIsOfClassExpIR#apply(IAnalysis)}. * @param node the calling {@link AIsOfClassExpIR} node */ public A caseAIsOfClassExpIR(AIsOfClassExpIR node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAIsOfClassExpIR(node)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this)); } if(node.getCheckedType() != null && !_visitedNodes.contains(node.getCheckedType())) { mergeReturns(retVal,node.getCheckedType().apply(this)); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { mergeReturns(retVal,node.getExp().apply(this)); } mergeReturns(retVal,outAIsOfClassExpIR(node)); return retVal; }
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; }
/** * Called by the {@link AIsOfClassExpIR} node from {@link AIsOfClassExpIR#apply(IAnalysis)}. * @param node the calling {@link AIsOfClassExpIR} node */ public A caseAIsOfClassExpIR(AIsOfClassExpIR node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAIsOfClassExpIR(node, question)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this, question)); } if(node.getCheckedType() != null && !_visitedNodes.contains(node.getCheckedType())) { mergeReturns(retVal,node.getCheckedType().apply(this, question)); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { mergeReturns(retVal,node.getExp().apply(this, question)); } mergeReturns(retVal,outAIsOfClassExpIR(node, question)); return retVal; }
public AIsOfClassExpIR consInstanceOf(ARecordDeclIR record, String formalParamName) { // Example: objRef instanceof classType ADefaultClassDeclIR enclosingClass = record.getAncestor(ADefaultClassDeclIR.class); ATypeNameIR typeName = new ATypeNameIR(); typeName.setDefiningClass(enclosingClass.getName()); typeName.setName(record.getName()); ARecordTypeIR recordType = new ARecordTypeIR(); recordType.setName(typeName); AIdentifierVarExpIR objRef = new AIdentifierVarExpIR(); objRef.setType(new AObjectTypeIR()); objRef.setIsLocal(true); objRef.setName(formalParamName); AIsOfClassExpIR instanceOfExp = new AIsOfClassExpIR(); instanceOfExp.setType(new ABoolBasicTypeIR()); instanceOfExp.setExp(objRef); instanceOfExp.setCheckedType(recordType); return instanceOfExp; }
AIsOfClassExpIR instanceOfExp = new AIsOfClassExpIR(); instanceOfExp.setType(new ABoolBasicTypeIR()); instanceOfExp.setExp(actualValue.clone()); instanceOfExp.setCheckedType(recordType.clone());