/*
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

package cx2x.xcodeml.xelement;

import org.w3c.dom.Element;
import cx2x.xcodeml.helper.*;

/**
 * The XfunctionCall represents the functionCall (7.5.1) element in XcodeML
 * intermediate representation.
 *
 * Elements: ( name, arguments? )
 * - Required:
 *   - name (Xname)
 * - Optional:
 *   - arguments (XargumentsTable)
 * Attribute:
 * - Optional: type (text), is_intrinsic (bool)
 *
 * @author clementval
 */

public class XfunctionCall extends XbaseElement {
  // Elements
  private XargumentsTable _arguments = null;
  private Xname _name = null;

  // Attributes
  private boolean _isInstrinsic = false;
  private String _type = null;

  /**
   * Xelement standard ctor. Pass the base element to the base class and read
   * inner information (elements and attributes).
   * @param baseElement The root element of the Xelement
   */
  public XfunctionCall(Element baseElement){
    super(baseElement);

    // Read attributes
    _isInstrinsic = XelementHelper.getBooleanAttributeValue(this,
      XelementName.ATTR_IS_INTRINSIC);
    _type = XelementHelper.getAttributeValue(this,
      XelementName.ATTR_TYPE);

    // Read element
    _arguments = XelementHelper.findArgumentsTable(this, false);
    _name = XelementHelper.findName(this, false);
  }

  /**
   * Check whether the function is an intrinsic function.
   * @return True if the fct is intrinsic. False otherwise.
   */
  public boolean isIntrinsic(){
    return _isInstrinsic;
  }


  /**
   * Set the value if the is_instrinsic attribute.
   * @param value boolean value of the attribute.
   */
  public void setIntrinsic(boolean value){
    if(value){
      baseElement.setAttribute(XelementName.ATTR_IS_INTRINSIC,
          XelementName.TRUE);
    } else {
      baseElement.setAttribute(XelementName.ATTR_IS_INTRINSIC,
          XelementName.FALSE);
    }
  }

  /**
   * Get the function type.
   * @return Type of the function as a String value.
   */
  public String getType(){
    return _type;
  }

  /**
   * Set the value of the type attribute.
   * @param type New value to be set.
   */
  public void setType(String type){
      baseElement.setAttribute(XelementName.ATTR_TYPE, type);
  }

  /**
   * Get the function's arguments table.
   * @return A XargumentsTable object containing the function's arguments.
   */
  public XargumentsTable getArgumentsTable(){
    return _arguments;
  }

  /**
   * Get the function name.
   * @return Name of the function as an Xname object.
   */
  public Xname getName(){
    return _name;
  }
}

@@ -126,16 +126,103 @@
 ement;%0A%0A
+import cx2x.xcodeml.exception.IllegalTransformationException;%0Aimport exc.object.Xcode;%0A
 import o
@@ -645,17 +645,57 @@
 eElement
- 
+%0A    implements Xclonable%3CXfunctionCall%3E%0A
 %7B%0A  // E
@@ -1133,16 +1133,141 @@
 ement);%0A
+    readElementInformation();%0A  %7D%0A%0A  /**%0A   * Read inner elements information.%0A   */%0A  private void readElementInformation()%7B
 %0A    // 
@@ -1346,32 +1346,34 @@
 lue(this,%0A      
+  
 XelementName.ATT
@@ -1442,24 +1442,26 @@
 this,%0A      
+  
 XelementName
@@ -2872,10 +2872,1215 @@
 me;%0A  %7D%0A
+%0A%0A  /**%0A   * Create a new functionCall element with the given function name.%0A   * @param returnType Return type value.%0A   * @param name       Name of the function to be inserted in the %22name%22%0A   *                   element.%0A   * @param nameType   Type of the function name.%0A   * @return A new XfunctionCall object with the given name and an empty%0A   * arguments' table%0A   */%0A  public static XfunctionCall create(XcodeProgram xcodeml, String returnType,%0A                                     String name, String nameType)%0A      throws IllegalTransformationException%0A  %7B%0A    XfunctionCall fctCall =%0A        XelementHelper.createEmpty(XfunctionCall.class, xcodeml);%0A    fctCall.setType(returnType);%0A    Xname fctName = XelementHelper.createEmpty(Xname.class, xcodeml);%0A    fctName.setValue(name);%0A    fctName.setType(nameType);%0A    XargumentsTable args =%0A        XelementHelper.createEmpty(XargumentsTable.class, xcodeml);%0A    fctCall.appendToChildren(fctName, false);%0A    fctCall.appendToChildren(args, false);%0A    fctCall.readElementInformation();%0A    return fctCall;%0A  %7D%0A%0A  @Override%0A  public XfunctionCall cloneObject() %7B%0A    Element clone = (Element)cloneNode();%0A    return new XfunctionCall(clone);%0A  %7D%0A
 %7D%0A

Implement clonable and create methods