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

/**
 * Stratego class support for functions
 */
signature
  constructors
    PHP4Function : ClassName

strategies
    
  /**
   * Succeeds if the current term is an instance of PHP function
   */
  instanceof-PHPFunction =
    instanceof-PHP4Function

  instanceof-PHP4Function =
    classes_instanceof(|PHP4Function())

strategies

  /**
   * Constructs a new function.
   *
   * @type  _ -> Function Object
   */
  new-php4-function(|ast) =
      <classes_get-class> PHP4Function()
    ; classes_new-instance
    ; classes_set-instance-field(|"reference-ast", ast)

/**
 * Properties
 */
strategies

  /**
   * Returns the name of the function
   *
   * @type Function Object -> String
   */
  get-name = instanceof-PHP4Function;
    get-name(get-php4-function-name)
    
  get-php4-function-name =
      get-function-name
   <+ ?OldFunctionDecl(<id>, _, _)
   <+ ?OldFunctionDeclRef(<id>, _, _)
  
  /**
   * Returns the body of the function
   *
   * @type Function Object -> String
   */
  get-body = instanceof-PHP4Function;
    get-body(get-php4-function-body)
    
  get-php4-function-body =
      get-function-body
   <+ ?OldFunctionDecl(_,_,<id>)
   <+ ?OldFunctionDeclRef(_, _,<id>)

  /**
   * Returns the number of parameters of the function
   *
   * @type Function object -> Int
   */
  get-param-count = instanceof-PHP4Function;
    get-param-count(get-params)

  /**
   * Returns the parameters of the function
   *
   * @type Function object -> List(Param)
   */
  get-params = instanceof-PHP4Function;
    get-params(php4-param-match)

  php4-param-match =
       param-match
   <+ ?OldFunctionDecl(_,<id>, _)
   <+ ?OldFunctionDeclRef(_,<id>, _)