public void validate() throws XPathException { stackFrameMap = getConfiguration().makeSlotManager(); checkTopLevel(null); // the check for duplicates is now done in the buildIndexes() method of XSLStylesheet if (match != null) { match = typeCheck("match", match); if (match.getNodeTest() instanceof EmptySequenceTest) { try { getConfiguration().getErrorListener().warning( new TransformerException("Match pattern cannot match any nodes", this)); } catch (TransformerException e) { compileError(XPathException.makeXPathException(e)); } } } markTailCalls(); // See if there are any required parameters AxisIterator declaredParams = iterateAxis(Axis.CHILD); while(true) { NodeInfo param = (NodeInfo)declaredParams.next(); if (param == null) { break; } if (param instanceof XSLParam && ((XSLParam)param).isRequiredParam()) { hasRequiredParams = true; break; } } }
if (isDeferredCompilation(compilation)) { createSkeletonTemplate(compilation, decl); compiledNamedTemplate.resetLocalParams(); isTailRecursive = markTailCalls(); Expression body = compileSequenceConstructor(compilation, decl, true); body.restoreParentPointers(); RetainedStaticContext rsc = makeRetainedStaticContext(); if (body.getRetainedStaticContext() == null) { isWithinDeclaredStreamableConstruct()) { checkStrictStreamability(body); if (getTemplateName() != null) { compileNamedTemplate(compilation, body, decl); compileTemplateRule(compilation, body, decl);
/** * Return the name of this template. Note that this may * be called before prepareAttributes has been called. * * @return the name of the template as a Structured QName. */ /*@Nullable*/ public StructuredQName getTemplateName() { //We use null to mean "not yet evaluated" try { if (getObjectName() == null) { // allow for forwards references String nameAtt = getAttributeValue("", "name"); if (nameAtt != null) { setObjectName(makeQName(nameAtt)); } } return getObjectName(); } catch (XPathException err) { return null; // the errors will be picked up later } }
@Override public void validateSubtree(ComponentDeclaration decl, boolean excludeStylesheet) throws XPathException { if (!isDeferredCompilation(getCompilation())) { super.validateSubtree(decl, excludeStylesheet); } else { try { validate(decl); } catch (XPathException err) { compileError(err); } } }
@Override public void processAllAttributes() throws XPathException { String mode = getAttributeValue("mode"); mode = mode == null ? "" : Whitespace.trim(mode); if (!isDeferredCompilation(getCompilation())) { super.processAllAttributes(); //TODO - sort out the duplicated code. This repeats the code below } else { processDefaultCollationAttribute(); processDefaultMode(); staticContext = new ExpressionContext(this, null); processAttributes(); } }
Expression block = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); if (block == null) { block = Literal.makeEmptySequence(); compiledTemplate.setBody(block); compiledTemplate.setStackFrameMap(stackFrameMap); compiledTemplate.setExecutable(getExecutable()); compiledTemplate.setSystemId(getSystemId()); compiledTemplate.setLineNumber(getLineNumber()); compiledTemplate.setHasRequiredParams(hasRequiredParams); compiledTemplate.setRequiredType(requiredType); exp = makeExpressionVisitor().simplify(block); } catch (XPathException e) { compileError(e); exp = TypeChecker.staticTypeCheck(exp, requiredType, false, role, makeExpressionVisitor()); compileError(err); compiledTemplate.init ( getObjectName(), getPrecedence(), getMinImportPrecedence()); if (getConfiguration().isCompileWithTracing()) { TraceWrapper trace = new TraceInstruction(exp, this); trace.setLocationId(allocateLocationId(getSystemId(), getLineNumber())); trace.setContainer(compiledTemplate); exp = trace;
AttributeCollection atts = getAttributeList(); String extraAsAtt = null; checkUnknownAttribute(atts.getNodeName(a)); StructuredQName defaultMode = getDefaultMode(); if (defaultMode == null) { defaultMode = Mode.UNNAMED_MODE_NAME; compileError("The mode attribute must be absent if the match attribute is absent", "XTSE0500"); getModeNames(); compileError(err); StructuredQName qName = makeQName(nameAtt); setObjectName(qName); if (compiledNamedTemplate != null /*bug3549*/) { compiledNamedTemplate.setTemplateName(qName); err.maybeSetErrorCode("XTSE0280"); err.setIsStaticError(true); compileError(err); if (prioritySpecified) { if (matchAtt == null) { compileError("The priority attribute must be absent if the match attribute is absent", "XTSE0500"); compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530");
AttributeCollection atts = getAttributeList(); String f = getNamePool().getClarkName(nc); if (f.equals(StandardNames.MODE)) { modeAtt = Whitespace.trim(atts.getValue(a)); asAtt = atts.getValue(a); } else { checkUnknownAttribute(nc); } else { if (matchAtt==null) { compileError("The mode attribute must be absent if the match attribute is absent", "XTSE0500"); compileError("The mode attribute must not be empty", "XTSE0550"); mname = Mode.ALL_MODES; } else { mname = makeQName(s); compileError("In the list of modes, the value " + s + " is duplicated", "XTSE0550"); compileError("mode='#all' cannot be combined with other modes", "XTSE0550"); StructuredQName qName = makeQName(nameAtt); setObjectName(qName); diagnosticId = nameAtt; compileError(err.getMessage(), "XTSE0280");
Configuration config = getConfiguration(); if (compiledNamedTemplate != null) { Expression body = compiledNamedTemplate.getBody(); ContextItemStaticInfo cisi = getConfiguration().makeContextItemStaticInfo(requiredContextItemType, mayOmitContextItem); ExpressionVisitor visitor = makeExpressionVisitor(); body = body.typeCheck(visitor, cisi); body = ExpressionTool.optimizeComponentBody(body, getCompilation(), visitor, cisi, true); compiledNamedTemplate.setBody(body); allocateLocalSlots(body); if (isExplaining()) { Logger err = getConfiguration().getLogger(); err.info("Optimized expression tree for named template at line " + getLineNumber() + " in " + getSystemId() + ':'); body.explain(err); ItemType contextItemType = getContextItemTypeForTemplateRule(); ContextItemStaticInfo cisi = config.makeContextItemStaticInfo(contextItemType, false); cisi.setContextPostureStriding(); ExpressionVisitor visitor = makeExpressionVisitor(); match.resetLocalStaticProperties(); match = match.optimize(visitor, cisi); if (!isDeferredCompilation(getCompilation())) { Expression body = compiledTemplateRules.values().stream().findFirst().map(TemplateRule::getBody).orElse(null); Optimizer opt = getConfiguration().obtainOptimizer(); try {
StructuredQName qName = template.getTemplateName(); if (qName != null) { exec.putNamedTemplate(qName, template.getCompiledTemplate()); } else { int thisPrecedence = template.getPrecedence(); int otherPrecedence = other.getPrecedence(); if (thisPrecedence == otherPrecedence) { template.compileError("Duplicate named template (see line " + other.getLineNumber() + " of " + other.getSystemId() + ')', "XTSE0660"); } else if (thisPrecedence < otherPrecedence) { exec.putNamedTemplate(qName, template.getCompiledTemplate());
public void validate(ComponentDeclaration decl) throws XPathException { stackFrameMap = getConfiguration().makeSlotManager(); checkTopLevel("XTSE0010", true); match = typeCheck("match", match); if (match.getItemType() instanceof ErrorType) { issueWarning(new XPathException("Pattern will never match anything", SaxonErrorCode.SXWN9015, this)); if (getPrincipalStylesheetModule().isDeclaredModes()) { RuleManager manager = getPrincipalStylesheetModule().getRuleManager(); if (modeNames != null) { for (StructuredQName name : modeNames) { if (name.equals(Mode.UNNAMED_MODE_NAME) && !manager.isUnnamedModeExplicit()) { compileError("The unnamed mode has not been declared in an xsl:mode declaration", "XTSE3085"); compileError("Mode name " + name.getDisplayName() + " has not been declared in an xsl:mode declaration", "XTSE3085"); compileError("The unnamed mode has not been declared in an xsl:mode declaration", "XTSE3085"); compileError("An abstract template must have no match attribute"); AxisIterator kids = iterateAxis(AxisInfo.CHILD); boolean hasContent = false; NodeImpl param; compileError("A template with visibility='abstract' must have no body");
private void compileNamedTemplate(Compilation compilation, Expression body, ComponentDeclaration decl) throws XPathException { RetainedStaticContext rsc = body.getRetainedStaticContext(); compiledNamedTemplate.setPackageData(rsc.getPackageData()); compiledNamedTemplate.setBody(body); compiledNamedTemplate.setStackFrameMap(stackFrameMap); compiledNamedTemplate.setSystemId(getSystemId()); compiledNamedTemplate.setLineNumber(getLineNumber()); compiledNamedTemplate.setHasRequiredParams(hasRequiredParams); compiledNamedTemplate.setRequiredType(requiredType); compiledNamedTemplate.setContextItemRequirements(requiredContextItemType, mayOmitContextItem, absentFocus); compiledNamedTemplate.setRetainedStaticContext(rsc); compiledNamedTemplate.setDeclaredVisibility(getDeclaredVisibility()); Component overridden = getOverriddenComponent(); if (overridden != null) { checkCompatibility(overridden); } ContextItemStaticInfo cisi = getConfiguration().makeContextItemStaticInfo(requiredContextItemType, mayOmitContextItem); Expression body2 = refineTemplateBody(body, cisi); compiledNamedTemplate.setBody(body2); }
} catch (XPathException e) { if (e.isReportableStatically()) { compileError(e); } else { body = new ErrorExpression(e); Configuration config = getConfiguration(); if (visibility != Visibility.ABSTRACT) { try { new RoleDiagnostic(RoleDiagnostic.TEMPLATE_RESULT, diagnosticId, 0); role.setErrorCode("XTTE0505"); body = config.getTypeChecker(false).staticTypeCheck(body, requiredType, role, makeExpressionVisitor()); compileError(err); if (getCompilation().getCompilerInfo().isCompileWithTracing()) { body = makeTraceInstruction(this, body); if (body instanceof TraceExpression) { ((TraceExpression) body).setProperty("match", matchAtt); ExpressionVisitor visitor = makeExpressionVisitor(); body = body.typeCheck(visitor, cisi); } catch (XPathException e) { compileError(e);
modeAtt = getAttributeValue("mode"); if (modeAtt == null) { modeAtt = "#default"; StructuredQName mname; if ("#default".equals(s)) { mname = getDefaultMode(); if (mname == null) { mname = Mode.UNNAMED_MODE_NAME; } else { try { mname = makeQName(s); } catch (XPathException e) { compileError(e.getMessage(), "XTSE0550"); mname = Mode.UNNAMED_MODE_NAME; compileError("In the list of modes, the value " + s + " is duplicated", "XTSE0550"); compileError("mode='#all' cannot be combined with other modes", "XTSE0550");
HashMap<SymbolicName, Component> componentIndex = stylesheetPackage.getComponentIndex(); XSLTemplate sourceTemplate = (XSLTemplate) decl.getSourceElement(); SymbolicName sName = sourceTemplate.getSymbolicName(); if (sName != null) { NamedTemplate compiledTemplate = ((XSLTemplate) decl.getSourceElement()).getCompiledNamedTemplate(); Component declaringComponent = compiledTemplate.makeDeclaringComponent(sourceTemplate.getVisibility(), getStylesheetPackage()); componentIndex.put(sName, declaringComponent); setLocalParamDetails(sourceTemplate, compiledTemplate); int otherPrecedence = otherTemplate.getPrecedence(); if (thisPrecedence == otherPrecedence) { String errorCode = sourceTemplate.getParent() instanceof XSLOverride ? "XTSE3055" : "XTSE0660"; sourceTemplate.compileError("Duplicate named template (see line " + otherTemplate.getSourceElement().getLineNumber() + " of " + otherTemplate.getSourceElement().getSystemId() + ')', errorCode); } else if (thisPrecedence < otherPrecedence) { Component declaringComponent = compiledTemplate.makeDeclaringComponent(sourceTemplate.getVisibility(), getStylesheetPackage()); componentIndex.put(sName, declaringComponent); templateIndex.put(sName.getComponentName(), decl); setLocalParamDetails(sourceTemplate, compiledTemplate); } else if (sourceTemplate.findAncestorElement(StandardNames.XSL_OVERRIDE) != null) { NamedTemplate compiledTemplate = sourceTemplate.getCompiledNamedTemplate();//new NamedTemplate(); Component declaringComponent = compiledTemplate.makeDeclaringComponent(sourceTemplate.getVisibility(), getStylesheetPackage()); componentIndex.put(sName, declaringComponent); templateIndex.put(sName.getComponentName(), decl); } else {
public void compileTemplateRule(Compilation compilation, Expression body, ComponentDeclaration decl) { Configuration config = getConfiguration(); if (getTemplateName() != null) { body = body.copy(new RebindingMap()); } ItemType contextItemType; ContextItemStaticInfo cisi; // the template can't be called by name, so the context item must match the match pattern contextItemType = match.getItemType(); if (contextItemType.equals(ErrorType.getInstance())) { // if the match pattern can't match anything, we produce a warning, not a hard error contextItemType = AnyItemType.getInstance(); } cisi = config.makeContextItemStaticInfo(contextItemType, false); body = refineTemplateBody(body, cisi); boolean needToCopy = false; for (TemplateRule rule : compiledTemplateRules.values()) { if (needToCopy) { body = body.copy(new RebindingMap()); } setCompiledTemplateRuleProperties(rule, body); needToCopy = true; rule.updateSlaveCopies(); } // following code needed only for diagnostics //body.verifyParentPointers(); }
public void checkCompatibility(Component component) { NamedTemplate other = (NamedTemplate) component.getActor(); if (!getSymbolicName().equals(other.getSymbolicName())) { throw new IllegalArgumentException(); compileError("The overriding template has a different required type from the overridden template", "XTSE3070"); return; mayOmitContextItem != other.isMayOmitContextItem() || absentFocus != other.isAbsentFocus()) { compileError("The required context item for the overriding template differs from that of the overridden template", "XTSE3070"); return; Set<StructuredQName> overriddenParams = new HashSet<>(); for (NamedTemplate.LocalParamInfo lp0 : otherParams) { XSLLocalParam lp1 = getParam(lp0.name); if (lp1 == null) { if (!lp0.isTunnel) { compileError("The overridden template declares a parameter " + lp0.name.getDisplayName() + " which is not declared in the overriding template", "XTSE3070"); AxisIterator params = iterateAxis(AxisInfo.CHILD); NodeInfo param; while ((param = params.next()) != null) {
private void createSkeletonTemplate(Compilation compilation, ComponentDeclaration decl) throws XPathException { StructuredQName[] modes = modeNames; if (isOmniMode()) { List<StructuredQName> all = new ArrayList<>(); all.add(Mode.UNNAMED_MODE_NAME); RuleManager mgr = getCompilation().getPrincipalStylesheetModule().getRuleManager(); for (Mode m : mgr.getAllNamedModes()) { all.add(m.getModeName()); } modes = all.toArray(new StructuredQName[0]); } for (StructuredQName modeName : modes) { TemplateRule templateRule = compiledTemplateRules.get(modeName); if (templateRule == null) { templateRule = getConfiguration().makeTemplateRule(); } templateRule.prepareInitializer(compilation, decl, modeName); compiledTemplateRules.put(modeName, templateRule); RetainedStaticContext rsc = makeRetainedStaticContext(); templateRule.setPackageData(rsc.getPackageData()); setCompiledTemplateRuleProperties(templateRule, null); } }
if (match != null) { StylesheetModule module = declaration.getModule(); RuleManager mgr = getCompilation().getPrincipalStylesheetModule().getRuleManager(); ExpressionVisitor visitor = ExpressionVisitor.make(getStaticContext()); for (StructuredQName modeName : getModeNames()) { Mode mode = mgr.obtainMode(modeName, false); if (mode == null) { boolean ok = getPrincipalStylesheetModule().checkAcceptableModeForPackage(this, mode); if (!ok) { return; ContextItemStaticInfo info = getConfiguration().makeContextItemStaticInfo(AnyItemType.getInstance(), false); ExpressionTool.copyLocationInfo(match, match2); match2.setOriginalText(match.toString()); rule = getConfiguration().makeTemplateRule(); compiledTemplateRules.put(modeName, rule); rule.setDeclaredStreamable(true); if (!match1.isMotionless()) { boolean fallback = getConfiguration().getBooleanProperty(Feature.STREAMING_FALLBACK); String message = "Template rule is declared streamable but the match pattern is not motionless"; if (fallback) { message += "\n * Falling back to non-streaming implementation"; getStaticContext().issueWarning(message, this); rule.setDeclaredStreamable(false); getCompilation().setFallbackToNonStreaming(true); } else {
if (getCompilation().getCompilerInfo().isGenerateByteCode() && !isTailRecursive) { ICompilerService compilerService = getConfiguration().makeCompilerService(Configuration.XSLT); if (getTemplateName() != null) { try { Expression exp = compiledNamedTemplate.getBody();