UniqueDWARFASTType.cpp revision 314564
1254721Semaste//===-- UniqueDWARFASTType.cpp ----------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "UniqueDWARFASTType.h" 11254721Semaste 12254721Semaste// C Includes 13254721Semaste// C++ Includes 14254721Semaste// Other libraries and framework includes 15254721Semaste// Project includes 16254721Semaste#include "lldb/Symbol/Declaration.h" 17254721Semaste 18314564Sdimbool UniqueDWARFASTTypeList::Find(const DWARFDIE &die, 19314564Sdim const lldb_private::Declaration &decl, 20314564Sdim const int32_t byte_size, 21314564Sdim UniqueDWARFASTType &entry) const { 22314564Sdim for (const UniqueDWARFASTType &udt : m_collection) { 23314564Sdim // Make sure the tags match 24314564Sdim if (udt.m_die.Tag() == die.Tag()) { 25314564Sdim // Validate byte sizes of both types only if both are valid. 26314564Sdim if (udt.m_byte_size < 0 || byte_size < 0 || 27314564Sdim udt.m_byte_size == byte_size) { 28314564Sdim // Make sure the file and line match 29314564Sdim if (udt.m_declaration == decl) { 30314564Sdim // The type has the same name, and was defined on the same 31314564Sdim // file and line. Now verify all of the parent DIEs match. 32314564Sdim DWARFDIE parent_arg_die = die.GetParent(); 33314564Sdim DWARFDIE parent_pos_die = udt.m_die.GetParent(); 34314564Sdim bool match = true; 35314564Sdim bool done = false; 36314564Sdim while (!done && match && parent_arg_die && parent_pos_die) { 37314564Sdim const dw_tag_t parent_arg_tag = parent_arg_die.Tag(); 38314564Sdim const dw_tag_t parent_pos_tag = parent_pos_die.Tag(); 39314564Sdim if (parent_arg_tag == parent_pos_tag) { 40314564Sdim switch (parent_arg_tag) { 41314564Sdim case DW_TAG_class_type: 42314564Sdim case DW_TAG_structure_type: 43314564Sdim case DW_TAG_union_type: 44314564Sdim case DW_TAG_namespace: { 45314564Sdim const char *parent_arg_die_name = parent_arg_die.GetName(); 46314564Sdim if (parent_arg_die_name == 47314564Sdim NULL) // Anonymous (i.e. no-name) struct 48254721Semaste { 49314564Sdim match = false; 50314564Sdim } else { 51314564Sdim const char *parent_pos_die_name = parent_pos_die.GetName(); 52314564Sdim if (parent_pos_die_name == NULL || 53314564Sdim ((parent_arg_die_name != parent_pos_die_name) && 54314564Sdim strcmp(parent_arg_die_name, parent_pos_die_name))) 55314564Sdim match = false; 56314564Sdim } 57314564Sdim } break; 58254721Semaste 59314564Sdim case DW_TAG_compile_unit: 60314564Sdim done = true; 61314564Sdim break; 62314564Sdim } 63254721Semaste } 64314564Sdim parent_arg_die = parent_arg_die.GetParent(); 65314564Sdim parent_pos_die = parent_pos_die.GetParent(); 66314564Sdim } 67314564Sdim 68314564Sdim if (match) { 69314564Sdim entry = udt; 70314564Sdim return true; 71314564Sdim } 72254721Semaste } 73314564Sdim } 74254721Semaste } 75314564Sdim } 76314564Sdim return false; 77254721Semaste} 78