/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_TOOLING_CLIENT_MANAGER_VARIABLE_MANAGER_H #define ECMASCRIPT_TOOLING_CLIENT_MANAGER_VARIABLE_MANAGER_H #include #include #include "tooling/client/manager/stack_manager.h" #include "tooling/base/pt_json.h" #include "tooling/base/pt_returns.h" #include "tooling/base/pt_types.h" using PtJson = panda::ecmascript::tooling::PtJson; using Result = panda::ecmascript::tooling::Result; using PropertyDescriptor = panda::ecmascript::tooling::PropertyDescriptor; using GetHeapUsageReturns = panda::ecmascript::tooling::GetHeapUsageReturns; using PropertyDescriptor = panda::ecmascript::tooling::PropertyDescriptor; using DescriptorMap = std::map>; using NodeData = std::variant>, std::unique_ptr, DescriptorMap>; namespace OHOS::ArkCompiler::Toolchain { class TreeNode { public: NodeData data; std::vector> children; TreeNode(int32_t CallFrameId) : data(CallFrameId) {} TreeNode(const std::map>& scopeInfo) : data(scopeInfo) {} TreeNode(std::unique_ptr descriptor) : data(std::move(descriptor)) {} TreeNode(DescriptorMap&& descriptorMap) : data(std::move(descriptorMap)) {} void AddChild(std::unique_ptr descriptor); void AddChild(DescriptorMap descriptorMap); void AddChild(std::unique_ptr child); void Print(int depth = 0) const; }; class Tree { public: Tree(int32_t rootValue) : root_(std::make_unique(rootValue)) {} Tree(const std::map>& dataMap, int32_t index); void Clear(); void Print() const; TreeNode* GetRoot() const; TreeNode* FindNodeWithObjectId(int32_t objectId) const; void AddVariableNode(TreeNode* parentNode, std::unique_ptr descriptor); void AddObjectNode(TreeNode* parentNode, std::unique_ptr descriptor); TreeNode* FindNodeWithCondition() const; void PrintRootAndImmediateChildren() const; int32_t FindObjectByIndex(int32_t index) const; private: std::unique_ptr root_ {}; int32_t index_ {1}; TreeNode* FindNodeWithObjectIdRecursive(TreeNode* node, int32_t objectId) const; TreeNode* FindNodeWithInnerKeyZero(TreeNode* node) const; int32_t FindObjectByIndexRecursive(const TreeNode* node, int32_t index) const; }; class VariableManager final { public: VariableManager(int32_t sessionId) : sessionId_(sessionId) {} void SetHeapUsageInfo(std::unique_ptr heapUsageReturns); void ShowHeapUsageInfo() const; void ShowVariableInfos() const; void ClearVariableInfo(); void InitializeTree(std::map> dataMap, int index = 0); void PrintVariableInfo(); TreeNode* FindNodeWithObjectId(int32_t objectId); int32_t FindObjectIdWithIndex(int index); void AddVariableInfo(TreeNode *parentNode, std::unique_ptr variableInfo); TreeNode* FindNodeObjectZero(); void Printinfo() const; private: [[maybe_unused]] int32_t sessionId_; GetHeapUsageReturns heapUsageInfo_ {}; Tree variableInfo_ {0}; VariableManager(const VariableManager&) = delete; VariableManager& operator=(const VariableManager&) = delete; }; } // OHOS::ArkCompiler::Toolchain #endif