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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use{
std::cell::Cell,
crate::{
makepad_live_compiler::*,
shader_ast::*,
shader_registry::ShaderRegistry
}
};
pub struct LhsChecker<'a> {
pub scopes: &'a Scopes,
pub shader_registry: &'a ShaderRegistry,
}
impl<'a> LhsChecker<'a> {
pub fn lhs_check_expr(&mut self, expr: &Expr) -> Result<(), LiveError> {
match expr.kind {
ExprKind::Cond {
span,
ref expr,
ref expr_if_true,
ref expr_if_false,
..
} => self.lhs_check_cond_expr(span, expr, expr_if_true, expr_if_false),
ExprKind::Bin {
span,
op,
ref left_expr,
ref right_expr,
..
} => self.lhs_check_bin_expr(span, op, left_expr, right_expr),
ExprKind::Un {span, op, ref expr} => self.lhs_check_un_expr(span, op, expr),
ExprKind::Field {
span,
ref expr,
field_ident,
} => self.lhs_check_field_expr(span, expr, field_ident),
ExprKind::Index {
span,
ref expr,
ref index_expr,
} => self.lhs_check_index_expr(span, expr, index_expr),
ExprKind::MethodCall {
span,
..
} => self.lhs_check_all_call_expr(span),
ExprKind::PlainCall {
span,
..
} => self.lhs_check_all_call_expr(span),
ExprKind::ClosureDef(_) => self.lhs_check_closure(expr.span),
ExprKind::BuiltinCall {
span,
..
} => self.lhs_check_all_call_expr(span),
ExprKind::ConsCall {
span,
..
} => self.lhs_check_all_call_expr(span),
ExprKind::StructCons {
span,
..
} => self.lhs_check_all_call_expr(span),
ExprKind::Var {
span,
ref kind,
..
} => self.lhs_check_var_expr(span, kind),
ExprKind::Lit {span, lit} => self.lhs_check_lit_expr(span, lit),
}
}
fn lhs_check_closure(
&mut self,
span: TokenSpan,
) -> Result<(), LiveError> {
return Err(LiveError {
origin: live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
});
}
fn lhs_check_cond_expr(
&mut self,
span: TokenSpan,
_expr: &Expr,
_expr_if_true: &Expr,
_expr_if_false: &Expr,
) -> Result<(), LiveError> {
return Err(LiveError {
origin: live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
});
}
fn lhs_check_bin_expr(
&mut self,
span: TokenSpan,
_op: BinOp,
_left_expr: &Expr,
_right_expr: &Expr,
) -> Result<(), LiveError> {
return Err(LiveError {
origin:live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
});
}
fn lhs_check_un_expr(&mut self, span: TokenSpan, _op: UnOp, _expr: &Expr) -> Result<(), LiveError> {
return Err(LiveError {
origin:live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
});
}
fn lhs_check_all_call_expr(
&mut self,
span: TokenSpan,
) -> Result<(), LiveError> {
return Err(LiveError {
origin:live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
});
}
fn lhs_check_field_expr(
&mut self,
span: TokenSpan,
expr: &Expr,
field_ident: Ident,
) -> Result<(), LiveError> {
match expr.ty.borrow().as_ref().unwrap(){
Ty::DrawShader(shader_ptr)=>{
let field_decl = self.shader_registry.draw_shader_defs.get(shader_ptr).unwrap().find_field(field_ident) .unwrap();
match &field_decl.kind{
DrawShaderFieldKind::Varying{..}=>{
Ok(())
}
_=>{
Err(LiveError {
origin:live_error_origin!(),
span:span.into(),
message: String::from("Can only assign to varying values for shader self"),
})
}
}
}
_=>{
self.lhs_check_expr(expr)
}
}
}
fn lhs_check_index_expr(
&mut self,
_span: TokenSpan,
expr: &Expr,
_index_expr: &Expr,
) -> Result<(), LiveError> {
self.lhs_check_expr(expr)
}
fn lhs_check_call_expr(
&mut self,
span: TokenSpan,
_ident_path: IdentPath,
_arg_exprs: &[Expr],
) -> Result<(), LiveError> {
return Err(LiveError {
origin:live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
});
}
fn lhs_check_var_expr(
&mut self,
span: TokenSpan,
kind: &Cell<Option<VarKind >>,
) -> Result<(), LiveError> {
if let VarKind::MutLocal{..} = kind.get().unwrap(){
Ok(())
}
else{
Err(LiveError {
origin:live_error_origin!(),
span:span.into(),
message: String::from("expression is not a valid left hand side"),
})
}
}
fn lhs_check_lit_expr(&mut self, _span: TokenSpan, _lit: Lit) -> Result<(), LiveError> {
Ok(())
}
}