net.sf.saxon.expr.instruct
Class GlobalVariable

java.lang.Object
  extended by net.sf.saxon.expr.Expression
      extended by net.sf.saxon.expr.instruct.Instruction
          extended by net.sf.saxon.expr.instruct.GeneralVariable
              extended by net.sf.saxon.expr.instruct.GlobalVariable
All Implemented Interfaces:
Serializable, SourceLocator, LocationProvider, SaxonLocator, Binding, Container, EvaluableItem, TailCallReturner, SequenceIterable, InstructionInfo, Locator
Direct Known Subclasses:
GlobalParam

public class GlobalVariable
extends GeneralVariable
implements Container

A compiled global variable in a stylesheet or query.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.expr.instruct.GeneralVariable
evaluationMode, referenceCount, slotNumber, variableQName
 
Fields inherited from class net.sf.saxon.expr.Expression
EVALUATE_METHOD, EVENT_FEED_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, PUSH_SELECTION, staticProperties, WATCH_METHOD
 
Constructor Summary
GlobalVariable()
          Create a global variable
 
Method Summary
protected  ValueRepresentation actuallyEvaluate(XPathContext context)
          Evaluate the global variable, and save its value for use in subsequent references.
 ValueRepresentation evaluateVariable(XPathContext context)
          Evaluate the variable
 int getContainerGranularity()
          Get the granularity of the container.
 Executable getExecutable()
          Get the executable containing this global variable
 int getHostLanguage()
          Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
 ValueRepresentation getSelectValue(XPathContext context)
          Evaluate the variable.
 boolean isGlobal()
          Is this a global variable?
 boolean isIndexedVariable()
          Ask whether this is an indexed variable
 void lookForCycles(Stack referees, XQueryFunctionLibrary globalFunctionLibrary)
          Check for cycles in this variable definition
 TailCall processLeavingTail(XPathContext context)
          Process the variable declaration
 void setContainsLocals(SlotManager map)
          The expression that initializes a global variable may itself use local variables.
protected static void setDependencies(Bindery bindery, GlobalVariable var, XPathContext context)
          Get the variable that is immediately dependent on this one, and register the dependency, so that circularities can be detected across threads.
 void setExecutable(Executable executable)
          Set the containing executable
 void setIndexedVariable()
          Mark this as an indexed variable, to allow fast searching
 
Methods inherited from class net.sf.saxon.expr.instruct.GeneralVariable
copy, evaluateItem, explain, getCardinality, getEvaluationMode, getInstructionNameCode, getItemType, getLocalSlotNumber, getRequiredType, getSelectExpression, getSlotNumber, getVariableQName, init, isAssignable, isImplicitlyRequiredParam, isRequiredParam, isTunnelParam, iterate, iterateSubExpressions, optimize, promoteInst, replaceSubExpression, setAssignable, setImplicitlyRequiredParam, setReferenceCount, setRequiredParam, setRequiredType, setSelectExpression, setSlotNumber, setTunnel, setVariableQName, simplify, typeCheck
 
Methods inherited from class net.sf.saxon.expr.instruct.Instruction
assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, createsNewNodes, dynamicError, evaluateAsString, getConstructType, getExpressionName, getImplementationMethod, getInstructionName, getIteratorFromProcessMethod, getSourceLocator, isXSLT, process, promote
 
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, evaluatePendingUpdates, explain, getColumnNumber, getColumnNumber, getContainer, getDependencies, getEvaluationMethod, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterateEvents, iterateSameFocusSubExpressions, markTailFunctionCalls, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, toString, typeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.expr.Container
getLocationProvider
 
Methods inherited from interface javax.xml.transform.SourceLocator
getColumnNumber, getLineNumber, getPublicId, getSystemId
 

Constructor Detail

GlobalVariable

public GlobalVariable()
Create a global variable

Method Detail

getExecutable

public Executable getExecutable()
Get the executable containing this global variable

Specified by:
getExecutable in interface Container
Overrides:
getExecutable in class Expression
Returns:
the containing executable

setExecutable

public void setExecutable(Executable executable)
Set the containing executable

Parameters:
executable - the executable that contains this global variable

getHostLanguage

public int getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container

Specified by:
getHostLanguage in interface Container
Overrides:
getHostLanguage in class Expression
Returns:
typically Configuration.XSLT or Configuration.XQUERY

setIndexedVariable

public void setIndexedVariable()
Mark this as an indexed variable, to allow fast searching


isIndexedVariable

public boolean isIndexedVariable()
Ask whether this is an indexed variable

Returns:
true if this variable is indexed

getContainerGranularity

public int getContainerGranularity()
Get the granularity of the container.

Specified by:
getContainerGranularity in interface Container
Returns:
0 for a temporary container created during parsing; 1 for a container that operates at the level of an XPath expression; 2 for a container at the level of a global function or template

setContainsLocals

public void setContainsLocals(SlotManager map)
The expression that initializes a global variable may itself use local variables. In this case a stack frame needs to be allocated while evaluating the global variable

Parameters:
map - The stack frame map for local variables used while evaluating this global variable.

isGlobal

public boolean isGlobal()
Is this a global variable?

Specified by:
isGlobal in interface Binding
Overrides:
isGlobal in class GeneralVariable
Returns:
true (yes, it is a global variable)

lookForCycles

public void lookForCycles(Stack referees,
                          XQueryFunctionLibrary globalFunctionLibrary)
                   throws XPathException
Check for cycles in this variable definition

Parameters:
referees - the calls leading up to this one; it's an error if this variable is on the stack, because that means it calls itself directly or indirectly. The stack may contain variable definitions (GlobalVariable objects) and user-defined functions (UserFunction objects). It will never contain the same object more than once.
globalFunctionLibrary - the library containing all global functions
Throws:
XPathException

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
                            throws XPathException
Process the variable declaration

Specified by:
processLeavingTail in interface TailCallReturner
Specified by:
processLeavingTail in class Instruction
Parameters:
context - The dynamic context of the transformation, giving access to the current node, the current variables, etc.
Returns:
null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.
Throws:
XPathException

getSelectValue

public ValueRepresentation getSelectValue(XPathContext context)
                                   throws XPathException
Evaluate the variable. That is, get the value of the select expression if present or the content of the element otherwise, either as a tree or as a sequence

Overrides:
getSelectValue in class GeneralVariable
Parameters:
context - the XPath dynamic context
Returns:
the result of evaluating the variable
Throws:
XPathException

evaluateVariable

public ValueRepresentation evaluateVariable(XPathContext context)
                                     throws XPathException
Evaluate the variable

Specified by:
evaluateVariable in interface Binding
Parameters:
context - the XPath dynamic evaluation context
Returns:
the result of evaluating the variable
Throws:
XPathException

actuallyEvaluate

protected ValueRepresentation actuallyEvaluate(XPathContext context)
                                        throws XPathException
Evaluate the global variable, and save its value for use in subsequent references.

Parameters:
context - the XPath dynamic context
Returns:
the value of the variable
Throws:
XPathException - if evaluation fails

setDependencies

protected static void setDependencies(Bindery bindery,
                                      GlobalVariable var,
                                      XPathContext context)
                               throws XPathException
Get the variable that is immediately dependent on this one, and register the dependency, so that circularities can be detected across threads. This relies on the fact that when the initialiser for variable X contains a reference to variable Y, then when Y is evaluated, a stack frame will be found on the context stack representing the evaluation of X. We don't set a dependency from X to Y if the value of Y was already available in the Bindery; it's not needed, because in this case we know that evaluation of Y is unproblematic, and can't lead to any circularities.

Parameters:
bindery - the Bindery
var - the global variable or parameter being evaluated
context - the dynamic evaluation context
Throws:
XPathException


Copyright (c) 2004-2010 Saxonica Limited. All rights reserved.