Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_DEX_FILE_H_ |
| 4 | #define ART_SRC_DEX_FILE_H_ |
| 5 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 6 | #include "globals.h" |
| 7 | #include "macros.h" |
| 8 | #include "object.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 9 | |
| 10 | namespace art { |
| 11 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 12 | class Class; |
| 13 | class Field; |
| 14 | class Method; |
| 15 | class String; |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 16 | union JValue; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 17 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 18 | class DexFile : public ObjectArray { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 19 | public: |
Carl Shapiro | 80d4dde | 2011-06-28 16:24:07 -0700 | [diff] [blame] | 20 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 21 | enum ArrayIndexes { |
| 22 | kStrings = 0, |
| 23 | kClasses = 1, |
| 24 | kMethods = 2, |
| 25 | kFields = 3, |
| 26 | kMax = 4, |
| 27 | }; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 28 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 29 | void Init(ObjectArray* strings, ObjectArray* classes, ObjectArray* methods, ObjectArray* fields); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 30 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 31 | size_t NumStrings() const { |
| 32 | return GetStrings()->GetLength(); |
| 33 | } |
| 34 | |
| 35 | size_t NumClasses() const { |
| 36 | return GetClasses()->GetLength(); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 39 | size_t NumMethods() const { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 40 | return GetMethods()->GetLength(); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 43 | size_t NumFields() const { |
| 44 | return GetFields()->GetLength(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 47 | String* GetResolvedString(uint32_t string_idx) const { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 48 | return down_cast<String*>(GetStrings()->Get(string_idx)); |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 51 | void SetResolvedString(uint32_t string_idx, String* resolved) { |
| 52 | GetStrings()->Set(string_idx, resolved); |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 55 | Class* GetResolvedClass(uint32_t class_idx) const { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 56 | return down_cast<Class*>(GetClasses()->Get(class_idx)); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 59 | void SetResolvedClass(uint32_t class_idx, Class* resolved) { |
| 60 | GetClasses()->Set(class_idx, resolved); |
| 61 | } |
| 62 | |
| 63 | Method* GetResolvedMethod(uint32_t method_idx) const { |
| 64 | return down_cast<Method*>(GetMethods()->Get(method_idx)); |
| 65 | } |
| 66 | |
| 67 | void SetResolvedMethod(uint32_t method_idx, Method* resolved) { |
| 68 | GetMethods()->Set(method_idx, resolved); |
| 69 | } |
| 70 | |
| 71 | Field* GetResolvedField(uint32_t field_idx) const { |
| 72 | return down_cast<Field*>(GetFields()->Get(field_idx)); |
| 73 | } |
| 74 | |
| 75 | void SetResolvedfield(uint32_t field_idx, Field* resolved) { |
| 76 | GetFields()->Set(field_idx, resolved); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 79 | private: |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 80 | ObjectArray* GetStrings() const { |
| 81 | return down_cast<ObjectArray*>(Get(kStrings)); |
| 82 | } |
| 83 | ObjectArray* GetClasses() const { |
| 84 | return down_cast<ObjectArray*>(Get(kClasses)); |
| 85 | } |
| 86 | ObjectArray* GetMethods() const { |
| 87 | return down_cast<ObjectArray*>(Get(kMethods)); |
| 88 | } |
| 89 | ObjectArray* GetFields() const { |
| 90 | return down_cast<ObjectArray*>(Get(kFields)); |
| 91 | } |
| 92 | DexFile(); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace art |
| 96 | |
| 97 | #endif // ART_SRC_DEX_FILE_H_ |