/* Generated By:JJTree: Do not edit this line. CLVFFunctionCallStatement.java */

package org.jetel.interpreter.ASTnode;

import org.jetel.interpreter.ExpParser;
import org.jetel.interpreter.TransformLangParserVisitor;
import org.jetel.interpreter.data.TLValue;
import org.jetel.interpreter.extensions.TLContext;
import org.jetel.interpreter.extensions.TLFunctionPrototype;

 

public class CLVFFunctionCallStatement extends SimpleNode {
  
    public  String name;
    public CLVFFunctionDeclaration callNode;
    public TLFunctionPrototype externalFunction;
    public TLContext context;
    public TLValue[] externalFunctionParams;
    
  public CLVFFunctionCallStatement(int id) {
    super(id);
  }

  public CLVFFunctionCallStatement(ExpParser p, int id) {
    super(p, id);
  }


  /** Accept the visitor. **/
  public Object jjtAccept(TransformLangParserVisitor visitor, Object data) {
    return visitor.visit(this, data);
  }
  
  public void setName(String name){
      this.name=name;
  }
  
  public void setCallNode(CLVFFunctionDeclaration callNode){
      this.callNode=callNode;
  }
  
  public void setExternalFunction(TLFunctionPrototype function) {
      this.externalFunction=function;
  }
  
  @Override public void init() {
	  	super.init();
          if (externalFunction!=null) {
              this.context=externalFunction.createContext();
              this.externalFunctionParams=new TLValue[jjtGetNumChildren()];
              //may not work for some: this.externalFunctionParams=new TLValue[requiredNumParams()];
          }
  }
  
  @Override public String toString() {
      return super.toString()+" name \""+name+"\" min #params: "+requiredNumParams();
  }
  
  public final int requiredNumParams() {
      if (externalFunction!=null)
          return externalFunction.getParameterTypes().length;
      else if (callNode!=null)
          return callNode.numParams;
      else
          return 0;
  }
  
  public final boolean validateParams() {
      if (externalFunction!=null) {
          int numParams=jjtGetNumChildren();
          int maxParams=externalFunction.getMaxParams();
          int minParams=externalFunction.getMinParams();
          int definedParams=externalFunction.getParameterTypes().length;
          
          return (numParams>=minParams && numParams<=maxParams);
      }
      return jjtGetNumChildren()==callNode.numParams;
  }
}

@@ -2231,32 +2231,56 @@
 etMinParams();%0D%0A
+//%09%09TODO test lengts%0D%0A//
           int de

remove variable definedParams, which is not read (findbugs)