diff options
author | Giuliano Procida <gprocida@google.com> | 2024-01-10 15:11:43 +0000 |
---|---|---|
committer | Giuliano Procida <gprocida@google.com> | 2024-02-09 12:51:03 +0000 |
commit | 628dcaa5073e8edf8e02c1b0ee187248cdd973e8 (patch) | |
tree | e14952440893e5d21b0ea737c72bcc8e2f0a6c8a | |
parent | 5ca51ea41d04986b1e9f321b8ba8c6460b9a7ca0 (diff) | |
download | stg-628dcaa5073e8edf8e02c1b0ee187248cdd973e8.tar.gz |
DWARF processor: give some locals more precise types
Where possible:
* make `const`
* use `Id` instead of `auto`
PiperOrigin-RevId: 597240899
Change-Id: Ic67cb678e87b4541525a7e11d89edd6f795a3f7f
-rw-r--r-- | dwarf_processor.cc | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/dwarf_processor.cc b/dwarf_processor.cc index ba88313..0ea8183 100644 --- a/dwarf_processor.cc +++ b/dwarf_processor.cc @@ -96,7 +96,7 @@ size_t GetByteSize(Entry& entry) { } Primitive::Encoding GetEncoding(Entry& entry) { - auto dwarf_encoding = entry.MaybeGetUnsignedConstant(DW_AT_encoding); + const auto dwarf_encoding = entry.MaybeGetUnsignedConstant(DW_AT_encoding); if (!dwarf_encoding) { Die() << "Encoding was not found for " << EntryToString(entry); } @@ -313,7 +313,7 @@ class Processor { void ProcessInternal(Entry& entry) { ++result_.processed_entries; - auto tag = entry.GetTag(); + const auto tag = entry.GetTag(); switch (tag) { case DW_TAG_array_type: ProcessArray(entry); @@ -414,7 +414,7 @@ class Processor { } void ProcessNamespace(Entry& entry) { - auto name = GetNameOrEmpty(entry); + const auto name = GetNameOrEmpty(entry); const PushScopeName push_scope_name(scope_, "namespace", name); ProcessAllChildren(entry); } @@ -433,7 +433,7 @@ class Processor { void ProcessTypedef(Entry& entry) { const std::string type_name = scope_ + GetName(entry); - auto referred_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); + const Id referred_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); const Id id = AddProcessedNode<Typedef>(entry, type_name, referred_type_id); if (!ShouldKeepDefinition(entry, type_name)) { // We always model (and keep) typedef definitions. But we should exclude @@ -445,7 +445,7 @@ class Processor { template<typename Node, typename KindType> void ProcessReference(Entry& entry, KindType kind) { - auto referred_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); + const Id referred_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); AddProcessedNode<Node>(entry, kind, referred_type_id); } @@ -483,7 +483,7 @@ class Processor { } void ProcessStructUnion(Entry& entry, StructUnion::Kind kind) { - std::string name = GetNameOrEmpty(entry); + const auto name = GetNameOrEmpty(entry); const std::string full_name = name.empty() ? std::string() : scope_ + name; const PushScopeName push_scope_name(scope_, kind, name); @@ -569,9 +569,9 @@ class Processor { } void ProcessMember(Entry& entry) { - std::string name = GetNameOrEmpty(entry); + const auto name = GetNameOrEmpty(entry); auto referred_type = GetReferredType(entry); - auto referred_type_id = GetIdForEntry(referred_type); + const Id referred_type_id = GetIdForEntry(referred_type); auto optional_bit_size = entry.MaybeGetUnsignedConstant(DW_AT_bit_size); // Member has DW_AT_bit_size if and only if it is bit field. // STG uses bit_size == 0 to mark that the member is not a bit field. @@ -617,7 +617,7 @@ class Processor { } void ProcessBaseClass(Entry& entry) { - const auto type_id = GetReferredTypeId(GetReferredType(entry)); + const Id type_id = GetReferredTypeId(GetReferredType(entry)); const auto byte_offset = entry.MaybeGetMemberByteOffset(); if (!byte_offset) { Die() << "No offset found for base class " << EntryToString(entry); @@ -638,7 +638,7 @@ class Processor { void ProcessArray(Entry& entry) { auto referred_type = GetReferredType(entry); - auto referred_type_id = GetIdForEntry(referred_type); + Id referred_type_id = GetIdForEntry(referred_type); auto children = entry.GetChildren(); // Multiple children in array describe multiple dimensions of this array. // For example, int[M][N] contains two children, M located in the first @@ -674,7 +674,8 @@ class Processor { AddProcessedNode<Enumeration>(entry, name); return; } - auto underlying_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); + const Id underlying_type_id = + GetReferredTypeId(MaybeGetReferredType(entry)); auto children = entry.GetChildren(); Enumeration::Enumerators enumerators; enumerators.reserve(children.size()); @@ -786,7 +787,7 @@ class Processor { auto name_with_context = GetNameWithContext(entry); auto referred_type = GetReferredType(entry); - auto referred_type_id = GetIdForEntry(referred_type); + const Id referred_type_id = GetIdForEntry(referred_type); if (auto address = entry.MaybeGetAddress(DW_AT_location)) { // Only external variables with address are useful for ABI monitoring @@ -823,7 +824,7 @@ class Processor { }; Subprogram GetSubprogram(Entry& entry) { - auto return_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); + const Id return_type_id = GetReferredTypeId(MaybeGetReferredType(entry)); std::vector<Id> parameters; for (auto& child : entry.GetChildren()) { @@ -919,7 +920,7 @@ class Processor { // Populate Id from method above with processed Node. template <typename Node, typename... Args> Id AddProcessedNode(Entry& entry, Args&&... args) { - auto id = GetIdForEntry(entry); + const Id id = GetIdForEntry(entry); graph_.Set<Node>(id, std::forward<Args>(args)...); return id; } |