throw new XPathException("Value of declared variable does not match its type"); GlobalVariableDefinition var = new GlobalVariableDefinition(); var.setVariableQName(qName); var.setRequiredType(type); var.setValueExpression(Literal.makeLiteral(val)); var.setIsParameter(external); if (userDeclaredVariables == null) { userDeclaredVariables = new HashSet();
/** * Fixup all references to global variables. * <p/> * This method is for internal use by the Query Parser only. * @param globalVariableMap a SlotManager that holds details of the assignment of slots to global variables. * @return a list containing the global variable definitions. */ public List fixupGlobalVariables(SlotManager globalVariableMap) throws XPathException { List varDefinitions = new ArrayList(20); Iterator[] iters = {variables.values().iterator(), libraryVariables.values().iterator()}; for (int i=0; i<2; i++) { while (iters[i].hasNext()) { GlobalVariableDefinition var = (GlobalVariableDefinition)iters[i].next(); int slot = globalVariableMap.allocateSlotNumber(var.getVariableQName()); GlobalVariable gv = var.getCompiledVariable(); if (gv == null) { var.compile(getExecutable(), slot); } if (!varDefinitions.contains(var)) { varDefinitions.add(var); } } } return varDefinitions; }
String oldloc = ""; if (old instanceof GlobalVariableDefinition && var instanceof GlobalVariableDefinition) { oldloc = " (see line " + ((GlobalVariableDefinition)old).getLineNumber(); String oldSysId = ((GlobalVariableDefinition)old).getSystemId(); if (oldSysId != null && !oldSysId.equals(((GlobalVariableDefinition)var).getSystemId())) { oldloc += " in module ((GlobalVariableDefinition)old).getSystemId()"; if (var instanceof GlobalVariableDefinition) { ExpressionLocation loc = new ExpressionLocation(); loc.setLineNumber(((GlobalVariableDefinition)var).getLineNumber()); loc.setSystemId(((GlobalVariableDefinition)var).getSystemId()); err.setLocator(loc); XPathException err = new XPathException("Duplicate definition of global variable " + var.getVariableQName().getDisplayName() + " (see line " + old.getLineNumber() + " in module " + old.getSystemId() + ')'); err.setErrorCode("XQST0049"); err.setIsStaticError(true); if (var instanceof GlobalVariableDefinition) { ExpressionLocation loc = new ExpressionLocation(); loc.setLineNumber(((GlobalVariableDefinition)var).getLineNumber()); loc.setSystemId(((GlobalVariableDefinition)var).getSystemId()); err.setLocator(loc);
GlobalVariableDefinition var = new GlobalVariableDefinition(); var.setLineNumber(t.getLineNumber()); var.setSystemId(env.getSystemId()); nextToken(); expect(Token.DOLLAR); String varName = t.currentTokenValue; StructuredQName varQName = makeStructuredQName(t.currentTokenValue, false); var.setVariableQName(varQName); requiredType = parseSequenceType(); var.setRequiredType(requiredType); nextToken(); Expression exp = parseExprSingle(); var.setIsParameter(false); var.setValueExpression(makeTracer(offset, exp, StandardNames.XSL_VARIABLE, varQName)); } else if (t.currentToken == Token.NAME) { if ("external".equals(t.currentTokenValue)) { var.setIsParameter(true); if (defaultValue != null) { var.setValueExpression(defaultValue);
/** * Check for circular definitions of global variables. * <p>This method is intended for internal use</p> * @param compiledVars a list of {@link GlobalVariableDefinition} objects to be checked */ public void checkForCircularities(List compiledVars, XQueryFunctionLibrary globalFunctionLibrary) throws XPathException { Iterator iter = compiledVars.iterator(); Stack stack = null; while (iter.hasNext()) {if (stack == null) {stack = new Stack();} GlobalVariableDefinition gvd = (GlobalVariableDefinition)iter.next(); GlobalVariable gv = gvd.getCompiledVariable(); gv.lookForCycles(stack, globalFunctionLibrary); } }
/** * Bind unbound variables (these are typically variables that reference another module * participating in a same-namespace cycle, since local forwards references are not allowed */ public void bindUnboundVariables() throws XPathException { for (Iterator iter = undeclaredVariables.values().iterator(); iter.hasNext();) { UndeclaredVariable uv = (UndeclaredVariable)iter.next(); StructuredQName qName = uv.getVariableQName(); VariableDeclaration var = (VariableDeclaration)variables.get(qName); if (var == null) { String uri = qName.getNamespaceURI(); if (importsNamespace(uri)) { QueryModule main = getTopLevelModule(); var = (VariableDeclaration)main.libraryVariables.get(qName); } } if (var == null) { XPathException err = new XPathException("Unresolved reference to variable $" + uv.getVariableQName().getDisplayName()); err.setErrorCode("XPST0008"); err.setIsStaticError(true); throw err; } else { GlobalVariableDefinition gvar = ((GlobalVariableDefinition)var); checkImportedType(gvar.getRequiredType(), gvar); uv.transferReferences(var); } } }
if (declaration instanceof GlobalVariableDefinition) { msg += "declaration of imported variable " + ((GlobalVariableDefinition)declaration).getVariableQName().getDisplayName(); } else { msg += "signature of imported function " +
while (iter.hasNext()) { BindingReference binding = (BindingReference)iter.next(); fixupReference(binding, th);
GlobalVariableDefinition var = new GlobalVariableDefinition(); var.setLineNumber(t.getLineNumber()); var.setSystemId(env.getSystemId()); nextToken(); expect(Token.DOLLAR); String varName = t.currentTokenValue; StructuredQName varQName = makeStructuredQName(t.currentTokenValue, false); var.setVariableQName(varQName); requiredType = parseSequenceType(); var.setRequiredType(requiredType); nextToken(); Expression exp = parseExprSingle(); var.setIsParameter(false); var.setValueExpression(makeTracer(offset, exp, StandardNames.XSL_VARIABLE, varQName)); } else if (t.currentToken == Token.NAME) { if ("external".equals(t.currentTokenValue)) { var.setIsParameter(true); if (defaultValue != null) { var.setValueExpression(defaultValue);
/** * Check for circular definitions of global variables. * <p>This method is intended for internal use</p> * @param compiledVars a list of {@link GlobalVariableDefinition} objects to be checked */ public void checkForCircularities(List compiledVars, XQueryFunctionLibrary globalFunctionLibrary) throws XPathException { Iterator iter = compiledVars.iterator(); Stack stack = null; while (iter.hasNext()) {if (stack == null) {stack = new Stack();} GlobalVariableDefinition gvd = (GlobalVariableDefinition)iter.next(); GlobalVariable gv = gvd.getCompiledVariable(); gv.lookForCycles(stack, globalFunctionLibrary); } }
/** * Bind unbound variables (these are typically variables that reference another module * participating in a same-namespace cycle, since local forwards references are not allowed */ public void bindUnboundVariables() throws XPathException { for (Iterator iter = undeclaredVariables.values().iterator(); iter.hasNext();) { UndeclaredVariable uv = (UndeclaredVariable)iter.next(); StructuredQName qName = uv.getVariableQName(); VariableDeclaration var = (VariableDeclaration)variables.get(qName); if (var == null) { String uri = qName.getNamespaceURI(); if (importsNamespace(uri)) { QueryModule main = getTopLevelModule(this); var = (VariableDeclaration)main.libraryVariables.get(qName); } } if (var == null) { XPathException err = new XPathException("Unresolved reference to variable $" + uv.getVariableQName().getDisplayName()); err.setErrorCode("XPST0008"); err.setIsStaticError(true); throw err; } else { GlobalVariableDefinition gvar = ((GlobalVariableDefinition)var); checkImportedType(gvar.getRequiredType(), gvar); uv.transferReferences(var); } } }
if (declaration instanceof GlobalVariableDefinition) { msg += "declaration of imported variable " + ((GlobalVariableDefinition)declaration).getVariableQName().getDisplayName(); } else { msg += "signature of imported function " +
while (iter.hasNext()) { BindingReference binding = (BindingReference)iter.next(); fixupReference(binding, th);
/** * Fixup all references to global variables. * <p/> * This method is for internal use by the Query Parser only. * @param globalVariableMap a SlotManager that holds details of the assignment of slots to global variables. * @return a list containing the global variable definitions. */ public List fixupGlobalVariables(SlotManager globalVariableMap) throws XPathException { List varDefinitions = new ArrayList(20); Iterator[] iters = {variables.values().iterator(), libraryVariables.values().iterator()}; for (int i=0; i<2; i++) { while (iters[i].hasNext()) { GlobalVariableDefinition var = (GlobalVariableDefinition)iters[i].next(); int slot = globalVariableMap.allocateSlotNumber(var.getVariableQName()); GlobalVariable gv = var.getCompiledVariable(); if (gv == null) { var.compile(getExecutable(), slot); } if (!varDefinitions.contains(var)) { varDefinitions.add(var); } } } return varDefinitions; }
String oldloc = ""; if (old instanceof GlobalVariableDefinition && var instanceof GlobalVariableDefinition) { oldloc = " (see line " + ((GlobalVariableDefinition)old).getLineNumber(); String oldSysId = ((GlobalVariableDefinition)old).getSystemId(); if (oldSysId != null && !oldSysId.equals(((GlobalVariableDefinition)var).getSystemId())) { oldloc += " in module ((GlobalVariableDefinition)old).getSystemId()"; if (var instanceof GlobalVariableDefinition) { ExpressionLocation loc = new ExpressionLocation(); loc.setLineNumber(((GlobalVariableDefinition)var).getLineNumber()); loc.setSystemId(((GlobalVariableDefinition)var).getSystemId()); err.setLocator(loc); XPathException err = new XPathException("Duplicate definition of global variable " + var.getVariableQName().getDisplayName() + " (see line " + old.getLineNumber() + " in module " + old.getSystemId() + ')'); err.setErrorCode("XQST0049"); err.setIsStaticError(true); if (var instanceof GlobalVariableDefinition) { ExpressionLocation loc = new ExpressionLocation(); loc.setLineNumber(((GlobalVariableDefinition)var).getLineNumber()); loc.setSystemId(((GlobalVariableDefinition)var).getSystemId()); err.setLocator(loc);
GlobalVariableDefinition gv = (GlobalVariableDefinition)viter.next(); List list = new ArrayList(10); Expression select = gv.getCompiledVariable().getSelectExpression(); if (select != null) { ExpressionTool.gatherReferencedVariables(select, list);
/** * Notify a reference to this variable of the data type * @param ref the variable reference * @param th the type hierarchy cache */ public void fixupReference(BindingReference ref, TypeHierarchy th) throws XPathException { final SequenceType type = getRequiredType(); Value constantValue = null; int properties = 0; Expression select = value; if (select instanceof Literal && !isParameter) { // 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(th), type.getPrimaryType()); if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) { constantValue = ((Literal)select).getValue(); } } if (select != null) { properties = select.getSpecialProperties(); } ref.setStaticType(type, constantValue, properties); }
GlobalVariableDefinition gv = (GlobalVariableDefinition)viter.next(); List list = new ArrayList(10); Expression select = gv.getCompiledVariable().getSelectExpression(); if (select != null) { ExpressionTool.gatherReferencedVariables(select, list);
/** * Notify a references to this variable of the data type * @param ref the variable reference * @param th the type hierarchy cache */ public void fixupReference(BindingReference ref, TypeHierarchy th) throws XPathException { final SequenceType type = getRequiredType(); Value constantValue = null; int properties = 0; Expression select = value; if (select instanceof Literal && !isParameter) { // 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(th), type.getPrimaryType()); if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) { constantValue = ((Literal)select).getValue(); } } if (select != null) { properties = select.getSpecialProperties(); } ref.setStaticType(type, constantValue, properties); }
GlobalVariable var = getCompiledVariable(); Expression value = var.getSelectExpression(); if (value != null) {