xref: /aosp_15_r20/art/libdexfile/dex/signature.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBDEXFILE_DEX_SIGNATURE_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_LIBDEXFILE_DEX_SIGNATURE_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <iosfwd>
21*795d594fSAndroid Build Coastguard Worker #include <string>
22*795d594fSAndroid Build Coastguard Worker #include <string_view>
23*795d594fSAndroid Build Coastguard Worker 
24*795d594fSAndroid Build Coastguard Worker #include <android-base/logging.h>
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker #include "base/value_object.h"
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker namespace art {
29*795d594fSAndroid Build Coastguard Worker 
30*795d594fSAndroid Build Coastguard Worker namespace dex {
31*795d594fSAndroid Build Coastguard Worker struct ProtoId;
32*795d594fSAndroid Build Coastguard Worker }  // namespace dex
33*795d594fSAndroid Build Coastguard Worker class DexFile;
34*795d594fSAndroid Build Coastguard Worker 
35*795d594fSAndroid Build Coastguard Worker // Abstract the signature of a method.
36*795d594fSAndroid Build Coastguard Worker class Signature : public ValueObject {
37*795d594fSAndroid Build Coastguard Worker  public:
38*795d594fSAndroid Build Coastguard Worker   std::string ToString() const;
39*795d594fSAndroid Build Coastguard Worker 
NoSignature()40*795d594fSAndroid Build Coastguard Worker   static Signature NoSignature() {
41*795d594fSAndroid Build Coastguard Worker     return Signature();
42*795d594fSAndroid Build Coastguard Worker   }
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker   bool IsVoid() const;
45*795d594fSAndroid Build Coastguard Worker   uint32_t GetNumberOfParameters() const;
46*795d594fSAndroid Build Coastguard Worker 
47*795d594fSAndroid Build Coastguard Worker   bool operator==(const Signature& rhs) const;
48*795d594fSAndroid Build Coastguard Worker   bool operator!=(const Signature& rhs) const {
49*795d594fSAndroid Build Coastguard Worker     return !(*this == rhs);
50*795d594fSAndroid Build Coastguard Worker   }
51*795d594fSAndroid Build Coastguard Worker 
52*795d594fSAndroid Build Coastguard Worker   bool operator==(std::string_view rhs) const;
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   // Three-way compare.
55*795d594fSAndroid Build Coastguard Worker   // Return a value >0 if `rhs` is higher than `*this`, <0 if lower and 0 if equal.
56*795d594fSAndroid Build Coastguard Worker   //
57*795d594fSAndroid Build Coastguard Worker   // The order is the same as the `ProtoId` order required by dex file specification if both
58*795d594fSAndroid Build Coastguard Worker   // signatures were in the same dex file.
59*795d594fSAndroid Build Coastguard Worker   int Compare(const Signature& rhs) const;
60*795d594fSAndroid Build Coastguard Worker 
61*795d594fSAndroid Build Coastguard Worker  private:
Signature(const DexFile * dex,const dex::ProtoId & proto)62*795d594fSAndroid Build Coastguard Worker   Signature(const DexFile* dex, const dex::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) {
63*795d594fSAndroid Build Coastguard Worker   }
64*795d594fSAndroid Build Coastguard Worker 
65*795d594fSAndroid Build Coastguard Worker   Signature() = default;
66*795d594fSAndroid Build Coastguard Worker 
67*795d594fSAndroid Build Coastguard Worker   friend class DexFile;
68*795d594fSAndroid Build Coastguard Worker 
69*795d594fSAndroid Build Coastguard Worker   const DexFile* dex_file_ = nullptr;
70*795d594fSAndroid Build Coastguard Worker   const dex::ProtoId* proto_id_ = nullptr;
71*795d594fSAndroid Build Coastguard Worker };
72*795d594fSAndroid Build Coastguard Worker std::ostream& operator<<(std::ostream& os, const Signature& sig);
73*795d594fSAndroid Build Coastguard Worker 
74*795d594fSAndroid Build Coastguard Worker }  // namespace art
75*795d594fSAndroid Build Coastguard Worker 
76*795d594fSAndroid Build Coastguard Worker #endif  // ART_LIBDEXFILE_DEX_SIGNATURE_H_
77