datex_core/decompiler/
options.rs1use crate::serde::Deserialize;
2use serde::Serialize;
3
4#[cfg_attr(feature = "wasm_runtime", derive(tsify::Tsify))]
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6pub struct DecompileOptions {
7 #[serde(default)]
8 pub formatting_options: FormattingOptions,
9 #[serde(default)]
11 pub resolve_slots: bool,
12}
13
14impl DecompileOptions {
15 pub fn json_compat() -> Self {
16 DecompileOptions {
17 formatting_options: FormattingOptions::json_compat(),
18 ..DecompileOptions::default()
19 }
20 }
21
22 pub fn colorized() -> Self {
24 DecompileOptions {
25 formatting_options: FormattingOptions::colorized(),
26 ..DecompileOptions::default()
27 }
28 }
29
30 pub fn compact() -> Self {
32 DecompileOptions {
33 formatting_options: FormattingOptions::compact(),
34 ..DecompileOptions::default()
35 }
36 }
37}
38
39#[cfg_attr(feature = "wasm_runtime", derive(tsify::Tsify))]
40#[derive(Clone, Debug, Copy, Default, Serialize, Deserialize)]
41pub enum IndentType {
42 #[default]
43 Spaces,
44 Tabs,
45}
46
47#[cfg_attr(feature = "wasm_runtime", derive(tsify::Tsify))]
48#[derive(Debug, Clone, Default, Serialize, Deserialize)]
49#[serde(tag = "type")]
50pub enum FormattingMode {
51 #[default]
53 Compact,
54 Pretty {
56 indent: usize,
57 #[serde(default)]
58 indent_type: IndentType,
59 },
60}
61
62impl FormattingMode {
63 pub fn pretty() -> Self {
64 FormattingMode::Pretty {
65 indent: 4,
66 indent_type: IndentType::Spaces,
67 }
68 }
69
70 pub fn compact() -> Self {
71 FormattingMode::Compact
72 }
73
74 pub fn pretty_with_indent(indent: usize, indent_type: IndentType) -> Self {
75 FormattingMode::Pretty {
76 indent,
77 indent_type,
78 }
79 }
80}
81
82#[cfg_attr(feature = "wasm_runtime", derive(tsify::Tsify))]
83#[derive(Debug, Clone, Default, Serialize, Deserialize)]
84pub struct FormattingOptions {
85 #[serde(default)]
86 pub mode: FormattingMode,
87 #[serde(default)]
88 pub json_compat: bool,
89 #[serde(default)]
90 pub colorized: bool,
91 #[serde(default)]
92 pub add_variant_suffix: bool,
93}
94
95impl FormattingOptions {
96 pub fn colorized() -> Self {
97 FormattingOptions {
98 colorized: true,
99 ..FormattingOptions::default()
100 }
101 }
102
103 pub fn json_compat() -> Self {
104 FormattingOptions {
105 json_compat: true,
106 ..FormattingOptions::default()
107 }
108 }
109
110 pub fn compact() -> Self {
111 FormattingOptions {
112 mode: FormattingMode::Compact,
113 ..FormattingOptions::default()
114 }
115 }
116
117 pub fn pretty() -> Self {
118 FormattingOptions {
119 mode: FormattingMode::pretty(),
120 ..FormattingOptions::default()
121 }
122 }
123
124 pub fn pretty_with_indent(indent: usize, indent_type: IndentType) -> Self {
125 FormattingOptions {
126 mode: FormattingMode::pretty_with_indent(indent, indent_type),
127 ..FormattingOptions::default()
128 }
129 }
130}