/*
 * $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: 1016210367142 %

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

import jsdai.lang.*;


public class X_IncrementControl extends StatementNode { // what is it?

  // public class X_IncrementControl extends SimpleNode {
  String variable_id;
  String variable_uid;
  String variable_scope_id;
  boolean increment_present = false;
  String bound1_str;
  String bound2_str;
  String increment_str;
  String java_str;

  public X_IncrementControl(int id) {
    super(id);
    increment_present = false;
  }

  public X_IncrementControl(Compiler2 p, int id) {
    super(p, id);
    increment_present = false;
  }

	public String getVariable_uid() {
		return variable_uid;
	}


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

  public Object childrenAccept(Compiler2Visitor visitor, Object data)
                        throws SdaiException {
    JavaClass jc = (JavaClass) data;

		int i_bound1 = 0;
		int i_bound2 = 1;
		int i_increment = 2;
		
		int ix [] = new int[5];
	  ix[0] = 0;
	  ix[1] = 1;
	  ix[2] = 2;
	  ix[3] = 3;
	  ix[4] = -55;

    if (jc != null) {
      if (jc.active) {
        // integer case
        //            jc.java_str4 = variable_id + "++";
        // Value case:
        //        jc.java_str4 = variable_id + ".inc()";
        jc.java_str4 = variable_uid + ".inc()";
      }
    }




    if (children != null) {
      // jc.java_str4 = "";
      for (int i = 0, j = -1; i < children.length; ++i) {
          if ((children[i] instanceof X_GroupQualifier) ||
              (children[i] instanceof X_AttributeQualifier) ||
              (children[i] instanceof X_IndexQualifier)) {
   					// the same continues
   					
   					if (j == 0) {
   						ix[0] = i;
   					  ix[1] = i+1;
   					  ix[2] = i+2;
   					} else
   					if (j == 1) {
   						ix[1] = i;
   						ix[2] = i + 1;
   					} else 
   					if (j == 2) {
   						ix[2] = i;
   					} else {
   					}

   				} else {
   					// a new thing
   					j++;
   					
 
   					if (j == 0) {
   						ix[0] = i;
   					  ix[1] = i+1;
   					  ix[2] = i+2;
   					} else
   					if (j == 1) {
   						ix[1] = i;
   						ix[2] = i + 1;
   					} else 
   					if (j == 2) {
   						ix[2] = i;
   					} else {
   					}
   				}
   				
   					
 				
			} // for 

		} // if
    
 // ix hold points of beginning, we need points of ending 
    
    i_bound1 = ix[0];
    i_bound2 = ix[1];
    i_increment = ix[2];

//    if (ix[4] != -55) {
//    	// somethig wrong
//			System.out.println("ERROR in increment control");
//    }
    
    
// System.out.println("--XX-- i_bound1: " + i_bound1 + ", i_bound2: " + i_bound2 + ", i_increment: " + i_increment);    
    
    if (children != null) {
      jc.java_str4 = ""; // why was it commented out?
      for (int i = 0; i < children.length; ++i) {
        children[i].jjtAccept(visitor, data);

        if (jc != null) {
          if (jc.active) {
            printDDebug("XPOORR B0 in increment control: " + children[i], jc);

            if (((SimpleNode) children[i]).java_contains_statements) {
              java_contains_statements = true;
              printDDebug("XPOORR B2: " + java_contains_statements, jc);

              // 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));
// System.out.println("XYX-1: " + ((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));
// System.out.println("XYX-2: " + ((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));
// System.out.println("XYX-3: " + ((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));
// System.out.println("XYX-4: " + ((SimpleNode) children[i]).initializing_code.elementAt(j));
              }
            }

            if (i == i_bound1) {
              // int case
              //                     jc.java_str2 = "int " + variable_id + "=" + jc.generated_java;
              // Value case
              if ((jc.variable_ids != null) && (variable_id != null)) {
                //									if (jc.variable_ids.contains(variable_id.toLowerCase())) {
                //											jc.java_str2 = variable_id + "=" + jc.generated_java;
                //									} else {
                //											jc.java_str2 = "Value " + variable_id + "=" + jc.generated_java;
                jc.java_str2 = "Value " + variable_uid + "=" + jc.generated_java;

                //									}
              } else if (variable_id != null) { // only implicit variable declared
                jc.java_str2 = "Value " + variable_uid + "=" + jc.generated_java;

                //									System.out.println("Warning: null encountered, jc.variable_ids: " +jc.variable_ids +" variable_id: " +variable_id);
              }
            } else if (i == i_bound2) {
              // int case
              //                      jc.java_str3 = variable_id + "<=" + jc.generated_java;
   	           // Value case
              //              jc.java_str3 = "Value.alloc(ExpressTypes.LOGICAL_TYPE).lequal(" + variable_id + ", " + jc.generated_java + ").getLogical() == 2";

// old
//              jc.java_str3 = "Value.alloc(ExpressTypes.LOGICAL_TYPE).lequal(_context, " + variable_uid + ", " + jc.generated_java + ").getLogical() == 2";
								jc.java_str3 = jc.generated_java;

              //              jc.java_str3 = "Value.lequal(" + variable_id + ", " + jc.generated_java + ") == 2";
            } else if (i == i_increment) {
              if (increment_present) {
                // int case - but increment is probably Value, so not correct
                //                        jc.java_str4 = variable_id + "+=" + jc.generated_java;
                // Value case
                //                jc.java_str4 = variable_id + ".inc(" + jc.generated_java + ")";
// old
//                jc.java_str4 = variable_uid + ".inc(" + jc.generated_java + ")";
									jc.java_str4 = jc.generated_java;

              } else {
                // int case
                //                        jc.java_str4 = variable_id + "++";
                // Value case
                //                jc.java_str4 = variable_id + ".inc()";
// old
//                jc.java_str4 = variable_uid + ".inc()";
									jc.java_str4 = "";
              }
            }
          }
        }
      }
    }

    return data;
  }
}
