public boolean isFieldRHS(INode node) { return node.getAncestor(AFieldDeclIR.class) != null; }
private boolean CanNullParentOfInnerList(List<? extends E> list, INode parent) { for (E e : list) { if(e.parent() != parent) return false; } return true; }
public String trans(INode node) throws AnalysisException { StringWriter writer = new StringWriter(); node.apply(mergeVisitor, writer); return writer.toString(); }
protected void setParent(INode n) { INode p = n.parent(); if (p != null) { p.removeChild(n); } n.parent(parent); }
private void replace(INode original, INode replacement) { INode parent = original.parent(); if (parent != null) { parent.replaceChild(original, replacement); } original.parent(null); }
private SExpIR getAssignmentExp(INode node, SExpIR fieldExp) { INode parent = node.parent(); if (parent instanceof AApplyExpIR && ((AApplyExpIR) parent).getRoot() == node) { AApplyExpIR applyExp = (AApplyExpIR) parent.clone(); applyExp.setRoot(fieldExp); return applyExp; } else { return fieldExp; } }
/** * Sets the {@code _body} child of this {@link ALetDefBindingTraceDeclIR} node. * @param value the new {@code _body} child of this {@link ALetDefBindingTraceDeclIR} node */ public void setBody(PIR value) { if (this._body != null) { this._body.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._body = value; }
/** * Returns a deep clone of {@code node} or {@code null} if {@code node} is {@code null}. * @param node the node which is cloned * @return a deep clone of {@code node} */ @SuppressWarnings("unchecked") protected <T extends INode> T cloneNode(T node) { if(node != null) { return (T) node.clone(); } return null; }
@Override public void caseABlockStmIR(ABlockStmIR node) throws org.overture.codegen.ir.analysis.AnalysisException { for (SStmIR s : new LinkedList<>(node.getStatements())) { s.apply(this); } if (node.parent() instanceof ABlockStmIR && isEmpty(node)) { /** * Only remove empty blocks from blocks, otherwise we can get into a situation where we destroy the tree. * For example, 'if exp then () else ()' */ node.parent().removeChild(node); return; } if (singleBlockWrapsBlock(node)) { SStmIR enclosedStm = node.getStatements().get(0); if (node.parent() != null) { node.parent().replaceChild(node, enclosedStm); } } }
@Override public void caseACallObjectStmIR(ACallObjectStmIR node) throws AnalysisException { ACallObjectExpStmIR callObjExpStm = new ACallObjectExpStmIR(); callObjExpStm.setArgs(node.getArgs()); callObjExpStm.setObj(node.getDesignator().apply(converter)); callObjExpStm.setFieldName(node.getFieldName()); callObjExpStm.setSourceNode(node.getSourceNode()); callObjExpStm.setTag(node.getTag()); callObjExpStm.setType(node.getType()); if (node.parent() != null) { node.parent().replaceChild(node, callObjExpStm); } else { log.error("Could not find parent of " + node); } } }
/** * Sets the {@code _seq} child of this {@link ASeqBindIR} node. * @param value the new {@code _seq} child of this {@link ASeqBindIR} node */ public void setSeq(SExpIR value) { if (this._seq != null) { this._seq.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._seq = value; }
protected void setParent(List<? extends E> list) { for (E n : list) { INode p = n.parent(); if (p != null) { p.removeChild(n); } n.parent(parent); } }
@SuppressWarnings("unchecked") public @Override Object clone() { LinkedList<E> clone = new LinkedList<E>(); for (E n : this) { clone.add((E) n.clone()); } return clone; }
private ANotUnaryExpIR transNotEquals(ANotEqualsBinaryExpIR notEqual) { ANotUnaryExpIR notUnary = new ANotUnaryExpIR(); notUnary.setType(new ABoolBasicTypeIR()); AEqualsBinaryExpIR equal = new AEqualsBinaryExpIR(); equal.setType(new ABoolBasicTypeIR()); equal.setLeft(notEqual.getLeft().clone()); equal.setRight(notEqual.getRight().clone()); notUnary.setExp(equal); // Replace the "notEqual" expression with the transformed expression INode parent = notEqual.parent(); // It may be the case that the parent is null if we execute e.g. [1] <> [1] in isolation if (parent != null) { parent.replaceChild(notEqual, notUnary); notEqual.parent(null); } return notUnary; }
/** * Sets the {@code _seq} child of this {@link ASeqCompAddStmIR} node. * @param value the new {@code _seq} child of this {@link ASeqCompAddStmIR} node */ public void setSeq(SExpIR value) { if (this._seq != null) { this._seq.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._seq = value; }
protected void setParentOfInnterList(List<? extends E> list, INode parent) { for (E e : list) { e.parent(parent); } }
private boolean isWithinTrace(INode node) { return node.getAncestor(ANamedTraceDeclIR.class) == trace; }
public String transNodeList(List<? extends INode> params, String sep) throws AnalysisException { StringBuilder sb = new StringBuilder(); Iterator<? extends INode> it = params.iterator(); while (it.hasNext()) { StringWriter writer = new StringWriter(); it.next().apply(mergeVisitor, writer); sb.append(writer.toString()); if (it.hasNext()) { sb.append(sep); } } return sb.toString(); }
/** * Returns a deep clone of {@code node} or {@code null} if {@code node} is {@code null}. * The old node-new node relation is put into {@code oldToNewMap}. * @param node the node which is cloned * @param oldToNewMap the map filled with the old node-new node relation * @return a deep clone of {@code node} */ @SuppressWarnings("unchecked") protected <T extends INode> T cloneNode(T node, java.util.Map<INode,INode> oldToNewMap) { if(node != null) { T clone = (T) node.clone(oldToNewMap); oldToNewMap.put(node,clone); return clone; } return null; }
node.parent().replaceChild(node, newNode); } else