当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
57 Star 30 Fork 160

OpenHarmony-SIG/arkcompiler_runtime_core
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mangling.h 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
Petrov Igor 提交于 2023-10-12 22:51 +08:00 . [CodeStyle] Fix \#define names in headers
/**
* Copyright (c) 2021-2022 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 PANDA_ASSEMBLER_MANGLING_H
#define PANDA_ASSEMBLER_MANGLING_H
#include "assembly-function.h"
#include <string>
#include <vector>
namespace panda::pandasm {
constexpr const std::string_view MANGLE_BEGIN = ":";
constexpr const std::string_view MANGLE_SEPARATOR = ";";
constexpr const std::string_view SIGNATURE_BEGIN = MANGLE_BEGIN;
constexpr const std::string_view SIGNATURE_TYPES_SEPARATOR = ",";
constexpr const std::string_view SIGNATURE_TYPES_SEPARATOR_L = "(";
constexpr const std::string_view SIGNATURE_TYPES_SEPARATOR_R = ")";
inline std::string DeMangleName(const std::string &name)
{
auto iter = name.find_first_of(MANGLE_BEGIN);
if (iter != std::string::npos) {
return name.substr(0, name.find_first_of(MANGLE_BEGIN));
}
return name;
}
inline std::string MangleFunctionName(const std::string &name, const std::vector<pandasm::Function::Parameter> &params,
const pandasm::Type &return_type)
{
std::string mangle_name {name};
mangle_name += MANGLE_BEGIN;
for (const auto &p : params) {
mangle_name += p.type.GetName() + std::string(MANGLE_SEPARATOR);
}
mangle_name += return_type.GetName() + std::string(MANGLE_SEPARATOR);
return mangle_name;
}
inline std::string MangleFieldName(const std::string &name, const pandasm::Type &type)
{
std::string mangle_name {name};
mangle_name += MANGLE_BEGIN;
mangle_name += type.GetName() + std::string(MANGLE_SEPARATOR);
return mangle_name;
}
inline std::string GetFunctionSignatureFromName(std::string name,
const std::vector<pandasm::Function::Parameter> &params)
{
name += SIGNATURE_BEGIN;
name += SIGNATURE_TYPES_SEPARATOR_L;
bool first = true;
for (const auto &p : params) {
name += (first) ? "" : SIGNATURE_TYPES_SEPARATOR;
first = false;
name += p.type.GetPandasmName();
}
name += SIGNATURE_TYPES_SEPARATOR_R;
return name;
}
inline std::string GetFunctionNameFromSignature(const std::string &sig)
{
return DeMangleName(sig);
}
inline bool IsSignatureOrMangled(const std::string &str)
{
return str.find(SIGNATURE_BEGIN) != std::string::npos;
}
} // namespace panda::pandasm
#endif // PANDA_ASSEMBLER_MANGLING_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony-sig/arkcompiler_runtime_core.git
git@gitee.com:openharmony-sig/arkcompiler_runtime_core.git
openharmony-sig
arkcompiler_runtime_core
arkcompiler_runtime_core
master

搜索帮助