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