blob: ae94dadb28387bfb6e14b626583e9944897acf7e [file] [log] [blame]
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +00001/*
2 * Copyright (C) 2018 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_TOOLS_VERIDEX_RESOLVER_H_
18#define ART_TOOLS_VERIDEX_RESOLVER_H_
19
20#include "dex/dex_file.h"
21#include "veridex.h"
22
23namespace art {
24
Nicolas Geoffraye8264772018-03-22 22:16:41 +000025class VeridexResolver;
26
27/**
28 * Map from the start of a dex file (ie DexFile::Begin()), to
29 * its corresponding resolver.
30 */
31using DexResolverMap = std::map<uintptr_t, VeridexResolver*>;
32
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000033class VeridexResolver {
34 public:
Nicolas Geoffraye8264772018-03-22 22:16:41 +000035 VeridexResolver(const DexFile& dex_file,
36 const DexResolverMap& dex_resolvers,
37 TypeMap& type_map)
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000038 : dex_file_(dex_file),
39 type_map_(type_map),
Nicolas Geoffraye8264772018-03-22 22:16:41 +000040 dex_resolvers_(dex_resolvers),
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000041 type_infos_(dex_file.NumTypeIds(), VeriClass()),
42 method_infos_(dex_file.NumMethodIds(), nullptr),
43 field_infos_(dex_file.NumFieldIds(), nullptr) {}
44
Nicolas Geoffraye8264772018-03-22 22:16:41 +000045 // Run on the defined classes of that dex file and populate our
46 // local type cache.
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000047 void Run();
48
Nicolas Geoffraye8264772018-03-22 22:16:41 +000049 // Return the class declared at `index`.
50 VeriClass* GetVeriClass(dex::TypeIndex index);
51
52 // Return the method declared at `method_index`.
53 VeriMethod GetMethod(uint32_t method_index);
54
55 // Return the field declared at `field_index`.
56 VeriField GetField(uint32_t field_index);
57
58 // Do a JLS lookup in `kls` to find a method.
59 VeriMethod LookupMethodIn(const VeriClass& kls,
60 const char* method_name,
61 const Signature& method_signature);
62
63 // Do a JLS lookup in `kls` to find a field.
64 VeriField LookupFieldIn(const VeriClass& kls,
65 const char* field_name,
66 const char* field_type);
67
68 // Resolve all type_id/method_id/field_id.
69 void ResolveAll();
70
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000071 private:
Nicolas Geoffraye8264772018-03-22 22:16:41 +000072 // Return the resolver where `kls` is from.
73 VeridexResolver* GetResolverOf(const VeriClass& kls) const;
74
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000075 const DexFile& dex_file_;
76 TypeMap& type_map_;
Nicolas Geoffraye8264772018-03-22 22:16:41 +000077 const DexResolverMap& dex_resolvers_;
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000078 std::vector<VeriClass> type_infos_;
79 std::vector<VeriMethod> method_infos_;
80 std::vector<VeriField> field_infos_;
81};
82
83} // namespace art
84
85#endif // ART_TOOLS_VERIDEX_RESOLVER_H_