improved structure layout generation
[repair.git] / Repair / RepairCompiler / structextract / typedata.c
index 5601a3a4a9f712050c9b28638573dc27169eb72d..9491146247771f642033f2ad82c46ea160620dad 100755 (executable)
@@ -70,6 +70,7 @@ char tag_is_relevant_entry(unsigned long tag)
     case DW_TAG_structure_type:
     case DW_TAG_union_type:
     case DW_TAG_base_type:
+    case DW_TAG_typedef:
     case DW_TAG_const_type:
     case DW_TAG_enumerator:
     case DW_TAG_subprogram:
@@ -223,7 +224,9 @@ char entry_is_listening_for_attribute(dwarf_entry* e, unsigned long attr)
               tag_is_member(tag) ||
               tag_is_function(tag) ||
               tag_is_formal_parameter(tag) ||
-              tag_is_function_type(tag));
+              tag_is_function_type(tag)||
+             tag==DW_TAG_typedef||
+             tag==DW_TAG_const_type);
     case DW_AT_upper_bound:
       return (tag==DW_TAG_subrange_type);
     case DW_AT_encoding:
@@ -257,6 +260,12 @@ char harvest_type_value(dwarf_entry* e, unsigned long value)
   if (tag ==DW_TAG_subrange_type) {
     ((array_bound*)e->entry_ptr)->target_ID = value;
     return 1;
+  } else if (tag==DW_TAG_typedef) {
+    ((tdef*)e->entry_ptr)->target_ID = value;
+    return 1;
+  } else if (tag==DW_TAG_const_type) {
+    ((consttype*)e->entry_ptr)->target_ID = value;
+    return 1;
   } else if (tag_is_modifier_type(tag))
     {
       ((modifier_type*)e->entry_ptr)->target_ID = value;
@@ -731,6 +740,34 @@ void link_entries_to_type_entries()
               bound_ptr->target_ptr=&dwarf_entry_array[target_index];
             }
       }
+      else if (tag==DW_TAG_typedef) {
+          char success = 0;
+          unsigned long target_index = 0;
+          tdef* bound_ptr = (tdef*)(cur_entry->entry_ptr);
+          unsigned long target_ID = bound_ptr->target_ID;
+
+          // Use a binary search to try to find the index of the entry in the
+          // array with the corresponding target_ID
+          success = binary_search_dwarf_entry_array(target_ID, &target_index);
+          if (success)
+            {
+              bound_ptr->target_ptr=&dwarf_entry_array[target_index];
+            }
+      }
+      else if (tag==DW_TAG_const_type) {
+          char success = 0;
+          unsigned long target_index = 0;
+          consttype* bound_ptr = (consttype*)(cur_entry->entry_ptr);
+          unsigned long target_ID = bound_ptr->target_ID;
+
+          // Use a binary search to try to find the index of the entry in the
+          // array with the corresponding target_ID
+          success = binary_search_dwarf_entry_array(target_ID, &target_index);
+          if (success)
+            {
+              bound_ptr->target_ptr=&dwarf_entry_array[target_index];
+            }
+      }
       else if (tag_is_function(tag))
         {
           char success = 0;
@@ -1175,6 +1212,12 @@ void initialize_dwarf_entry_ptr(dwarf_entry* e)
       else if (e->tag_name==DW_TAG_subrange_type) {
        e->entry_ptr=calloc(1,sizeof(array_bound));
       }
+      else if (e->tag_name==DW_TAG_typedef) {
+       e->entry_ptr=calloc(1,sizeof(tdef));
+      }
+      else if (e->tag_name==DW_TAG_const_type) {
+       e->entry_ptr=calloc(1,sizeof(consttype));
+      }
       else if (tag_is_modifier_type(e->tag_name))
         {
           e->entry_ptr = calloc(1, sizeof(modifier_type));