public SourceBinding hasImplicitBinding(StructuredQName name) { if (name.getLocalPart().equals("value") && name.hasURI("")) { SourceBinding sb = new SourceBinding(this); sb.setVariableQName(new StructuredQName("", "", "value")); assert ((XSLAccumulator)getParent()) != null; sb.setDeclaredType(((XSLAccumulator)getParent()).getResultType()); sb.setProperty(SourceBinding.IMPLICITLY_DECLARED, true); return sb; } else { return null; } } }
public void checkAgainstRequiredType(SequenceType required) throws XPathException { sourceBinding.checkAgainstRequiredType(required); }
/** * Get the name of the variable * * @return the variable's name */ public StructuredQName getVariableQName() { if (name == null) { try { processVariableName(sourceElement.getAttributeValue("", "name")); } catch (XPathException e) { return errorName(); } } return name; }
public WithParam compileWithParam(Expression parent, Compilation exec, ComponentDeclaration decl) throws XPathException { sourceBinding.handleSequenceConstructor(exec, decl); WithParam inst = new WithParam(); inst.setSelectExpression(parent, sourceBinding.getSelectExpression()); inst.setVariableQName(sourceBinding.getVariableQName()); inst.setRequiredType(sourceBinding.getInferredType(true)); return inst; }
/** * Compile a global xsl:param element: this ensures space is available for local variables declared within * this global variable */ public void compileDeclaration(Compilation compilation, ComponentDeclaration decl) throws XPathException { if (sourceBinding.isStatic()) { super.compileDeclaration(compilation, decl); } else if (!redundant) { sourceBinding.handleSequenceConstructor(compilation, decl); GlobalParam binding = (GlobalParam)compiledVariable; binding.setPackageData(getCompilation().getPackageData()); binding.makeDeclaringComponent(Visibility.PUBLIC, getContainingPackage()); Expression select = sourceBinding.getSelectExpression(); binding.setSelectExpression(select); binding.setVariableQName(sourceBinding.getVariableQName()); initializeBinding(binding); binding.setRequiredType(getRequiredType()); binding.setRequiredParam(sourceBinding.hasProperty(SourceBinding.REQUIRED)); binding.setImplicitlyRequiredParam(sourceBinding.hasProperty(SourceBinding.IMPLICITLY_REQUIRED)); sourceBinding.fixupBinding(binding); //compiledVariable = binding; Component overridden = getOverriddenComponent(); if (overridden != null) { checkCompatibility(overridden); } } }
String f = atts.getQName(a); if (f.equals("name")) { if (name == null || name.equals(errorName())) { processVariableName(atts.getValue(a)); String requiredAtt = Whitespace.trim(atts.getValue(a)); boolean required = sourceElement.processBooleanAttribute("required", requiredAtt); setProperty(REQUIRED, required); } else if (f.equals("tunnel")) { String tunnelAtt = Whitespace.trim(atts.getValue(a)); boolean tunnel = sourceElement.processBooleanAttribute("tunnel", tunnelAtt); setProperty(TUNNEL, tunnel); } else if (NamespaceConstant.SAXON.equals(atts.getURI(a))) { if (atts.getLocalName(a).equals("as")) { name = errorName(); declaredType = combineTypeDeclarations(asAtt, extraAsAtt);
if (sourceBinding.hasProperty(SourceBinding.IMPLICITLY_DECLARED)) { supRef.setSuppliedType(sourceBinding.getDeclaredType()); return supRef; if (sourceBinding.hasProperty(SourceBinding.GLOBAL)) { var = new GlobalVariableReference(qName); GlobalVariable compiledVar = ((XSLGlobalVariable) sourceBinding.getSourceElement()).getCompiledVariable(); if (compiledVar != null && element.getCompilation().getCompilerInfo().isJustInTimeCompilation()) { var.fixup(compiledVar); var.setStaticType(compiledVar.getRequiredType(), sourceBinding.getConstantValue(), 0); } else { sourceBinding.registerReference(var); sourceBinding.registerReference(var); return var;
public void validate(ComponentDeclaration decl) throws XPathException { if (sourceBinding.hasProperty(SourceBinding.REQUIRED)) { if (sourceBinding.getSelectExpression() != null) { // NB, we do this test before setting the default select attribute compileError("The select attribute must be absent when required='yes'", "XTSE0010"); } if (hasChildNodes()) { compileError("A parameter specifying required='yes' must have empty content", "XTSE0010"); } Visibility vis = getVisibility(); if (!sourceBinding.isStatic() && !(vis == Visibility.PUBLIC || vis == Visibility.FINAL || vis == Visibility.ABSTRACT)) { compileError("The visibility of a required non-static parameter must be public, final, or abstract", "XTSE3370"); } } super.validate(decl); }
final SequenceType type = getInferredType(true); final TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy(); GroundedValue constantValue = null; int properties = 0; if (!hasProperty(ASSIGNABLE) && !hasProperty(PARAM) && !(visibility == Visibility.PUBLIC || visibility == Visibility.ABSTRACT)) { reference.fixup(compiledGlobalVariable); reference.setStaticType(type, getConstantValue(), properties);
public void validate(ComponentDeclaration decl) throws XPathException { StructuredQName name = sourceBinding.getVariableQName(); if (name.equals(((XSLLocalParam) node).sourceBinding.getVariableQName())) { compileError("The name of the parameter is not unique", "XTSE0580"); if (sourceBinding.hasProperty(SourceBinding.REQUIRED)) { if (sourceBinding.getSelectExpression() != null) {
checkAgainstRequiredType(declaredType); if (select == null && !hasProperty(DISALLOWS_CONTENT) && visibility != Visibility.ABSTRACT) { AxisIterator kids = sourceElement.iterateAxis(AxisInfo.CHILD); NodeInfo first = kids.next(); } else { if (sourceElement instanceof XSLLocalParam || sourceElement instanceof XSLGlobalParam) { if (!hasProperty(REQUIRED)) { if (Cardinality.allowsZero(declaredType.getCardinality())) { select = Literal.makeEmptySequence(); setProperty(IMPLICITLY_REQUIRED, true);
let.setInstruction(true); let.setRequiredType(var.getRequiredType()); let.setVariableQName(sourceBinding.getVariableQName()); let.setSequence(sourceBinding.getSelectExpression()); let.setAction(tail); sourceBinding.fixupBinding(let); locationId = ((StyleElement) node).allocateLocation(); let.setLocation(locationId); TraceExpression t = new TraceExpression(let); t.setConstructType(LocationKind.LET_EXPRESSION); t.setObjectName(var.getSourceBinding().getVariableQName()); t.setNamespaceResolver(getNamespaceResolver()); contents.add(t);
public GroundedValue<?> getConstantValue() { if (constantValue == null) { final SequenceType type = getInferredType(true); final TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy(); if (!hasProperty(ASSIGNABLE) && !hasProperty(PARAM) && !(visibility == Visibility.PUBLIC || visibility == Visibility.ABSTRACT)) { if (select instanceof Literal) { // we can't rely on the constant value because it hasn't yet been type-checked, // which could change it (eg by numeric promotion). Rather than attempt all the type-checking // now, we do a quick check. See test bug64 int relation = th.relationship(select.getItemType(), type.getPrimaryType()); if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) { constantValue = ((Literal) select).getValue(); } } } } return constantValue; }
/** * 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; }
if (hasProperty(PARAM) || hasProperty(ASSIGNABLE) || !(visibility == Visibility.PRIVATE || visibility == Visibility.FINAL)) { SequenceType declared = getDeclaredType(); return inferredType = declared == null ? SequenceType.ANY_SEQUENCE : declared;
@Override public void fixupReferences() throws XPathException { sourceBinding.fixupReferences(null); super.fixupReferences(); }
/** * Get the static type of the parameter. This is the declared type, because we cannot know * the actual value in advance. */ public SequenceType getRequiredType() { SequenceType declaredType = sourceBinding.getDeclaredType(); if (declaredType != null) { return declaredType; } else { return SequenceType.ANY_SEQUENCE; } }
/** * Get the static type of the variable. This is the declared type, unless the value * is statically known and constant, in which case it is the actual type of the value. */ public SequenceType getRequiredType() { return sourceBinding.getInferredType(true); }
/** * For each local parameter definition, fix up all references to the function parameter * @param fn the compiled user function */ private void bindParameterDefinitions(UserFunction fn) { UserFunctionParameter[] params = fn.getParameterDefinitions(); int count = 0; AxisIterator kids = iterateAxis(AxisInfo.CHILD); NodeInfo node; while ((node = kids.next()) != null) { if (node instanceof XSLLocalParam) { UserFunctionParameter param = params[count++]; param.setRequiredType(((XSLLocalParam) node).getRequiredType()); param.setVariableQName(((XSLLocalParam) node).getVariableQName()); param.setSlotNumber(((XSLLocalParam) node).getSlotNumber()); ((XSLLocalParam) node).getSourceBinding().fixupBinding(param); } } }
/** * Process the QName of the variable. Validate the name and place it in the "name" field; * if invalid, construct an error message and place a dummy name in the "name" field for * recovery purposes. * * @param nameAttribute the lexical QName * @throws XPathException if the name is invalid */ private void processVariableName(String nameAttribute) throws XPathException { try { if (nameAttribute != null) { name = sourceElement.makeQName(nameAttribute); } } catch (XPathException err) { name = errorName(); StructuredQName n = StructuredQName.fromClarkName("name"); throw new XPathException("Invalid variable name: " + err.getMessage() + (nameAttribute.startsWith("$") ? " (No '$' sign needed)" : ""), "XTSE0020", new AttributeLocation(sourceElement, n)); } }