• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_RUNTIME_INCLUDE_TOOLING_PT_LOCATION_H_
17 #define PANDA_RUNTIME_INCLUDE_TOOLING_PT_LOCATION_H_
18 
19 #include <cstring>
20 
21 #include "libpandafile/file_items.h"
22 #include "libpandabase/macros.h"
23 
24 namespace panda::tooling {
25 class PtLocation {
26 public:
27     using EntityId = panda_file::File::EntityId;
28 
PtLocation(const char * panda_file,EntityId method_id,uint32_t bytecode_offset)29     explicit PtLocation(const char *panda_file, EntityId method_id, uint32_t bytecode_offset)
30         : panda_file_(panda_file), method_id_(method_id), bytecode_offset_(bytecode_offset)
31     {
32     }
33 
GetPandaFile()34     const char *GetPandaFile() const
35     {
36         return panda_file_;
37     }
38 
GetMethodId()39     EntityId GetMethodId() const
40     {
41         return method_id_;
42     }
43 
GetBytecodeOffset()44     uint32_t GetBytecodeOffset() const
45     {
46         return bytecode_offset_;
47     }
48 
49     bool operator==(const PtLocation &location) const
50     {
51         return method_id_ == location.method_id_ && bytecode_offset_ == location.bytecode_offset_ &&
52                ::strcmp(panda_file_, location.panda_file_) == 0;
53     }
54 
55     ~PtLocation() = default;
56 
57     DEFAULT_COPY_SEMANTIC(PtLocation);
58     DEFAULT_MOVE_SEMANTIC(PtLocation);
59 
60 private:
61     const char *panda_file_;
62     EntityId method_id_;
63     uint32_t bytecode_offset_ {0};
64 };
65 
66 }  // namespace panda::tooling
67 
68 #endif  // PANDA_RUNTIME_INCLUDE_TOOLING_PT_LOCATION_H_
69