* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2026 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*/
#include "ProjectParserMemScope.h"
#include <ProjectAnalyze.h>
#include "pch.h"
#include "CommonDefs.h"
#include "DataBaseManager.h"
#include "MemScopeParser.h"
#include "MemScopeService.h"
namespace Dic::Module {
using namespace Dic::Server;
void ProjectParserMemScope::Parser(const std::vector<ProjectExplorerInfo> &projectInfos, ImportActionRequest &request,
ImportActionResponse &response) {
ModuleRequestHandler::SetBaseResponse(request, response);
if (std::empty(projectInfos)) {
SendParseFailEvent("", "", "Project explorer info is not existed.");
return;
}
response.command = Protocol::REQ_RES_IMPORT_ACTION;
response.moduleName = MODULE_TIMELINE;
response.body.reset = true;
response.body.isLeaks = true;
for (auto &item : projectInfos[0].projectFileTree) {
for (auto &subItem : item->subParseFile) {
subItem->rankId = subItem->parseFilePath;
}
}
ModuleRequestHandler::SetResponseResult(response, true);
if (!Global::ProjectExplorerManager::Instance().UpdateParseFileInfo(
projectInfos[0].projectName, projectInfos[0].subParseFileInfo)) {
ServerLog::Error("Failed to update project in parsing");
response.result = false;
return;
}
response.body.projectFileTree = projectInfos[0].projectFileTree;
MemScopeParser::Instance().AsyncParseMemScopeDbFile(projectInfos[0].fileName);
SetBaseActionOfResponse(response, projectInfos[0].fileName, projectInfos[0].fileName, projectInfos[0].fileName,
{projectInfos[0].fileName}, static_cast<int64_t>(ProjectTypeEnum::DB_MEMSCOPE));
}
ProjectTypeEnum ProjectParserMemScope::GetProjectType(const std::string &dataPath) {
return ProjectTypeEnum::DB_MEMSCOPE;
}
std::vector<std::string> ProjectParserMemScope::GetParseFileByImportFile(
const std::string &importFile, std::string &error) {
if (FileUtil::IsFolder(importFile)) {
error = "Supports import only from a single-file memscope database.";
return {};
}
return {importFile};
}
void ProjectParserMemScope::BuildProjectExploreInfo(
ProjectExplorerInfo &projectInfo, const std::vector<std::string> &parsedFiles) {
ProjectParserBase::BuildProjectExploreInfo(projectInfo, parsedFiles);
for (const auto &parsedFile : parsedFiles) {
auto parseFileInfo = std::make_shared<ParseFileInfo>();
parseFileInfo->parseFilePath = parsedFile;
parseFileInfo->type = ParseFileType::RANK;
parseFileInfo->curDirName = FileUtil::GetFileName(parsedFile);
parseFileInfo->subId = parsedFile;
parseFileInfo->fileId = parsedFile;
parseFileInfo->rankId = parsedFile;
projectInfo.AddSubParseFileInfo(parseFileInfo);
}
}
bool ProjectParserMemScope::IsMemScopeDbFile(const std::string &filename) {
return std::regex_match(filename, std::regex(memScopeDbReg));
}
static ProjectAnalyzeRegister<ProjectParserMemScope> pRegMemScope(ParserType::DB_MEMSCOPE);
}