summaryrefslogtreecommitdiff
path: root/Source/Core/Common/CWDemangler.h
blob: b15aa9492659b8fe5e88e809e6ac7df0e01eee85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2026 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Based on: https://github.com/encounter/cwdemangle
// Copyright 2024 Luke Street <luke@street.dev>
// SPDX-License-Identifier: CC0-1.0

#pragma once

#include <optional>
#include <string>

#include "Common/CommonTypes.h"

namespace CWDemangler
{

// Options for [demangle].
struct DemangleOptions
{
  // Replace `(void)` function parameters with `()`
  bool omit_empty_parameters = true;
  // Enable Metrowerks extension types (`__int128`, `__vec2x32float__`, etc.)
  //
  // Disabled by default since they conflict with template argument literals
  // and can't always be demangled correctly.
  bool mw_extensions = false;
};

struct DemangleTemplateArgsResult
{
  std::string_view name;
  std::string args;
};

struct DemangleNameResult
{
  std::string class_name;
  std::string full;
  std::string_view rest;
};

struct DemangleArgResult
{
  std::string arg_pre;
  std::string arg_post;
  std::string_view rest;
};

struct DemangleFunctionArgsResult
{
  std::string args;
  std::string_view rest;
};

std::optional<DemangleTemplateArgsResult> demangle_template_args(std::string_view str,
                                                                 DemangleOptions options);
std::optional<DemangleNameResult> demangle_name(std::string_view str, DemangleOptions options);
std::optional<DemangleNameResult> demangle_qualified_name(std::string_view str,
                                                          DemangleOptions options);
std::optional<DemangleArgResult> demangle_arg(std::string_view str, DemangleOptions options);
std::optional<DemangleFunctionArgsResult> demangle_function_args(std::string_view str,
                                                                 DemangleOptions options);
std::optional<std::string> demangle_special_function(std::string_view str,
                                                     std::string_view class_name,
                                                     DemangleOptions options);
std::optional<std::string> demangle(std::string_view str, DemangleOptions options);
}  // namespace CWDemangler