|
|
|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xalan.internal.xsltc.compiler; |
|
|
|
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
|
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
*/ |
|
class VariableRefBase extends Expression { |
|
|
|
|
|
|
|
*/ |
|
protected VariableBase _variable; |
|
|
|
|
|
|
|
|
|
*/ |
|
protected Closure _closure = null; |
|
|
|
public VariableRefBase(VariableBase variable) { |
|
_variable = variable; |
|
variable.addReference(this); |
|
} |
|
|
|
public VariableRefBase() { |
|
_variable = null; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public VariableBase getVariable() { |
|
return _variable; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void addParentDependency() { |
|
SyntaxTreeNode node = this; |
|
while (node != null && node instanceof TopLevelElement == false) { |
|
node = node.getParent(); |
|
} |
|
|
|
TopLevelElement parent = (TopLevelElement) node; |
|
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); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public boolean equals(Object obj) { |
|
return obj == this || (obj instanceof VariableRefBase) |
|
&& (_variable == ((VariableRefBase) obj)._variable); |
|
} |
|
|
|
@Override |
|
public int hashCode() { |
|
return Objects.hashCode(this._variable); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public String toString() { |
|
return "variable-ref("+_variable.getName()+'/'+_variable.getType()+')'; |
|
} |
|
|
|
@Override |
|
public Type typeCheck(SymbolTable stable) |
|
throws TypeCheckError |
|
{ |
|
|
|
if (_type != null) return _type; |
|
|
|
|
|
if (_variable.isLocal()) { |
|
SyntaxTreeNode node = getParent(); |
|
do { |
|
if (node instanceof Closure) { |
|
_closure = (Closure) node; |
|
break; |
|
} |
|
if (node instanceof TopLevelElement) { |
|
break; |
|
} |
|
node = node.getParent(); |
|
} while (node != null); |
|
|
|
if (_closure != null) { |
|
_closure.addVariable(this); |
|
} |
|
} |
|
|
|
|
|
_type = _variable.getType(); |
|
|
|
// If that does not work we must force a type-check (this is normally |
|
|
|
if (_type == null) { |
|
_variable.typeCheck(stable); |
|
_type = _variable.getType(); |
|
} |
|
|
|
|
|
addParentDependency(); |
|
|
|
|
|
return _type; |
|
} |
|
|
|
} |