1use super::{TreeDisplay, TreeFormatter};
4use crate::r#type::variable::*;
5
6impl TreeDisplay for ModuleVariableDirective {
7 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
8 match self {
9 ModuleVariableDirective::Tex { directive, span } => {
10 f.root(&format!(
11 "ModuleVariableDirective::Tex [{}]",
12 f.format_raw(*span, source)
13 ))?;
14 f.field_with_child(true, "directive", directive, source)
15 }
16 ModuleVariableDirective::Shared { directive, span } => {
17 f.root(&format!(
18 "ModuleVariableDirective::Shared [{}]",
19 f.format_raw(*span, source)
20 ))?;
21 f.field_with_child(true, "directive", directive, source)
22 }
23 ModuleVariableDirective::Global { directive, span } => {
24 f.root(&format!(
25 "ModuleVariableDirective::Global [{}]",
26 f.format_raw(*span, source)
27 ))?;
28 f.field_with_child(true, "directive", directive, source)
29 }
30 ModuleVariableDirective::Const { directive, span } => {
31 f.root(&format!(
32 "ModuleVariableDirective::Const [{}]",
33 f.format_raw(*span, source)
34 ))?;
35 f.field_with_child(true, "directive", directive, source)
36 }
37 }
38 }
39}
40
41impl TreeDisplay for VariableDirective {
42 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
43 f.root(&format!(
44 "VariableDirective [{}]",
45 f.format_raw(self.span, source)
46 ))?;
47 f.field_vec(false, "attributes", &self.attributes, source)?;
48 f.field_vec(false, "modifiers", &self.modifiers, source)?;
49 f.field_with_child(false, "ty", &self.ty, source)?;
50 f.field(false, "name", &self.name.val)?;
51 f.field(false, "array_dims", &format!("{:?}", self.array_dims))?;
52 f.field_option(true, "initializer", &self.initializer, source)
53 }
54}
55
56impl TreeDisplay for VariableModifier {
57 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
58 match self {
59 VariableModifier::Vector { value, span } => {
60 f.root(&format!(
61 "VariableModifier::Vector [{}]",
62 f.format_raw(*span, source)
63 ))?;
64 f.field(true, "value", &value.to_string())
65 }
66 VariableModifier::Alignment { value, span } => {
67 f.root(&format!(
68 "VariableModifier::Alignment [{}]",
69 f.format_raw(*span, source)
70 ))?;
71 f.field(true, "value", &value.to_string())
72 }
73 VariableModifier::Ptr { span } => f.root(&format!(
74 "VariableModifier::Ptr [{}]",
75 f.format_raw(*span, source)
76 )),
77 }
78 }
79}
80
81impl TreeDisplay for ParameterDirective {
82 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
83 match self {
84 ParameterDirective::Register { ty, name, span } => {
85 f.root(&format!(
86 "ParameterDirective::Register [{}]",
87 f.format_raw(*span, source)
88 ))?;
89 f.field_with_child(false, "ty", ty, source)?;
90 f.field(true, "name", &name.val)
91 }
92 ParameterDirective::Parameter {
93 align,
94 ptr,
95 space,
96 ty,
97 name,
98 array,
99 span,
100 } => {
101 f.root(&format!(
102 "ParameterDirective::Parameter [{}]",
103 f.format_raw(*span, source)
104 ))?;
105 match align {
106 Some(a) => f.field(false, "align", &format!("Some({})", a))?,
107 None => f.field(false, "align", "None")?,
108 }
109 f.field(false, "ptr", &ptr.to_string())?;
110 f.field_option(false, "space", space, source)?;
111 f.field_with_child(false, "ty", ty, source)?;
112 f.field(false, "name", &name.val)?;
113 f.field(true, "array", &format!("{:?}", array))
114 }
115 }
116 }
117}
118
119impl TreeDisplay for ParamStateSpace {
120 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
121 let (variant, span) = match self {
122 ParamStateSpace::Const { span } => ("Const", span),
123 ParamStateSpace::Global { span } => ("Global", span),
124 ParamStateSpace::Local { span } => ("Local", span),
125 ParamStateSpace::Shared { span } => ("Shared", span),
126 };
127 f.root(&format!(
128 "ParamStateSpace::{} [{}]",
129 variant,
130 f.format_raw(*span, source)
131 ))
132 }
133}
134
135impl TreeDisplay for InitializerValue {
136 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
137 match self {
138 InitializerValue::NumericLiteral { value, span } => {
139 f.root(&format!(
140 "InitializerValue::NumericLiteral [{}]",
141 f.format_raw(*span, source)
142 ))?;
143 f.field(true, "value", &format!("{:?}", value))
144 }
145 InitializerValue::FunctionSymbol { name, span } => {
146 f.root(&format!(
147 "InitializerValue::FunctionSymbol [{}]",
148 f.format_raw(*span, source)
149 ))?;
150 f.field(true, "name", &name.val)
151 }
152 InitializerValue::StringLiteral { value, span } => {
153 f.root(&format!(
154 "InitializerValue::StringLiteral [{}]",
155 f.format_raw(*span, source)
156 ))?;
157 f.field(true, "value", &format!("\"{}\"", value))
158 }
159 }
160 }
161}
162
163impl TreeDisplay for GlobalInitializer {
164 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
165 match self {
166 GlobalInitializer::Scalar { value, span } => {
167 f.root(&format!(
168 "GlobalInitializer::Scalar [{}]",
169 f.format_raw(*span, source)
170 ))?;
171 f.field_with_child(true, "value", value, source)
172 }
173 GlobalInitializer::Aggregate { values, span } => f.root(&format!(
174 "GlobalInitializer::Aggregate [{}] ({} values)",
175 f.format_raw(*span, source),
176 values.len()
177 )),
178 }
179 }
180}