* are first pushed onto the stack. Then the function class associated
* with the node is used to evaluate the function.
*/
final public Object visit(ASTFunNode node, Object data) throws ParseException {
JepRuntime runtime = getThreadJepRuntime(this);
PostfixCommandI pfmc = node.getPFMC();
// check if the function class is set
if (pfmc == null) {
throw new ParseException("No function class associated with " + node.getName());
}
// evaluate all children (each leaves their result on the stack)
if (debug) {
System.out.println("Stack size after childrenAccept: " + runtime.stack.size());
}
Comparable<?>[] parameters = pfmc.evaluate(node, runtime);
if(pfmc.isAutoBox()){
ComparativeBaseList list = null;
int index = -1;
for(int i=0;i<parameters.length;i++){
if(parameters[i] instanceof ComparativeBaseList){
index = i;
list = (ComparativeBaseList)parameters[i];
break;
}else{
}
}
if(index >=0){
for(int i=0;i<parameters.length;i++){
if(i != index){
if(parameters[i] instanceof Comparative){
parameters[i] =((Comparative) parameters[i]).getValue();
}
}
}
for(Comparative comp:list.getList()){
parameters[index] = comp.getValue();
Comparable<?> value = pfmc.getResult(parameters);
if(value instanceof Comparative){
comp.setComparison(((Comparative) value).getComparison());
comp.setValue(((Comparative) value).getValue());
}else{
comp.setValue(value);
}
}
if(pfmc instanceof Declare){
Declare declare = (Declare) pfmc;
declare.declare(runtime, list);
}else{
runtime.stack.push(list);
}
}else{
//分析每个参数是否是 Comparative 类型
Comparative lastComparative = null;
for(int i=0;i<parameters.length;i++){
if(parameters[i] instanceof Comparative){
lastComparative = ((Comparative) parameters[i]);
parameters[i] =((Comparative) parameters[i]).getValue();
}
}
Comparable<?> result = pfmc.getResult(parameters);
if(lastComparative != null){
lastComparative.setValue(result);
result = lastComparative;
}
if(pfmc instanceof Declare){
Declare declare = (Declare) pfmc;
declare.declare(runtime, result);
}else{
runtime.stack.push(result);
}
}
}else{
if(pfmc instanceof Declare){
Declare declare = (Declare) pfmc;
declare.declare(runtime, pfmc.getResult(parameters));
}else{
runtime.stack.push(pfmc.getResult(parameters));
}
}
if (debug) {