• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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_LIBDEXFILE_DEX_TYPE_REFERENCE_H_
18 #define ART_LIBDEXFILE_DEX_TYPE_REFERENCE_H_
19 
20 #include <stdint.h>
21 
22 #include <android-base/logging.h>
23 
24 #include "dex/dex_file_types.h"
25 #include "dex/string_reference.h"
26 
27 namespace art {
28 
29 class DexFile;
30 
31 // A type is located by its DexFile and the string_ids_ table index into that DexFile.
32 class TypeReference : public DexFileReference {
33  public:
TypeReference(const DexFile * dex_file,dex::TypeIndex index)34   TypeReference(const DexFile* dex_file, dex::TypeIndex index)
35       : DexFileReference(dex_file, index.index_) {}
36 
TypeIndex()37   dex::TypeIndex TypeIndex() const {
38     return dex::TypeIndex(index);
39   }
40 };
41 
42 // Compare the actual referenced type names. Used for type reference deduplication.
43 struct TypeReferenceValueComparator {
operatorTypeReferenceValueComparator44   bool operator()(const TypeReference& tr1, const TypeReference& tr2) const {
45     // Note that we want to deduplicate identical boot image types even if they are
46     // referenced by different dex files, so we simply compare the descriptors.
47     StringReference sr1(tr1.dex_file, tr1.dex_file->GetTypeId(tr1.TypeIndex()).descriptor_idx_);
48     StringReference sr2(tr2.dex_file, tr2.dex_file->GetTypeId(tr2.TypeIndex()).descriptor_idx_);
49     return StringReferenceValueComparator()(sr1, sr2);
50   }
51 };
52 
53 }  // namespace art
54 
55 #endif  // ART_LIBDEXFILE_DEX_TYPE_REFERENCE_H_
56