1 /* 2 * Copyright (c) 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 #ifndef ECMASCRIPT_TOOLING_CLIENT_MANAGER_SOURCE_MANAGER_H 16 #define ECMASCRIPT_TOOLING_CLIENT_MANAGER_SOURCE_MANAGER_H 17 18 #include <iostream> 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "tooling/base/pt_json.h" 25 #include "tooling/base/pt_types.h" 26 27 namespace OHOS::ArkCompiler::Toolchain { 28 using PtJson = panda::ecmascript::tooling::PtJson; 29 using Result = panda::ecmascript::tooling::Result; 30 class SourceManager { 31 public: SourceManager(int32_t sessionId)32 SourceManager(int32_t sessionId) : sessionId_(sessionId) {} 33 34 void SendRequeSource(int scriptId); 35 void EnableReply(const std::unique_ptr<PtJson> json); 36 void GetFileName(); 37 void SetFileName(int scriptId, const std::string& fileName); 38 void SetFileSource(int scriptIdIndex, const std::string& fileSource); 39 std::vector<std::string> GetFileSource(int scriptId); 40 void GetDebugSources(const std::unique_ptr<PtJson> json); 41 void ListSourceCodeWithParameters(int startLine, int endLine); 42 void ListSource(int startLine, int endLine); 43 void GetListSource(std::string startLine, std::string endLine); 44 45 private: 46 [[maybe_unused]] int32_t sessionId_; 47 int32_t scriptId_ = 0; 48 int32_t debugLineNum_ = 0; 49 std::unordered_map<int, int> scriptIdMap_ {}; 50 std::unordered_map<int, std::pair<std::string, std::vector<std::string>>> fileSource_ {}; 51 SourceManager(const SourceManager&) = delete; 52 SourceManager& operator=(const SourceManager&) = delete; 53 }; 54 } // OHOS::ArkCompiler::Toolchain 55 #endif