private <T extends STypeIR> List<T> getTypes(STypeIR type, Class<T> filter) { List<T> filteredTypes = new LinkedList<>(); if (filter.isInstance(type)) { filteredTypes.add(filter.cast(type)); } else if (type instanceof AUnionTypeIR) { List<STypeIR> types = ((AUnionTypeIR) type).getTypes(); for (STypeIR t : types) { filteredTypes.addAll(getTypes(t, filter)); } } return filteredTypes; }
/** * Returns a deep clone of this {@link AUnionTypeIR} node. * @return a deep clone of this {@link AUnionTypeIR} node */ public AUnionTypeIR clone() { return new AUnionTypeIR( _sourceNode, _tag, _metaData, _optional, cloneNode(_namedInvType), cloneList(_types) ); }
/** * Called by the {@link AUnionTypeIR} node from {@link AUnionTypeIR#apply(IIsaAnalysis)}. * @param node the calling {@link AUnionTypeIR} node */ public void caseAUnionTypeIR(AUnionTypeIR node) throws AnalysisException { _visitedNodes.add(node); inAUnionTypeIR(node); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { node.getNamedInvType().apply(this); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getTypes()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } outAUnionTypeIR(node); }
List<STypeIR> types = ((AUnionTypeIR) objectType).getTypes(); } else AUnionTypeIR unionTypes = new AUnionTypeIR(); unionTypes.setTypes(fieldTypes);
for (STypeIR nextType : unionType.getTypes()) AUnionTypeIR fieldType = new AUnionTypeIR(); fieldType.getTypes().add(t.getTypes().get(i).clone());
public boolean allowsNull(STypeIR type) { if (type instanceof AUnionTypeIR) { AUnionTypeIR unionType = (AUnionTypeIR) type; if (BooleanUtils.isTrue(unionType.getOptional())) { return true; } for (STypeIR t : unionType.getTypes()) { if (allowsNull(t)) { return true; } } return false; } else { return /* type instanceof AObjectTypeIR || */type != null && (type instanceof AUnknownTypeIR || BooleanUtils.isTrue(type.getOptional()) || isWrapperType(type)); } }
public SSeqTypeIR getSeqType(AUnionTypeIR unionType) { AUnionTypeIR seqOf = new AUnionTypeIR(); seqOf.setTypes(findElementTypes(unionType, new CollectionTypeStrategy() { @Override public boolean isCollectionType(STypeIR type) { return type instanceof SSeqTypeIR; } @Override public STypeIR getElementType(STypeIR type) { return ((SSeqTypeIR) type).getSeqOf(); } })); ASeqSeqTypeIR seqType = new ASeqSeqTypeIR(); seqType.setEmpty(false); seqType.setSeqOf(seqOf); return seqType; }
/** * Creates a new tree field only constructor {@code AUnionTypeIR TAG=union} 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 types_ the {@link NodeList} node for the {@code types} child of this {@link AUnionTypeIR} node */ public AUnionTypeIR(Boolean optional_, ANamedTypeDeclIR namedInvType_, List<? extends STypeIR> types_) { super(null,null,null,optional_,namedInvType_); this.setTypes(types_); }
} else AUnionTypeIR unionTypeCg = new AUnionTypeIR(); unionTypeCg.getTypes().add(typeCg); } else
public SSetTypeIR getSetType(AUnionTypeIR unionType) { AUnionTypeIR setOf = new AUnionTypeIR(); setOf.setTypes(findElementTypes(unionType, new CollectionTypeStrategy() { @Override public boolean isCollectionType(STypeIR type) { return type instanceof SSetTypeIR; } @Override public STypeIR getElementType(STypeIR type) { return ((SSetTypeIR) type).getSetOf(); } })); ASetSetTypeIR setType = new ASetSetTypeIR(); setType.setEmpty(false); setType.setSetOf(setOf); return setType; }
/** * Creates a new complete constructor {@code AUnionTypeIR} 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 types_ the {@link NodeList} node for the {@code types} child of this {@link AUnionTypeIR} node */ public AUnionTypeIR(SourceNode sourceNode_, Object tag_, List<? extends ClonableString> metaData_, Boolean optional_, ANamedTypeDeclIR namedInvType_, List<? extends STypeIR> types_) { super(sourceNode_,tag_,metaData_,optional_,namedInvType_); this.setTypes(types_); }
public boolean mayBeValueType(STypeIR type) { if (type instanceof AUnionTypeIR) { LinkedList<STypeIR> types = ((AUnionTypeIR) type).getTypes(); for (STypeIR t : types) { if (mayBeValueType(t)) { return true; } } return false; } else { return type instanceof ARecordTypeIR || type instanceof ATupleTypeIR || type instanceof SSeqTypeIR || type instanceof SSetTypeIR || type instanceof SMapTypeIR; } }
/** * Called by the {@link AUnionTypeIR} node from {@link AUnionTypeIR#apply(IAnalysis)}. * @param node the calling {@link AUnionTypeIR} node */ public void caseAUnionTypeIR(AUnionTypeIR node) throws AnalysisException { _visitedNodes.add(node); inAUnionTypeIR(node); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { node.getNamedInvType().apply(this); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getTypes()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } outAUnionTypeIR(node); }
/** * Creates a deep clone of this {@link AUnionTypeIR} 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 AUnionTypeIR} node */ public AUnionTypeIR clone(Map<INode,INode> oldToNewMap) { AUnionTypeIR node = new AUnionTypeIR( _sourceNode, _tag, _metaData, _optional, cloneNode(_namedInvType, oldToNewMap), cloneList(_types, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
public List<STypeIR> findElementTypes(AUnionTypeIR unionType, CollectionTypeStrategy strategy) { List<STypeIR> elementTypes = new LinkedList<STypeIR>(); for (int i = 0; i < unionType.getTypes().size(); i++) { STypeIR type = unionType.getTypes().get(i); if (type instanceof AUnionTypeIR) { elementTypes.addAll(findElementTypes((AUnionTypeIR) type, strategy)); } else if (strategy.isCollectionType(type)) { elementTypes.add(strategy.getElementType(type)); } } return elementTypes; }
/** * Called by the {@link AUnionTypeIR} node from {@link AUnionTypeIR#apply(IAnalysis)}. * @param node the calling {@link AUnionTypeIR} node */ public void caseAUnionTypeIR(AUnionTypeIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inAUnionTypeIR(node, question); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { node.getNamedInvType().apply(this, question); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getTypes()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this, question); } } } outAUnionTypeIR(node, question); }
public boolean isUnionOfType(AUnionTypeIR unionType, Class<? extends STypeIR> type) { try { for (STypeIR t : unionType.getTypes()) { if(t instanceof AUnionTypeIR) { if(!isUnionOfType((AUnionTypeIR) t, type)) { return false; } } else if (!(t instanceof AQuoteTypeIR)) { return false; } } } catch (Error t)// Hack for stackoverflowError { return false; } return true; }
/** * Called by the {@link AUnionTypeIR} node from {@link AUnionTypeIR#apply(IAnalysis)}. * @param node the calling {@link AUnionTypeIR} node */ public A caseAUnionTypeIR(AUnionTypeIR node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAUnionTypeIR(node)); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { mergeReturns(retVal,node.getNamedInvType().apply(this)); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getTypes()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { mergeReturns(retVal,e.apply(this)); } } } mergeReturns(retVal,outAUnionTypeIR(node)); return retVal; }
LinkedList<STypeIR> types = ((AUnionTypeIR) field.getObject().getType()).getTypes();
/** * Called by the {@link AUnionTypeIR} node from {@link AUnionTypeIR#apply(IAnalysis)}. * @param node the calling {@link AUnionTypeIR} node */ public A caseAUnionTypeIR(AUnionTypeIR node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAUnionTypeIR(node, question)); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { mergeReturns(retVal,node.getNamedInvType().apply(this, question)); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getTypes()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { mergeReturns(retVal,e.apply(this, question)); } } } mergeReturns(retVal,outAUnionTypeIR(node, question)); return retVal; }