private void fillValueWithMetadata( final TemplateTree tree, final ValueNode root, final Object metadata, final Map<String, Set<Object>> excluded, final boolean prune, final boolean overwrite) throws ParseException { final List<ValueNode> children = new ArrayList<>(root.children); for (ValueNode node : children) { final ValueNode origNode = new ValueNode(node); final Object obj = getValue(node, metadata, excluded, overwrite); if (obj instanceof Collection && !((Collection) obj).isEmpty()) { final Iterator it = ((Collection) obj).iterator(); int i = node.ordinal; while (it.hasNext()) { Object child = it.next(); node = tree.duplicateNode(origNode, i); if (node.isField()) { node.value = valueToString(node, child, !prune, overwrite); } else { fillValueWithMetadata(tree, node, child, excluded, prune, overwrite); } i++; } } else { if (node.isField()) { node.value = valueToString(node, obj, !prune, overwrite); } else { fillValueWithMetadata(tree, node, obj, excluded, prune, overwrite); } } } }
private static boolean matchNode(final ValueNode origin, final ValueNode candidate) { if (Objects.equals(origin.type, candidate.type)) { if (origin.render != null && origin.render.contains("readonly") && !Objects.equals(origin.defaultValue, candidate.value)) { return false; } else if (!origin.getPredefinedValues().isEmpty() && !origin.getPredefinedValues().contains(candidate.value)) { return false; } for (ValueNode originChild : origin.children) { final List<ValueNode> candidateChildren = candidate.getChildrenByName(originChild.name); if (!originChild.multiple && candidateChildren.size() > 1) { return false; } for (ValueNode candidateChild : candidateChildren) { if (!matchNode(originChild, candidateChild)) { return false; } } } return true; } return false; }
/** * Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed * to work. * * @param depth The depth of this node in the tree */ public void printSubNodes(int depth) { if (SanityManager.DEBUG) { super.printSubNodes(depth); if (subquery != null) { printLabel(depth, "subquery: "); subquery.treePrint(depth + 1); } if (orderByList != null) { printLabel(depth, "orderByList: "); orderByList.treePrint(depth + 1); } if (offset != null) { printLabel(depth, "offset: "); offset.treePrint(depth + 1); } if (fetchFirst != null) { printLabel(depth, "fetchFirst: "); fetchFirst.treePrint(depth + 1); } } }
/** * Accept the visitor for all visitable children of this node. * * @param v the visitor * @exception StandardException on error */ void acceptChildren(Visitor v) throws StandardException { super.acceptChildren(v); if (testCondition != null) { testCondition = (ValueNode) testCondition.accept(v); } if (thenElseList != null) { thenElseList = (ValueNodeList) thenElseList.accept(v); } }
/** * Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed * to work. * * @param depth The depth of this node in the tree */ public void printSubNodes(int depth) { super.printSubNodes(depth); if (testCondition != null) { printLabel(depth, "testCondition: "); testCondition.treePrint(depth + 1); } if (thenElseList != null) { printLabel(depth, "thenElseList: "); thenElseList.treePrint(depth + 1); } }
public Stamp getReturnStamp() { Stamp returnStamp = null; for (ReturnNode returnNode : getNodes(ReturnNode.TYPE)) { ValueNode result = returnNode.result(); if (result != null) { if (returnStamp == null) { returnStamp = result.stamp(); } else { returnStamp = returnStamp.meet(result.stamp()); } } } return returnStamp; }
/** * Accept the visitor for all visitable children of this node. * * @param v the visitor * @exception StandardException on error */ void acceptChildren(Visitor v) throws StandardException { super.acceptChildren(v); if (receiver != null) { receiver = (ValueNode) receiver.accept(v); } if (leftOperand != null) { leftOperand = (ValueNode) leftOperand.accept(v); } if (rightOperand != null) { rightOperand = (ValueNode) rightOperand.accept(v); } }
/** * Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed * to work. * * @param depth The depth of this node in the tree */ public void printSubNodes(int depth) { super.printSubNodes(depth); if (value != null) { printLabel(depth, "value: "); value.treePrint(depth + 1); } }
/** * Accept the visitor for all visitable children of this node. * * @param v the visitor * @exception StandardException on error */ void acceptChildren(Visitor v) throws StandardException { super.acceptChildren(v); if (javaNode != null) { javaNode = (JavaValueNode) javaNode.accept(v); } }
/** * Tries to find an original value of the given node by traversing through proxies and unambiguous * phis. Note that this method will perform an exhaustive search through phis. It is intended to * be used during graph building, when phi nodes aren't yet canonicalized. * * @param proxy The node whose original value should be determined. */ public static ValueNode originalValue(ValueNode proxy) { ValueNode v = proxy; do { if (v instanceof ValueProxy) { v = ((ValueProxy) v).getOriginalValue(); } else if (v instanceof PhiNode) { v = ((PhiNode) v).singleValue(); } else { break; } } while (v != null); // if the simple check fails (this can happen for complicated phi/proxy/phi constructs), we // do an exhaustive search if (v == null) { NodeWorkList worklist = proxy.graph().createNodeWorkList(); worklist.add(proxy); for (Node node : worklist) { if (node instanceof ValueProxy) { worklist.add(((ValueProxy) node).getOriginalValue()); } else if (node instanceof PhiNode) { worklist.addAll(((PhiNode) node).values()); } else { if (v == null) { v = (ValueNode) node; } else { return null; } } } } return v; }
/** * Accept the visitor for all visitable children of this node. * * @param v the visitor * @exception StandardException on error */ void acceptChildren(Visitor v) throws StandardException { super.acceptChildren(v); if (value != null) { value = (ValueNode) value.accept(v); } }
/** * Prints the sub-nodes of this object. See QueryTreeNode for how tree printing is supposed to * work. * * @param depth The depth of this node in the tree */ public void printSubNodes(int depth) { if (SanityManager.DEBUG) { super.printSubNodes(depth); printLabel(depth, "javaNode: "); javaNode.treePrint(depth + 1); } }
public boolean isTrue(Env env) throws EvaluationError { int leftVal = left.value(env); int rightVal = right.value(env); switch (op) { case '<': return leftVal < rightVal; case '>': return leftVal > rightVal; case '=': return leftVal == rightVal; default: throw new EvaluationError(String.format("Invalid operator %c", op)); } }
/** @see QueryTreeNode#acceptChildren */ void acceptChildren(Visitor v) throws StandardException { super.acceptChildren(v); subquery.accept(v); if (orderByList != null) { orderByList.accept(v); } if (offset != null) { offset.accept(v); } if (fetchFirst != null) { fetchFirst.accept(v); } }
/** {@inheritDoc} */ protected boolean isEquivalent(ValueNode o) throws StandardException { if (isSameNodeType(o)) { ConditionalNode other = (ConditionalNode) o; return testCondition.isEquivalent(other.testCondition) && thenElseList.isEquivalent(other.thenElseList); } return false; }
/** * Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed * to work. * * @param depth The depth of this node in the tree */ public void printSubNodes(int depth) { super.printSubNodes(depth); if (receiver != null) { printLabel(depth, "receiver: "); receiver.treePrint(depth + 1); } if (leftOperand != null) { printLabel(depth, "leftOperand: "); leftOperand.treePrint(depth + 1); } if (rightOperand != null) { printLabel(depth, "rightOperand: "); rightOperand.treePrint(depth + 1); } }
/** Fill this node with a deep copy of the given node. */ public void copyFrom(QueryTreeNode node) throws StandardException { super.copyFrom(node); ConditionalNode other = (ConditionalNode) node; this.testCondition = (ValueNode) getNodeFactory().copyNode(other.testCondition, getParserContext()); this.thenElseList = (ValueNodeList) getNodeFactory().copyNode(other.thenElseList, getParserContext()); this.thisIsNullIfNode = other.thisIsNullIfNode; }
/** * Flatten this FSqry into the outer query block. The steps in flattening are: o Mark all * ResultColumns as redundant, so that they are "skipped over" at generate(). o Append the * wherePredicates to the outer list. o Return the fromList so that the caller will merge the 2 * lists RESOLVE - FSqrys with subqueries are currently not flattenable. Some of them can be * flattened, however. We need to merge the subquery list when we relax this restriction. * * <p>NOTE: This method returns NULL when flattening RowResultSetNodes (the node for a VALUES * clause). The reason is that no reference is left to the RowResultSetNode after flattening is * done - the expressions point directly to the ValueNodes in the RowResultSetNode's * ResultColumnList. * * @param rcl The RCL from the outer query * @param outerPList PredicateList to append wherePredicates to. * @param sql The SubqueryList from the outer query * @param gbl The group by list, if any * @param havingClause The HAVING clause, if any * @return FromList The fromList from the underlying SelectNode. * @exception StandardException Thrown on error */ public FromList flatten( ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) throws StandardException { FromList fromList = null; SelectNode selectNode; resultColumns.setRedundant(); subquery.getResultColumns().setRedundant(); /* ** RESOLVE: Each type of result set should know how to remap itself. */ if (subquery instanceof SelectNode) { selectNode = (SelectNode) subquery; fromList = selectNode.getFromList(); // selectNode.getResultColumns().setRedundant(); if (selectNode.getWherePredicates().size() > 0) { outerPList.destructiveAppend(selectNode.getWherePredicates()); } if (selectNode.getWhereSubquerys().size() > 0) { sql.destructiveAppend(selectNode.getWhereSubquerys()); } } else if (!(subquery instanceof RowResultSetNode)) { if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "subquery expected to be either a SelectNode or a RowResultSetNode, but is a " + subquery.getClass().getName()); } } /* Remap all ColumnReferences from the outer query to this node. * (We replace those ColumnReferences with clones of the matching * expression in the SELECT's RCL. */ rcl.remapColumnReferencesToExpressions(); outerPList.remapColumnReferencesToExpressions(); if (gbl != null) { gbl.remapColumnReferencesToExpressions(); } if (havingClause != null) { havingClause.remapColumnReferencesToExpressions(); } return fromList; }
@Override public void setVirtualEntry(State objectState, int index, ValueNode value) { ObjectState obj = (ObjectState) objectState; assert obj != null && obj.isVirtual() : "not virtual: " + obj; ObjectState valueState = state.getObjectState(value); ValueNode newValue = value; if (valueState == null) { newValue = getReplacedValue(value); assert obj.getEntry(index) == null || obj.getEntry(index).kind() == newValue.kind() || (isObjectEntry(obj.getEntry(index)) && isObjectEntry(newValue)); } else { if (valueState.getState() != EscapeState.Virtual) { newValue = valueState.getMaterializedValue(); assert newValue.kind() == Kind.Object; } else { newValue = valueState.getVirtualObject(); } assert obj.getEntry(index) == null || isObjectEntry(obj.getEntry(index)); } obj.setEntry(index, newValue); }
/** Fill this node with a deep copy of the given node. */ public void copyFrom(QueryTreeNode node) throws StandardException { super.copyFrom(node); TernaryOperatorNode other = (TernaryOperatorNode) node; this.operator = other.operator; this.methodName = other.methodName; this.operatorType = other.operatorType; this.receiver = (ValueNode) getNodeFactory().copyNode(other.receiver, getParserContext()); this.leftOperand = (ValueNode) getNodeFactory().copyNode(other.leftOperand, getParserContext()); this.rightOperand = (ValueNode) getNodeFactory().copyNode(other.rightOperand, getParserContext()); this.resultInterfaceType = other.resultInterfaceType; this.receiverInterfaceType = other.receiverInterfaceType; this.leftInterfaceType = other.leftInterfaceType; this.rightInterfaceType = other.rightInterfaceType; }
/** * Process a node as part of this search. * * @param node the next node encountered in the search * @param worklist if non-null, {@code node} will be added to this list. Otherwise, {@code node} * is treated as a candidate result. * @return true if the search should continue, false if a definitive {@link #result} has been * found */ private boolean process(ValueNode node, NodeWorkList worklist) { if (node.isAlive()) { if (worklist == null) { if (result == null) { // Initial candidate result: continue search result = node; } else if (result != node) { // Conflicts with existing candidate: stop search with null result result = null; return false; } } else { worklist.add(node); } } return true; }
public OriginalValueSearch(ValueNode proxy) { NodeWorkList worklist = proxy.graph().createNodeWorkList(); worklist.add(proxy); for (Node node : worklist) { if (node instanceof LimitedValueProxy) { ValueNode originalValue = ((LimitedValueProxy) node).getOriginalNode(); if (!process(originalValue, worklist)) { return; } } else if (node instanceof PhiNode) { for (Node value : ((PhiNode) node).values()) { if (!process((ValueNode) value, worklist)) { return; } } } else { if (!process((ValueNode) node, null)) { return; } } } }
private ValueNode extractSubTreeFromMetadata( final ValueNode root, final Object metadata, final Map<String, Set<Object>> excluded) throws ParseException { if (root.isField()) { root.value = valueToString(root, metadata, false, false); return root; } final List<ValueNode> children = new ArrayList<>(root.children); for (ValueNode node : children) { final ValueNode origNode = new ValueNode(node); final Object obj = getValue(node, metadata, excluded, false); if (obj instanceof Collection && !((Collection) obj).isEmpty()) { final Iterator it = ((Collection) obj).iterator(); int i = node.ordinal; boolean first = true; while (it.hasNext()) { Object child = it.next(); if (!first) { node = new ValueNode(origNode, root, i); } if (node.isField()) { node.value = valueToString(node, child, false, false); } else { extractSubTreeFromMetadata(node, child, excluded); } first = false; i++; } } else { if (node.isField()) { node.value = valueToString(node, obj, false, false); } else { extractSubTreeFromMetadata(node, obj, excluded); } } } return root; }
/** Override behavior in superclass. */ public DataTypeDescriptor getType() throws StandardException { return value.getType(); }
/** * @see ValueNode#getConstantValueAsObject * @exception StandardException Thrown on error */ Object getConstantValueAsObject() throws StandardException { return value.getConstantValueAsObject(); }
/** * Return whether or not this expression tree represents a constant expression. * * @return Whether or not this expression tree represents a constant expression. */ public boolean isConstantExpression() { return (testCondition.isConstantExpression() && thenElseList.isConstantExpression()); }
private static boolean isObjectEntry(ValueNode value) { return value.kind() == Kind.Object || value instanceof VirtualObjectNode; }
public GuardedValueNode(ValueNode object, GuardingNode guard) { this(object, guard, object.stamp()); }
@Override public void generate(NodeLIRBuilderTool generator) { if (object.getStackKind() != JavaKind.Void && object.getStackKind() != JavaKind.Illegal) { generator.setResult(this, generator.operand(object)); } }