• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LIBDEXFILE_DEX_SIGNATURE_H_
18 #define ART_LIBDEXFILE_DEX_SIGNATURE_H_
19 
20 #include <iosfwd>
21 #include <string>
22 #include <string_view>
23 
24 #include <android-base/logging.h>
25 
26 #include "base/value_object.h"
27 
28 namespace art {
29 
30 namespace dex {
31 struct ProtoId;
32 }  // namespace dex
33 class DexFile;
34 
35 // Abstract the signature of a method.
36 class Signature : public ValueObject {
37  public:
38   std::string ToString() const;
39 
NoSignature()40   static Signature NoSignature() {
41     return Signature();
42   }
43 
44   bool IsVoid() const;
45   uint32_t GetNumberOfParameters() const;
46 
47   bool operator==(const Signature& rhs) const;
48   bool operator!=(const Signature& rhs) const {
49     return !(*this == rhs);
50   }
51 
52   bool operator==(std::string_view rhs) const;
53 
54   // Three-way compare.
55   // Return a value >0 if `rhs` is higher than `*this`, <0 if lower and 0 if equal.
56   //
57   // The order is the same as the `ProtoId` order required by dex file specification if both
58   // signatures were in the same dex file.
59   int Compare(const Signature& rhs) const;
60 
61  private:
Signature(const DexFile * dex,const dex::ProtoId & proto)62   Signature(const DexFile* dex, const dex::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) {
63   }
64 
65   Signature() = default;
66 
67   friend class DexFile;
68 
69   const DexFile* dex_file_ = nullptr;
70   const dex::ProtoId* proto_id_ = nullptr;
71 };
72 std::ostream& operator<<(std::ostream& os, const Signature& sig);
73 
74 }  // namespace art
75 
76 #endif  // ART_LIBDEXFILE_DEX_SIGNATURE_H_
77