package x2x.translator.xcodeml.xelement;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * The XfctType represents the FfunctionType (3.4) element in XcodeML
 * intermediate representation.
 *
 * Elements:
 * - Optional:
 *   - params TODO
 * Attributes:
 * - Required: type (text), return_type (text)
 * - Optional: result_name (text), is_recursive (bool), is_program (bool),
 *   is_internal (bool)
 */

public class XfctType extends Xtype implements Xclonable<XfctType> {

  private String _returnType = null;
  private boolean _isProgram = false;

  // attributes
  private String _result_name = null;
  private boolean _is_recursive = false;
  private boolean _is_program = false;
  private boolean _is_internal = false;

  public XfctType(Element element){
    super(element);
    readFctTypeInformation();
  }

  private void readFctTypeInformation(){
    _returnType = XelementHelper.getAttributeValue(baseElement,
      XelementName.ATTR_RETURN_TYPE);

    String value = XelementHelper.getAttributeValue(baseElement,
      XelementName.ATTR_IS_PROGRAM);

    if(value != null && value.equals(XelementName.TRUE)){
      _isProgram = true;
    }

    // TODO read parameters as Xname element

    // read optional attributes
    _result_name = XelementHelper.getAttributeValue(baseElement,
      XelementName.ATTR_RESULT_NAME);
    _is_recursive = XelementHelper.getBooleanAttributeValue(baseElement,
      XelementName.ATTR_IS_RECURSIVE);
    _is_program = XelementHelper.getBooleanAttributeValue(baseElement,
        XelementName.ATTR_IS_PROGRAM);
    _is_internal = XelementHelper.getBooleanAttributeValue(baseElement,
        XelementName.ATTR_IS_INTERNAL);
  }

  public String getReturnType(){
    return _returnType;
  }

  public boolean isProgram(){
    return _isProgram;
  }

  public XfctType cloneObject(){
    Node clone = clone();
    return new XfctType((Element)clone);
  }

}

@@ -522,51 +522,22 @@
 ll;%0A
+%0A
   
-private boolean _isProgram = false;%0A%0A  //
+// optional
  att
@@ -564,26 +564,25 @@
 ring _result
-_n
+N
 ame = null;%0A
@@ -598,26 +598,25 @@
  boolean _is
-_r
+R
 ecursive = f
@@ -638,26 +638,25 @@
  boolean _is
-_p
+P
 rogram = fal
@@ -676,26 +676,25 @@
  boolean _is
-_i
+I
 nternal = fa
@@ -1212,26 +1212,25 @@
 %0A    _result
-_n
+N
 ame = Xeleme
@@ -1314,18 +1314,17 @@
 %0A    _is
-_r
+R
 ecursive
@@ -1425,18 +1425,17 @@
 %0A    _is
-_p
+P
 rogram =
@@ -1534,18 +1534,17 @@
 %0A    _is
-_i
+I
 nternal 
@@ -1639,24 +1639,208 @@
 RNAL);%0A  %7D%0A%0A
+  public String getResultName()%7B%0A    return _resultName;%0A  %7D%0A%0A  public boolean isRecursive()%7B%0A    return _isRecursive;%0A  %7D%0A%0A  public boolean isInternal()%7B%0A    return _isInternal;%0A  %7D%0A%0A
   public Str

Add accessor and unify typo