/** * Make an expression that either calls this function, or that is equivalent to a call * on this function * @param arguments the supplied arguments to the function call * @return either a function call on this function, or an expression that delivers * the same result */ public Expression makeFunctionCall(Expression... arguments) { Expression e = new SystemFunctionCall(this, arguments); e.setRetainedStaticContext(getRetainedStaticContext()); return e; }
/** * Make an expression that either calls this function, or that is equivalent to a call * on this function * @param arguments the supplied arguments to the function call * @return either a function call on this function, or an expression that delivers * the same result */ public Expression makeFunctionCall(Expression... arguments) { Expression e = new SystemFunctionCall(this, arguments); e.setRetainedStaticContext(getRetainedStaticContext()); return e; }
/** * Find any necessary preconditions for the satisfaction of this expression * as a set of boolean expressions to be evaluated on the context node * * @return A set of conditions, or null if none have been computed */ public Set<Expression> getPreconditions() { HashSet<Expression> pre = new HashSet<>(1); /*Expression args[] = new Expression[1]; args[0] = this.copy(); pre.add(SystemFunctionCall.makeSystemFunction( "exists", args));*/ Expression a = this.copy(new RebindingMap()); a.setRetainedStaticContext(getRetainedStaticContext()); pre.add(a); return pre; } }
/** * Find any necessary preconditions for the satisfaction of this expression * as a set of boolean expressions to be evaluated on the context node * * @return A set of conditions, or null if none have been computed */ public Set<Expression> getPreconditions() { HashSet<Expression> pre = new HashSet<>(1); /*Expression args[] = new Expression[1]; args[0] = this.copy(); pre.add(SystemFunctionCall.makeSystemFunction( "exists", args));*/ Expression a = this.copy(new RebindingMap()); a.setRetainedStaticContext(getRetainedStaticContext()); pre.add(a); return pre; } }
/** * Make a system function call (one in the standard function namespace). * * @param name The local name of the function. * @param rsc Necessary information about the static context * @param arguments the arguments to the function call * @return a FunctionCall that implements this function, if it * exists, or null if the function is unknown. */ /*@Nullable*/ public static Expression makeCall(String name, RetainedStaticContext rsc, Expression... arguments) { SystemFunction f = makeFunction(name, rsc, arguments.length); if (f == null) { return null; } Expression expr = f.makeFunctionCall(arguments); expr.setRetainedStaticContext(rsc); return expr; }
/** * Set the retained static context * @param rsc the static context to be retained */ public void setRetainedStaticContext(RetainedStaticContext rsc) { if (rsc != null) { retainedStaticContext = rsc; for (Operand o : operands()) { if (o != null) { Expression child = o.getChildExpression(); if (child != null && child.retainedStaticContext == null) { child.setRetainedStaticContext(rsc); } } } } }
/** * Make a system function call (one in the standard function namespace). * * @param name The local name of the function. * @param rsc Necessary information about the static context * @param arguments the arguments to the function call * @return a FunctionCall that implements this function, if it * exists, or null if the function is unknown. */ /*@Nullable*/ public static Expression makeCall(String name, RetainedStaticContext rsc, Expression... arguments) { SystemFunction f = makeFunction(name, rsc, arguments.length); if (f == null) { return null; } Expression expr = f.makeFunctionCall(arguments); expr.setRetainedStaticContext(rsc); return expr; }
/** * Set the retained static context * @param rsc the static context to be retained */ public void setRetainedStaticContext(RetainedStaticContext rsc) { if (rsc != null) { retainedStaticContext = rsc; for (Operand o : operands()) { if (o != null) { Expression child = o.getChildExpression(); if (child != null && child.retainedStaticContext == null) { child.setRetainedStaticContext(rsc); } } } } }
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { // xsl:break containing a sequence constructor is compiled into a call on the sequence constructor, then // the break instruction Expression val = select; if (val == null) { val = compileSequenceConstructor(exec, decl, false); } Expression brake = new BreakInstr(); brake.setRetainedStaticContext(makeRetainedStaticContext()); return Block.makeBlock(val, brake); }
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { // xsl:break containing a sequence constructor is compiled into a call on the sequence constructor, then // the break instruction Expression val = select; if (val == null) { val = compileSequenceConstructor(exec, decl, false); } Expression brake = new BreakInstr(); brake.setRetainedStaticContext(makeRetainedStaticContext()); return Block.makeBlock(val, brake); }
private Expression makeGetCall(ExpressionVisitor visitor, BuiltInFunctionSet fnSet, ContextItemStaticInfo contextInfo, Expression[] arguments) throws XPathException { Expression target = arguments[0]; Expression key = ((SquareArrayConstructor)arguments[1]).getOperanda().getOperand(0).getChildExpression(); Expression getter = fnSet.makeFunction("get", 2).makeFunctionCall(target, key); getter.setRetainedStaticContext(target.getRetainedStaticContext()); return getter.typeCheck(visitor, contextInfo); }
private Expression makeGetCall(ExpressionVisitor visitor, BuiltInFunctionSet fnSet, ContextItemStaticInfo contextInfo, Expression[] arguments) throws XPathException { Expression target = arguments[0]; Expression key = ((SquareArrayConstructor)arguments[1]).getOperanda().getOperand(0).getChildExpression(); Expression getter = fnSet.makeFunction("get", 2).makeFunctionCall(target, key); getter.setRetainedStaticContext(target.getRetainedStaticContext()); return getter.typeCheck(visitor, contextInfo); }
public void validate() throws XPathException { contentExp = AttributeValueTemplate.make(getStringValue(), getStaticContext()); contentExp = new ValueOf(contentExp, false, true); contentExp.setRetainedStaticContext(((StyleElement)getParent()).makeRetainedStaticContext()); contentExp = ((StyleElement)getParent()).typeCheck("tvt", contentExp); } }
public void validate() throws XPathException { contentExp = AttributeValueTemplate.make(getStringValue(), getStaticContext()); contentExp = new ValueOf(contentExp, false, true); contentExp.setRetainedStaticContext(((StyleElement)getParent()).makeRetainedStaticContext()); contentExp = ((StyleElement)getParent()).typeCheck("tvt", contentExp); } }
private NamedTemplate readNamedTemplate(NodeInfo templateElement) throws XPathException { StylesheetPackage pack = packStack.peek(); localBindings = new Stack<>(); StructuredQName templateName = getQNameAttribute(templateElement, "name"); String flags = templateElement.getAttributeValue("", "flags"); int slots = getIntegerAttribute(templateElement, "slots"); SequenceType contextType = parseSequenceType(templateElement, "cxt"); ItemType contextItemType = contextType == null ? AnyItemType.getInstance() : contextType.getPrimaryType(); NamedTemplate template = new NamedTemplate(templateName); template.setStackFrameMap(new SlotManager(slots)); template.setPackageData(pack); template.setRequiredType(parseSequenceType(templateElement, "as")); template.setContextItemRequirements(contextItemType, flags.contains("o"), !flags.contains("s")); NodeInfo bodyElement = getChildWithRole(templateElement, "body"); if (bodyElement == null) { template.setBody(Literal.makeEmptySequence()); } else { Expression body = loadExpression(bodyElement); template.setBody(body); RetainedStaticContext rsc = body.getRetainedStaticContext(); body.setRetainedStaticContext(rsc); // to propagate it to the subtree } return template; }
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { if (select == null) { Expression b = compileSequenceConstructor(exec, decl, true); if (b == null) { b = Literal.makeEmptySequence(); b.setRetainedStaticContext(makeRetainedStaticContext()); } try { Expression atomizedSortKey = Atomizer.makeAtomizer(b, null); atomizedSortKey = atomizedSortKey.simplify(); ExpressionTool.copyLocationInfo(b, atomizedSortKey); sortKeyDefinition.setSortKey(atomizedSortKey, true); select = atomizedSortKey; } catch (XPathException e) { compileError(e); } } // Simplify the sort key definition - this is especially important in the case where // all aspects of the sort key are known statically. sortKeyDefinition = (SortKeyDefinition)sortKeyDefinition.simplify(); // not an executable instruction return null; }
/** * 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; }
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { if (select == null) { Expression b = compileSequenceConstructor(exec, decl, true); if (b == null) { b = Literal.makeEmptySequence(); b.setRetainedStaticContext(makeRetainedStaticContext()); } try { Expression atomizedSortKey = Atomizer.makeAtomizer(b); atomizedSortKey = atomizedSortKey.simplify(); ExpressionTool.copyLocationInfo(b, atomizedSortKey); sortKeyDefinition.setSortKey(atomizedSortKey, true); select = atomizedSortKey; } catch (XPathException e) { compileError(e); } } // Simplify the sort key definition - this is especially important in the case where // all aspects of the sort key are known statically. sortKeyDefinition = (SortKeyDefinition)sortKeyDefinition.simplify(); // not an executable instruction return null; }
/** * Evaluate a use-when attribute * * @param expression the expression to be evaluated * @param location identifies the location of the expression in case error need to be reported * @param baseUri the base URI of the element containing the expression * @return the effective boolean value of the result of evaluating the expression * @throws XPathException if evaluation of the expression fails */ public boolean evaluateUseWhen(String expression, AttributeLocation location, String baseUri) throws XPathException { UseWhenStaticContext staticContext = new UseWhenStaticContext(compilation, startTag); staticContext.setBaseURI(baseUri); staticContext.setContainingLocation(location); setNamespaceBindings(staticContext); Expression expr = ExpressionTool.make(expression, staticContext, 0, Token.EOF, null); expr.setRetainedStaticContext(staticContext.makeRetainedStaticContext()); expr = typeCheck(expr, staticContext); SlotManager stackFrameMap = allocateSlots(expression, expr); XPathContext dynamicContext = makeDynamicContext(staticContext); //dynamicContext.getController().getExecutable().setFunctionLibrary((FunctionLibraryList)staticContext.getFunctionLibrary()); ((XPathContextMajor) dynamicContext).openStackFrame(stackFrameMap); return expr.effectiveBooleanValue(dynamicContext); }
/** * Get the corresponding Procedure object that results from the compilation of this * StylesheetProcedure */ public Actor getActor() throws XPathException { GlobalVariable gv = getCompiledVariable(); if (gv == null) { gv = this instanceof XSLGlobalParam ? new GlobalParam() : new GlobalVariable(); gv.setPackageData(getCompilation().getPackageData()); gv.makeDeclaringComponent(getVisibility(), getContainingPackage()); gv.setRequiredType(sourceBinding.getDeclaredType()); gv.setDeclaredVisibility(getDeclaredVisibility()); gv.setVariableQName(sourceBinding.getVariableQName()); gv.setSystemId(getSystemId()); gv.setLineNumber(getLineNumber()); RetainedStaticContext rsc = makeRetainedStaticContext(); gv.setRetainedStaticContext(rsc); if (gv.getBody() != null) { gv.getBody().setRetainedStaticContext(rsc); } compiledVariable = gv; } return gv; }