• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_DEBUGGER_JS_PT_LOCATION_H
17 #define ECMASCRIPT_DEBUGGER_JS_PT_LOCATION_H
18 
19 #include <cstring>
20 
21 #include "ecmascript/jspandafile/js_pandafile.h"
22 #include "libpandafile/file.h"
23 #include "libpandabase/macros.h"
24 
25 namespace panda::ecmascript::tooling {
26 class JSPtLocation {
27 public:
28     using EntityId = panda_file::File::EntityId;
29 
30     JSPtLocation(const JSPandaFile *jsPandaFile, EntityId methodId, uint32_t bytecodeOffset,
jsPandaFile_(jsPandaFile)31         const std::string &sourceFile = "") : jsPandaFile_(jsPandaFile), methodId_(methodId),
32         bytecodeOffset_(bytecodeOffset), sourceFile_(sourceFile)
33     {
34     }
35 
GetJsPandaFile()36     const JSPandaFile *GetJsPandaFile() const
37     {
38         return jsPandaFile_;
39     }
40 
GetSourceFile()41     const std::string &GetSourceFile() const
42     {
43         return sourceFile_;
44     }
45 
GetMethodId()46     EntityId GetMethodId() const
47     {
48         return methodId_;
49     }
50 
GetBytecodeOffset()51     uint32_t GetBytecodeOffset() const
52     {
53         return bytecodeOffset_;
54     }
55 
56     bool operator==(const JSPtLocation &location) const
57     {
58         return methodId_ == location.methodId_ && bytecodeOffset_ == location.bytecodeOffset_ &&
59                jsPandaFile_ == location.jsPandaFile_;
60     }
61 
ToString()62     std::string ToString() const
63     {
64         std::stringstream location;
65         location << "[";
66         location << "methodId:" << methodId_ << ", ";
67         location << "bytecodeOffset:" << bytecodeOffset_ << ", ";
68         location << "sourceFile:" << "\""<< sourceFile_ << "\""<< ", ";
69         location << "jsPandaFile:" << "\"" << jsPandaFile_->GetJSPandaFileDesc() << "\"";
70         location << "]";
71         return location.str();
72     }
73 
74     ~JSPtLocation() = default;
75 
76     DEFAULT_COPY_SEMANTIC(JSPtLocation);
77     DEFAULT_MOVE_SEMANTIC(JSPtLocation);
78 
79 private:
80     const JSPandaFile *jsPandaFile_ {nullptr};
81     EntityId methodId_;
82     uint32_t bytecodeOffset_ {0};
83     std::string sourceFile_; // mainly used for breakpoint
84 };
85 }  // namespace panda::ecmascript::tooling
86 
87 #endif  // ECMASCRIPT_DEBUGGER_JS_PT_LOCATION_H
88