Changeset 78
- Timestamp:
- 08/05/07 02:57:38 (17 months ago)
- Location:
- trunk/pcc
- Files:
-
- 5 modified
-
compiler/ast.scm (modified) (1 diff)
-
compiler/evaluate.scm (modified) (1 diff)
-
compiler/generate.scm (modified) (1 diff)
-
compiler/parser.scm (modified) (2 diffs)
-
runtime/php-object.scm (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pcc/compiler/ast.scm
r39 r78 110 110 name 111 111 value 112 static?) 112 static? 113 visibility) 113 114 (final-class method-decl::declaration 114 115 name -
trunk/pcc/compiler/evaluate.scm
r39 r78 750 750 (if (null? (property-decl-value prop)) 751 751 (make-container '()) 752 (d/evaluate (property-decl-value prop)))))) 752 (d/evaluate (property-decl-value prop))) 753 (property-decl-visibility prop)))) 753 754 754 755 ;; PHP5 class constants -
trunk/pcc/compiler/generate.scm
r39 r78 782 782 ; (get-location (property-decl-value prop)) 783 783 ''() 784 (get-value (property-decl-value prop)) 785 )) 784 (get-value (property-decl-value prop))) 785 ',(property-decl-visibility prop) 786 ) 786 787 code))) 787 788 (php-hash-for-each class-constants -
trunk/pcc/compiler/parser.scm
r39 r78 234 234 ((class-function) class-function) 235 235 ((varkey class-vars semi) class-vars) 236 ;; XXX public, private, and protected don't do anything yet 236 ((public class-vars semi) 237 (parse-require-php5) 238 class-vars) 237 239 ((private class-vars semi) 238 240 (parse-require-php5) 239 class-vars) 240 ((public class-vars semi) 241 (parse-require-php5) 242 class-vars) 241 (map (lambda (c) (property-decl-visibility-set! c 'private) c) class-vars)) 243 242 ((protected class-vars semi) 244 243 (parse-require-php5) 245 class-vars)244 (map (lambda (c) (property-decl-visibility-set! c 'protected) c) class-vars)) 246 245 ((static class-vars semi) 247 246 (parse-require-php5) … … 254 253 (class-var 255 254 ((var equals decl-literal) 256 (make-property-decl *parse-loc* var decl-literal #f ))255 (make-property-decl *parse-loc* var decl-literal #f 'public)) 257 256 ((var) 258 (make-property-decl *parse-loc* var '() #f )))257 (make-property-decl *parse-loc* var '() #f 'public))) 259 258 260 259 (decl-literal -
trunk/pcc/runtime/php-object.scm
r51 r78 72 72 (construct-php-object-sans-constructor class-name) 73 73 (get-declared-php-classes) 74 (define-php-property class-name property-name value )75 (define-php-method class-name method-name method) 74 (define-php-property class-name property-name value visibility) 75 (define-php-method class-name method-name method) 76 76 (define-class-constant class-name constant-name value) 77 77 (lookup-class-constant class-name constant-name))) … … 100 100 ;;a hashtable mapping names of declared properties to an index in a property vector 101 101 declared-property-offsets 102 ;;properties is a vector of properties102 ;;properties is a vector of all properties (which points to actual php data) 103 103 properties 104 ;; a list of protected properties (unmangled) 105 protected-properties 106 ;; a list of private properties (unmangled) 107 private-properties 104 108 ;;extended properties is either #f or a php-hash of non-declared properties 105 109 extended-properties … … 592 596 #f)))) 593 597 594 ; XXX update for PHP5595 598 (define (%class-name-canonicalize name) 596 599 "define class names as case-insensitive strings" 597 ; (string->symbol598 600 (string-downcase (mkstr name))) 599 ;))600 601 601 602 ; XXX update for PHP5 … … 625 626 ;define the root of the class hierarchy 626 627 (let ((stdclass (%php-class "stdClass" "stdclass" #f #f 627 (make-hashtable) (make-vector 0) 628 (make-hashtable) (make-vector 0) '() '() 628 629 (make-php-hash) (make-php-hash) 629 630 #f #f #f (make-php-hash))) 630 631 (inc-class (%php-class "__PHP_Incomplete_Class" "__php_incomplete_class" #f #f 631 (make-hashtable) (make-vector 0) 632 (make-hashtable) (make-vector 0) '() '() 632 633 (make-php-hash) (make-php-hash) 633 634 #f #f #f (make-php-hash)) )) … … 636 637 (hashtable-put! %php-class-registry "__php_incomplete_class" inc-class))) 637 638 639 ;; XXX this is in newer versions of bigloo, yank it when we upgrade 640 (define (list-copy list) 641 (if (null? list) 642 '() 643 (cons (car list) 644 (list-copy (cdr list))))) 638 645 639 646 (define (define-php-class name parent-name) … … 646 653 (php-error "Defining class " name ": unable to find parent class " parent-name)) 647 654 (let* ((canonical-name (%class-name-canonicalize name)) 648 (new-class (%php-class (string-downcase (mkstr name)) 655 (new-class (%php-class (if PHP5? 656 (mkstr name) 657 (string-downcase (mkstr name))) 649 658 canonical-name 650 659 parent-class … … 653 662 (%php-class-declared-property-offsets parent-class)) 654 663 (copy-properties-vector (%php-class-properties parent-class)) 664 '() ; private props 665 (list-copy (%php-class-protected-properties parent-class)) 655 666 (copy-php-data (%php-class-extended-properties parent-class)) 656 667 (copy-php-data (%php-class-methods parent-class)) … … 715 726 method)))) 716 727 717 (define (define-php-property class-name property-name value) 728 (define (mangle-property-private prop) 729 "mangle given property string to private visibility" 730 (mkstr prop ":private")) 731 732 (define (mangle-property-protected prop) 733 "mangle given property string to protected visibility" 734 (mkstr prop ":protected")) 735 736 (define (%property-name-mangle name visibility) 737 (cond 738 ((eqv? 'public visibility) 739 name) 740 ((eqv? 'private visibility) 741 (mangle-property-private name)) 742 ((eqv? 'protected visibility) 743 (mangle-property-protected name)))) 744 745 (define (define-php-property class-name property-name value visibility) 718 746 (let ((the-class (%lookup-class class-name))) 719 747 (unless the-class … … 721 749 (let* ((properties (%php-class-properties the-class)) 722 750 (offset (vector-length properties)) 723 (canonical-name (%property-name-canonicalize property-name))) 724 (aif (hashtable-get (%php-class-declared-property-offsets the-class) canonical-name) 751 (canonical-name (%property-name-canonicalize property-name)) 752 (mangled-name (%property-name-mangle canonical-name visibility))) 753 (aif (hashtable-get (%php-class-declared-property-offsets the-class) mangled-name) 725 754 ;; already defined, just set it 726 755 (vector-set! properties it (make-container (maybe-unbox value))) … … 732 761 (cruddy-push-extend (make-container (maybe-unbox value)) properties)) 733 762 (hashtable-put! (%php-class-declared-property-offsets the-class) 734 canonical-name763 mangled-name 735 764 offset) 736 765 ;store the reverse, too 737 766 (hashtable-put! (%php-class-declared-property-offsets the-class) 738 767 offset 739 canonical-name)))))) 768 mangled-name) 769 ;store visibility 770 (when (eqv? 'private visibility) 771 (%php-class-private-properties-set! the-class (cons canonical-name (%php-class-private-properties the-class)))) 772 (when (eqv? 'protected visibility) 773 (%php-class-protected-properties-set! the-class (cons canonical-name (%php-class-protected-properties the-class))))))))) 740 774 741 775 (define (%lookup-class name) … … 778 812 #f)))) 779 813 814 ;; this handles visibility mangling 815 ;; it will check in order: public (no mangle), protected, private 816 ;; it makes no attempt to restrict the property, it simply returns it if available in mangled form 780 817 (define (%prop-offset obj prop-canon-name) 781 (hashtable-get 782 (%php-class-declared-property-offsets 783 (%php-object-class obj)) 784 prop-canon-name)) 785 818 (let ((prop (hashtable-get 819 (%php-class-declared-property-offsets 820 (%php-object-class obj)) 821 prop-canon-name))) 822 (if (or prop (not PHP5?)) 823 ; found a public 824 prop 825 (let ((prop (hashtable-get 826 (%php-class-declared-property-offsets 827 (%php-object-class obj)) 828 (mangle-property-protected prop-canon-name)))) 829 (if prop 830 ; found a protected 831 prop 832 ; either privte or nothin' 833 (hashtable-get 834 (%php-class-declared-property-offsets 835 (%php-object-class obj)) 836 (mangle-property-private prop-canon-name))))))) 837 786 838 ;;;;the actual property looker-uppers 787 839 (define (%lookup-prop-ref obj property)
