/*
 * $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_InstantiationForeachControl.java */

package jsdai.expressCompiler;


import java.io.*;
import java.util.*;
import jsdai.SExtended_dictionary_schema.*;
import jsdai.lang.*;


public class X_InstantiationForeachControl extends SimpleNode {

	String iterator_name;
	String iterator_uid;
	String index_name;
	String index_uid;
	String variable_scope_id;


  public X_InstantiationForeachControl(int id) {
    super(id);
  }

  public X_InstantiationForeachControl(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 SdaiException {
    JavaClass jc = (JavaClass) data;

 jc.pw.println("\t\t// <EntityInstantiationLoop>: INSIDE  InstantiationForeachControl before children");

 jc.pw.println("\t\t\t// iterator_name: " + iterator_name);
 jc.pw.println("\t\t\t// iterator_uid: " + iterator_uid);
 jc.pw.println("\t\t\t// index_name: " + index_name);
 jc.pw.println("\t\t\t// index_uid: " + index_uid);
 jc.pw.println("\t\t\t// variable_scope_id: " + variable_scope_id);

		jc.index_uid = index_uid;
		jc.iterator_uid = iterator_uid;

	
		String par_ref = "";
		String attr_ref = "";


    if (children != null) {
      // variable_declaration = "";
      variable_names = new Vector();
      variable_declarations = new Vector();
      statements = new Vector();
      initializing_code = new Vector();

      // generated_code = "";     
      for (int i = 0; i < children.length; ++i) {
        children[i].jjtAccept(visitor, data);

        if (jc != null) {
          if (jc.active) {
            // if (children[i] instanceof ExpressionNode) {
            // if (((ExpressionNode)children[i]).java_contains_statements) {
            move_up_java_statements = true; // temporarily

            if (move_up_java_statements) { // basicly almost the same as if expression node.

              if (((SimpleNode) children[i]).java_contains_statements) {
                java_contains_statements = true;

                // variable_declaration += "\n" + ((SimpleNode)children[i]).variable_declaration;
                for (int j = 0; j < ((SimpleNode) children[i]).variable_names.size(); j++) {
                  variable_names.add(((SimpleNode) children[i]).variable_names.elementAt(j));
                }

                for (int j = 0; j < ((SimpleNode) children[i]).variable_declarations.size(); j++) {
                  variable_declarations.add(((SimpleNode) children[i]).variable_declarations.elementAt(j));
                }

                for (int j = 0; j < ((SimpleNode) children[i]).statements.size(); j++) {
                  statements.add(((SimpleNode) children[i]).statements.elementAt(j));
                }

                // initializing_code += "\n" + ((SimpleNode)children[i]).initializing_code;
                for (int j = 0; j < ((SimpleNode) children[i]).initializing_code.size(); j++) {
                  initializing_code.add(((SimpleNode) children[i]).initializing_code.elementAt(j));
                }
              } // if contains statements
            } // if move_up_java_statements

            // } // if ExpressionNode

						 jc.pw.println("\t\t\t// child node: " + children[i]);
						 jc.pw.println("\t\t\t// generated_java: " + generated_java);
						 jc.pw.println("\t\t\t// jc.generated_java: " + jc.generated_java);

						 if (children[i] instanceof X_SourceParameterRef) {
						 	 par_ref = jc.generated_java;
						 } else
						 if (children[i] instanceof X_AttributeRef) {
						 	attr_ref = jc.generated_java;
						 }

          } // if active
        } // if jc not null
      } // loop through all the children
      jc.generated_java = par_ref + attr_ref;
    } // if has children

    return data;
  }





}
