changeset 7:7fec19e27411

Add more comment
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 08 Sep 2010 21:35:16 +0800
parents 165781cb4cdd
children 5502f175d348
files src/cospy.c
diffstat 1 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/cospy.c	Wed Sep 08 21:29:30 2010 +0800
+++ b/src/cospy.c	Wed Sep 08 21:35:16 2010 +0800
@@ -10,6 +10,10 @@
 
 int plugin_is_GPL_compatible;
 
+/*! \brief Parse a tree of type and return respective string.
+ *
+ * \return a string for the type.  It must be free through ggc_free().
+ */
 static char *
 parse_type(tree type_node) {
     tree type_v;
@@ -22,6 +26,7 @@
     int type_str_len;
     int i, ptr_i;
     
+    /* Collect pointers */
     type_v = type_node;
     while(TREE_CODE(type_v) == POINTER_TYPE) {
 	if(TREE_READONLY(type_v))
@@ -30,21 +35,6 @@
 	lvl++;
     }
 
-    type_decl = TYPE_NAME(type_v);
-    type_name = DECL_NAME(type_decl);
-    base_type_name = IDENTIFIER_POINTER(type_name);
-    
-    type_str_len = lvl + strlen(base_type_name) + const_cnt * 5; /* "const" */
-    if(TREE_READONLY(type_v))
-	type_str_len += 6;	/* "const " */
-    type_str = (char *)ggc_alloc(type_str_len + 1);
-    
-    type_str[0] = 0;
-    if(TREE_READONLY(type_v))
-	strcpy(type_str, "const ");
-    
-    strcat(type_str, base_type_name);
-    
     pointers = (tree *)ggc_alloc(sizeof(tree) * lvl);
     type_v = type_node;
     for(ptr_i = 0; ptr_i < lvl; ptr_i++) {
@@ -52,6 +42,24 @@
 	type_v = TREE_TYPE(type_v);
     }
 
+    /* Get name of base type */
+    type_decl = TYPE_NAME(type_v);
+    type_name = DECL_NAME(type_decl);
+    base_type_name = IDENTIFIER_POINTER(type_name);
+    
+    /* Compute total length of string of full type */
+    type_str_len = lvl + strlen(base_type_name) + const_cnt * 5; /* "const" */
+    if(TREE_READONLY(type_v))
+	type_str_len += 6;	/* "const " */
+    type_str = (char *)ggc_alloc(type_str_len + 1);
+    
+    /* modify const for base type */
+    type_str[0] = 0;
+    if(TREE_READONLY(type_v))
+	strcpy(type_str, "const ");
+    strcat(type_str, base_type_name);
+    
+    /* Add pointers and const modifications after base type */
     i = strlen(type_str);
     for(ptr_i = lvl - 1; ptr_i >= 0; ptr_i--) {
 	type_v = pointers[ptr_i];