public static OperandUsage typeDeterminedUsage(net.sf.saxon.type.ItemType type) { if (type.isPlainType()) { return OperandUsage.ABSORPTION; } else if (type instanceof NodeTest || type == AnyItemType.getInstance()) { return OperandUsage.NAVIGATION; } else { return OperandUsage.INSPECTION; } }
public static OperandUsage typeDeterminedUsage(net.sf.saxon.type.ItemType type) { if (type.isPlainType()) { return OperandUsage.ABSORPTION; } else if (type instanceof NodeTest || type == AnyItemType.getInstance()) { return OperandUsage.NAVIGATION; } else { return OperandUsage.INSPECTION; } }
/** * Attempt to optimize a call on saxon:stream(). Return null if no optimization is possible. * * @param select the expression that selects the items to be copied * @return null if no optimization is possible, or an expression that does an optimized * copy of these items otherwise */ /*@Nullable*/ public Expression optimizeSaxonStreamFunction(ExpressionVisitor visitor, ContextItemStaticInfo cisi, Expression select) throws XPathException { if (select.getItemType().isPlainType()) { return select; } return null; }
/** * Attempt to optimize a call on saxon:stream(). Return null if no optimization is possible. * * @param select the expression that selects the items to be copied * @return null if no optimization is possible, or an expression that does an optimized * copy of these items otherwise */ /*@Nullable*/ public Expression optimizeSaxonStreamFunction(ExpressionVisitor visitor, ContextItemStaticInfo cisi, Expression select) throws XPathException { if (select.getItemType().isPlainType()) { return select; } return null; }
/** * Determine whether this instruction creates new nodes. * The result depends on the type of the select expression. */ public final boolean mayCreateNewNodes() { return !getSelect().getItemType().isPlainType(); }
public boolean subsumes(ItemType other) { net.sf.saxon.type.ItemType otherType = other.getUnderlyingItemType(); if (!otherType.isPlainType()) { return false; } AtomicType type = (AtomicType) otherType; return subsumesUnderlyingType(type); }
public boolean subsumes(ItemType other) { net.sf.saxon.type.ItemType otherType = other.getUnderlyingItemType(); if (!otherType.isPlainType()) { return false; } AtomicType type = (AtomicType) otherType; return subsumesUnderlyingType(type); }
/** * Determine whether this instruction creates new nodes. * The result depends on the type of the select expression. */ public final boolean mayCreateNewNodes() { return !getSelect().getItemType().isPlainType(); }
/** * Get the primitive item type corresponding to this item type. For item(), * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, * it is the value representing the node kind, for example Type.ELEMENT. * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. * For other atomic types it is the primitive type as defined in XML Schema, * except that INTEGER is considered to be a primitive type. */ /*@NotNull*/ public BuiltInAtomicType getPrimitiveItemType() { if (isPrimitiveType()) { return this; } else { ItemType s = (ItemType) getBaseType(); assert s != null; if (s.isPlainType()) { return (BuiltInAtomicType)s.getPrimitiveItemType(); } else { return this; } } }
private AbstractExpression exprFor (InstanceOfExpression expr) { ItemType type = expr.getRequiredItemType(); String typeExpr; if (type.isPlainType()) { typeExpr = type.toString(); } else if (type instanceof NodeTest) { lux.xpath.NodeTest nodeTest = nodeTestFor((NodeTest)type); typeExpr = nodeTest.toString(); } else { throw new LuxException ("Unsupported node test in instance-of expression: " + expr.toString()); } return new InstanceOf(typeExpr, exprFor (expr.getBaseExpression())); }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { selectOp.optimize(visitor, contextItemType); if (Literal.isEmptySequence(getSelect())) { return getSelect(); } adoptChildExpression(getSelect()); if (getSelect().getItemType().isPlainType()) { return getSelect(); } return this; }
/** * Simplify an expression. This performs any static optimization (by rewriting the expression * as a different expression). The default implementation simplifies its operands. * * @return the simplified expression (or the original if unchanged, or if modified in-situ) * @throws XPathException if an error is discovered during expression * rewriting */ @Override public Expression simplify() throws XPathException { if (valueOp != null && !valueOp.getChildExpression().getItemType().isPlainType()) { valueOp.setChildExpression(Atomizer.makeAtomizer(valueOp.getChildExpression(), null)); } preallocateNumberer(getConfiguration()); return super.simplify(); }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { selectOp.optimize(visitor, contextItemType); if (Literal.isEmptySequence(getSelect())) { return getSelect(); } adoptChildExpression(getSelect()); if (getSelect().getItemType().isPlainType()) { return getSelect(); } return this; }
/** * Simplify an expression. This performs any static optimization (by rewriting the expression * as a different expression). The default implementation simplifies its operands. * * @return the simplified expression (or the original if unchanged, or if modified in-situ) * @throws XPathException if an error is discovered during expression * rewriting */ @Override public Expression simplify() throws XPathException { if (valueOp != null && !valueOp.getChildExpression().getItemType().isPlainType()) { valueOp.setChildExpression(Atomizer.makeAtomizer(valueOp.getChildExpression())); } preallocateNumberer(getConfiguration()); return super.simplify(); }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression exp = super.optimize(visitor, contextInfo); if (exp == this) { // Since it's an error for the result to have more than one item, there's no point sorting the input setBaseExpression(getBaseExpression().unordered(true, false)); if (getBaseExpression().getItemType().isPlainType() && !Cardinality.allowsMany(getBaseExpression().getCardinality())) { return getBaseExpression(); } return this; } else { return exp; } }
public Expression processValueOf(Expression select, Configuration config) { TypeHierarchy th = config.getTypeHierarchy(); if (!select.getItemType().isPlainType()) { select = Atomizer.makeAtomizer(select, null); } if (Cardinality.allowsMany(select.getCardinality())) { select = FirstItemExpression.makeFirstItemExpression(select); } if (!th.isSubType(select.getItemType(), BuiltInAtomicType.STRING)) { select = new AtomicSequenceConverter(select, BuiltInAtomicType.STRING); ((AtomicSequenceConverter) select).allocateConverterStatically(config, false); } return select; }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression exp = super.optimize(visitor, contextInfo); if (exp == this) { // Since it's an error for the result to have more than one item, there's no point sorting the input setBaseExpression(getBaseExpression().unordered(true, false)); if (getBaseExpression().getItemType().isPlainType() && !Cardinality.allowsMany(getBaseExpression().getCardinality())) { return getBaseExpression(); } return this; } else { return exp; } }
public Expression processValueOf(Expression select, Configuration config) { TypeHierarchy th = config.getTypeHierarchy(); if (!select.getItemType().isPlainType()) { select = Atomizer.makeAtomizer(select); } if (Cardinality.allowsMany(select.getCardinality())) { select = FirstItemExpression.makeFirstItemExpression(select); } if (!th.isSubType(select.getItemType(), BuiltInAtomicType.STRING)) { select = new AtomicSequenceConverter(select, BuiltInAtomicType.STRING); ((AtomicSequenceConverter) select).allocateConverterStatically(config, false); } return select; }
/** * Determine the static cardinality of the expression */ public int computeCardinality() { ItemType in = getOperandItemType(); Expression operand = getBaseExpression(); if (singleValued) { return operand.getCardinality(); } else if (untyped && in instanceof NodeTest) { return operand.getCardinality(); } else if (Cardinality.allowsMany(operand.getCardinality())) { return StaticProperty.ALLOWS_ZERO_OR_MORE; } else if (in.isPlainType()) { return operand.getCardinality(); } else if (in instanceof NodeTest) { SchemaType schemaType = ((NodeTest) in).getContentType(); if (schemaType.isAtomicType()) { // can return at most one atomic value per node return operand.getCardinality(); } } return StaticProperty.ALLOWS_ZERO_OR_MORE; }
/** * Make an expression that extracts the first item of a sequence, after atomization */ /*@NotNull*/ public static Expression makeFirstItem(Expression exp, StaticContext env) { if (Literal.isEmptySequence(exp)) { return exp; } final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!exp.getItemType().isPlainType()) { exp = Atomizer.makeAtomizer(exp, null); } if (Cardinality.allowsMany(exp.getCardinality())) { exp = FirstItemExpression.makeFirstItemExpression(exp); } if (!th.isSubType(exp.getItemType(), BuiltInAtomicType.STRING)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); ((AtomicSequenceConverter) exp).allocateConverterStatically(env.getConfiguration(), false); } return exp; }