Home | History | Annotate | Download | only in utils
      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_COMPILER_UTILS_TYPE_REFERENCE_H_
     18 #define ART_COMPILER_UTILS_TYPE_REFERENCE_H_
     19 
     20 #include <stdint.h>
     21 
     22 #include "base/logging.h"
     23 #include "dex_file_types.h"
     24 #include "string_reference.h"
     25 
     26 namespace art {
     27 
     28 class DexFile;
     29 
     30 // A type is located by its DexFile and the string_ids_ table index into that DexFile.
     31 struct TypeReference {
     32   TypeReference(const DexFile* file, dex::TypeIndex index) : dex_file(file), type_index(index) { }
     33 
     34   const DexFile* dex_file;
     35   dex::TypeIndex type_index;
     36 };
     37 
     38 // Compare the actual referenced type names. Used for type reference deduplication.
     39 struct TypeReferenceValueComparator {
     40   bool operator()(TypeReference tr1, TypeReference tr2) const {
     41     // Note that we want to deduplicate identical boot image types even if they are
     42     // referenced by different dex files, so we simply compare the descriptors.
     43     StringReference sr1(tr1.dex_file, tr1.dex_file->GetTypeId(tr1.type_index).descriptor_idx_);
     44     StringReference sr2(tr2.dex_file, tr2.dex_file->GetTypeId(tr2.type_index).descriptor_idx_);
     45     return StringReferenceValueComparator()(sr1, sr2);
     46   }
     47 };
     48 
     49 }  // namespace art
     50 
     51 #endif  // ART_COMPILER_UTILS_TYPE_REFERENCE_H_
     52