dex_file-inl.h revision fc0e94bed3f88ed7e50854fd8dfaf5dcb345250f
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 17#ifndef ART_RUNTIME_DEX_FILE_INL_H_ 18#define ART_RUNTIME_DEX_FILE_INL_H_ 19 20#include "base/logging.h" 21#include "base/stringpiece.h" 22#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 40inline 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 50inline const DexFile::TryItem* DexFile::GetTryItems(const CodeItem& code_item, uint32_t offset) { 51 const uint16_t* insns_end_ = &code_item.insns_[code_item.insns_size_in_code_units_]; 52 return reinterpret_cast<const TryItem*> 53 (RoundUp(reinterpret_cast<uint32_t>(insns_end_), 4)) + offset; 54} 55 56} // namespace art 57 58#endif // ART_RUNTIME_DEX_FILE_INL_H_ 59