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

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

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


public class X_PowerOp extends SimpleNode {
  int op_count = 0;
	int[] operations;
	String[] operands;
  int[] operand_types;
  EEntity[] exact_operand_types;

  public X_PowerOp(int id) {
    super(id);

    operations = new int[2];
    operands = new String[2];
    operand_types = new int[2];
    exact_operand_types = new EEntity[2];

    op_count = 0;
  }

  public X_PowerOp(Compiler2 p, int id) {
    super(p, id);
    operations = new int[2];
    operands = new String[2];
    operand_types = new int[2];
    exact_operand_types = new EEntity[2];
    op_count = 0;
  }

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

  /** Accept the visitor. **/
  public Object childrenAccept(Compiler2Visitor visitor, Object data)
                        throws SdaiException {
    JavaClass jc = (JavaClass) data;
    String op_type_str = "default";
    String operator_str = "DefaultPowerOp";
    String cast_1 = "";
    String cast_2 = "";
    int operand_1_type;
    int operand_2_type;
    int result_type = 0;
    EEntity exact_result_type = null;

    if (jc.flag_value) {
      if (children != null) {
        // additional java code forwarded, if present
        variable_names = new Vector();
        variable_declarations = new Vector();
        statements = new Vector();
        initializing_code = new Vector();

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

          if (jc != null) {
            if (jc.active) {
              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 (children[i] instanceof X_IndexQualifier) {
                operands[op_count - 1] += jc.generated_java;
              } else if (children[i] instanceof X_AttributeQualifier) {
                operands[op_count - 1] += jc.generated_java;
              } else if (children[i] instanceof X_GroupQualifier) {
                operands[op_count - 1] += jc.generated_java;
              } else {
                operands[op_count] = jc.generated_java;
                op_count++;
              }


              //							System.out.println("CHILDREN: " +children[i] +"  count: " +op_count);
              printActive("XP In PoweOP, operand: " + i + ", value: " + jc.generated_java, jc);

              //              operand_types[i] = jc.type_of_operand; // may be no longer needed
              //               if (jc.type_of_operand >= JavaClass.T_AGGREGATE) { // may be no longer needed
              //                 exact_operand_types[i] = jc.type_of_aggregate; // may be no longer needed
              //               }
              jc.generated_java = "";
            } // jc active
          } // jc not null
        } // for - loop through children
      } // if children

      if (jc != null) {
        if (jc.active) {
          jc.generated_java = operands[0];

          for (int i = 0; i < (op_count - 1); ++i) {
            operator_str = "exponent";

            String value_instance_string;
            String alloc_type_str;

            //                if ((jc.flag_alloc_type) && ((jc.alloc_type_depth + 1) == jc.indent) && (i == children.length-2)) {
            if ((jc.flag_alloc_type) && ((jc.alloc_type_depth + 1) == jc.indent) && 
                    (i == op_count - 2)) {
              alloc_type_str = jc.alloc_type;
              jc.flag_alloc_type = false;
              jc.alloc_type = "";
            } else {
              alloc_type_str = "ExpressTypes.GENERIC_TYPE";
            }

            //                if ((jc.flag_non_temporary_value_instance) && ((jc.assignment_depth + 1) == jc.indent) && (i == children.length-2)) {
            if ((jc.flag_non_temporary_value_instance) && 
                    ((jc.assignment_depth + 1) == jc.indent) && (i == op_count - 2)) {
              // if ((jc.flag_non_temporary_value_instance) && ((jc.assignment_depth + 1) == jc.indent)) {
              value_instance_string = jc.value_instance;
              jc.flag_non_temporary_value_instance = false;
              jc.value_instance = "";
            } else {
              value_instance_string = "Value.alloc(" + alloc_type_str + ").";
            }

            jc.generated_java = value_instance_string + operator_str + "(_context, " + jc.generated_java + 
                                ", " + operands[i + 1] + ")";
          } // for children
        } // if active
      } // if jc not null
    } else { // old stuff - not value

      // no old stuff here, replaced directly
    } // if not value

    if (jc != null) {
      if (jc.active) {
        jc.type_of_operand = result_type;
      }
    }

    // } // if not value
    return data;
  }
}
