blob: 1f4afa33c9a98f4347f9a1dae91a1608be3931a3 [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
6#include "src/globals.h"
7#include "src/macros.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -07008#include "src/raw_dex_file.h"
9
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
Carl Shapiro1fb86202011-06-27 17:43:13 -070018class DexFile {
19 public:
Carl Shapiro80d4dde2011-06-28 16:24:07 -070020 // Opens a .dex file from the file system. Returns NULL on failure.
21 static DexFile* OpenFile(const char* filename);
22
Carl Shapiro80d4dde2011-06-28 16:24:07 -070023 // Opens a .dex file from a RawDexFile. Takes ownership of the
24 // RawDexFile.
25 static DexFile* Open(RawDexFile* raw);
Carl Shapiro1fb86202011-06-27 17:43:13 -070026
27 // Close and deallocate.
28 ~DexFile();
29
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070030 size_t NumTypes() const {
Carl Shapiro1fb86202011-06-27 17:43:13 -070031 return num_classes_;
32 }
33
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070034 size_t NumMethods() const {
Carl Shapiro1fb86202011-06-27 17:43:13 -070035 return num_methods_;
36 }
37
Brian Carlstrom6cc18452011-07-18 15:10:33 -070038 bool HasClass(const StringPiece& descriptor) {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070039 return raw_->FindClassDef(descriptor) != NULL;
40 }
41
42 RawDexFile* GetRaw() const {
43 return raw_.get();
44 }
45
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070046 String* GetResolvedString(uint32_t string_idx) const {
Carl Shapiro565f5072011-07-10 13:39:43 -070047 CHECK_LT(string_idx, num_strings_);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070048 return strings_[string_idx];
49 }
50
51 void SetResolvedString(String* resolved, uint32_t string_idx) {
Carl Shapiro565f5072011-07-10 13:39:43 -070052 CHECK_LT(string_idx, num_strings_);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070053 strings_[string_idx] = resolved;
54 }
55
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070056 Class* GetResolvedClass(uint32_t class_idx) const {
Carl Shapiro565f5072011-07-10 13:39:43 -070057 CHECK_LT(class_idx, num_classes_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070058 return classes_[class_idx];
59 }
60
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070061 void SetResolvedClass(Class* resolved, uint32_t class_idx) {
Carl Shapiro565f5072011-07-10 13:39:43 -070062 CHECK_LT(class_idx, num_classes_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070063 classes_[class_idx] = resolved;
64 }
65
Carl Shapiro1fb86202011-06-27 17:43:13 -070066 private:
67 DexFile(RawDexFile* raw) : raw_(raw) {};
68
69 void Init();
70
Carl Shapiro1fb86202011-06-27 17:43:13 -070071 // Table of contents for interned String objects.
72 String** strings_;
73 size_t num_strings_;
74
75 // Table of contents for Class objects.
76 Class** classes_;
77 size_t num_classes_;
78
79 // Table of contents for methods.
80 Method** methods_;
81 size_t num_methods_;
82
83 // Table of contents for fields.
84 Field** fields_;
85 size_t num_fields_;
86
87 // The size of the DEX file, in bytes.
88 size_t length_;
89
90 // The underlying dex file.
Carl Shapiro7e782482011-06-28 16:30:04 -070091 scoped_ptr<RawDexFile> raw_;
Carl Shapiro1fb86202011-06-27 17:43:13 -070092
93 DISALLOW_COPY_AND_ASSIGN(DexFile);
94};
95
96} // namespace art
97
98#endif // ART_SRC_DEX_FILE_H_