/*
 * $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/
 */

// %modified: 1016210369071 %

/* Generated By:JJTree: Do not edit this line. X_IfStmt.java */
package jsdai.expressCompiler;

import java.util.*;


public class X_IfStmt
  extends StatementNode {

  // public class X_IfStmt extends SimpleNode {
  String condition_exp = "";
  int if_count = 0;
  int else_count = 0;
  String if_statements = "";
  String else_statements = "";

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

  public X_IfStmt(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;
    boolean first_time_if = true;
    boolean first_time_else = true;
    int if_current_count = 0;

    if (children != null) {

      // for contained statements
      variable_names = new Vector();
      variable_declarations = new Vector();
      statements = new Vector();
      initializing_code = new Vector();
      variable_names_tmp = new Vector();
      variable_declarations_tmp = new Vector();
      statements_tmp = new Vector();
      initializing_code_tmp = new Vector();

      // jc.java_str4 = "";
      if_statements = "";
      else_statements = "";

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

        if (jc != null) {
          if (jc.active) {
						printDDebug	("<><> if count: " + if_count + ", else count: " + else_count, jc);

            if (children[i] instanceof X_IfCondition) {
              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));
                }
              }

              condition_exp = jc.generated_java;
              jc.generated_java = "";
              // condition_exp = jc.print_string;
              // condition_exp = (String)initializing_code.elementAt(0);
            } else { // if contains statements
              if (if_current_count < if_count) {

                // statements in if part
                if_statements += ((SimpleNode)children[i]).forwarded_java;
                ((SimpleNode)children[i]).forwarded_java = "";
                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_tmp.add((( SimpleNode )children[i]).variable_names.elementAt(j));
                  }

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

                    if (first_time_if) {
											printDDebug("### IFFF 01: " + if_statements, jc);
                      if_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).variable_declarations.elementAt(j);
											printDDebug("### IFFF 02: " + if_statements, jc);
                      first_time_if = false;
                    } else {
											printDDebug("### IFFF 03: " + if_statements, jc);
                      if_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).variable_declarations.elementAt(j);
											printDDebug("### IFFF 04: " + if_statements, jc);
                    }
                  }

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

                    if (first_time_if) {
											printDDebug("### IFFF 05: " + if_statements, jc);
                      if_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).statements.elementAt(j);
											printDDebug("### IFFF 06: " + if_statements, jc);
                      first_time_if = false;
                    } else {
											printDDebug("### IFFF 07: " + if_statements, jc);
                      if_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).statements.elementAt(j);
											printDDebug("### IFFF 08: " + if_statements, jc);
                    }
                  }

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


                if_current_count++;

                if (first_time_if) {

                  //                        if_statements += jc.print_tabs + jc.print_string;
									printDDebug("### IFFF 09: " + if_statements, jc);
//                  if_statements += jc.print_string;
									if_statements += ((SimpleNode)children[i]).generated_java;
									((SimpleNode)children[i]).generated_java = "";
                  if_statements += jc.generated_java;
									printDDebug("### IFFF 10: " + if_statements, jc);
                  first_time_if = false;
 //                 jc.print_string = "";
                } else {

                  //                        if_statements += "\n" + jc.print_tabs + jc.print_string;
									printDDebug("### IFFF 11: " + if_statements, jc);
//                  if_statements += jc.print_tabs + jc.print_string;
									if_statements += jc.print_tabs + ((SimpleNode)children[i]).generated_java;
									((SimpleNode)children[i]).generated_java = "";
                  if_statements += jc.print_tabs + jc.generated_java;
									printDDebug("### IFFF 12: " + if_statements, jc);
 //                 jc.print_string = "";
                }

								printDDebug("### IFFF 13: " + if_statements, jc);
              } else {

                // statements in else part
                else_statements += ((SimpleNode)children[i]).forwarded_java;
                ((SimpleNode)children[i]).forwarded_java = "";
                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_tmp.add((( SimpleNode )children[i]).variable_names.elementAt(j));
                  }

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

                    if (first_time_else) {
                      else_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).variable_declarations.elementAt(j);
                      first_time_else = false;
                    } else {
                      else_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).variable_declarations.elementAt(j);
                    }
                  }

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

                    if (first_time_else) {
                      else_statements += "\n" + jc.print_tabs + ( String )(( SimpleNode )children[i]).statements.elementAt(j);
                      first_time_else = false;
                    } else {
                      else_statements += "\n" + jc.print_tabs + ( String )(( 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_tmp.add((( SimpleNode )children[i]).initializing_code.elementAt(j));
                  }
                } // if contains statements


                if (first_time_else) {

                  //                        else_statements += jc.print_tabs + jc.print_string;
//                  else_statements += jc.print_string;
									else_statements += ((SimpleNode)children[i]).generated_java;
									((SimpleNode)children[i]).generated_java = "";
                  else_statements += jc.generated_java;
                  first_time_else = false;
//                  jc.print_string = "";
                } else {

                  //                        else_statements += "\n" + jc.print_tabs + jc.print_string;
//                  else_statements += jc.print_tabs + jc.print_string;
									else_statements +=  jc.print_tabs + ((SimpleNode)children[i]).generated_java;
									((SimpleNode)children[i]).generated_java = "";
                  else_statements += jc.print_tabs + jc.generated_java;
//                  jc.print_string = "";
                }
              }
            } // not X_IfCondition


						printDDebug("### IFFF 14: " + if_statements, jc);
          }
        }
      }

      // System.out.println("### IFFF 14: " + if_statements);
    }

    return data;
  }
}
