dmantipov updated this revision to Diff 291870.
dmantipov added a comment.

Use std::pair rather than an ad-hoc two-member trivial structures. Since 
std::pair provides the default constructor to initialize both members, no extra 
C++ glue is required for emplace_back()'ing the pairs into containers.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87675/new/

https://reviews.llvm.org/D87675

Files:
  lldb/include/lldb/Symbol/Function.h
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3638,10 +3638,8 @@
         LocationInCaller = parse_simple_location(i);
     }
 
-    if (LocationInCallee && LocationInCaller) {
-      CallSiteParameter param = {*LocationInCallee, *LocationInCaller};
-      parameters.push_back(param);
-    }
+    if (LocationInCallee && LocationInCaller)
+      parameters.emplace_back(*LocationInCallee, *LocationInCaller);
   }
   return parameters;
 }
@@ -3793,12 +3791,12 @@
     if (log && parameters.size()) {
       for (const CallSiteParameter &param : parameters) {
         StreamString callee_loc_desc, caller_loc_desc;
-        param.LocationInCallee.GetDescription(&callee_loc_desc,
-                                              eDescriptionLevelBrief,
-                                              LLDB_INVALID_ADDRESS, nullptr);
-        param.LocationInCaller.GetDescription(&caller_loc_desc,
-                                              eDescriptionLevelBrief,
-                                              LLDB_INVALID_ADDRESS, nullptr);
+        param.first.GetDescription(&callee_loc_desc,
+                                   eDescriptionLevelBrief,
+                                   LLDB_INVALID_ADDRESS, nullptr);
+        param.second.GetDescription(&caller_loc_desc,
+                                    eDescriptionLevelBrief,
+                                    LLDB_INVALID_ADDRESS, nullptr);
         LLDB_LOG(log, "CollectCallEdges: \tparam: {0} => {1}",
                  callee_loc_desc.GetString(), caller_loc_desc.GetString());
       }
Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
@@ -69,11 +69,7 @@
     }
   };
 
-  struct Atom {
-    AtomType type;
-    dw_form_t form;
-  };
-
+  typedef std::pair<AtomType, dw_form_t> Atom;
   typedef std::vector<DIEInfo> DIEInfoArray;
   typedef std::vector<Atom> AtomArray;
 
Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -154,7 +154,7 @@
 }
 
 void DWARFMappedHash::Prologue::AppendAtom(AtomType type, dw_form_t form) {
-  atoms.push_back({type, form});
+  atoms.emplace_back(type, form);
   atom_mask |= 1u << type;
   switch (form) {
   case DW_FORM_indirect:
@@ -269,12 +269,12 @@
     return false;
 
   for (size_t i = 0; i < num_atoms; ++i) {
-    DWARFFormValue form_value(nullptr, header_data.atoms[i].form);
+    DWARFFormValue form_value(nullptr, header_data.atoms[i].second);
 
     if (!form_value.ExtractValue(data, offset_ptr))
       return false;
 
-    switch (header_data.atoms[i].type) {
+    switch (header_data.atoms[i].first) {
     case eAtomTypeDIEOffset: // DIE offset, check form for encoding
       hash_data.die_offset =
           DWARFFormValue::IsDataForm(form_value.Form())
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
@@ -49,8 +49,8 @@
       for (uint32_t i = 0; i < num_descriptors; ++i) {
         const DWARFDebugArangeSet::Descriptor &descriptor =
             set.GetDescriptorRef(i);
-        m_aranges.Append(RangeToDIE::Entry(descriptor.address,
-                                           descriptor.length, cu_offset));
+        m_aranges.Append(RangeToDIE::Entry(descriptor.first,
+                                           descriptor.second, cu_offset));
       }
     }
     set.Clear();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
@@ -30,11 +30,7 @@
                       // space, this value is 0.
   };
 
-  struct Descriptor {
-    dw_addr_t address;
-    dw_addr_t length;
-    dw_addr_t end_address() const { return address + length; }
-  };
+  typedef std::pair<dw_addr_t, dw_addr_t> Descriptor; // { address, length }
 
   DWARFDebugArangeSet();
   void Clear();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
@@ -98,23 +98,16 @@
 
   *offset_ptr = m_offset + first_tuple_offset;
 
-  Descriptor arangeDescriptor;
-
-  static_assert(sizeof(arangeDescriptor.address) ==
-                    sizeof(arangeDescriptor.length),
-                "DWARFDebugArangeSet::Descriptor.address and "
-                "DWARFDebugArangeSet::Descriptor.length must have same size");
-
   while (data.ValidOffset(*offset_ptr)) {
-    arangeDescriptor.address = data.GetMaxU64(offset_ptr, m_header.addr_size);
-    arangeDescriptor.length = data.GetMaxU64(offset_ptr, m_header.addr_size);
+    dw_addr_t address = data.GetMaxU64(offset_ptr, m_header.addr_size);
+    dw_attr_t length = data.GetMaxU64(offset_ptr, m_header.addr_size);
 
     // Each set of tuples is terminated by a 0 for the address and 0 for
     // the length.
-    if (!arangeDescriptor.address && !arangeDescriptor.length)
+    if (!address && !length)
       return llvm::ErrorSuccess();
 
-    m_arange_descriptors.push_back(arangeDescriptor);
+    m_arange_descriptors.emplace_back(address, length);
   }
 
   return llvm::make_error<llvm::object::GenericBinaryError>(
@@ -125,8 +118,8 @@
 public:
   DescriptorContainsAddress(dw_addr_t address) : m_address(address) {}
   bool operator()(const DWARFDebugArangeSet::Descriptor &desc) const {
-    return (m_address >= desc.address) &&
-           (m_address < (desc.address + desc.length));
+    return (m_address >= desc.first) &&
+           (m_address < (desc.first + desc.second));
   }
 
 private:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -382,33 +382,33 @@
     parent.GetDeclContext(context);
   switch (tag) {
   case DW_TAG_module:
-    context.push_back({CompilerContextKind::Module, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Module, ConstString(GetName()));
     break;
   case DW_TAG_namespace:
-    context.push_back({CompilerContextKind::Namespace, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Namespace, ConstString(GetName()));
     break;
   case DW_TAG_structure_type:
-    context.push_back({CompilerContextKind::Struct, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Struct, ConstString(GetName()));
     break;
   case DW_TAG_union_type:
-    context.push_back({CompilerContextKind::Union, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Union, ConstString(GetName()));
     break;
   case DW_TAG_class_type:
-    context.push_back({CompilerContextKind::Class, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Class, ConstString(GetName()));
     break;
   case DW_TAG_enumeration_type:
-    context.push_back({CompilerContextKind::Enum, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Enum, ConstString(GetName()));
     break;
   case DW_TAG_subprogram:
-    context.push_back(
-        {CompilerContextKind::Function, ConstString(GetPubname())});
+    context.emplace_back(CompilerContextKind::Function,
+                         ConstString(GetPubname()));
     break;
   case DW_TAG_variable:
-    context.push_back(
-        {CompilerContextKind::Variable, ConstString(GetPubname())});
+    context.emplace_back(CompilerContextKind::Variable,
+                         ConstString(GetPubname()));
     break;
   case DW_TAG_typedef:
-    context.push_back({CompilerContextKind::Typedef, ConstString(GetName())});
+    context.emplace_back(CompilerContextKind::Typedef, ConstString(GetName()));
     break;
   default:
     break;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -52,8 +52,10 @@
   DWARFAttributes();
   ~DWARFAttributes();
 
-  void Append(const DWARFUnit *cu, dw_offset_t attr_die_offset,
-              dw_attr_t attr, dw_form_t form);
+  void Append(const DWARFUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr,
+              dw_form_t form) {
+    m_infos.emplace_back(cu, attr_die_offset, attr, form);
+  }
   const DWARFUnit *CompileUnitAtIndex(uint32_t i) const {
     return m_infos[i].cu;
   }
@@ -77,6 +79,11 @@
                                 // case we have DW_FORM_ref_addr values
     dw_offset_t die_offset;
     DWARFAttribute attr;
+
+    AttributeValue(const DWARFUnit *cu, dw_offset_t die_offset, dw_attr_t attr,
+                   dw_form_t form)
+      : cu(cu), die_offset(die_offset),
+        attr(attr, form, DWARFFormValue::ValueType()) {}
   };
   typedef llvm::SmallVector<AttributeValue, 8> collection;
   collection m_infos;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
@@ -25,13 +25,6 @@
   return UINT32_MAX;
 }
 
-void DWARFAttributes::Append(const DWARFUnit *cu, dw_offset_t attr_die_offset,
-                             dw_attr_t attr, dw_form_t form) {
-  AttributeValue attr_value = {
-      cu, attr_die_offset, {attr, form, DWARFFormValue::ValueType()}};
-  m_infos.push_back(attr_value);
-}
-
 bool DWARFAttributes::ExtractFormValueAtIndex(
     uint32_t i, DWARFFormValue &form_value) const {
   const DWARFUnit *cu = CompileUnitAtIndex(i);
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -60,7 +60,7 @@
     if (form == DW_FORM_implicit_const)
       val.value.sval = data.GetULEB128(offset_ptr);
 
-    m_attributes.push_back(DWARFAttribute(attr, form, val));
+    m_attributes.emplace_back(attr, form, val);
   }
 
   return llvm::make_error<llvm::object::GenericBinaryError>(
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1896,18 +1896,16 @@
           if (!size)
             return false;
           llvm::APInt apint(*size, uval64, is_signed);
-          template_param_infos.args.push_back(
-              clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed),
-                                      ClangUtil::GetQualType(clang_type)));
-        } else {
-          template_param_infos.args.push_back(
-              clang::TemplateArgument(ClangUtil::GetQualType(clang_type)));
-        }
+          template_param_infos.args.emplace_back(
+              ast, llvm::APSInt(apint, !is_signed),
+              ClangUtil::GetQualType(clang_type));
+        } else
+          template_param_infos.args.emplace_back(
+              ClangUtil::GetQualType(clang_type));
       } else {
         auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name);
         template_param_infos.names.push_back(name);
-        template_param_infos.args.push_back(
-            clang::TemplateArgument(clang::TemplateName(tplt_type)));
+        template_param_infos.args.emplace_back(clang::TemplateName(tplt_type));
       }
     }
   }
@@ -2743,10 +2741,10 @@
 
       ClangASTMetadata metadata;
       metadata.SetUserID(die.GetID());
-      delayed_properties.push_back(DelayedAddObjCClassProperty(
+      delayed_properties.emplace_back(
           class_clang_type, prop_name, member_type->GetLayoutCompilerType(),
           ivar_decl, prop_setter_name, prop_getter_name, prop_attributes,
-          &metadata));
+          &metadata);
 
       if (ivar_decl)
         m_ast.SetMetadataAsUserID(ivar_decl, die.GetID());
Index: lldb/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -801,7 +801,7 @@
   const CallSiteParameter *matched_param = nullptr;
   for (const CallSiteParameter &param : call_edge->GetCallSiteParameters()) {
     DataExtractor param_subexpr_extractor;
-    if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
+    if (!param.first.GetExpressionData(param_subexpr_extractor))
       continue;
     lldb::offset_t param_subexpr_offset = 0;
     const void *param_subexpr_data =
@@ -831,7 +831,7 @@
   // TODO: Add support for DW_OP_push_object_address within a DW_OP_entry_value
   // subexpresion whenever llvm does.
   Value result;
-  const DWARFExpression &param_expr = matched_param->LocationInCaller;
+  const DWARFExpression &param_expr = matched_param->second;
   if (!param_expr.Evaluate(&parent_exe_ctx,
                            parent_frame->GetRegisterContext().get(),
                            /*loclist_base_addr=*/LLDB_INVALID_ADDRESS,
Index: lldb/include/lldb/Symbol/Function.h
===================================================================
--- lldb/include/lldb/Symbol/Function.h
+++ lldb/include/lldb/Symbol/Function.h
@@ -252,14 +252,9 @@
 
 class Function;
 
-/// \class CallSiteParameter Function.h "lldb/Symbol/Function.h"
-///
-/// Represent the locations of a parameter at a call site, both in the caller
-/// and in the callee.
-struct CallSiteParameter {
-  DWARFExpression LocationInCallee;
-  DWARFExpression LocationInCaller;
-};
+/// Represent the locations of a parameter at a call site, in the callee
+/// and in the caller, first and second, respectively.
+using CallSiteParameter = std::pair<DWARFExpression, DWARFExpression>;
 
 /// A vector of \c CallSiteParameter.
 using CallSiteParameterArray = llvm::SmallVector<CallSiteParameter, 0>;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to