/*
 * $Id$
 *
 * JSDAI(TM), a way to implement STEP, ISO 10303
 * Copyright (C) 1997-2008, LKSoftWare GmbH, Germany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License
 * version 3 as published by the Free Software Foundation (AGPL v3).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * JSDAI is a registered trademark of LKSoftWare GmbH, Germany
 * This software is also available under commercial licenses.
 * See also http://www.jsdai.net/
 */

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

package jsdai.expressCompiler;

public class X_IdParameter extends SimpleNode {
  public X_IdParameter(int id) {
    super(id);
  }

  public X_IdParameter(Compiler2 p, int id) {
    super(p, id);
  }


  /** Accept the visitor. **/
  public Object jjtAccept(Compiler2Visitor visitor, Object data) throws jsdai.lang.SdaiException {
    return visitor.visit(this, data);
  }

  public Object childrenAccept(Compiler2Visitor visitor, Object data)
                            throws jsdai.lang.SdaiException {
    JavaClass jc = ( JavaClass )data;
		java.io.PrintWriter pw = jc.pw;
		String ref_name="_missing_source_parameter_name_";
		int order=0;

    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
					children[i].jjtAccept(visitor, data);
					if(children[i] instanceof X_SourceParameterRef){
							if (((X_SourceParameterRef)children[i]).partition == jc.partition) { 
									ref_name = ((X_SourceParameterRef)children[i]).name;
									order = ((X_SourceParameterRef)children[i]).order;
							}
					} else
				  if(children[i] instanceof X_Expression){
						// now we have an intermediate expression node, so what is above is left only for the case if this node is removed
			      SimpleNode child = (SimpleNode)children[i];
			      for (int ii = 0; ii < child.children.length; ++ii) {
							if(child.children[ii] instanceof X_SourceParameterRef){
								if (((X_SourceParameterRef)child.children[ii]).partition == jc.partition) { 
									ref_name = ((X_SourceParameterRef)child.children[ii]).name;
									order = ((X_SourceParameterRef)child.children[ii]).order;
								}
							}		
						}
					}		
			}
			if(jc.second_pass){
				//					pw.println("\t\t\t\tsrc_par_id = ((Integer)src_id_map.get(\""+ref_name+"\")).intValue();");
					pw.println("\t\t\t\t" +ref_name +" = (Value)((Vector)binding_inst_extent.elementAt(j)).elementAt(src_par_id_" +ref_name +");");
					pw.println("\t\t\t\tValue identified_by_" +order +"_current = " +jc.generated_java +";");
			}else{
				//					pw.println("\t\t\tsrc_par_id = ((Integer)src_id_map.get(\""+ref_name+"\")).intValue();");
					pw.println("\t\t\tValue " +ref_name +" = (Value)((Vector)binding_inst_extent.elementAt(i)).elementAt(src_par_id_" +ref_name +");");
					if (jc.single_map_call) {
						pw.println("\t\t\tValue identified_by_" + order + " = input;");
					} else {
						pw.println("\t\t\tValue identified_by_" +order +" = " +jc.generated_java +";");
					}
			}

		}
		return data;
	}
}
