Changeset 543

Show
Ignore:
Timestamp:
06/06/08 10:54:03 (7 months ago)
Author:
weyrick
Message:

implement unsetting of object properties. because of the way we implement properties,
this required overhead for each property lookup, which needs to be refactored out
when this gets optimized.

Location:
trunk/pcc
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pcc/compiler/evaluate.scm

    r541 r543  
    873873                ; always return null 
    874874                NULL) 
    875              ; normal unset 
    876              (%unset-eval-assign lval))))) 
     875             ; unset (remove) property 
     876             (php-object-property-unset obj-e prop-e))))) 
    877877 
    878878(define-method (unset lval::hash-lookup) 
  • trunk/pcc/compiler/generate.scm

    r541 r543  
    17881788                       (php-object-class obj-evald) 
    17891789                       "__unset") 
    1790                       ; we call __isset when the caller doesn't have visibility access 
     1790                      ; we call __unset when the caller doesn't have visibility access 
    17911791                      ; (whether it's actually declared for real or not) or when it 
    17921792                      ; would have visibility but it's not declared 
     
    17961796                                 ,the-property)))) 
    17971797                 (convert-to-boolean (call-php-method-1 obj-evald "__unset" ,the-property)) 
    1798                  ; normal isset 
    1799                  ,(update-value lval ''())))))) 
     1798                 ; unset (remove) property 
     1799                 (php-object-property-unset obj-evald ,the-property)))))) 
    18001800 
    18011801;;;;isset 
  • trunk/pcc/runtime/php-object.scm

    r514 r543  
    6464    (php-class-props class-name) 
    6565    (php-object-has-declared-property? obj::struct property::bstring) 
     66    (php-object-property-unset obj::struct property::bstring) 
    6667    (php-object-property/index obj::struct property::int property-name) 
    6768    (php-object-property/string obj property::bstring access-type) 
     
    295296                      (prop-key (hashtable-get offsets-table i))) 
    296297                   ; if it's not in offsets table, it's a static and we skip it 
    297                    (when prop-key 
     298                   (when (and prop-key (not (eqv? prop-value 'prop-unset))) 
    298299                      (php-hash-insert! property-hash 
    299300                                        prop-key 
     
    322323;              (fprint (current-error-port) "ref-status is " (mkstr (container-reference? prop-value))) 
    323324               ; if we don't have prop key, it's a static and we skip it 
    324                (when prop-key 
     325               (when (and prop-key (not (eqv? prop-value 'prop-unset))) 
    325326                  (thunk ;note the reverse lookup to get the name 
    326327                   (mkstr prop-key) 
     
    349350                         (prop-key (hashtable-get offsets-table i))) 
    350351                      ; if it's not in offsets table, it's a static and we skip it 
    351                       (when prop-key 
     352                      (when (and prop-key (not (eqv? prop-value 'prop-unset)))                 
    352353                         (php-hash-insert! property-hash 
    353354                                           ;note the reverse lookup to get the name 
     
    586587                                                      (%property-name-canonicalize property-name)) 
    587588                                       property)) 
     589 
     590   ; XXX check for 'prop-unset ? 
    588591   (vector-ref (%php-object-properties obj) property) 
    589592    
     
    15431546;;;;the actual property looker-uppers 
    15441547 
     1548(define (php-object-property-unset obj::struct property::bstring) 
     1549   "remove the property from the object, only available via unset()" 
     1550   (if (php-object? obj) 
     1551       (let* ((canon-name (%property-name-canonicalize property)) 
     1552              (offset (%prop-offset obj canon-name 'all))) 
     1553          ; first check declared 
     1554          (when offset 
     1555              ; we can't remove it since the classes offset hash will still point 
     1556              ; here (and needs to for other instances) so we set it to a special value 
     1557              (vector-set! (%php-object-properties obj) offset 'prop-unset)) 
     1558          ; check extended 
     1559          (when (php-hash-contains? (%php-object-extended-properties obj) canon-name) 
     1560             (php-hash-remove! (%php-object-extended-properties obj) canon-name)) 
     1561          NULL))) 
     1562 
    15451563(define (php-object-has-declared-property? obj::struct property::bstring) 
    15461564   "see if the object has the specified declared property, regardless of visibility" 
     
    15561574      (if offset 
    15571575          ; declared 
    1558           (vector-ref (%php-object-properties obj) offset) 
     1576          (let ((val (vector-ref (%php-object-properties obj) offset))) 
     1577             (if (eqv? val 'prop-unset) 
     1578                 NULL 
     1579                 val)) 
    15591580          ; not declared. maybe use __get 
    15601581          (let ((get-method (%lookup-method (%php-object-class obj) "__get"))) 
     
    15731594      (if offset 
    15741595          ; declared 
    1575           (container-value (vector-ref (%php-object-properties obj) offset)) 
     1596          (let ((val (vector-ref (%php-object-properties obj) offset))) 
     1597             (if (eqv? val 'prop-unset) 
     1598                 NULL 
     1599                 (container-value val))) 
    15761600          ; not declared. maybe use __get 
    15771601          (let ((get-method (%lookup-method (%php-object-class obj) "__get")))