Index: /trunk/mkstructinfo.awk
===================================================================
--- /trunk/mkstructinfo.awk	(revision 719)
+++ /trunk/mkstructinfo.awk	(revision 837)
@@ -5,4 +5,9 @@
 	incomment = 0;
 	buffer_len = 0;
+}
+function printstruct(structname) {
+	printf "define(`ELEMENTSOF_%s', `%s')\n", structname, ELEMENTSOF[structname];
+	printf "define(`COUNTOF_%s', `%s')\n", structname, COUNTOF[structname];
+	printf "define(`SIZEOF_%s', `(  %s  )')\n", structname, SIZEOF[structname];
 }
 
@@ -35,9 +40,10 @@
 	if (instruct) {
 		sub(";", "");
-		if (instruct == 1 && $2) {
-			instruct = $2;
+		structname = instruct;
+		if (structname == 1 && $2) {
+			structname = $2;
 		}
-		if (instruct in typedefs) {
-			instruct = typedefs[instruct];
+		if (structname in typedefs) {
+			structname = typedefs[structname];
 		}
 		sizeinfo = "";
@@ -47,5 +53,5 @@
 				sizeinfo = sizeinfo " + ";
 			}
-			sizeinfo = sizeinfo "sizeof(((" instruct "*)NULL)->" buffer[i] ")";
+			sizeinfo = sizeinfo "sizeof(((" structname "*)NULL)->" buffer[i] ")";
 
 			if (i == 0) {
@@ -56,7 +62,8 @@
 			}
 		}
-		printf "define(`ELEMENTSOF_%s', `%s')\n", instruct, elms;
-		printf "define(`COUNTOF_%s', `%s')\n", instruct, i;
-		printf "define(`SIZEOF_%s', `(  %s  )')\n", instruct, sizeinfo;
+		ELEMENTSOF[structname] = elms;
+		COUNTOF[structname]    = i;
+		SIZEOF[structname]     = sizeinfo;
+		printstruct(structname);
 		print "\n";
 		for (i in buffer) {
@@ -149,5 +156,15 @@
 /^typedef struct [^{]*;/ {
 	sub(";", "");
-	typedefs[$3] = $4;
+	typename=$3;
+	newtypename=$4;
+	typedefs[typename] = newtypename;
+	if (ELEMENTSOF[typename]) {
+		ELEMENTSOF[newtypename] = ELEMENTSOF[typename];
+		COUNTOF[newtypename]    = COUNTOF[typename];
+		sub(/.*/, SIZEOF[typename]);
+		gsub(typename, newtypename);
+		SIZEOF[newtypename]     = $0;
+		printstruct(newtypename);
+	}
 	next;
 }
Index: /trunk/processor/processor.m4
===================================================================
--- /trunk/processor/processor.m4	(revision 833)
+++ /trunk/processor/processor.m4	(revision 837)
@@ -16,15 +16,13 @@
 /* }}} */
 dnl ====================================================
-dnl {{{ zend_compiled_variable
 #ifdef IS_CV
-DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `
+DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `dnl {{{
 	DISPATCH(int, name_len)
 	PROC_ZSTRING_L(, name, name_len)
 	DISPATCH(ulong, hash_value)
 ')
-#endif
-dnl }}}
-dnl {{{ zend_uint
-DEF_STRUCT_P_FUNC(`zend_uint', , `
+dnl }}}
+#endif
+DEF_STRUCT_P_FUNC(`zend_uint', , `dnl {{{
 	IFCOPY(`dst[0] = src[0];')
 	IFDPRINT(`
@@ -35,7 +33,6 @@
 ')
 dnl }}}
-dnl {{{ int
 #ifndef ZEND_ENGINE_2
-DEF_STRUCT_P_FUNC(`int', , `
+DEF_STRUCT_P_FUNC(`int', , `dnl {{{
 	IFCOPY(`*dst = *src;')
 	IFDPRINT(`
@@ -45,16 +42,14 @@
 	DONE_SIZE(sizeof(src[0]))
 ')
-#endif
-dnl }}}
-dnl {{{ zend_try_catch_element
-#ifdef ZEND_ENGINE_2
-DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `
+dnl }}}
+#endif
+#ifdef ZEND_ENGINE_2
+DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{
 	DISPATCH(zend_uint, try_op)
 	DISPATCH(zend_uint, catch_op)
 ')
-#endif /* ifdef ZEND_ENGINE_2 */
-dnl }}}
-dnl {{{ zend_brk_cont_element
-DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `
+dnl }}}
+#endif
+DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{
 #ifdef ZEND_ENGINE_2_2
 	DISPATCH(int, start)
@@ -227,7 +222,6 @@
 ')
 dnl }}}
-dnl {{{ zend_arg_info
-#ifdef ZEND_ENGINE_2
-DEF_STRUCT_P_FUNC(`zend_arg_info', , `
+#ifdef ZEND_ENGINE_2
+DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{
 	DISPATCH(zend_uint, name_len)
 	PROC_ZSTRING_L(, name, name_len)
@@ -246,6 +240,6 @@
 #endif
 ')
-#endif
-dnl }}}
+dnl }}}
+#endif
 #ifdef HAVE_XCACHE_CONSTANT
 DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{
@@ -281,7 +275,6 @@
 ')
 dnl }}}
-dnl {{{ zend_property_info
-#ifdef ZEND_ENGINE_2
-DEF_STRUCT_P_FUNC(`zend_property_info', , `
+#ifdef ZEND_ENGINE_2
+DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{
 	DISPATCH(zend_uint, flags)
 	DISPATCH(int, name_length)
@@ -300,6 +293,56 @@
 #endif
 ')
-#endif
-dnl }}}
+dnl }}}
+#endif
+#ifdef ZEND_ENGINE_2_4
+DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{
+	DISPATCH(unsigned int, mname_len)
+	PROC_STRING_L(method_name, mname_len)
+	COPYNULL(ce)
+	DISPATCH(unsigned int, cname_len)
+	PROC_STRING_L(class_name, cname_len)
+')
+dnl }}}
+DEF_STRUCT_P_FUNC(`zend_trait_alias', , `dnl {{{
+	STRUCT_P(zend_trait_method_reference, trait_method)
+	DISPATCH(unsigned int, alias_len)
+	PROC_STRING_L(alias, alias_len)
+	DISPATCH(zend_uint, modifiers)
+	COPYNULL(function)
+')
+dnl }}}
+DEF_STRUCT_P_FUNC(`zend_trait_precedence', , `dnl {{{
+	STRUCT_P(zend_trait_method_reference, trait_method)
+	COPYNULL(exclude_from_classes)
+	COPYNULL(function)
+')
+dnl }}}
+DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
+	IFDASM(`
+		pushdefFUNC_NAME(`zend_trait_alias')
+		FUNC_NAME (dst, src[0] TSRMLS_CC);
+		popdef(`FUNC_NAME')
+	', `
+		ALLOC(dst[0], zend_trait_alias)
+		STRUCT_P_EX(zend_trait_alias, dst[0], src[0], `[0]', `', ` ')
+		FIXPOINTER_EX(zend_trait_alias, dst[0])
+	')
+	DONE_SIZE(sizeof(zend_trait_alias))
+')
+dnl }}}
+DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
+	IFDASM(`
+		pushdefFUNC_NAME(`zend_trait_precedence')
+		FUNC_NAME (dst, src[0] TSRMLS_CC);
+		popdef(`FUNC_NAME')
+	', `
+		ALLOC(dst[0], zend_trait_precedence)
+		STRUCT_P_EX(zend_trait_precedence, dst[0], src[0], `[0]', `', ` ')
+		FIXPOINTER_EX(zend_trait_precedence, dst[0])
+	')
+	DONE_SIZE(sizeof(zend_trait_precedence))
+')
+dnl }}}
+#endif
 DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
 	IFCALCCOPY(`
@@ -359,6 +402,15 @@
 	STRUCT(HashTable, constants_table, HashTable_zval_ptr)
 
+#ifdef ZEND_ENGINE_2_2
 	dnl runtime binding: ADD_INTERFACE will deal with it
+	COPYNULL(`interfaces')
+	COPYNULL(`num_interfaces')
+
+#	ifdef ZEND_ENGINE_2_4
 	dnl runtime binding: ADD_TRAIT will deal with it
+	COPYNULL(traits)
+	COPYNULL(num_traits)
+#	endif
+#else
 	IFRESTORE(`
 		if (src->num_interfaces) {
@@ -369,64 +421,11 @@
 			COPYNULL(`interfaces')
 		}
-#	ifdef ZEND_ENGINE_2_4
-		if (src->num_traits) {
-			CALLOC(dst->traits, zend_class_entry*, src->num_traits)
-			DONE(`traits')
-			DONE(`trait_aliases')
-			DONE(`trait_precedences')
-		}
-		else {
-			COPYNULL(`traits')
-			COPYNULL(`trait_aliases')
-			COPYNULL(`trait_precedences')
-		}
-#	endif
-	')
-	IFDASM(`
-		if (src->num_interfaces) {
-			/*
-			int i;
-			zval *arr;
-			ALLOC_INIT_ZVAL(arr);
-			array_init(arr);
-			for (i = 0; i < src->num_interfaces; i ++) {
-				zval *zv;
-				ALLOC_INIT_ZVAL(zv);
-				ZVAL_STRING(src->num_interfaces);
-			}
-			add_assoc_zval_ex(dst, ZEND_STRS("interfaces"), arr);
-			*/
-			DONE(`interfaces')
-		}
-		else {
-			COPYNULL(`interfaces')
-		}
-#	ifdef ZEND_ENGINE_2_4
-		if (src->num_traits) {
-			DONE(`traits')
-			DONE(`trait_aliases')
-			DONE(`trait_precedences')
-		}
-		else {
-			COPYNULL(`traits')
-			COPYNULL(`trait_aliases')
-			COPYNULL(`trait_precedences')
-		}
-#	endif
-	')
-	IFRESTORE(`', `
-		IFDASM(`', `
-			DONE(`interfaces')
-#	ifdef ZEND_ENGINE_2_4
-			DONE(`traits')
-			DONE(`trait_aliases')
-			DONE(`trait_precedences')
-#	endif
-		')
+	', `
+		DONE(`interfaces')
 	')
 	DISPATCH(zend_uint, num_interfaces)
-#	ifdef ZEND_ENGINE_2_4
-	DISPATCH(zend_uint, num_traits)
-#	endif
+#endif
+	STRUCT_ARRAY(, zend_trait_alias_ptr, trait_aliases)
+	STRUCT_ARRAY(, zend_trait_precedence_ptr, trait_precedences)
 
 #	ifdef ZEND_ENGINE_2_4
@@ -1139,6 +1138,5 @@
 ')
 dnl }}}
-dnl {{{ xc_entry_t
-DEF_STRUCT_P_FUNC(`xc_entry_t', , `
+DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
 	DISPATCH(xc_entry_type_t, type)
 	DISPATCH(size_t, size)
Index: /trunk/processor/main.m4
===================================================================
--- /trunk/processor/main.m4	(revision 836)
+++ /trunk/processor/main.m4	(revision 837)
@@ -181,4 +181,5 @@
 	IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));')
 	IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
+	assert(patsubst($1, dst, src) == NULL);
 ')
 dnl }}}
