blob: 63393176c24f2e523fa8a247117aad95f06f9858 [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_DEX_FILE_H_
4#define ART_SRC_DEX_FILE_H_
5
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07006#include "globals.h"
7#include "macros.h"
8#include "object.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -07009
10namespace art {
11
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070012class Class;
13class Field;
14class Method;
15class String;
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070016union JValue;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070017
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070018class DexFile : public ObjectArray {
Carl Shapiro1fb86202011-06-27 17:43:13 -070019 public:
Carl Shapiro80d4dde2011-06-28 16:24:07 -070020
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021 enum ArrayIndexes {
22 kStrings = 0,
23 kClasses = 1,
24 kMethods = 2,
25 kFields = 3,
26 kMax = 4,
27 };
Carl Shapiro1fb86202011-06-27 17:43:13 -070028
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029 void Init(ObjectArray* strings, ObjectArray* classes, ObjectArray* methods, ObjectArray* fields);
Carl Shapiro1fb86202011-06-27 17:43:13 -070030
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070031 size_t NumStrings() const {
32 return GetStrings()->GetLength();
33 }
34
35 size_t NumClasses() const {
36 return GetClasses()->GetLength();
Carl Shapiro1fb86202011-06-27 17:43:13 -070037 }
38
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070039 size_t NumMethods() const {
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070040 return GetMethods()->GetLength();
Carl Shapiro1fb86202011-06-27 17:43:13 -070041 }
42
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070043 size_t NumFields() const {
44 return GetFields()->GetLength();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070045 }
46
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070047 String* GetResolvedString(uint32_t string_idx) const {
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070048 return down_cast<String*>(GetStrings()->Get(string_idx));
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070049 }
50
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070051 void SetResolvedString(uint32_t string_idx, String* resolved) {
52 GetStrings()->Set(string_idx, resolved);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070053 }
54
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070055 Class* GetResolvedClass(uint32_t class_idx) const {
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070056 return down_cast<Class*>(GetClasses()->Get(class_idx));
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070057 }
58
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070059 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 Shapiro0e5d75d2011-07-06 18:28:37 -070077 }
78
Carl Shapiro1fb86202011-06-27 17:43:13 -070079 private:
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070080 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 Shapiro1fb86202011-06-27 17:43:13 -070093};
94
95} // namespace art
96
97#endif // ART_SRC_DEX_FILE_H_