• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 ECMASCRIPT_TOOLING_BACKEND_JS_PT_LOCATION_H
17 #define ECMASCRIPT_TOOLING_BACKEND_JS_PT_LOCATION_H
18 
19 #include <cstring>
20 
21 #include "libpandafile/file.h"
22 #include "libpandabase/macros.h"
23 
24 namespace panda::ecmascript::tooling {
25 class JSPtLocation {
26 public:
27     using EntityId = panda_file::File::EntityId;
28 
JSPtLocation(const char * pandaFile,EntityId methodId,uint32_t bytecodeOffset)29     explicit JSPtLocation(const char *pandaFile, EntityId methodId, uint32_t bytecodeOffset)
30         : pandaFile_(pandaFile), methodId_(methodId), bytecodeOffset_(bytecodeOffset)
31     {
32     }
33 
GetPandaFile()34     const char *GetPandaFile() const
35     {
36         return pandaFile_;
37     }
38 
GetMethodId()39     EntityId GetMethodId() const
40     {
41         return methodId_;
42     }
43 
GetBytecodeOffset()44     uint32_t GetBytecodeOffset() const
45     {
46         return bytecodeOffset_;
47     }
48 
49     bool operator==(const JSPtLocation &location) const
50     {
51         return methodId_ == location.methodId_ && bytecodeOffset_ == location.bytecodeOffset_ &&
52                ::strcmp(pandaFile_, location.pandaFile_) == 0;
53     }
54 
55     ~JSPtLocation() = default;
56 
57     DEFAULT_COPY_SEMANTIC(JSPtLocation);
58     DEFAULT_MOVE_SEMANTIC(JSPtLocation);
59 
60 private:
61     const char *pandaFile_;
62     EntityId methodId_;
63     uint32_t bytecodeOffset_ {0};
64 };
65 }  // namespace panda::ecmascript::tooling
66 
67 #endif  // ECMASCRIPT_TOOLING_BACKEND_JS_PT_LOCATION_H
68