blob: 6cb8258aa1ab89e52d284daae7fba2b30a18424b [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "src/dex_file.h"
4#include "src/heap.h"
5#include "src/globals.h"
6#include "src/logging.h"
7#include "src/object.h"
8#include "src/raw_dex_file.h"
9
10namespace art {
11
Carl Shapiro80d4dde2011-06-28 16:24:07 -070012DexFile* DexFile::OpenFile(const char* filename) {
13 RawDexFile* raw = RawDexFile::OpenFile(filename);
14 return Open(raw);
15}
16
Carl Shapiro80d4dde2011-06-28 16:24:07 -070017DexFile* DexFile::Open(RawDexFile* raw) {
Carl Shapiro1fb86202011-06-27 17:43:13 -070018 if (raw == NULL) {
19 return NULL;
20 }
21 DexFile* dex_file = new DexFile(raw);
22 dex_file->Init();
23 return dex_file;
24}
25
26DexFile::~DexFile() {
Carl Shapiro1fb86202011-06-27 17:43:13 -070027 delete[] strings_;
28 delete[] classes_;
29 delete[] methods_;
30 delete[] fields_;
31}
32
33void DexFile::Init() {
34 num_strings_ = raw_->NumStringIds();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070035 strings_ = new String*[num_strings_]();
Carl Shapiro1fb86202011-06-27 17:43:13 -070036
37 num_classes_ = raw_->NumTypeIds();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070038 classes_ = new Class*[num_classes_]();
Carl Shapiro1fb86202011-06-27 17:43:13 -070039
40 num_methods_ = raw_->NumMethodIds();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070041 methods_ = new Method*[num_methods_]();
Carl Shapiro1fb86202011-06-27 17:43:13 -070042
43 num_fields_ = raw_->NumFieldIds();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070044 fields_ = new Field*[num_fields_]();
Carl Shapiro1fb86202011-06-27 17:43:13 -070045}
46
Carl Shapiro1fb86202011-06-27 17:43:13 -070047} // namespace art