if (!kd.getBody().getItemType().equals(BuiltInAtomicType.STRING)) { Expression exp = new AtomicSequenceConverter(kd.getBody(), BuiltInAtomicType.STRING); ((AtomicSequenceConverter) exp).allocateConverterStatically(config, false); kd.setBody(exp);
/** * Type-check the expression */ /*@NotNull*/ public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { typeCheckChildren(visitor, contextInfo); Configuration config = visitor.getConfiguration(); final TypeHierarchy th = config.getTypeHierarchy(); Expression operand = getBaseExpression(); if (th.isSubType(operand.getItemType(), requiredItemType)) { return operand; } else { if (converter == null) { allocateConverterStatically(config, true); } return this; } }
/** * Make a string-join expression that concatenates the string-values of items in * a sequence with intervening spaces. This may be simplified later as a result * of type-checking. * * @param exp the base expression, evaluating to a sequence * @param env the static context * @return a call on string-join to create a string containing the * representations of the items in the sequence separated by spaces. */ /*@Nullable*/ public static Expression makeStringJoin(Expression exp, /*@NotNull*/ StaticContext env) { exp = Atomizer.makeAtomizer(exp, null); ItemType t = exp.getItemType(); if (!t.equals(BuiltInAtomicType.STRING) && !t.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); ((AtomicSequenceConverter) exp).allocateConverterStatically(env.getConfiguration(), false); } if (exp.getCardinality() == StaticProperty.EXACTLY_ONE) { return exp; } else { RetainedStaticContext rsc = new RetainedStaticContext(env); Expression fn = SystemFunction.makeCall("string-join", rsc, exp, new StringLiteral(StringValue.SINGLE_SPACE)); ExpressionTool.copyLocationInfo(exp, fn); return fn; } }
if (!kd.getBody().getItemType().equals(BuiltInAtomicType.STRING)) { Expression exp = new AtomicSequenceConverter(kd.getBody(), BuiltInAtomicType.STRING); ((AtomicSequenceConverter) exp).allocateConverterStatically(config, false); kd.setBody(exp);
/** * Make a string-join expression that concatenates the string-values of items in * a sequence with intervening spaces. This may be simplified later as a result * of type-checking. * * @param exp the base expression, evaluating to a sequence * @param env the static context * @return a call on string-join to create a string containing the * representations of the items in the sequence separated by spaces. */ /*@Nullable*/ public static Expression makeStringJoin(Expression exp, /*@NotNull*/ StaticContext env) { exp = Atomizer.makeAtomizer(exp); ItemType t = exp.getItemType(); if (!t.equals(BuiltInAtomicType.STRING) && !t.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); ((AtomicSequenceConverter) exp).allocateConverterStatically(env.getConfiguration(), false); } if (exp.getCardinality() == StaticProperty.EXACTLY_ONE) { return exp; } else { RetainedStaticContext rsc = new RetainedStaticContext(env); Expression fn = SystemFunction.makeCall("string-join", rsc, exp, new StringLiteral(StringValue.SINGLE_SPACE)); ExpressionTool.copyLocationInfo(exp, fn); return fn; } }
/** * Type-check the expression */ /*@NotNull*/ public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { typeCheckChildren(visitor, contextInfo); Configuration config = visitor.getConfiguration(); final TypeHierarchy th = config.getTypeHierarchy(); Expression operand = getBaseExpression(); if (th.isSubType(operand.getItemType(), requiredItemType)) { return operand; } else { if (converter == null) { allocateConverterStatically(config, true); } return this; } }
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; }
/** * Simplify an expression * */ /*@NotNull*/ public Expression simplify() throws XPathException { Expression operand = getBaseExpression().simplify(); setBaseExpression(operand); if (operand instanceof Literal && requiredItemType instanceof AtomicType) { if (Literal.isEmptySequence(operand)) { return operand; } Configuration config = getConfiguration(); allocateConverterStatically(config, true); if (converter != null) { GroundedValue<?> val = iterate(new EarlyEvaluationContext(config)).materialize(); return Literal.makeLiteral(val, operand); } } return this; }
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; }
/** * Simplify an expression * */ /*@NotNull*/ public Expression simplify() throws XPathException { Expression operand = getBaseExpression().simplify(); setBaseExpression(operand); if (operand instanceof Literal && requiredItemType instanceof AtomicType) { if (Literal.isEmptySequence(operand)) { return operand; } Configuration config = getConfiguration(); allocateConverterStatically(config, true); if (converter != null) { GroundedValue<?> val = iterate(new EarlyEvaluationContext(config)).materialize(); return Literal.makeLiteral(val, operand); } } return this; }
/** * Construct an expression that implements the rules of "constructing simple content": * given an expression to select the base sequence, and an expression to compute the separator, * build an (unoptimized) expression to produce the value of the node as a string. * * @param select the expression that selects the base sequence * @param separator the expression that computes the separator * @param env the static context * @return an expression that returns a string containing the string value of the constructed node */ public static Expression makeSimpleContentConstructor(Expression select, Expression separator, StaticContext env) { RetainedStaticContext rsc = select.getLocalRetainedStaticContext(); if (rsc == null) { rsc = env.makeRetainedStaticContext(); } // Merge adjacent text nodes select = AdjacentTextNodeMerger.makeAdjacentTextNodeMerger(select); // Atomize the result select = Atomizer.makeAtomizer(select, null); // Convert each atomic value to a string select = new AtomicSequenceConverter(select, BuiltInAtomicType.STRING); select.setRetainedStaticContext(rsc); ((AtomicSequenceConverter) select).allocateConverterStatically(env.getConfiguration(), false); // Join the resulting strings with a separator if (select.getCardinality() != StaticProperty.EXACTLY_ONE) { select = SystemFunction.makeCall("string-join", rsc, select, separator); } // All that's left for the instruction to do is to construct the right kind of node return select; }
/** * Construct an expression that implements the rules of "constructing simple content": * given an expression to select the base sequence, and an expression to compute the separator, * build an (unoptimized) expression to produce the value of the node as a string. * * @param select the expression that selects the base sequence * @param separator the expression that computes the separator * @param env the static context * @return an expression that returns a string containing the string value of the constructed node */ public static Expression makeSimpleContentConstructor(Expression select, Expression separator, StaticContext env) { RetainedStaticContext rsc = select.getLocalRetainedStaticContext(); if (rsc == null) { rsc = env.makeRetainedStaticContext(); } // Merge adjacent text nodes select = AdjacentTextNodeMerger.makeAdjacentTextNodeMerger(select); // Atomize the result select = Atomizer.makeAtomizer(select); // Convert each atomic value to a string select = new AtomicSequenceConverter(select, BuiltInAtomicType.STRING); select.setRetainedStaticContext(rsc); ((AtomicSequenceConverter) select).allocateConverterStatically(env.getConfiguration(), false); // Join the resulting strings with a separator if (select.getCardinality() != StaticProperty.EXACTLY_ONE) { select = SystemFunction.makeCall("string-join", rsc, select, separator); } // All that's left for the instruction to do is to construct the right kind of node return select; }
/** * 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; }
/** * 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); } 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; }