Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14590 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97994 invoked by uid 1010); 3 Feb 2005 19:49:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 97956 invoked from network); 3 Feb 2005 19:49:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2005 19:49:50 -0000 X-Host-Fingerprint: 217.160.92.50 geburtsjahr.neunzehnhunderteinundachtzig.de Linux 2.4/2.6 Received: from ([217.160.92.50:37225] helo=geburtsjahr.neunzehnhunderteinundachtzig.de) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id 87/49-10528-C5082024 for ; Thu, 03 Feb 2005 14:49:49 -0500 Received: from bauernhof (pD9EBEF54.dip.t-dialin.net [217.235.239.84]) by geburtsjahr.neunzehnhunderteinundachtzig.de (Postfix) with ESMTP id 32A047EB1 for ; Thu, 3 Feb 2005 20:51:33 +0100 (CET) Received: from sparkasse (unknown [192.168.1.7]) by bauernhof (Postfix) with ESMTP id AFFB5630EC for ; Thu, 3 Feb 2005 20:49:34 +0100 (CET) Date: Thu, 3 Feb 2005 20:49:08 +0100 User-Agent: KMail/1.7.1 Organization: Mayflower GmbH To: internals@lists.php.net MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_0AoAC//cJQMhdbZ" Message-ID: <200502032049.08331.schlueter@mayflower.de> Subject: [patch] ReflectionProperty::getLinenumber From: schlueter@mayflower.de (Johannes Schlueter) --Boundary-00=_0AoAC//cJQMhdbZ Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, here's a patch which is lying around on my disk for quite a while: It adds = a=20 ReflectionProperty::getLinenumber()-Method to find the Linenumber where a=20 property was defined. I wrote it while working on a little code-browser=20 thing. This method corresponds to the already existing Reflection[Class| =46unction|Method]::get[Start|End]Line() Methods. As you can see I extended the zend_property_info structure to hold the linenumber. If an extension registers a property using zend_declare_property it is assumed that the property was defined at line 0. johannes The patch is also available at=20 http://anonsvn.schlueters.de/svn/phpatches/HEAD/reflectionProperty_getLinen= umber.diff =2D-=20 Johannes Schl=C3=BCter schlueter@mayflower.de Mayflower GmbH / ThinkPHP Tel: 089 / 24 20 54 - 33 Sendlinger Str. 42a Fax: 089 / 24 20 54 - 29 80331 M=C3=BCnchen http://www.mayflower.de --Boundary-00=_0AoAC//cJQMhdbZ Content-Type: text/x-diff; charset="iso-8859-1"; name="reflectionProperty_getLinenumber.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="reflectionProperty_getLinenumber.diff" Index: Zend/zend_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_API.c,v retrieving revision 1.269 diff -u -r1.269 zend_API.c --- Zend/zend_API.c 2 Nov 2004 13:10:37 -0000 1.269 +++ Zend/zend_API.c 6 Dec 2004 23:21:46 -0000 @@ -1882,8 +1882,7 @@ return module->version; } - -ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC) +ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, int line TSRMLS_DC) { zend_property_info property_info; HashTable *target_symbol_table; @@ -1945,12 +1944,18 @@ } property_info.flags = access_type; property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1); + property_info.line = line; zend_hash_update(&ce->properties_info, name, name_length + 1, &property_info, sizeof(zend_property_info), NULL); return SUCCESS; } +ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC) +{ + return zend_declare_property_ex(ce, name, name_length, property, access_type, 0 TSRMLS_CC); +} + ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC) { zval *property; Index: Zend/zend_API.h =================================================================== RCS file: /repository/ZendEngine2/zend_API.h,v retrieving revision 1.192 diff -u -r1.192 zend_API.h --- Zend/zend_API.h 4 Oct 2004 20:17:04 -0000 1.192 +++ Zend/zend_API.h 6 Dec 2004 23:21:48 -0000 @@ -187,6 +187,7 @@ ZEND_API char *zend_get_module_version(char *module_name); ZEND_API int zend_get_module_started(char *module_name); ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC); +ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, int line TSRMLS_DC); ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC); ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC); ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type TSRMLS_DC); Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.601 diff -u -r1.601 zend_compile.c --- Zend/zend_compile.c 6 Dec 2004 11:53:30 -0000 1.601 +++ Zend/zend_compile.c 6 Dec 2004 23:21:55 -0000 @@ -2714,7 +2714,7 @@ property->type = IS_NULL; } - zend_declare_property(CG(active_class_entry), var_name->u.constant.value.str.val, var_name->u.constant.value.str.len, property, access_type TSRMLS_CC); + zend_declare_property_ex(CG(active_class_entry), var_name->u.constant.value.str.val, var_name->u.constant.value.str.len, property, access_type, zend_get_compiled_lineno(TSRMLS_C) TSRMLS_CC); efree(var_name->u.constant.value.str.val); } Index: Zend/zend_compile.h =================================================================== RCS file: /repository/ZendEngine2/zend_compile.h,v retrieving revision 1.297 diff -u -r1.297 zend_compile.h --- Zend/zend_compile.h 27 Oct 2004 17:58:45 -0000 1.297 +++ Zend/zend_compile.h 6 Dec 2004 23:21:57 -0000 @@ -138,6 +138,7 @@ char *name; int name_length; ulong h; + int line; } zend_property_info; Index: Zend/zend_reflection_api.c =================================================================== RCS file: /repository/ZendEngine2/zend_reflection_api.c,v retrieving revision 1.140 diff -u -r1.140 zend_reflection_api.c --- Zend/zend_reflection_api.c 24 Nov 2004 19:56:54 -0000 1.140 +++ Zend/zend_reflection_api.c 6 Dec 2004 23:22:04 -0000 @@ -3316,6 +3316,20 @@ zend_reflection_class_factory(ref->ce, return_value TSRMLS_CC); } +/* {{{ proto public long ReflectionProperty::getLinenumber() + Get the linenumber where the property is defined */ +ZEND_METHOD(reflection_property, getLinenumber) +{ + reflection_object *intern; + property_reference *ref; + + METHOD_NOTSTATIC_NUMPARAMS(0); + GET_REFLECTION_OBJECT_PTR(ref); + + RETURN_LONG(ref->prop->line); +} +/* }}} */ + /* {{{ proto public static mixed ReflectionExtension::export(string name [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_extension, export) @@ -3670,6 +3684,7 @@ ZEND_ME(reflection_property, isDefault, NULL, 0) ZEND_ME(reflection_property, getModifiers, NULL, 0) ZEND_ME(reflection_property, getDeclaringClass, NULL, 0) + ZEND_ME(reflection_property, getLinenumber, NULL, 0) {NULL, NULL, NULL} }; --Boundary-00=_0AoAC//cJQMhdbZ--