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

package cx2x.xcodeml.xnode;

import org.w3c.dom.Element;

/**
 * The XfunctionDefinition represents the FfunctionDefinition (5.3) element in
 * XcodeML intermediate representation.
 *
 * Elements: (name, symbols?, params?, declarations?, body)
 * - Required:
 *   - name (text)
 *   - body (Xbody)
 * - Optional:
 *   - symbols (XsymbolTable)
 *   - params  (Xparams)
 *   - declarations (XdeclTable)
 *
 * Can have lineno and file attributes
 *
 * @author clementval
 */

public class XfunctionDefinition extends Xnode {

  // Elements
  private XsymbolTable _symbolTable = null;
  private Xnode _params = null;
  private XdeclTable _declTable = null;
  private Xnode _body = null;
  private Xnode _name = null;

  /**
   * Element standard ctor. Pass the base element to the base class and read
   * inner information (elements and attributes).
   * @param baseElement The root of the element.
   */
  public XfunctionDefinition(Element baseElement){
    super(baseElement);
    Xnode symbols = find(Xcode.SYMBOLS);
    _symbolTable = (symbols != null) ? new XsymbolTable(symbols.getElement())
        : null;
    Xnode declarations = find(Xcode.DECLARATIONS);
    _declTable = (declarations != null) ?
        new XdeclTable(declarations.getElement()) : null;
    _params = find(Xcode.PARAMS);
    _body = find(Xcode.BODY);
    _name = find(Xcode.NAME);
  }

  /**
   * Get the function's symbols table.
   * @return A XsymbolTable object containing the function's symbols.
   */
  public XsymbolTable getSymbolTable(){
    return _symbolTable;
  }

  /**
   * Get the function's declarations table.
   * @return A XdeclTable object containing the function's declarations.
   */
  public XdeclTable getDeclarationTable(){
    return _declTable;
  }

  /**
   * Get the function's body.
   * @return A Xbody object for the function.
   */
  public Xnode getBody(){
    return _body;
  }

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

  /**
   * Get the parameters list.
   * @return Parameters list.
   */
  public Xnode getParams(){
    return _params;
  }

  /**
   * Create an identical copy of the current function definition.
   * @return A new XfunctionDefinition object that is the clone of this function definition.
   */
  public XfunctionDefinition cloneObject(){
    Element clone = (Element)cloneNode();
    return new XfunctionDefinition(clone);
  }
}

@@ -641,16 +641,22 @@
 private 
+final 
 XsymbolT
@@ -668,31 +668,24 @@
 _symbolTable
- = null
 ;%0A  private 
@@ -680,24 +680,30 @@
 ;%0A  private 
+final 
 Xnode _param
@@ -703,23 +703,16 @@
  _params
- = null
 ;%0A  priv
@@ -715,16 +715,22 @@
 private 
+final 
 XdeclTab
@@ -742,23 +742,16 @@
 eclTable
- = null
 ;%0A  priv
@@ -750,24 +750,30 @@
 ;%0A  private 
+final 
 Xnode _body 
@@ -771,23 +771,16 @@
 de _body
- = null
 ;%0A  priv
@@ -783,16 +783,22 @@
 private 
+final 
 Xnode _n
@@ -804,15 +804,8 @@
 name
- = null
 ;%0A%0A 
@@ -1115,23 +1115,14 @@
     
-_symbolTable = 
+assert
 (sym
@@ -1134,18 +1134,36 @@
 != null)
- ?
+;%0A    _symbolTable =
  new Xsy
@@ -1197,23 +1197,8 @@
 t())
-%0A        : null
 ;%0A  
@@ -1254,21 +1254,14 @@
     
-_declTable = 
+assert
 (dec
@@ -1282,18 +1282,26 @@
 ull)
- ?%0A       
+;%0A    _declTable =
  new
@@ -1342,15 +1342,8 @@
 t())
- : null
 ;%0A  
@@ -1434,16 +1434,70 @@
 .NAME);%0A
+    assert(_name != null);%0A    assert(_body != null);%0A
   %7D%0A%0A  /

Add assertion