private Expression makeSequenceTypeExpression(Expression lhs, int operator, /*@NotNull*/ SequenceType type) { switch (operator) { case Token.INSTANCE_OF: return new InstanceOfExpression(lhs, type); case Token.TREAT_AS: return TreatExpression.make(lhs, type); default: throw new IllegalArgumentException(); } }
private Expression makeSequenceTypeExpression(Expression lhs, int operator, /*@NotNull*/ SequenceType type) { switch (operator) { case Token.INSTANCE_OF: return new InstanceOfExpression(lhs, type); case Token.TREAT_AS: return TreatExpression.make(lhs, type); default: throw new IllegalArgumentException(); } }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new InstanceOfExpression(getBaseExpression().copy(), SequenceType.makeSequenceType(targetType, targetCardinality)); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new InstanceOfExpression(getBaseExpression().copy(), SequenceType.makeSequenceType(targetType, targetCardinality)); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings variable references that need to be rebound */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { InstanceOfExpression exp = new InstanceOfExpression(getBaseExpression().copy(rebindings), SequenceType.makeSequenceType(targetType, targetCardinality)); ExpressionTool.copyLocationInfo(this, exp); return exp; }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings variable references that need to be rebound */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { InstanceOfExpression exp = new InstanceOfExpression(getBaseExpression().copy(rebindings), SequenceType.makeSequenceType(targetType, targetCardinality)); ExpressionTool.copyLocationInfo(this, exp); return exp; }
/** * Parse an "instance of" expression * Expr ("instance" "of") SequenceType * * @throws XPathException if any error is encountered * @return the resulting subexpression */ private Expression parseInstanceOfExpression() throws XPathException { Expression exp = parseTreatExpression(); if (t.currentToken == Token.INSTANCE_OF) { nextToken(); exp = new InstanceOfExpression(exp, parseSequenceType()); setLocation(exp); } return exp; }
/** * Parse an "instance of" expression * Expr ("instance" "of") SequenceType * * @throws XPathException if any error is encountered * @return the resulting subexpression */ private Expression parseInstanceOfExpression() throws XPathException { Expression exp = parseTreatExpression(); if (t.currentToken == Token.INSTANCE_OF) { nextToken(); exp = new InstanceOfExpression(exp, parseSequenceType()); setLocation(exp); } return exp; }
/** * Override the parsing of top-level expressions * * @return the parsed expression * @throws net.sf.saxon.trans.XPathException * */ /*@NotNull*/ public Expression parseExpression() throws XPathException { Tokenizer t = getTokenizer(); if (inPredicate > 0) { return super.parseExpression(); } else if (allowSaxonExtensions && t.currentToken == Token.NODEKIND && (t.currentTokenValue.equals("tuple") || t.currentTokenValue.equals("map") || t.currentTokenValue.equals("array"))) { ItemType type = parserExtension.parseExtendedItemType(this); Expression expr = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(type, StaticProperty.EXACTLY_ONE)); expr = new FilterExpression(new ContextItemExpression(), expr); setLocation(expr); while (t.currentToken == Token.LSQB) { expr = parsePredicate(expr); } return expr; } else { return parseBinaryExpression(parsePathExpression(), 10); } }
/** * Override the parsing of top-level expressions * * @return the parsed expression * @throws net.sf.saxon.trans.XPathException * */ /*@NotNull*/ public Expression parseExpression() throws XPathException { Tokenizer t = getTokenizer(); if (inPredicate > 0) { return super.parseExpression(); } else if (allowSaxonExtensions && t.currentToken == Token.NODEKIND && (t.currentTokenValue.equals("tuple") || t.currentTokenValue.equals("map") || t.currentTokenValue.equals("array"))) { ItemType type = parserExtension.parseExtendedItemType(this); Expression expr = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(type, StaticProperty.EXACTLY_ONE)); expr = new FilterExpression(new ContextItemExpression(), expr); setLocation(expr); while (t.currentToken == Token.LSQB) { expr = parsePredicate(expr); } return expr; } else { return parseBinaryExpression(parsePathExpression(), 10); } }
Expression isDouble = new InstanceOfExpression( var, SequenceType.makeSequenceType(BuiltInAtomicType.DOUBLE, StaticProperty.ALLOWS_ZERO_OR_ONE)); Expression isDecimal = new InstanceOfExpression( var, SequenceType.makeSequenceType(BuiltInAtomicType.DECIMAL, StaticProperty.ALLOWS_ZERO_OR_ONE)); Expression isFloat = new InstanceOfExpression( var, SequenceType.makeSequenceType(BuiltInAtomicType.FLOAT, StaticProperty.ALLOWS_ZERO_OR_ONE)); Expression isString = new InstanceOfExpression( var, SequenceType.makeSequenceType(BuiltInAtomicType.STRING, StaticProperty.ALLOWS_ZERO_OR_ONE)); Expression isUntypedAtomic = new InstanceOfExpression( var, SequenceType.makeSequenceType(BuiltInAtomicType.UNTYPED_ATOMIC, StaticProperty.ALLOWS_ZERO_OR_ONE)); Expression isBoolean = new InstanceOfExpression( var, SequenceType.makeSequenceType(BuiltInAtomicType.BOOLEAN, StaticProperty.ALLOWS_ZERO_OR_ONE));
Expression isDouble = new InstanceOfExpression( var, BuiltInAtomicType.DOUBLE.zeroOrOne()); Expression isDecimal = new InstanceOfExpression( var, BuiltInAtomicType.DECIMAL.zeroOrOne()); Expression isFloat = new InstanceOfExpression( var, BuiltInAtomicType.FLOAT.zeroOrOne()); Expression isString = new InstanceOfExpression( var, BuiltInAtomicType.STRING.zeroOrOne()); Expression isUntypedAtomic = new InstanceOfExpression( var, BuiltInAtomicType.UNTYPED_ATOMIC.zeroOrOne()); Expression isBoolean = new InstanceOfExpression( var, BuiltInAtomicType.BOOLEAN.zeroOrOne());
public Expression compile(Executable exec) throws XPathException { Copy inst = new Copy(copyNamespaces, inheritNamespaces, schemaType, validationAction); Expression content = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); if (attributeSets != null) { UseAttributeSets use = new UseAttributeSets(attributeSets); // The use-attribute-sets is ignored unless the context item is an element node. So we // wrap the UseAttributeSets instruction in a conditional to perform a run-time test Expression condition = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(NodeKindTest.ELEMENT, StaticProperty.EXACTLY_ONE)); Expression choice = Choose.makeConditional(condition, use); if (content == null) { content = choice; } else { content = Block.makeBlock(choice, content); content.setLocationId( allocateLocationId(getSystemId(), getLineNumber())); } } if (content == null) { content = Literal.makeEmptySequence(); } inst.setContentExpression(content); return inst; }
public Expression compile(Executable exec) throws XPathException { Copy inst = new Copy(copyNamespaces, inheritNamespaces, schemaType, validationAction); Expression content = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); if (attributeSets != null) { UseAttributeSets use = new UseAttributeSets(attributeSets); // The use-attribute-sets is ignored unless the context item is an element node. So we // wrap the UseAttributeSets instruction in a conditional to perform a run-time test Expression condition = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(NodeKindTest.ELEMENT, StaticProperty.EXACTLY_ONE)); Expression choice = Choose.makeConditional(condition, use); if (content == null) { content = choice; } else { content = Block.makeBlock(choice, content); content.setLocationId( allocateLocationId(getSystemId(), getLineNumber())); } } if (content == null) { content = Literal.makeEmptySequence(); } inst.setContentExpression(content); return inst; }
public Expression compile(Executable exec) throws XPathException { Copy inst = new Copy(copyNamespaces, inheritNamespaces, schemaType, validationAction); Expression content = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); if (attributeSets != null) { UseAttributeSets use = new UseAttributeSets(attributeSets); // The use-attribute-sets is ignored unless the context item is an element node. So we // wrap the UseAttributeSets instruction in a conditional to perform a run-time test Expression condition = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(NodeKindTest.ELEMENT, StaticProperty.EXACTLY_ONE)); Expression choice = Choose.makeConditional(condition, use); if (content == null) { content = choice; } else { content = Block.makeBlock(choice, content); content.setLocationId( allocateLocationId(getSystemId(), getLineNumber())); } } if (content == null) { content = Literal.makeEmptySequence(); } inst.setContentExpression(content); return inst; }
let.setVariableQName(varName); InstanceOfExpression condition = new InstanceOfExpression(new LocalVariableReference(let), SequenceType.SINGLE_NUMERIC); LocalVariableReference ref = new LocalVariableReference(let); ref.setStaticType(SequenceType.SINGLE_NUMERIC, null, 0);
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { Expression exp = super.optimize(visitor, contextItemType); if (exp == this) { if (resultItemType == null) { resultItemType = computeItemType(visitor.getConfiguration().getTypeHierarchy()); } if (visitor.isOptimizeForStreaming()) { UType type = contextItemType.getItemType().getUType(); if (!type.intersection(MultipleNodeKindTest.LEAF.getUType()).equals(UType.VOID)) { Expression copyOf = new CopyOf( new ContextItemExpression(), false, getValidationAction(), getSchemaType(), false); NodeTest leafTest = new MultipleNodeKindTest(type.intersection(MultipleNodeKindTest.LEAF.getUType())); Expression[] conditions = new Expression[]{ new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(leafTest, StaticProperty.EXACTLY_ONE)), Literal.makeLiteral(BooleanValue.TRUE, this)}; Expression[] actions = new Expression[]{copyOf, this}; Choose choose = new Choose(conditions, actions); ExpressionTool.copyLocationInfo(this, choose); return choose; } } } return exp; }
Expression condition = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(NodeKindTest.ELEMENT, StaticProperty.EXACTLY_ONE));
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { Expression exp = super.optimize(visitor, contextItemType); if (exp == this) { if (resultItemType == null) { resultItemType = computeItemType(visitor.getConfiguration().getTypeHierarchy()); } if (visitor.isOptimizeForStreaming()) { UType type = contextItemType.getItemType().getUType(); if (!type.intersection(MultipleNodeKindTest.LEAF.getUType()).equals(UType.VOID)) { Expression copyOf = new CopyOf( new ContextItemExpression(), false, getValidationAction(), getSchemaType(), false); NodeTest leafTest = new MultipleNodeKindTest(type.intersection(MultipleNodeKindTest.LEAF.getUType())); Expression[] conditions = new Expression[]{ new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(leafTest, StaticProperty.EXACTLY_ONE)), Literal.makeLiteral(BooleanValue.TRUE, this)}; Expression[] actions = new Expression[]{copyOf, this}; Choose choose = new Choose(conditions, actions); ExpressionTool.copyLocationInfo(this, choose); return choose; } } } return exp; }
Expression condition = new InstanceOfExpression( new ContextItemExpression(), SequenceType.makeSequenceType(NodeKindTest.ELEMENT, StaticProperty.EXACTLY_ONE));