module php/reflect/version4/class
imports
  php/reflect/oo/classes

/**
 * Stratego class support for class
 */
signature
  constructors
    PHP4Class : ClassName

strategies

  /**
   * Succeeds if the current term is an instance of PHP Class
   */
  instanceof-PHPClass =
    instanceof-PHP4Class

  instanceof-PHP4Class =
    classes_instanceof(|PHP4Class())

strategies

  /**
   * Constructs a new Class.
   *
   * @type  _ -> Class Object
   */
  new-php4-class(|ast) =
    { this :
      <classes_get-class> PHP4Class()
    ; classes_new-instance
    ; ?this
    ; classes_set-instance-field(|"reference-ast", ast)
    ; classes_set-instance-field(|"classes-table" , <new-hashtable>)
    ; classes_set-instance-field(|"function-table", <new-hashtable>)
    ; classes_set-instance-field(|"function-table", <new-hashtable>)
    ; <add-php4-function-objects(|this)> ast
    ;!this
    }

  add-php4-function-objects(|this) =
     collect-all(match-php4-function-decl)
    ; map({ast, fun:
        ?ast 
        ; fun := <new-php4-function(|ast)>
        ; <add-function(|fun)> this
      })

/**
 * Properties
 */
strategies

  /**
   * Returns the name of the class
   *
   * @type Class Object -> String
   */
  get-name = instanceof-PHP4Class;
    get-name(get-php4-class-name)
    
  get-php4-class-name =
      get-class-name
      
  /**
   * Returns the name of the class
   * it extends (if any)
   *
   * @type Class Object -> String
   */
  get-extends = instanceof-PHP4Class;
    get-extends(get-php4-extends-name)
    
  get-php4-extends-name =
      get-extends-name

  /**
   * Returns the instance-variables of this class
   *
   * @type Class Object -> List(InstanceVariable)
   */
  get-instance-variables = instanceof-PHP4Class;
    get-instance-variables(match-php4-instance-variable)

  match-php4-instance-variable =
    match-instance-variable
    
strategies
   /**
    * Returns the function object of the constructor of
    * this class.
    *
    * @type PHP4Class Object -> Function Object
    */
    get-class-constructor = instanceof-PHP4Class;
     (( ?class
     ; name := <get-name> class
     ; ((<get-function(|name)> class)
       <+
       ( parent := <get-class-parent> class
       ; <get-function(|name)> parent
       ))
     )
     <+
     ( get-class-parent
     ; get-class-constructor
     ))