Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_DEX_FILE_INL_H_ |
| 18 | #define ART_RUNTIME_DEX_FILE_INL_H_ |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 19 | |
| 20 | #include "base/logging.h" |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 21 | #include "base/stringpiece.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 22 | #include "dex_file.h" |
| 23 | #include "leb128.h" |
| 24 | #include "utils.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | inline 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 | |
| 33 | inline 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 Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 40 | inline 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 Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 50 | inline const Signature DexFile::GetMethodSignature(const MethodId& method_id) const { |
| 51 | return Signature(this, GetProtoId(method_id.proto_idx_)); |
| 52 | } |
| 53 | |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 54 | inline 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 62 | #endif // ART_RUNTIME_DEX_FILE_INL_H_ |