package x2x.translator.xcodeml.xelement;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * The Xbound represents the lowerBound and upperBound (8.12, 8.13) element in
 * XcodeML intermediate representation.
 *
 * Elements:
 * - exprModel TODO move to exprModel
 */

// TODO have a derived class for upper and lower bound

public class Xbound {
  private String _value = null;
  private boolean _constant = false;
  private boolean _var = false;
  private Element _boundElement = null;

  public Xbound(Element boundElement){
    _boundElement = boundElement;
    readRangeValue();
  }

  public boolean isContant(){
    return _constant;
  }

  public boolean isVar(){
    return _var;
  }

  public String getValue(){
    return _value;
  }

  private void readRangeValue(){
    Element constant = XelementHelper
      .findFirstElement(_boundElement, XelementName.INT_CONST);
    Element var = XelementHelper
      .findFirstElement(_boundElement, XelementName.VAR);
    if(constant != null){
      _constant = true;
      _value = constant.getTextContent();
    } else if(var != null){
      _var = true;
      _value = var.getTextContent();
    }
  }


  @Override
  public boolean equals(Object ob) {
    if (ob == null) return false;
    if (ob.getClass() != getClass()) return false;
    Xbound other = (Xbound)ob;

    if(isVar() != other.isVar()){
      return false;
    }

    if(isContant() != isContant()){
      return false;
    }

    if (!getValue().toLowerCase().equals(other.getValue())){
      return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    return _value.hashCode();
  }

}

@@ -441,17 +441,19 @@
 oolean _
-v
+isV
 ar = fal
@@ -495,16 +495,44 @@
  = null;
+%0A  private Xvar _var = null;
 %0A%0A  publ
@@ -720,17 +720,19 @@
 return _
-v
+isV
 ar;%0A  %7D%0A
@@ -784,16 +784,134 @@
 e;%0A  %7D%0A%0A
+  public String getType()%7B%0A    if(isVar() && _var != null) %7B%0A      return _var.getType();%0A    %7D%0A    return null;%0A  %7D%0A%0A
   privat
@@ -1255,17 +1255,19 @@
 %0A      _
-v
+isV
 ar = tru
@@ -1261,32 +1261,60 @@
  _isVar = true;%0A
+      _var = new Xvar(var);%0A
       _value = v

Add access to type if it's a var