Hi,

here's a patch which is lying around on my disk for quite a while: It adds a 
ReflectionProperty::getLinenumber()-Method to find the Linenumber where a 
property was defined. I wrote it while working on a little code-browser 
thing. This method corresponds to the already existing Reflection[Class|
Function|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 
http://anonsvn.schlueters.de/svn/phpatches/HEAD/reflectionProperty_getLinenumber.diff
-- 
Johannes SchlÃter                      [EMAIL PROTECTED]
Mayflower GmbH / ThinkPHP              Tel: 089 / 24 20 54 - 33
Sendlinger Str. 42a                    Fax: 089 / 24 20 54 - 29
80331 MÃnchen                          http://www.mayflower.de
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}
 };
 

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to