| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2016 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | * | 
|  | 16 | * Header file of an in-memory representation of DEX files. | 
|  | 17 | */ | 
|  | 18 |  | 
|  | 19 | #ifndef ART_DEXLAYOUT_DEX_IR_H_ | 
|  | 20 | #define ART_DEXLAYOUT_DEX_IR_H_ | 
|  | 21 |  | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 22 | #include <map> | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 23 | #include <vector> | 
|  | 24 | #include <stdint.h> | 
|  | 25 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 26 | #include "dex_file-inl.h" | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 27 | #include "leb128.h" | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 28 | #include "utf.h" | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 29 |  | 
|  | 30 | namespace art { | 
|  | 31 | namespace dex_ir { | 
|  | 32 |  | 
|  | 33 | // Forward declarations for classes used in containers or pointed to. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 34 | class AnnotationItem; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 35 | class AnnotationsDirectoryItem; | 
|  | 36 | class AnnotationSetItem; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 37 | class AnnotationSetRefList; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 38 | class ClassData; | 
|  | 39 | class ClassDef; | 
|  | 40 | class CodeItem; | 
|  | 41 | class DebugInfoItem; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 42 | class EncodedAnnotation; | 
|  | 43 | class EncodedArrayItem; | 
|  | 44 | class EncodedValue; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 45 | class FieldId; | 
|  | 46 | class FieldItem; | 
|  | 47 | class Header; | 
|  | 48 | class MapList; | 
|  | 49 | class MapItem; | 
|  | 50 | class MethodId; | 
|  | 51 | class MethodItem; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 52 | class ParameterAnnotation; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 53 | class ProtoId; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 54 | class StringData; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 55 | class StringId; | 
|  | 56 | class TryItem; | 
|  | 57 | class TypeId; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 58 | class TypeList; | 
|  | 59 |  | 
|  | 60 | // Item size constants. | 
|  | 61 | static constexpr size_t kHeaderItemSize = 112; | 
|  | 62 | static constexpr size_t kStringIdItemSize = 4; | 
|  | 63 | static constexpr size_t kTypeIdItemSize = 4; | 
|  | 64 | static constexpr size_t kProtoIdItemSize = 12; | 
|  | 65 | static constexpr size_t kFieldIdItemSize = 8; | 
|  | 66 | static constexpr size_t kMethodIdItemSize = 8; | 
|  | 67 | static constexpr size_t kClassDefItemSize = 32; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 68 |  | 
|  | 69 | // Visitor support | 
|  | 70 | class AbstractDispatcher { | 
|  | 71 | public: | 
|  | 72 | AbstractDispatcher() = default; | 
|  | 73 | virtual ~AbstractDispatcher() { } | 
|  | 74 |  | 
|  | 75 | virtual void Dispatch(Header* header) = 0; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 76 | virtual void Dispatch(const StringData* string_data) = 0; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 77 | virtual void Dispatch(const StringId* string_id) = 0; | 
|  | 78 | virtual void Dispatch(const TypeId* type_id) = 0; | 
|  | 79 | virtual void Dispatch(const ProtoId* proto_id) = 0; | 
|  | 80 | virtual void Dispatch(const FieldId* field_id) = 0; | 
|  | 81 | virtual void Dispatch(const MethodId* method_id) = 0; | 
|  | 82 | virtual void Dispatch(ClassData* class_data) = 0; | 
|  | 83 | virtual void Dispatch(ClassDef* class_def) = 0; | 
|  | 84 | virtual void Dispatch(FieldItem* field_item) = 0; | 
|  | 85 | virtual void Dispatch(MethodItem* method_item) = 0; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 86 | virtual void Dispatch(EncodedArrayItem* array_item) = 0; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 87 | virtual void Dispatch(CodeItem* code_item) = 0; | 
|  | 88 | virtual void Dispatch(TryItem* try_item) = 0; | 
|  | 89 | virtual void Dispatch(DebugInfoItem* debug_info_item) = 0; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 90 | virtual void Dispatch(AnnotationItem* annotation_item) = 0; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 91 | virtual void Dispatch(AnnotationSetItem* annotation_set_item) = 0; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 92 | virtual void Dispatch(AnnotationSetRefList* annotation_set_ref_list) = 0; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 93 | virtual void Dispatch(AnnotationsDirectoryItem* annotations_directory_item) = 0; | 
|  | 94 | virtual void Dispatch(MapList* map_list) = 0; | 
|  | 95 | virtual void Dispatch(MapItem* map_item) = 0; | 
|  | 96 |  | 
|  | 97 | private: | 
|  | 98 | DISALLOW_COPY_AND_ASSIGN(AbstractDispatcher); | 
|  | 99 | }; | 
|  | 100 |  | 
|  | 101 | // Collections become owners of the objects added by moving them into unique pointers. | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 102 | template<class T> class CollectionBase { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 103 | public: | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 104 | CollectionBase() = default; | 
|  | 105 |  | 
|  | 106 | uint32_t GetOffset() const { return offset_; } | 
|  | 107 | void SetOffset(uint32_t new_offset) { offset_ = new_offset; } | 
|  | 108 |  | 
|  | 109 | private: | 
|  | 110 | uint32_t offset_ = 0; | 
|  | 111 |  | 
|  | 112 | DISALLOW_COPY_AND_ASSIGN(CollectionBase); | 
|  | 113 | }; | 
|  | 114 |  | 
|  | 115 | template<class T> class CollectionVector : public CollectionBase<T> { | 
|  | 116 | public: | 
|  | 117 | CollectionVector() = default; | 
|  | 118 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 119 | void AddIndexedItem(T* object, uint32_t offset, uint32_t index) { | 
|  | 120 | object->SetOffset(offset); | 
|  | 121 | object->SetIndex(index); | 
|  | 122 | collection_.push_back(std::unique_ptr<T>(object)); | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 123 | } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 124 | uint32_t Size() const { return collection_.size(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 125 | std::vector<std::unique_ptr<T>>& Collection() { return collection_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 126 |  | 
|  | 127 | private: | 
|  | 128 | std::vector<std::unique_ptr<T>> collection_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 129 |  | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 130 | DISALLOW_COPY_AND_ASSIGN(CollectionVector); | 
|  | 131 | }; | 
|  | 132 |  | 
|  | 133 | template<class T> class CollectionMap : public CollectionBase<T> { | 
|  | 134 | public: | 
|  | 135 | CollectionMap() = default; | 
|  | 136 |  | 
| Mathieu Chartier | a2973d7 | 2017-02-14 17:12:20 -0800 | [diff] [blame] | 137 | // Returns the existing item if it is already inserted, null otherwise. | 
|  | 138 | T* GetExistingObject(uint32_t offset) { | 
|  | 139 | auto it = collection_.find(offset); | 
|  | 140 | return it != collection_.end() ? it->second.get() : nullptr; | 
|  | 141 | } | 
|  | 142 |  | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 143 | void AddItem(T* object, uint32_t offset) { | 
|  | 144 | object->SetOffset(offset); | 
| Mathieu Chartier | a2973d7 | 2017-02-14 17:12:20 -0800 | [diff] [blame] | 145 | auto it = collection_.emplace(offset, std::unique_ptr<T>(object)); | 
|  | 146 | CHECK(it.second) << "CollectionMap already has an object with offset " << offset << " " | 
|  | 147 | << " and address " << it.first->second.get(); | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 148 | } | 
|  | 149 | uint32_t Size() const { return collection_.size(); } | 
|  | 150 | std::map<uint32_t, std::unique_ptr<T>>& Collection() { return collection_; } | 
|  | 151 |  | 
|  | 152 | private: | 
|  | 153 | std::map<uint32_t, std::unique_ptr<T>> collection_; | 
|  | 154 |  | 
|  | 155 | DISALLOW_COPY_AND_ASSIGN(CollectionMap); | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 156 | }; | 
|  | 157 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 158 | class Collections { | 
|  | 159 | public: | 
|  | 160 | Collections() = default; | 
|  | 161 |  | 
|  | 162 | std::vector<std::unique_ptr<StringId>>& StringIds() { return string_ids_.Collection(); } | 
|  | 163 | std::vector<std::unique_ptr<TypeId>>& TypeIds() { return type_ids_.Collection(); } | 
|  | 164 | std::vector<std::unique_ptr<ProtoId>>& ProtoIds() { return proto_ids_.Collection(); } | 
|  | 165 | std::vector<std::unique_ptr<FieldId>>& FieldIds() { return field_ids_.Collection(); } | 
|  | 166 | std::vector<std::unique_ptr<MethodId>>& MethodIds() { return method_ids_.Collection(); } | 
|  | 167 | std::vector<std::unique_ptr<ClassDef>>& ClassDefs() { return class_defs_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 168 | std::map<uint32_t, std::unique_ptr<StringData>>& StringDatas() | 
|  | 169 | { return string_datas_.Collection(); } | 
|  | 170 | std::map<uint32_t, std::unique_ptr<TypeList>>& TypeLists() { return type_lists_.Collection(); } | 
|  | 171 | std::map<uint32_t, std::unique_ptr<EncodedArrayItem>>& EncodedArrayItems() | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 172 | { return encoded_array_items_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 173 | std::map<uint32_t, std::unique_ptr<AnnotationItem>>& AnnotationItems() | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 174 | { return annotation_items_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 175 | std::map<uint32_t, std::unique_ptr<AnnotationSetItem>>& AnnotationSetItems() | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 176 | { return annotation_set_items_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 177 | std::map<uint32_t, std::unique_ptr<AnnotationSetRefList>>& AnnotationSetRefLists() | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 178 | { return annotation_set_ref_lists_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 179 | std::map<uint32_t, std::unique_ptr<AnnotationsDirectoryItem>>& AnnotationsDirectoryItems() | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 180 | { return annotations_directory_items_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 181 | std::map<uint32_t, std::unique_ptr<DebugInfoItem>>& DebugInfoItems() | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 182 | { return debug_info_items_.Collection(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 183 | std::map<uint32_t, std::unique_ptr<CodeItem>>& CodeItems() { return code_items_.Collection(); } | 
|  | 184 | std::map<uint32_t, std::unique_ptr<ClassData>>& ClassDatas() { return class_datas_.Collection(); } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 185 |  | 
|  | 186 | void CreateStringId(const DexFile& dex_file, uint32_t i); | 
|  | 187 | void CreateTypeId(const DexFile& dex_file, uint32_t i); | 
|  | 188 | void CreateProtoId(const DexFile& dex_file, uint32_t i); | 
|  | 189 | void CreateFieldId(const DexFile& dex_file, uint32_t i); | 
|  | 190 | void CreateMethodId(const DexFile& dex_file, uint32_t i); | 
|  | 191 | void CreateClassDef(const DexFile& dex_file, uint32_t i); | 
|  | 192 |  | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 193 | TypeList* CreateTypeList(const DexFile::TypeList* type_list, uint32_t offset); | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 194 | EncodedArrayItem* CreateEncodedArrayItem(const uint8_t* static_data, uint32_t offset); | 
|  | 195 | AnnotationItem* CreateAnnotationItem(const DexFile::AnnotationItem* annotation, uint32_t offset); | 
|  | 196 | AnnotationSetItem* CreateAnnotationSetItem(const DexFile& dex_file, | 
| Jeff Hao | be9b44b | 2017-02-16 13:34:38 -0800 | [diff] [blame] | 197 | const DexFile::AnnotationSetItem* disk_annotations_item, uint32_t offset); | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 198 | AnnotationsDirectoryItem* CreateAnnotationsDirectoryItem(const DexFile& dex_file, | 
|  | 199 | const DexFile::AnnotationsDirectoryItem* disk_annotations_item, uint32_t offset); | 
|  | 200 | CodeItem* CreateCodeItem( | 
|  | 201 | const DexFile& dex_file, const DexFile::CodeItem& disk_code_item, uint32_t offset); | 
|  | 202 | ClassData* CreateClassData(const DexFile& dex_file, const uint8_t* encoded_data, uint32_t offset); | 
|  | 203 |  | 
|  | 204 | StringId* GetStringId(uint32_t index) { return StringIds()[index].get(); } | 
|  | 205 | TypeId* GetTypeId(uint32_t index) { return TypeIds()[index].get(); } | 
|  | 206 | ProtoId* GetProtoId(uint32_t index) { return ProtoIds()[index].get(); } | 
|  | 207 | FieldId* GetFieldId(uint32_t index) { return FieldIds()[index].get(); } | 
|  | 208 | MethodId* GetMethodId(uint32_t index) { return MethodIds()[index].get(); } | 
|  | 209 | ClassDef* GetClassDef(uint32_t index) { return ClassDefs()[index].get(); } | 
|  | 210 |  | 
|  | 211 | StringId* GetStringIdOrNullPtr(uint32_t index) { | 
|  | 212 | return index == DexFile::kDexNoIndex ? nullptr : GetStringId(index); | 
|  | 213 | } | 
|  | 214 | TypeId* GetTypeIdOrNullPtr(uint16_t index) { | 
|  | 215 | return index == DexFile::kDexNoIndex16 ? nullptr : GetTypeId(index); | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | uint32_t StringIdsOffset() const { return string_ids_.GetOffset(); } | 
|  | 219 | uint32_t TypeIdsOffset() const { return type_ids_.GetOffset(); } | 
|  | 220 | uint32_t ProtoIdsOffset() const { return proto_ids_.GetOffset(); } | 
|  | 221 | uint32_t FieldIdsOffset() const { return field_ids_.GetOffset(); } | 
|  | 222 | uint32_t MethodIdsOffset() const { return method_ids_.GetOffset(); } | 
|  | 223 | uint32_t ClassDefsOffset() const { return class_defs_.GetOffset(); } | 
|  | 224 | uint32_t StringDatasOffset() const { return string_datas_.GetOffset(); } | 
|  | 225 | uint32_t TypeListsOffset() const { return type_lists_.GetOffset(); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 226 | uint32_t EncodedArrayItemsOffset() const { return encoded_array_items_.GetOffset(); } | 
|  | 227 | uint32_t AnnotationItemsOffset() const { return annotation_items_.GetOffset(); } | 
|  | 228 | uint32_t AnnotationSetItemsOffset() const { return annotation_set_items_.GetOffset(); } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 229 | uint32_t AnnotationSetRefListsOffset() const { return annotation_set_ref_lists_.GetOffset(); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 230 | uint32_t AnnotationsDirectoryItemsOffset() const | 
|  | 231 | { return annotations_directory_items_.GetOffset(); } | 
|  | 232 | uint32_t DebugInfoItemsOffset() const { return debug_info_items_.GetOffset(); } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 233 | uint32_t CodeItemsOffset() const { return code_items_.GetOffset(); } | 
|  | 234 | uint32_t ClassDatasOffset() const { return class_datas_.GetOffset(); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 235 | uint32_t MapListOffset() const { return map_list_offset_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 236 |  | 
|  | 237 | void SetStringIdsOffset(uint32_t new_offset) { string_ids_.SetOffset(new_offset); } | 
|  | 238 | void SetTypeIdsOffset(uint32_t new_offset) { type_ids_.SetOffset(new_offset); } | 
|  | 239 | void SetProtoIdsOffset(uint32_t new_offset) { proto_ids_.SetOffset(new_offset); } | 
|  | 240 | void SetFieldIdsOffset(uint32_t new_offset) { field_ids_.SetOffset(new_offset); } | 
|  | 241 | void SetMethodIdsOffset(uint32_t new_offset) { method_ids_.SetOffset(new_offset); } | 
|  | 242 | void SetClassDefsOffset(uint32_t new_offset) { class_defs_.SetOffset(new_offset); } | 
|  | 243 | void SetStringDatasOffset(uint32_t new_offset) { string_datas_.SetOffset(new_offset); } | 
|  | 244 | void SetTypeListsOffset(uint32_t new_offset) { type_lists_.SetOffset(new_offset); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 245 | void SetEncodedArrayItemsOffset(uint32_t new_offset) | 
|  | 246 | { encoded_array_items_.SetOffset(new_offset); } | 
|  | 247 | void SetAnnotationItemsOffset(uint32_t new_offset) { annotation_items_.SetOffset(new_offset); } | 
|  | 248 | void SetAnnotationSetItemsOffset(uint32_t new_offset) | 
|  | 249 | { annotation_set_items_.SetOffset(new_offset); } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 250 | void SetAnnotationSetRefListsOffset(uint32_t new_offset) | 
|  | 251 | { annotation_set_ref_lists_.SetOffset(new_offset); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 252 | void SetAnnotationsDirectoryItemsOffset(uint32_t new_offset) | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 253 | { annotations_directory_items_.SetOffset(new_offset); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 254 | void SetDebugInfoItemsOffset(uint32_t new_offset) { debug_info_items_.SetOffset(new_offset); } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 255 | void SetCodeItemsOffset(uint32_t new_offset) { code_items_.SetOffset(new_offset); } | 
|  | 256 | void SetClassDatasOffset(uint32_t new_offset) { class_datas_.SetOffset(new_offset); } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 257 | void SetMapListOffset(uint32_t new_offset) { map_list_offset_ = new_offset; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 258 |  | 
|  | 259 | uint32_t StringIdsSize() const { return string_ids_.Size(); } | 
|  | 260 | uint32_t TypeIdsSize() const { return type_ids_.Size(); } | 
|  | 261 | uint32_t ProtoIdsSize() const { return proto_ids_.Size(); } | 
|  | 262 | uint32_t FieldIdsSize() const { return field_ids_.Size(); } | 
|  | 263 | uint32_t MethodIdsSize() const { return method_ids_.Size(); } | 
|  | 264 | uint32_t ClassDefsSize() const { return class_defs_.Size(); } | 
| David Sehr | cdcfde7 | 2016-09-26 07:44:04 -0700 | [diff] [blame] | 265 | uint32_t StringDatasSize() const { return string_datas_.Size(); } | 
|  | 266 | uint32_t TypeListsSize() const { return type_lists_.Size(); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 267 | uint32_t EncodedArrayItemsSize() const { return encoded_array_items_.Size(); } | 
|  | 268 | uint32_t AnnotationItemsSize() const { return annotation_items_.Size(); } | 
|  | 269 | uint32_t AnnotationSetItemsSize() const { return annotation_set_items_.Size(); } | 
| David Sehr | cdcfde7 | 2016-09-26 07:44:04 -0700 | [diff] [blame] | 270 | uint32_t AnnotationSetRefListsSize() const { return annotation_set_ref_lists_.Size(); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 271 | uint32_t AnnotationsDirectoryItemsSize() const { return annotations_directory_items_.Size(); } | 
|  | 272 | uint32_t DebugInfoItemsSize() const { return debug_info_items_.Size(); } | 
| David Sehr | cdcfde7 | 2016-09-26 07:44:04 -0700 | [diff] [blame] | 273 | uint32_t CodeItemsSize() const { return code_items_.Size(); } | 
|  | 274 | uint32_t ClassDatasSize() const { return class_datas_.Size(); } | 
|  | 275 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 276 | private: | 
|  | 277 | EncodedValue* ReadEncodedValue(const uint8_t** data); | 
|  | 278 | EncodedValue* ReadEncodedValue(const uint8_t** data, uint8_t type, uint8_t length); | 
|  | 279 | void ReadEncodedValue(const uint8_t** data, uint8_t type, uint8_t length, EncodedValue* item); | 
|  | 280 |  | 
|  | 281 | ParameterAnnotation* GenerateParameterAnnotation(const DexFile& dex_file, MethodId* method_id, | 
|  | 282 | const DexFile::AnnotationSetRefList* annotation_set_ref_list, uint32_t offset); | 
|  | 283 | MethodItem* GenerateMethodItem(const DexFile& dex_file, ClassDataItemIterator& cdii); | 
|  | 284 |  | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 285 | CollectionVector<StringId> string_ids_; | 
|  | 286 | CollectionVector<TypeId> type_ids_; | 
|  | 287 | CollectionVector<ProtoId> proto_ids_; | 
|  | 288 | CollectionVector<FieldId> field_ids_; | 
|  | 289 | CollectionVector<MethodId> method_ids_; | 
|  | 290 | CollectionVector<ClassDef> class_defs_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 291 |  | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 292 | CollectionMap<StringData> string_datas_; | 
|  | 293 | CollectionMap<TypeList> type_lists_; | 
|  | 294 | CollectionMap<EncodedArrayItem> encoded_array_items_; | 
|  | 295 | CollectionMap<AnnotationItem> annotation_items_; | 
|  | 296 | CollectionMap<AnnotationSetItem> annotation_set_items_; | 
|  | 297 | CollectionMap<AnnotationSetRefList> annotation_set_ref_lists_; | 
|  | 298 | CollectionMap<AnnotationsDirectoryItem> annotations_directory_items_; | 
|  | 299 | CollectionMap<DebugInfoItem> debug_info_items_; | 
|  | 300 | CollectionMap<CodeItem> code_items_; | 
|  | 301 | CollectionMap<ClassData> class_datas_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 302 |  | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 303 | uint32_t map_list_offset_ = 0; | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 304 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 305 | DISALLOW_COPY_AND_ASSIGN(Collections); | 
|  | 306 | }; | 
|  | 307 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 308 | class Item { | 
|  | 309 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 310 | Item() { } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 311 | virtual ~Item() { } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 312 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 313 | uint32_t GetOffset() const { return offset_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 314 | uint32_t GetSize() const { return size_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 315 | void SetOffset(uint32_t offset) { offset_ = offset; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 316 | void SetSize(uint32_t size) { size_ = size; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 317 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 318 | protected: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 319 | Item(uint32_t offset, uint32_t size) : offset_(offset), size_(size) { } | 
|  | 320 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 321 | uint32_t offset_ = 0; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 322 | uint32_t size_ = 0; | 
|  | 323 | }; | 
|  | 324 |  | 
|  | 325 | class IndexedItem : public Item { | 
|  | 326 | public: | 
|  | 327 | IndexedItem() { } | 
|  | 328 | virtual ~IndexedItem() { } | 
|  | 329 |  | 
|  | 330 | uint32_t GetIndex() const { return index_; } | 
|  | 331 | void SetIndex(uint32_t index) { index_ = index; } | 
|  | 332 |  | 
|  | 333 | protected: | 
|  | 334 | IndexedItem(uint32_t offset, uint32_t size, uint32_t index) | 
|  | 335 | : Item(offset, size), index_(index) { } | 
|  | 336 |  | 
|  | 337 | uint32_t index_ = 0; | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 338 | }; | 
|  | 339 |  | 
|  | 340 | class Header : public Item { | 
|  | 341 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 342 | Header(const uint8_t* magic, | 
|  | 343 | uint32_t checksum, | 
|  | 344 | const uint8_t* signature, | 
|  | 345 | uint32_t endian_tag, | 
|  | 346 | uint32_t file_size, | 
|  | 347 | uint32_t header_size, | 
|  | 348 | uint32_t link_size, | 
|  | 349 | uint32_t link_offset, | 
|  | 350 | uint32_t data_size, | 
|  | 351 | uint32_t data_offset) | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 352 | : Item(0, kHeaderItemSize), | 
|  | 353 | checksum_(checksum), | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 354 | endian_tag_(endian_tag), | 
|  | 355 | file_size_(file_size), | 
|  | 356 | header_size_(header_size), | 
|  | 357 | link_size_(link_size), | 
|  | 358 | link_offset_(link_offset), | 
|  | 359 | data_size_(data_size), | 
|  | 360 | data_offset_(data_offset) { | 
|  | 361 | memcpy(magic_, magic, sizeof(magic_)); | 
|  | 362 | memcpy(signature_, signature, sizeof(signature_)); | 
|  | 363 | } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 364 | ~Header() OVERRIDE { } | 
|  | 365 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 366 | static size_t ItemSize() { return kHeaderItemSize; } | 
|  | 367 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 368 | const uint8_t* Magic() const { return magic_; } | 
|  | 369 | uint32_t Checksum() const { return checksum_; } | 
|  | 370 | const uint8_t* Signature() const { return signature_; } | 
|  | 371 | uint32_t EndianTag() const { return endian_tag_; } | 
|  | 372 | uint32_t FileSize() const { return file_size_; } | 
|  | 373 | uint32_t HeaderSize() const { return header_size_; } | 
|  | 374 | uint32_t LinkSize() const { return link_size_; } | 
|  | 375 | uint32_t LinkOffset() const { return link_offset_; } | 
|  | 376 | uint32_t DataSize() const { return data_size_; } | 
|  | 377 | uint32_t DataOffset() const { return data_offset_; } | 
|  | 378 |  | 
|  | 379 | void SetChecksum(uint32_t new_checksum) { checksum_ = new_checksum; } | 
|  | 380 | void SetSignature(const uint8_t* new_signature) { | 
|  | 381 | memcpy(signature_, new_signature, sizeof(signature_)); | 
|  | 382 | } | 
|  | 383 | void SetFileSize(uint32_t new_file_size) { file_size_ = new_file_size; } | 
|  | 384 | void SetHeaderSize(uint32_t new_header_size) { header_size_ = new_header_size; } | 
|  | 385 | void SetLinkSize(uint32_t new_link_size) { link_size_ = new_link_size; } | 
|  | 386 | void SetLinkOffset(uint32_t new_link_offset) { link_offset_ = new_link_offset; } | 
|  | 387 | void SetDataSize(uint32_t new_data_size) { data_size_ = new_data_size; } | 
|  | 388 | void SetDataOffset(uint32_t new_data_offset) { data_offset_ = new_data_offset; } | 
|  | 389 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 390 | Collections& GetCollections() { return collections_; } | 
| Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 391 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 392 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 393 |  | 
|  | 394 | private: | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 395 | uint8_t magic_[8]; | 
|  | 396 | uint32_t checksum_; | 
|  | 397 | uint8_t signature_[DexFile::kSha1DigestSize]; | 
|  | 398 | uint32_t endian_tag_; | 
|  | 399 | uint32_t file_size_; | 
|  | 400 | uint32_t header_size_; | 
|  | 401 | uint32_t link_size_; | 
|  | 402 | uint32_t link_offset_; | 
|  | 403 | uint32_t data_size_; | 
|  | 404 | uint32_t data_offset_; | 
|  | 405 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 406 | Collections collections_; | 
|  | 407 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(Header); | 
|  | 409 | }; | 
|  | 410 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 411 | class StringData : public Item { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 412 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 413 | explicit StringData(const char* data) : data_(strdup(data)) { | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 414 | size_ = UnsignedLeb128Size(CountModifiedUtf8Chars(data)) + strlen(data); | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 415 | } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 416 |  | 
|  | 417 | const char* Data() const { return data_.get(); } | 
|  | 418 |  | 
|  | 419 | void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); } | 
|  | 420 |  | 
|  | 421 | private: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 422 | UniqueCPtr<const char> data_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 423 |  | 
|  | 424 | DISALLOW_COPY_AND_ASSIGN(StringData); | 
|  | 425 | }; | 
|  | 426 |  | 
|  | 427 | class StringId : public IndexedItem { | 
|  | 428 | public: | 
|  | 429 | explicit StringId(StringData* string_data) : string_data_(string_data) { | 
|  | 430 | size_ = kStringIdItemSize; | 
|  | 431 | } | 
|  | 432 | ~StringId() OVERRIDE { } | 
|  | 433 |  | 
|  | 434 | static size_t ItemSize() { return kStringIdItemSize; } | 
|  | 435 |  | 
|  | 436 | const char* Data() const { return string_data_->Data(); } | 
|  | 437 | StringData* DataItem() const { return string_data_; } | 
|  | 438 |  | 
|  | 439 | void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); } | 
|  | 440 |  | 
|  | 441 | private: | 
|  | 442 | StringData* string_data_; | 
|  | 443 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 444 | DISALLOW_COPY_AND_ASSIGN(StringId); | 
|  | 445 | }; | 
|  | 446 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 447 | class TypeId : public IndexedItem { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 448 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 449 | explicit TypeId(StringId* string_id) : string_id_(string_id) { size_ = kTypeIdItemSize; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 450 | ~TypeId() OVERRIDE { } | 
|  | 451 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 452 | static size_t ItemSize() { return kTypeIdItemSize; } | 
|  | 453 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 454 | StringId* GetStringId() const { return string_id_; } | 
|  | 455 |  | 
|  | 456 | void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); } | 
|  | 457 |  | 
|  | 458 | private: | 
|  | 459 | StringId* string_id_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 460 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 461 | DISALLOW_COPY_AND_ASSIGN(TypeId); | 
|  | 462 | }; | 
|  | 463 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 464 | using TypeIdVector = std::vector<const TypeId*>; | 
|  | 465 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 466 | class TypeList : public Item { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 467 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 468 | explicit TypeList(TypeIdVector* type_list) : type_list_(type_list) { | 
|  | 469 | size_ = sizeof(uint32_t) + (type_list->size() * sizeof(uint16_t)); | 
|  | 470 | } | 
|  | 471 | ~TypeList() OVERRIDE { } | 
|  | 472 |  | 
|  | 473 | const TypeIdVector* GetTypeList() const { return type_list_.get(); } | 
|  | 474 |  | 
|  | 475 | private: | 
|  | 476 | std::unique_ptr<TypeIdVector> type_list_; | 
|  | 477 |  | 
|  | 478 | DISALLOW_COPY_AND_ASSIGN(TypeList); | 
|  | 479 | }; | 
|  | 480 |  | 
|  | 481 | class ProtoId : public IndexedItem { | 
|  | 482 | public: | 
|  | 483 | ProtoId(const StringId* shorty, const TypeId* return_type, TypeList* parameters) | 
|  | 484 | : shorty_(shorty), return_type_(return_type), parameters_(parameters) | 
|  | 485 | { size_ = kProtoIdItemSize; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 486 | ~ProtoId() OVERRIDE { } | 
|  | 487 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 488 | static size_t ItemSize() { return kProtoIdItemSize; } | 
|  | 489 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 490 | const StringId* Shorty() const { return shorty_; } | 
|  | 491 | const TypeId* ReturnType() const { return return_type_; } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 492 | const TypeList* Parameters() const { return parameters_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 493 |  | 
|  | 494 | void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); } | 
|  | 495 |  | 
|  | 496 | private: | 
|  | 497 | const StringId* shorty_; | 
|  | 498 | const TypeId* return_type_; | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 499 | TypeList* parameters_;  // This can be nullptr. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 500 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 501 | DISALLOW_COPY_AND_ASSIGN(ProtoId); | 
|  | 502 | }; | 
|  | 503 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 504 | class FieldId : public IndexedItem { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 505 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 506 | FieldId(const TypeId* klass, const TypeId* type, const StringId* name) | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 507 | : class_(klass), type_(type), name_(name) { size_ = kFieldIdItemSize; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 508 | ~FieldId() OVERRIDE { } | 
|  | 509 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 510 | static size_t ItemSize() { return kFieldIdItemSize; } | 
|  | 511 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 512 | const TypeId* Class() const { return class_; } | 
|  | 513 | const TypeId* Type() const { return type_; } | 
|  | 514 | const StringId* Name() const { return name_; } | 
|  | 515 |  | 
|  | 516 | void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); } | 
|  | 517 |  | 
|  | 518 | private: | 
|  | 519 | const TypeId* class_; | 
|  | 520 | const TypeId* type_; | 
|  | 521 | const StringId* name_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 522 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 523 | DISALLOW_COPY_AND_ASSIGN(FieldId); | 
|  | 524 | }; | 
|  | 525 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 526 | class MethodId : public IndexedItem { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 527 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 528 | MethodId(const TypeId* klass, const ProtoId* proto, const StringId* name) | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 529 | : class_(klass), proto_(proto), name_(name) { size_ = kMethodIdItemSize; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 530 | ~MethodId() OVERRIDE { } | 
|  | 531 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 532 | static size_t ItemSize() { return kMethodIdItemSize; } | 
|  | 533 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 534 | const TypeId* Class() const { return class_; } | 
|  | 535 | const ProtoId* Proto() const { return proto_; } | 
|  | 536 | const StringId* Name() const { return name_; } | 
|  | 537 |  | 
|  | 538 | void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); } | 
|  | 539 |  | 
|  | 540 | private: | 
|  | 541 | const TypeId* class_; | 
|  | 542 | const ProtoId* proto_; | 
|  | 543 | const StringId* name_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 544 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 545 | DISALLOW_COPY_AND_ASSIGN(MethodId); | 
|  | 546 | }; | 
|  | 547 |  | 
|  | 548 | class FieldItem : public Item { | 
|  | 549 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 550 | FieldItem(uint32_t access_flags, const FieldId* field_id) | 
|  | 551 | : access_flags_(access_flags), field_id_(field_id) { } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 552 | ~FieldItem() OVERRIDE { } | 
|  | 553 |  | 
|  | 554 | uint32_t GetAccessFlags() const { return access_flags_; } | 
|  | 555 | const FieldId* GetFieldId() const { return field_id_; } | 
|  | 556 |  | 
|  | 557 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 558 |  | 
|  | 559 | private: | 
|  | 560 | uint32_t access_flags_; | 
|  | 561 | const FieldId* field_id_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 562 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 563 | DISALLOW_COPY_AND_ASSIGN(FieldItem); | 
|  | 564 | }; | 
|  | 565 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 566 | using FieldItemVector = std::vector<std::unique_ptr<FieldItem>>; | 
|  | 567 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 568 | class MethodItem : public Item { | 
|  | 569 | public: | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 570 | MethodItem(uint32_t access_flags, const MethodId* method_id, CodeItem* code) | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 571 | : access_flags_(access_flags), method_id_(method_id), code_(code) { } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 572 | ~MethodItem() OVERRIDE { } | 
|  | 573 |  | 
|  | 574 | uint32_t GetAccessFlags() const { return access_flags_; } | 
|  | 575 | const MethodId* GetMethodId() const { return method_id_; } | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 576 | CodeItem* GetCodeItem() { return code_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 577 |  | 
|  | 578 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 579 |  | 
|  | 580 | private: | 
|  | 581 | uint32_t access_flags_; | 
|  | 582 | const MethodId* method_id_; | 
| Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 583 | CodeItem* code_;  // This can be nullptr. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 584 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 585 | DISALLOW_COPY_AND_ASSIGN(MethodItem); | 
|  | 586 | }; | 
|  | 587 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 588 | using MethodItemVector = std::vector<std::unique_ptr<MethodItem>>; | 
|  | 589 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 590 | class EncodedValue { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 591 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 592 | explicit EncodedValue(uint8_t type) : type_(type) { } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 593 |  | 
|  | 594 | int8_t Type() const { return type_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 595 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 596 | void SetBoolean(bool z) { u_.bool_val_ = z; } | 
|  | 597 | void SetByte(int8_t b) { u_.byte_val_ = b; } | 
|  | 598 | void SetShort(int16_t s) { u_.short_val_ = s; } | 
|  | 599 | void SetChar(uint16_t c) { u_.char_val_ = c; } | 
|  | 600 | void SetInt(int32_t i) { u_.int_val_ = i; } | 
|  | 601 | void SetLong(int64_t l) { u_.long_val_ = l; } | 
|  | 602 | void SetFloat(float f) { u_.float_val_ = f; } | 
|  | 603 | void SetDouble(double d) { u_.double_val_ = d; } | 
|  | 604 | void SetStringId(StringId* string_id) { u_.string_val_ = string_id; } | 
|  | 605 | void SetTypeId(TypeId* type_id) { u_.type_val_ = type_id; } | 
|  | 606 | void SetFieldId(FieldId* field_id) { u_.field_val_ = field_id; } | 
|  | 607 | void SetMethodId(MethodId* method_id) { u_.method_val_ = method_id; } | 
|  | 608 | void SetEncodedArray(EncodedArrayItem* encoded_array) { encoded_array_.reset(encoded_array); } | 
|  | 609 | void SetEncodedAnnotation(EncodedAnnotation* encoded_annotation) | 
|  | 610 | { encoded_annotation_.reset(encoded_annotation); } | 
|  | 611 |  | 
|  | 612 | bool GetBoolean() const { return u_.bool_val_; } | 
|  | 613 | int8_t GetByte() const { return u_.byte_val_; } | 
|  | 614 | int16_t GetShort() const { return u_.short_val_; } | 
|  | 615 | uint16_t GetChar() const { return u_.char_val_; } | 
|  | 616 | int32_t GetInt() const { return u_.int_val_; } | 
|  | 617 | int64_t GetLong() const { return u_.long_val_; } | 
|  | 618 | float GetFloat() const { return u_.float_val_; } | 
|  | 619 | double GetDouble() const { return u_.double_val_; } | 
|  | 620 | StringId* GetStringId() const { return u_.string_val_; } | 
|  | 621 | TypeId* GetTypeId() const { return u_.type_val_; } | 
|  | 622 | FieldId* GetFieldId() const { return u_.field_val_; } | 
|  | 623 | MethodId* GetMethodId() const { return u_.method_val_; } | 
|  | 624 | EncodedArrayItem* GetEncodedArray() const { return encoded_array_.get(); } | 
|  | 625 | EncodedAnnotation* GetEncodedAnnotation() const { return encoded_annotation_.get(); } | 
|  | 626 |  | 
|  | 627 | EncodedAnnotation* ReleaseEncodedAnnotation() { return encoded_annotation_.release(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 628 |  | 
|  | 629 | private: | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 630 | uint8_t type_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 631 | union { | 
|  | 632 | bool bool_val_; | 
|  | 633 | int8_t byte_val_; | 
|  | 634 | int16_t short_val_; | 
|  | 635 | uint16_t char_val_; | 
|  | 636 | int32_t int_val_; | 
|  | 637 | int64_t long_val_; | 
|  | 638 | float float_val_; | 
|  | 639 | double double_val_; | 
|  | 640 | StringId* string_val_; | 
|  | 641 | TypeId* type_val_; | 
|  | 642 | FieldId* field_val_; | 
|  | 643 | MethodId* method_val_; | 
|  | 644 | } u_; | 
|  | 645 | std::unique_ptr<EncodedArrayItem> encoded_array_; | 
|  | 646 | std::unique_ptr<EncodedAnnotation> encoded_annotation_; | 
|  | 647 |  | 
|  | 648 | DISALLOW_COPY_AND_ASSIGN(EncodedValue); | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 649 | }; | 
|  | 650 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 651 | using EncodedValueVector = std::vector<std::unique_ptr<EncodedValue>>; | 
|  | 652 |  | 
|  | 653 | class AnnotationElement { | 
|  | 654 | public: | 
|  | 655 | AnnotationElement(StringId* name, EncodedValue* value) : name_(name), value_(value) { } | 
|  | 656 |  | 
|  | 657 | StringId* GetName() const { return name_; } | 
|  | 658 | EncodedValue* GetValue() const { return value_.get(); } | 
|  | 659 |  | 
|  | 660 | private: | 
|  | 661 | StringId* name_; | 
|  | 662 | std::unique_ptr<EncodedValue> value_; | 
|  | 663 |  | 
|  | 664 | DISALLOW_COPY_AND_ASSIGN(AnnotationElement); | 
|  | 665 | }; | 
|  | 666 |  | 
|  | 667 | using AnnotationElementVector = std::vector<std::unique_ptr<AnnotationElement>>; | 
|  | 668 |  | 
|  | 669 | class EncodedAnnotation { | 
|  | 670 | public: | 
|  | 671 | EncodedAnnotation(TypeId* type, AnnotationElementVector* elements) | 
|  | 672 | : type_(type), elements_(elements) { } | 
|  | 673 |  | 
|  | 674 | TypeId* GetType() const { return type_; } | 
|  | 675 | AnnotationElementVector* GetAnnotationElements() const { return elements_.get(); } | 
|  | 676 |  | 
|  | 677 | private: | 
|  | 678 | TypeId* type_; | 
|  | 679 | std::unique_ptr<AnnotationElementVector> elements_; | 
|  | 680 |  | 
|  | 681 | DISALLOW_COPY_AND_ASSIGN(EncodedAnnotation); | 
|  | 682 | }; | 
|  | 683 |  | 
|  | 684 | class EncodedArrayItem : public Item { | 
|  | 685 | public: | 
|  | 686 | explicit EncodedArrayItem(EncodedValueVector* encoded_values) | 
|  | 687 | : encoded_values_(encoded_values) { } | 
|  | 688 |  | 
|  | 689 | EncodedValueVector* GetEncodedValues() const { return encoded_values_.get(); } | 
|  | 690 |  | 
|  | 691 | private: | 
|  | 692 | std::unique_ptr<EncodedValueVector> encoded_values_; | 
|  | 693 |  | 
|  | 694 | DISALLOW_COPY_AND_ASSIGN(EncodedArrayItem); | 
|  | 695 | }; | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 696 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 697 | class ClassData : public Item { | 
|  | 698 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 699 | ClassData(FieldItemVector* static_fields, | 
|  | 700 | FieldItemVector* instance_fields, | 
|  | 701 | MethodItemVector* direct_methods, | 
|  | 702 | MethodItemVector* virtual_methods) | 
|  | 703 | : static_fields_(static_fields), | 
|  | 704 | instance_fields_(instance_fields), | 
|  | 705 | direct_methods_(direct_methods), | 
|  | 706 | virtual_methods_(virtual_methods) { } | 
|  | 707 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 708 | ~ClassData() OVERRIDE = default; | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 709 | FieldItemVector* StaticFields() { return static_fields_.get(); } | 
|  | 710 | FieldItemVector* InstanceFields() { return instance_fields_.get(); } | 
|  | 711 | MethodItemVector* DirectMethods() { return direct_methods_.get(); } | 
|  | 712 | MethodItemVector* VirtualMethods() { return virtual_methods_.get(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 713 |  | 
|  | 714 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 715 |  | 
|  | 716 | private: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 717 | std::unique_ptr<FieldItemVector> static_fields_; | 
|  | 718 | std::unique_ptr<FieldItemVector> instance_fields_; | 
|  | 719 | std::unique_ptr<MethodItemVector> direct_methods_; | 
|  | 720 | std::unique_ptr<MethodItemVector> virtual_methods_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 721 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 722 | DISALLOW_COPY_AND_ASSIGN(ClassData); | 
|  | 723 | }; | 
|  | 724 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 725 | class ClassDef : public IndexedItem { | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 726 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 727 | ClassDef(const TypeId* class_type, | 
|  | 728 | uint32_t access_flags, | 
|  | 729 | const TypeId* superclass, | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 730 | TypeList* interfaces, | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 731 | const StringId* source_file, | 
|  | 732 | AnnotationsDirectoryItem* annotations, | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 733 | EncodedArrayItem* static_values, | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 734 | ClassData* class_data) | 
|  | 735 | : class_type_(class_type), | 
|  | 736 | access_flags_(access_flags), | 
|  | 737 | superclass_(superclass), | 
|  | 738 | interfaces_(interfaces), | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 739 | source_file_(source_file), | 
|  | 740 | annotations_(annotations), | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 741 | class_data_(class_data), | 
|  | 742 | static_values_(static_values) { size_ = kClassDefItemSize; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 743 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 744 | ~ClassDef() OVERRIDE { } | 
|  | 745 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 746 | static size_t ItemSize() { return kClassDefItemSize; } | 
|  | 747 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 748 | const TypeId* ClassType() const { return class_type_; } | 
|  | 749 | uint32_t GetAccessFlags() const { return access_flags_; } | 
|  | 750 | const TypeId* Superclass() const { return superclass_; } | 
| Jeff Hao | cc82959 | 2017-03-14 16:13:39 -0700 | [diff] [blame] | 751 | const TypeList* Interfaces() { return interfaces_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 752 | uint32_t InterfacesOffset() { return interfaces_ == nullptr ? 0 : interfaces_->GetOffset(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 753 | const StringId* SourceFile() const { return source_file_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 754 | AnnotationsDirectoryItem* Annotations() const { return annotations_; } | 
| Nicolas Geoffray | fd1a6c2 | 2016-10-04 11:01:17 +0000 | [diff] [blame] | 755 | ClassData* GetClassData() { return class_data_; } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 756 | EncodedArrayItem* StaticValues() { return static_values_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 757 |  | 
| Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 758 | MethodItem* GenerateMethodItem(Header& header, ClassDataItemIterator& cdii); | 
|  | 759 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 760 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 761 |  | 
|  | 762 | private: | 
|  | 763 | const TypeId* class_type_; | 
|  | 764 | uint32_t access_flags_; | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 765 | const TypeId* superclass_;  // This can be nullptr. | 
|  | 766 | TypeList* interfaces_;  // This can be nullptr. | 
|  | 767 | const StringId* source_file_;  // This can be nullptr. | 
|  | 768 | AnnotationsDirectoryItem* annotations_;  // This can be nullptr. | 
|  | 769 | ClassData* class_data_;  // This can be nullptr. | 
|  | 770 | EncodedArrayItem* static_values_;  // This can be nullptr. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 771 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 772 | DISALLOW_COPY_AND_ASSIGN(ClassDef); | 
|  | 773 | }; | 
|  | 774 |  | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 775 | class TypeAddrPair { | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 776 | public: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 777 | TypeAddrPair(const TypeId* type_id, uint32_t address) : type_id_(type_id), address_(address) { } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 778 |  | 
|  | 779 | const TypeId* GetTypeId() const { return type_id_; } | 
|  | 780 | uint32_t GetAddress() const { return address_; } | 
|  | 781 |  | 
|  | 782 | private: | 
| Jeff Hao | cc82959 | 2017-03-14 16:13:39 -0700 | [diff] [blame] | 783 | const TypeId* type_id_;  // This can be nullptr. | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 784 | uint32_t address_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 785 |  | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 786 | DISALLOW_COPY_AND_ASSIGN(TypeAddrPair); | 
|  | 787 | }; | 
|  | 788 |  | 
|  | 789 | using TypeAddrPairVector = std::vector<std::unique_ptr<const TypeAddrPair>>; | 
|  | 790 |  | 
|  | 791 | class CatchHandler { | 
|  | 792 | public: | 
|  | 793 | explicit CatchHandler(bool catch_all, uint16_t list_offset, TypeAddrPairVector* handlers) | 
|  | 794 | : catch_all_(catch_all), list_offset_(list_offset), handlers_(handlers) { } | 
|  | 795 |  | 
|  | 796 | bool HasCatchAll() const { return catch_all_; } | 
|  | 797 | uint16_t GetListOffset() const { return list_offset_; } | 
|  | 798 | TypeAddrPairVector* GetHandlers() const { return handlers_.get(); } | 
|  | 799 |  | 
|  | 800 | private: | 
|  | 801 | bool catch_all_; | 
|  | 802 | uint16_t list_offset_; | 
|  | 803 | std::unique_ptr<TypeAddrPairVector> handlers_; | 
|  | 804 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 805 | DISALLOW_COPY_AND_ASSIGN(CatchHandler); | 
|  | 806 | }; | 
|  | 807 |  | 
|  | 808 | using CatchHandlerVector = std::vector<std::unique_ptr<const CatchHandler>>; | 
|  | 809 |  | 
|  | 810 | class TryItem : public Item { | 
|  | 811 | public: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 812 | TryItem(uint32_t start_addr, uint16_t insn_count, const CatchHandler* handlers) | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 813 | : start_addr_(start_addr), insn_count_(insn_count), handlers_(handlers) { } | 
|  | 814 | ~TryItem() OVERRIDE { } | 
|  | 815 |  | 
|  | 816 | uint32_t StartAddr() const { return start_addr_; } | 
|  | 817 | uint16_t InsnCount() const { return insn_count_; } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 818 | const CatchHandler* GetHandlers() const { return handlers_; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 819 |  | 
|  | 820 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 821 |  | 
|  | 822 | private: | 
|  | 823 | uint32_t start_addr_; | 
|  | 824 | uint16_t insn_count_; | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 825 | const CatchHandler* handlers_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 826 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 827 | DISALLOW_COPY_AND_ASSIGN(TryItem); | 
|  | 828 | }; | 
|  | 829 |  | 
|  | 830 | using TryItemVector = std::vector<std::unique_ptr<const TryItem>>; | 
|  | 831 |  | 
| David Sehr | d1e44e2 | 2016-10-06 17:09:32 -0700 | [diff] [blame] | 832 | class CodeFixups { | 
|  | 833 | public: | 
|  | 834 | CodeFixups(std::vector<TypeId*>* type_ids, | 
|  | 835 | std::vector<StringId*>* string_ids, | 
|  | 836 | std::vector<MethodId*>* method_ids, | 
|  | 837 | std::vector<FieldId*>* field_ids) | 
|  | 838 | : type_ids_(type_ids), | 
|  | 839 | string_ids_(string_ids), | 
|  | 840 | method_ids_(method_ids), | 
|  | 841 | field_ids_(field_ids) { } | 
|  | 842 |  | 
|  | 843 | std::vector<TypeId*>* TypeIds() const { return type_ids_.get(); } | 
|  | 844 | std::vector<StringId*>* StringIds() const { return string_ids_.get(); } | 
|  | 845 | std::vector<MethodId*>* MethodIds() const { return method_ids_.get(); } | 
|  | 846 | std::vector<FieldId*>* FieldIds() const { return field_ids_.get(); } | 
|  | 847 |  | 
|  | 848 | private: | 
|  | 849 | std::unique_ptr<std::vector<TypeId*>> type_ids_; | 
|  | 850 | std::unique_ptr<std::vector<StringId*>> string_ids_; | 
|  | 851 | std::unique_ptr<std::vector<MethodId*>> method_ids_; | 
|  | 852 | std::unique_ptr<std::vector<FieldId*>> field_ids_; | 
|  | 853 |  | 
|  | 854 | DISALLOW_COPY_AND_ASSIGN(CodeFixups); | 
|  | 855 | }; | 
|  | 856 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 857 | class CodeItem : public Item { | 
|  | 858 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 859 | CodeItem(uint16_t registers_size, | 
|  | 860 | uint16_t ins_size, | 
|  | 861 | uint16_t outs_size, | 
|  | 862 | DebugInfoItem* debug_info, | 
|  | 863 | uint32_t insns_size, | 
|  | 864 | uint16_t* insns, | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 865 | TryItemVector* tries, | 
|  | 866 | CatchHandlerVector* handlers) | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 867 | : registers_size_(registers_size), | 
|  | 868 | ins_size_(ins_size), | 
|  | 869 | outs_size_(outs_size), | 
|  | 870 | debug_info_(debug_info), | 
|  | 871 | insns_size_(insns_size), | 
|  | 872 | insns_(insns), | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 873 | tries_(tries), | 
|  | 874 | handlers_(handlers) { } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 875 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 876 | ~CodeItem() OVERRIDE { } | 
|  | 877 |  | 
|  | 878 | uint16_t RegistersSize() const { return registers_size_; } | 
|  | 879 | uint16_t InsSize() const { return ins_size_; } | 
|  | 880 | uint16_t OutsSize() const { return outs_size_; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 881 | uint16_t TriesSize() const { return tries_ == nullptr ? 0 : tries_->size(); } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 882 | DebugInfoItem* DebugInfo() const { return debug_info_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 883 | uint32_t InsnsSize() const { return insns_size_; } | 
|  | 884 | uint16_t* Insns() const { return insns_.get(); } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 885 | TryItemVector* Tries() const { return tries_.get(); } | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 886 | CatchHandlerVector* Handlers() const { return handlers_.get(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 887 |  | 
| David Sehr | d1e44e2 | 2016-10-06 17:09:32 -0700 | [diff] [blame] | 888 | void SetCodeFixups(CodeFixups* fixups) { fixups_.reset(fixups); } | 
|  | 889 | CodeFixups* GetCodeFixups() const { return fixups_.get(); } | 
|  | 890 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 891 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 892 |  | 
|  | 893 | private: | 
|  | 894 | uint16_t registers_size_; | 
|  | 895 | uint16_t ins_size_; | 
|  | 896 | uint16_t outs_size_; | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 897 | DebugInfoItem* debug_info_;  // This can be nullptr. | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 898 | uint32_t insns_size_; | 
|  | 899 | std::unique_ptr<uint16_t[]> insns_; | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 900 | std::unique_ptr<TryItemVector> tries_;  // This can be nullptr. | 
|  | 901 | std::unique_ptr<CatchHandlerVector> handlers_;  // This can be nullptr. | 
| David Sehr | d1e44e2 | 2016-10-06 17:09:32 -0700 | [diff] [blame] | 902 | std::unique_ptr<CodeFixups> fixups_;  // This can be nullptr. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 903 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 904 | DISALLOW_COPY_AND_ASSIGN(CodeItem); | 
|  | 905 | }; | 
|  | 906 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 907 | struct PositionInfo { | 
|  | 908 | PositionInfo(uint32_t address, uint32_t line) : address_(address), line_(line) { } | 
|  | 909 |  | 
|  | 910 | uint32_t address_; | 
|  | 911 | uint32_t line_; | 
|  | 912 | }; | 
|  | 913 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 914 | using PositionInfoVector = std::vector<std::unique_ptr<PositionInfo>>; | 
|  | 915 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 916 | struct LocalInfo { | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 917 | LocalInfo(const char* name, | 
|  | 918 | const char* descriptor, | 
|  | 919 | const char* signature, | 
|  | 920 | uint32_t start_address, | 
|  | 921 | uint32_t end_address, | 
|  | 922 | uint16_t reg) | 
|  | 923 | : name_(name), | 
|  | 924 | descriptor_(descriptor), | 
|  | 925 | signature_(signature), | 
|  | 926 | start_address_(start_address), | 
|  | 927 | end_address_(end_address), | 
|  | 928 | reg_(reg) { } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 929 |  | 
|  | 930 | std::string name_; | 
|  | 931 | std::string descriptor_; | 
|  | 932 | std::string signature_; | 
|  | 933 | uint32_t start_address_; | 
|  | 934 | uint32_t end_address_; | 
|  | 935 | uint16_t reg_; | 
|  | 936 | }; | 
|  | 937 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 938 | using LocalInfoVector = std::vector<std::unique_ptr<LocalInfo>>; | 
|  | 939 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 940 | class DebugInfoItem : public Item { | 
|  | 941 | public: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 942 | DebugInfoItem(uint32_t debug_info_size, uint8_t* debug_info) | 
|  | 943 | : debug_info_size_(debug_info_size), debug_info_(debug_info) { } | 
|  | 944 |  | 
|  | 945 | uint32_t GetDebugInfoSize() const { return debug_info_size_; } | 
|  | 946 | uint8_t* GetDebugInfo() const { return debug_info_.get(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 947 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 948 | PositionInfoVector& GetPositionInfo() { return positions_; } | 
|  | 949 | LocalInfoVector& GetLocalInfo() { return locals_; } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 950 |  | 
|  | 951 | private: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 952 | uint32_t debug_info_size_; | 
|  | 953 | std::unique_ptr<uint8_t[]> debug_info_; | 
|  | 954 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 955 | PositionInfoVector positions_; | 
|  | 956 | LocalInfoVector locals_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 957 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 958 | DISALLOW_COPY_AND_ASSIGN(DebugInfoItem); | 
|  | 959 | }; | 
|  | 960 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 961 | class AnnotationItem : public Item { | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 962 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 963 | AnnotationItem(uint8_t visibility, EncodedAnnotation* annotation) | 
|  | 964 | : visibility_(visibility), annotation_(annotation) { } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 965 |  | 
|  | 966 | uint8_t GetVisibility() const { return visibility_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 967 | EncodedAnnotation* GetAnnotation() const { return annotation_.get(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 968 |  | 
|  | 969 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 970 |  | 
|  | 971 | private: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 972 | uint8_t visibility_; | 
|  | 973 | std::unique_ptr<EncodedAnnotation> annotation_; | 
|  | 974 |  | 
|  | 975 | DISALLOW_COPY_AND_ASSIGN(AnnotationItem); | 
|  | 976 | }; | 
|  | 977 |  | 
|  | 978 | class AnnotationSetItem : public Item { | 
|  | 979 | public: | 
|  | 980 | explicit AnnotationSetItem(std::vector<AnnotationItem*>* items) : items_(items) { | 
|  | 981 | size_ = sizeof(uint32_t) + items->size() * sizeof(uint32_t); | 
|  | 982 | } | 
|  | 983 | ~AnnotationSetItem() OVERRIDE { } | 
|  | 984 |  | 
|  | 985 | std::vector<AnnotationItem*>* GetItems() { return items_.get(); } | 
|  | 986 |  | 
|  | 987 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 988 |  | 
|  | 989 | private: | 
|  | 990 | std::unique_ptr<std::vector<AnnotationItem*>> items_; | 
|  | 991 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 992 | DISALLOW_COPY_AND_ASSIGN(AnnotationSetItem); | 
|  | 993 | }; | 
|  | 994 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 995 | class AnnotationSetRefList : public Item { | 
|  | 996 | public: | 
|  | 997 | explicit AnnotationSetRefList(std::vector<AnnotationSetItem*>* items) : items_(items) { | 
|  | 998 | size_ = sizeof(uint32_t) + items->size() * sizeof(uint32_t); | 
|  | 999 | } | 
|  | 1000 | ~AnnotationSetRefList() OVERRIDE { } | 
|  | 1001 |  | 
|  | 1002 | std::vector<AnnotationSetItem*>* GetItems() { return items_.get(); } | 
|  | 1003 |  | 
|  | 1004 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 1005 |  | 
|  | 1006 | private: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 1007 | std::unique_ptr<std::vector<AnnotationSetItem*>> items_;  // Elements of vector can be nullptr. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1008 |  | 
|  | 1009 | DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefList); | 
|  | 1010 | }; | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1011 |  | 
|  | 1012 | class FieldAnnotation { | 
|  | 1013 | public: | 
|  | 1014 | FieldAnnotation(FieldId* field_id, AnnotationSetItem* annotation_set_item) | 
|  | 1015 | : field_id_(field_id), annotation_set_item_(annotation_set_item) { } | 
|  | 1016 |  | 
|  | 1017 | FieldId* GetFieldId() const { return field_id_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1018 | AnnotationSetItem* GetAnnotationSetItem() const { return annotation_set_item_; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1019 |  | 
|  | 1020 | private: | 
|  | 1021 | FieldId* field_id_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1022 | AnnotationSetItem* annotation_set_item_; | 
|  | 1023 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1024 | DISALLOW_COPY_AND_ASSIGN(FieldAnnotation); | 
|  | 1025 | }; | 
|  | 1026 |  | 
|  | 1027 | using FieldAnnotationVector = std::vector<std::unique_ptr<FieldAnnotation>>; | 
|  | 1028 |  | 
|  | 1029 | class MethodAnnotation { | 
|  | 1030 | public: | 
|  | 1031 | MethodAnnotation(MethodId* method_id, AnnotationSetItem* annotation_set_item) | 
|  | 1032 | : method_id_(method_id), annotation_set_item_(annotation_set_item) { } | 
|  | 1033 |  | 
|  | 1034 | MethodId* GetMethodId() const { return method_id_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1035 | AnnotationSetItem* GetAnnotationSetItem() const { return annotation_set_item_; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1036 |  | 
|  | 1037 | private: | 
|  | 1038 | MethodId* method_id_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1039 | AnnotationSetItem* annotation_set_item_; | 
|  | 1040 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1041 | DISALLOW_COPY_AND_ASSIGN(MethodAnnotation); | 
|  | 1042 | }; | 
|  | 1043 |  | 
|  | 1044 | using MethodAnnotationVector = std::vector<std::unique_ptr<MethodAnnotation>>; | 
|  | 1045 |  | 
|  | 1046 | class ParameterAnnotation { | 
|  | 1047 | public: | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1048 | ParameterAnnotation(MethodId* method_id, AnnotationSetRefList* annotations) | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1049 | : method_id_(method_id), annotations_(annotations) { } | 
|  | 1050 |  | 
|  | 1051 | MethodId* GetMethodId() const { return method_id_; } | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1052 | AnnotationSetRefList* GetAnnotations() { return annotations_; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1053 |  | 
|  | 1054 | private: | 
|  | 1055 | MethodId* method_id_; | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1056 | AnnotationSetRefList* annotations_; | 
|  | 1057 |  | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1058 | DISALLOW_COPY_AND_ASSIGN(ParameterAnnotation); | 
|  | 1059 | }; | 
|  | 1060 |  | 
|  | 1061 | using ParameterAnnotationVector = std::vector<std::unique_ptr<ParameterAnnotation>>; | 
|  | 1062 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 1063 | class AnnotationsDirectoryItem : public Item { | 
|  | 1064 | public: | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1065 | AnnotationsDirectoryItem(AnnotationSetItem* class_annotation, | 
|  | 1066 | FieldAnnotationVector* field_annotations, | 
|  | 1067 | MethodAnnotationVector* method_annotations, | 
|  | 1068 | ParameterAnnotationVector* parameter_annotations) | 
|  | 1069 | : class_annotation_(class_annotation), | 
|  | 1070 | field_annotations_(field_annotations), | 
|  | 1071 | method_annotations_(method_annotations), | 
|  | 1072 | parameter_annotations_(parameter_annotations) { } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 1073 |  | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1074 | AnnotationSetItem* GetClassAnnotation() const { return class_annotation_; } | 
| David Sehr | 853a8e1 | 2016-09-01 13:03:50 -0700 | [diff] [blame] | 1075 | FieldAnnotationVector* GetFieldAnnotations() { return field_annotations_.get(); } | 
|  | 1076 | MethodAnnotationVector* GetMethodAnnotations() { return method_annotations_.get(); } | 
|  | 1077 | ParameterAnnotationVector* GetParameterAnnotations() { return parameter_annotations_.get(); } | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 1078 |  | 
|  | 1079 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 1080 |  | 
|  | 1081 | private: | 
| Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 1082 | AnnotationSetItem* class_annotation_;  // This can be nullptr. | 
|  | 1083 | std::unique_ptr<FieldAnnotationVector> field_annotations_;  // This can be nullptr. | 
|  | 1084 | std::unique_ptr<MethodAnnotationVector> method_annotations_;  // This can be nullptr. | 
|  | 1085 | std::unique_ptr<ParameterAnnotationVector> parameter_annotations_;  // This can be nullptr. | 
| Jeff Hao | 3ab96b4 | 2016-09-09 18:35:01 -0700 | [diff] [blame] | 1086 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 1087 | DISALLOW_COPY_AND_ASSIGN(AnnotationsDirectoryItem); | 
|  | 1088 | }; | 
|  | 1089 |  | 
|  | 1090 | // TODO(sehr): implement MapList. | 
|  | 1091 | class MapList : public Item { | 
|  | 1092 | public: | 
|  | 1093 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 1094 |  | 
|  | 1095 | private: | 
|  | 1096 | DISALLOW_COPY_AND_ASSIGN(MapList); | 
|  | 1097 | }; | 
|  | 1098 |  | 
|  | 1099 | class MapItem : public Item { | 
|  | 1100 | public: | 
|  | 1101 | void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); } | 
|  | 1102 |  | 
|  | 1103 | private: | 
|  | 1104 | DISALLOW_COPY_AND_ASSIGN(MapItem); | 
|  | 1105 | }; | 
|  | 1106 |  | 
| David Sehr | 9037a3a | 2017-03-30 17:50:24 -0700 | [diff] [blame] | 1107 | // Interface for building a vector of file sections for use by other clients. | 
|  | 1108 | struct DexFileSection { | 
|  | 1109 | public: | 
|  | 1110 | DexFileSection(const std::string& name, uint16_t type, uint32_t size, uint32_t offset) | 
|  | 1111 | : name(name), type(type), size(size), offset(offset) { } | 
|  | 1112 | std::string name; | 
|  | 1113 | // The type (DexFile::MapItemType). | 
|  | 1114 | uint16_t type; | 
|  | 1115 | // The size (in elements, not bytes). | 
|  | 1116 | uint32_t size; | 
|  | 1117 | // The byte offset from the start of the file. | 
|  | 1118 | uint32_t offset; | 
|  | 1119 | }; | 
|  | 1120 |  | 
|  | 1121 | enum class SortDirection { | 
|  | 1122 | kSortAscending, | 
|  | 1123 | kSortDescending | 
|  | 1124 | }; | 
|  | 1125 |  | 
|  | 1126 | std::vector<DexFileSection> GetSortedDexFileSections(dex_ir::Header* header, | 
|  | 1127 | SortDirection direction); | 
|  | 1128 |  | 
| David Sehr | 7629f60 | 2016-08-07 16:01:51 -0700 | [diff] [blame] | 1129 | }  // namespace dex_ir | 
|  | 1130 | }  // namespace art | 
|  | 1131 |  | 
|  | 1132 | #endif  // ART_DEXLAYOUT_DEX_IR_H_ |