blob: c57a1e7582b8289f077f6846e60b5da6e292a608 [file] [log] [blame]
Ian Rogers4f6ad8a2013-03-18 15:27:28 -07001/*
2 * Copyright (C) 2011 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_DEX_FILE_INL_H_
18#define ART_RUNTIME_DEX_FILE_INL_H_
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070019
20#include "base/logging.h"
Ian Rogersfc0e94b2013-09-23 23:51:32 -070021#include "base/stringpiece.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070022#include "dex_file.h"
23#include "leb128.h"
24#include "utils.h"
25
26namespace art {
27
28inline int32_t DexFile::GetStringLength(const StringId& string_id) const {
29 const byte* ptr = begin_ + string_id.string_data_off_;
30 return DecodeUnsignedLeb128(&ptr);
31}
32
33inline const char* DexFile::GetStringDataAndLength(const StringId& string_id, uint32_t* length) const {
34 DCHECK(length != NULL) << GetLocation();
35 const byte* ptr = begin_ + string_id.string_data_off_;
36 *length = DecodeUnsignedLeb128(&ptr);
37 return reinterpret_cast<const char*>(ptr);
38}
39
Ian Rogersfc0e94b2013-09-23 23:51:32 -070040inline StringPiece DexFile::StringDataAsStringPieceByIdx(uint32_t idx) const {
41 if (idx == kDexNoIndex) {
42 return StringPiece();
43 }
44 const StringId& string_id = GetStringId(idx);
45 uint32_t length;
46 const char* data = GetStringDataAndLength(string_id, &length);
47 return StringPiece(data, static_cast<int>(length));
48}
49
Ian Rogersd91d6d62013-09-25 20:26:14 -070050inline const Signature DexFile::GetMethodSignature(const MethodId& method_id) const {
51 return Signature(this, GetProtoId(method_id.proto_idx_));
52}
53
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070054inline const DexFile::TryItem* DexFile::GetTryItems(const CodeItem& code_item, uint32_t offset) {
55 const uint16_t* insns_end_ = &code_item.insns_[code_item.insns_size_in_code_units_];
56 return reinterpret_cast<const TryItem*>
57 (RoundUp(reinterpret_cast<uint32_t>(insns_end_), 4)) + offset;
58}
59
60} // namespace art
61
Brian Carlstromfc0e3212013-07-17 14:40:12 -070062#endif // ART_RUNTIME_DEX_FILE_INL_H_