FileDocCategorySizeDatePackage
VariableRefBase.javaAPI DocJava SE 5 API4074Fri Aug 26 14:55:36 BST 2005com.sun.org.apache.xalan.internal.xsltc.compiler

VariableRefBase

public class VariableRefBase extends Expression
author
Morten Jorgensen
author
Santiago Pericas-Geertsen

Fields Summary
protected final VariableBase
_variable
A reference to the associated variable.
protected Closure
_closure
A reference to the enclosing expression/instruction for which a closure is needed (Predicate, Number or Sort).
Constructors Summary
public VariableRefBase(VariableBase variable)


       
	_variable = variable;
	variable.addReference(this);
    
public VariableRefBase()

	_variable = null;
    
Methods Summary
public booleanequals(java.lang.Object obj)
Two variable references are deemed equal if they refer to the same variable.

	try {
	    return (_variable == ((VariableRefBase) obj)._variable);
	} 
	catch (ClassCastException e) {
	    return false;
	}
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.VariableBasefindParentVariable()
Returns a reference to any parent variable

	SyntaxTreeNode node = this;
	while (node != null && !(node instanceof VariableBase)) {
	    node = node.getParent();
	}
	return (VariableBase) node;
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.VariableBasegetVariable()
Returns a reference to the associated variable

	return _variable;
    
public java.lang.StringtoString()
Returns a string representation of this variable reference on the format 'variable-ref()'.

return
Variable reference description

	return "variable-ref("+_variable.getName()+'/"+_variable.getType()+')";
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypetypeCheck(com.sun.org.apache.xalan.internal.xsltc.compiler.SymbolTable stable)

	// Returned cached type if available
	if (_type != null) return _type;

	// Find nearest closure to add a variable reference
	if (_variable.isLocal()) {
	    SyntaxTreeNode node = getParent();
	    do {
		if (node instanceof Closure) {
		    _closure = (Closure) node;
		    break;
		}
		if (node instanceof TopLevelElement) {
		    break;	// way up in the tree
		}
		node = node.getParent();
	    } while (node != null);

	    if (_closure != null) {
		_closure.addVariable(this);
	    }
	}

	// Insert a dependency link from one variable to another
        VariableBase parent = findParentVariable();
        if (parent != null) {
            VariableBase var = _variable;
            if (_variable._ignore) {
                if (_variable instanceof Variable) {
                    var = parent.getSymbolTable()
                                .lookupVariable(_variable._name);
                } else if (_variable instanceof Param) {
                    var = parent.getSymbolTable().lookupParam(_variable._name);
                }
            }
            parent.addDependency(var);
        }

        // Attempt to get the cached variable type
        _type = _variable.getType();

        // If that does not work we must force a type-check (this is normally
        // only needed for globals in included/imported stylesheets
        if (_type == null) {
            _variable.typeCheck(stable);
            _type = _variable.getType();
        }

        // Return the type of the referenced variable
        return _type;