module php/reflect/common/function
imports
  php/reflect/oo/classes


strategies
  /**
   * Succeeds if the current term is an instance of PHP function
   * Since this is an abstract class there are no instances
   */
  instanceof-PHPFunction =
    fail

/**
 * Properties
 */
strategies

  /**
   * Returns the name of the function
   *
   * @type Function Object -> String
   */
  get-name(s) = instanceof-PHPFunction;
      get-reference-ast
    ; s
    
  get-function-name =
      ?FunctionDecl(<id>, _, _)
   <+ ?FunctionDeclRef(<id>, _, _)

  /**
   * Returns the body of the function
   *
   * @type Function Object -> AST 
   */
  get-body(s) = instanceof-PHPFunction;
      get-reference-ast
    ; s
    
  get-function-body =
      ?FunctionDecl(_, _, <id>)
   <+ ?FunctionDeclRef(_, _, <id>)
 
 /**
   * Returns the number of parameters of the function
   *
   * @type Function object -> Int
   */
  get-param-count(s) = instanceof-PHPFunction;
      s
    ; length
    
  /**
   * Returns the parameters of the function
   *
   * @type Function object -> List(Param)
   */
  get-params(s) = instanceof-PHPFunction;
      get-reference-ast
    ; s 

  param-match = 
      ?FunctionDecl(_,<id>, _)
   <+ ?FunctionDeclRef(_,<id>, _)

/**
 * AST representation
 */
strategies

  /** 
   * Returns the AST of the function.
   *
   * @type Function Object -> AST
   */
  get-ast = instanceof-PHPFunction;
    get-reference-ast
    
  get-reference-ast = instanceof-PHPFunction;
    classes_get-instance-field(|"reference-ast")  
    
  set-reference-ast(|refast) = instanceof-PHPFunction;
    classes_set-instance-field(|"reference-ast", refast)