aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/expr/lower.rs')
-rw-r--r--crates/ra_hir/src/expr/lower.rs630
1 files changed, 630 insertions, 0 deletions
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs
new file mode 100644
index 000000000..6afd80989
--- /dev/null
+++ b/crates/ra_hir/src/expr/lower.rs
@@ -0,0 +1,630 @@
1use ra_arena::Arena;
2use ra_syntax::{
3 ast::{
4 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner,
5 TypeAscriptionOwner,
6 },
7 AstNode, AstPtr,
8};
9use test_utils::tested_by;
10
11use crate::{
12 name::{AsName, Name, SELF_PARAM},
13 path::GenericArgs,
14 ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy},
15 type_ref::TypeRef,
16 DefWithBody, Either, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path,
17 Resolver, Source,
18};
19
20use super::{
21 ArithOp, Array, BinaryOp, BindingAnnotation, Body, BodySourceMap, CmpOp, Expr, ExprId, Literal,
22 LogicOp, MatchArm, Ordering, Pat, PatId, PatPtr, RecordFieldPat, RecordLitField, Statement,
23};
24
25pub(super) fn lower(
26 db: &impl HirDatabase,
27 resolver: Resolver,
28 file_id: HirFileId,
29 owner: DefWithBody,
30 params: Option<ast::ParamList>,
31 body: Option<ast::Expr>,
32) -> (Body, BodySourceMap) {
33 ExprCollector {
34 resolver,
35 db,
36 original_file_id: file_id,
37 current_file_id: file_id,
38 source_map: BodySourceMap::default(),
39 body: Body {
40 owner,
41 exprs: Arena::default(),
42 pats: Arena::default(),
43 params: Vec::new(),
44 body_expr: ExprId((!0).into()),
45 },
46 }
47 .collect(params, body)
48}
49
50struct ExprCollector<DB> {
51 db: DB,
52 resolver: Resolver,
53 // Expr collector expands macros along the way. original points to the file
54 // we started with, current points to the current macro expansion. source
55 // maps don't support macros yet, so we only record info into source map if
56 // current == original (see #1196)
57 original_file_id: HirFileId,
58 current_file_id: HirFileId,
59
60 body: Body,
61 source_map: BodySourceMap,
62}
63
64impl<'a, DB> ExprCollector<&'a DB>
65where
66 DB: HirDatabase,
67{
68 fn collect(
69 mut self,
70 param_list: Option<ast::ParamList>,
71 body: Option<ast::Expr>,
72 ) -> (Body, BodySourceMap) {
73 if let Some(param_list) = param_list {
74 if let Some(self_param) = param_list.self_param() {
75 let ptr = AstPtr::new(&self_param);
76 let param_pat = self.alloc_pat(
77 Pat::Bind {
78 name: SELF_PARAM,
79 mode: BindingAnnotation::Unannotated,
80 subpat: None,
81 },
82 Either::B(ptr),
83 );
84 self.body.params.push(param_pat);
85 }
86
87 for param in param_list.params() {
88 let pat = match param.pat() {
89 None => continue,
90 Some(pat) => pat,
91 };
92 let param_pat = self.collect_pat(pat);
93 self.body.params.push(param_pat);
94 }
95 };
96
97 self.body.body_expr = self.collect_expr_opt(body);
98 (self.body, self.source_map)
99 }
100
101 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
102 let ptr = Either::A(ptr);
103 let id = self.body.exprs.alloc(expr);
104 if self.current_file_id == self.original_file_id {
105 self.source_map.expr_map.insert(ptr, id);
106 }
107 self.source_map
108 .expr_map_back
109 .insert(id, Source { file_id: self.current_file_id, ast: ptr });
110 id
111 }
112 // desugared exprs don't have ptr, that's wrong and should be fixed
113 // somehow.
114 fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId {
115 self.body.exprs.alloc(expr)
116 }
117 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
118 let ptr = Either::B(ptr);
119 let id = self.body.exprs.alloc(expr);
120 if self.current_file_id == self.original_file_id {
121 self.source_map.expr_map.insert(ptr, id);
122 }
123 self.source_map
124 .expr_map_back
125 .insert(id, Source { file_id: self.current_file_id, ast: ptr });
126 id
127 }
128 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
129 let id = self.body.pats.alloc(pat);
130 if self.current_file_id == self.original_file_id {
131 self.source_map.pat_map.insert(ptr, id);
132 }
133 self.source_map.pat_map_back.insert(id, Source { file_id: self.current_file_id, ast: ptr });
134 id
135 }
136
137 fn empty_block(&mut self) -> ExprId {
138 let block = Expr::Block { statements: Vec::new(), tail: None };
139 self.body.exprs.alloc(block)
140 }
141
142 fn missing_expr(&mut self) -> ExprId {
143 self.body.exprs.alloc(Expr::Missing)
144 }
145
146 fn missing_pat(&mut self) -> PatId {
147 self.body.pats.alloc(Pat::Missing)
148 }
149
150 fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
151 let syntax_ptr = AstPtr::new(&expr);
152 match expr {
153 ast::Expr::IfExpr(e) => {
154 let then_branch = self.collect_block_opt(e.then_branch());
155
156 let else_branch = e.else_branch().map(|b| match b {
157 ast::ElseBranch::Block(it) => self.collect_block(it),
158 ast::ElseBranch::IfExpr(elif) => {
159 let expr: ast::Expr = ast::Expr::cast(elif.syntax().clone()).unwrap();
160 self.collect_expr(expr)
161 }
162 });
163
164 let condition = match e.condition() {
165 None => self.missing_expr(),
166 Some(condition) => match condition.pat() {
167 None => self.collect_expr_opt(condition.expr()),
168 // if let -- desugar to match
169 Some(pat) => {
170 let pat = self.collect_pat(pat);
171 let match_expr = self.collect_expr_opt(condition.expr());
172 let placeholder_pat = self.missing_pat();
173 let arms = vec![
174 MatchArm { pats: vec![pat], expr: then_branch, guard: None },
175 MatchArm {
176 pats: vec![placeholder_pat],
177 expr: else_branch.unwrap_or_else(|| self.empty_block()),
178 guard: None,
179 },
180 ];
181 return self
182 .alloc_expr(Expr::Match { expr: match_expr, arms }, syntax_ptr);
183 }
184 },
185 };
186
187 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
188 }
189 ast::Expr::TryBlockExpr(e) => {
190 let body = self.collect_block_opt(e.body());
191 self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
192 }
193 ast::Expr::BlockExpr(e) => self.collect_block(e),
194 ast::Expr::LoopExpr(e) => {
195 let body = self.collect_block_opt(e.loop_body());
196 self.alloc_expr(Expr::Loop { body }, syntax_ptr)
197 }
198 ast::Expr::WhileExpr(e) => {
199 let body = self.collect_block_opt(e.loop_body());
200
201 let condition = match e.condition() {
202 None => self.missing_expr(),
203 Some(condition) => match condition.pat() {
204 None => self.collect_expr_opt(condition.expr()),
205 // if let -- desugar to match
206 Some(pat) => {
207 tested_by!(infer_while_let);
208 let pat = self.collect_pat(pat);
209 let match_expr = self.collect_expr_opt(condition.expr());
210 let placeholder_pat = self.missing_pat();
211 let break_ = self.alloc_expr_desugared(Expr::Break { expr: None });
212 let arms = vec![
213 MatchArm { pats: vec![pat], expr: body, guard: None },
214 MatchArm { pats: vec![placeholder_pat], expr: break_, guard: None },
215 ];
216 let match_expr =
217 self.alloc_expr_desugared(Expr::Match { expr: match_expr, arms });
218 return self.alloc_expr(Expr::Loop { body: match_expr }, syntax_ptr);
219 }
220 },
221 };
222
223 self.alloc_expr(Expr::While { condition, body }, syntax_ptr)
224 }
225 ast::Expr::ForExpr(e) => {
226 let iterable = self.collect_expr_opt(e.iterable());
227 let pat = self.collect_pat_opt(e.pat());
228 let body = self.collect_block_opt(e.loop_body());
229 self.alloc_expr(Expr::For { iterable, pat, body }, syntax_ptr)
230 }
231 ast::Expr::CallExpr(e) => {
232 let callee = self.collect_expr_opt(e.expr());
233 let args = if let Some(arg_list) = e.arg_list() {
234 arg_list.args().map(|e| self.collect_expr(e)).collect()
235 } else {
236 Vec::new()
237 };
238 self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
239 }
240 ast::Expr::MethodCallExpr(e) => {
241 let receiver = self.collect_expr_opt(e.expr());
242 let args = if let Some(arg_list) = e.arg_list() {
243 arg_list.args().map(|e| self.collect_expr(e)).collect()
244 } else {
245 Vec::new()
246 };
247 let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
248 let generic_args = e.type_arg_list().and_then(GenericArgs::from_ast);
249 self.alloc_expr(
250 Expr::MethodCall { receiver, method_name, args, generic_args },
251 syntax_ptr,
252 )
253 }
254 ast::Expr::MatchExpr(e) => {
255 let expr = self.collect_expr_opt(e.expr());
256 let arms = if let Some(match_arm_list) = e.match_arm_list() {
257 match_arm_list
258 .arms()
259 .map(|arm| MatchArm {
260 pats: arm.pats().map(|p| self.collect_pat(p)).collect(),
261 expr: self.collect_expr_opt(arm.expr()),
262 guard: arm
263 .guard()
264 .and_then(|guard| guard.expr())
265 .map(|e| self.collect_expr(e)),
266 })
267 .collect()
268 } else {
269 Vec::new()
270 };
271 self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr)
272 }
273 ast::Expr::PathExpr(e) => {
274 let path =
275 e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing);
276 self.alloc_expr(path, syntax_ptr)
277 }
278 ast::Expr::ContinueExpr(_e) => {
279 // FIXME: labels
280 self.alloc_expr(Expr::Continue, syntax_ptr)
281 }
282 ast::Expr::BreakExpr(e) => {
283 let expr = e.expr().map(|e| self.collect_expr(e));
284 self.alloc_expr(Expr::Break { expr }, syntax_ptr)
285 }
286 ast::Expr::ParenExpr(e) => {
287 let inner = self.collect_expr_opt(e.expr());
288 // make the paren expr point to the inner expression as well
289 self.source_map.expr_map.insert(Either::A(syntax_ptr), inner);
290 inner
291 }
292 ast::Expr::ReturnExpr(e) => {
293 let expr = e.expr().map(|e| self.collect_expr(e));
294 self.alloc_expr(Expr::Return { expr }, syntax_ptr)
295 }
296 ast::Expr::RecordLit(e) => {
297 let path = e.path().and_then(Path::from_ast);
298 let mut field_ptrs = Vec::new();
299 let record_lit = if let Some(nfl) = e.record_field_list() {
300 let fields = nfl
301 .fields()
302 .inspect(|field| field_ptrs.push(AstPtr::new(field)))
303 .map(|field| RecordLitField {
304 name: field
305 .name_ref()
306 .map(|nr| nr.as_name())
307 .unwrap_or_else(Name::missing),
308 expr: if let Some(e) = field.expr() {
309 self.collect_expr(e)
310 } else if let Some(nr) = field.name_ref() {
311 // field shorthand
312 self.alloc_expr_field_shorthand(
313 Expr::Path(Path::from_name_ref(&nr)),
314 AstPtr::new(&field),
315 )
316 } else {
317 self.missing_expr()
318 },
319 })
320 .collect();
321 let spread = nfl.spread().map(|s| self.collect_expr(s));
322 Expr::RecordLit { path, fields, spread }
323 } else {
324 Expr::RecordLit { path, fields: Vec::new(), spread: None }
325 };
326
327 let res = self.alloc_expr(record_lit, syntax_ptr);
328 for (i, ptr) in field_ptrs.into_iter().enumerate() {
329 self.source_map.field_map.insert((res, i), ptr);
330 }
331 res
332 }
333 ast::Expr::FieldExpr(e) => {
334 let expr = self.collect_expr_opt(e.expr());
335 let name = match e.field_access() {
336 Some(kind) => kind.as_name(),
337 _ => Name::missing(),
338 };
339 self.alloc_expr(Expr::Field { expr, name }, syntax_ptr)
340 }
341 ast::Expr::AwaitExpr(e) => {
342 let expr = self.collect_expr_opt(e.expr());
343 self.alloc_expr(Expr::Await { expr }, syntax_ptr)
344 }
345 ast::Expr::TryExpr(e) => {
346 let expr = self.collect_expr_opt(e.expr());
347 self.alloc_expr(Expr::Try { expr }, syntax_ptr)
348 }
349 ast::Expr::CastExpr(e) => {
350 let expr = self.collect_expr_opt(e.expr());
351 let type_ref = TypeRef::from_ast_opt(e.type_ref());
352 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
353 }
354 ast::Expr::RefExpr(e) => {
355 let expr = self.collect_expr_opt(e.expr());
356 let mutability = Mutability::from_mutable(e.is_mut());
357 self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr)
358 }
359 ast::Expr::PrefixExpr(e) => {
360 let expr = self.collect_expr_opt(e.expr());
361 if let Some(op) = e.op_kind() {
362 self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr)
363 } else {
364 self.alloc_expr(Expr::Missing, syntax_ptr)
365 }
366 }
367 ast::Expr::LambdaExpr(e) => {
368 let mut args = Vec::new();
369 let mut arg_types = Vec::new();
370 if let Some(pl) = e.param_list() {
371 for param in pl.params() {
372 let pat = self.collect_pat_opt(param.pat());
373 let type_ref = param.ascribed_type().map(TypeRef::from_ast);
374 args.push(pat);
375 arg_types.push(type_ref);
376 }
377 }
378 let body = self.collect_expr_opt(e.body());
379 self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr)
380 }
381 ast::Expr::BinExpr(e) => {
382 let lhs = self.collect_expr_opt(e.lhs());
383 let rhs = self.collect_expr_opt(e.rhs());
384 let op = e.op_kind().map(BinaryOp::from);
385 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr)
386 }
387 ast::Expr::TupleExpr(e) => {
388 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
389 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
390 }
391
392 ast::Expr::ArrayExpr(e) => {
393 let kind = e.kind();
394
395 match kind {
396 ArrayExprKind::ElementList(e) => {
397 let exprs = e.map(|expr| self.collect_expr(expr)).collect();
398 self.alloc_expr(Expr::Array(Array::ElementList(exprs)), syntax_ptr)
399 }
400 ArrayExprKind::Repeat { initializer, repeat } => {
401 let initializer = self.collect_expr_opt(initializer);
402 let repeat = self.collect_expr_opt(repeat);
403 self.alloc_expr(
404 Expr::Array(Array::Repeat { initializer, repeat }),
405 syntax_ptr,
406 )
407 }
408 }
409 }
410
411 ast::Expr::Literal(e) => {
412 let lit = match e.kind() {
413 LiteralKind::IntNumber { suffix } => {
414 let known_name = suffix
415 .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known));
416
417 Literal::Int(
418 Default::default(),
419 known_name.unwrap_or(UncertainIntTy::Unknown),
420 )
421 }
422 LiteralKind::FloatNumber { suffix } => {
423 let known_name = suffix
424 .and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known));
425
426 Literal::Float(
427 Default::default(),
428 known_name.unwrap_or(UncertainFloatTy::Unknown),
429 )
430 }
431 LiteralKind::ByteString => Literal::ByteString(Default::default()),
432 LiteralKind::String => Literal::String(Default::default()),
433 LiteralKind::Byte => {
434 Literal::Int(Default::default(), UncertainIntTy::Known(IntTy::u8()))
435 }
436 LiteralKind::Bool => Literal::Bool(Default::default()),
437 LiteralKind::Char => Literal::Char(Default::default()),
438 };
439 self.alloc_expr(Expr::Literal(lit), syntax_ptr)
440 }
441 ast::Expr::IndexExpr(e) => {
442 let base = self.collect_expr_opt(e.base());
443 let index = self.collect_expr_opt(e.index());
444 self.alloc_expr(Expr::Index { base, index }, syntax_ptr)
445 }
446
447 // FIXME implement HIR for these:
448 ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
449 ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
450 ast::Expr::MacroCall(e) => {
451 let ast_id = self
452 .db
453 .ast_id_map(self.current_file_id)
454 .ast_id(&e)
455 .with_file_id(self.current_file_id);
456
457 if let Some(path) = e.path().and_then(Path::from_ast) {
458 if let Some(def) = self.resolver.resolve_path_as_macro(self.db, &path) {
459 let call_id = MacroCallLoc { def: def.id, ast_id }.id(self.db);
460 let file_id = call_id.as_file(MacroFileKind::Expr);
461 if let Some(node) = self.db.parse_or_expand(file_id) {
462 if let Some(expr) = ast::Expr::cast(node) {
463 log::debug!("macro expansion {:#?}", expr.syntax());
464 let old_file_id =
465 std::mem::replace(&mut self.current_file_id, file_id);
466 let id = self.collect_expr(expr);
467 self.current_file_id = old_file_id;
468 return id;
469 }
470 }
471 }
472 }
473 // FIXME: Instead of just dropping the error from expansion
474 // report it
475 self.alloc_expr(Expr::Missing, syntax_ptr)
476 }
477 }
478 }
479
480 fn collect_expr_opt(&mut self, expr: Option<ast::Expr>) -> ExprId {
481 if let Some(expr) = expr {
482 self.collect_expr(expr)
483 } else {
484 self.missing_expr()
485 }
486 }
487
488 fn collect_block(&mut self, expr: ast::BlockExpr) -> ExprId {
489 let syntax_node_ptr = AstPtr::new(&expr.clone().into());
490 let block = match expr.block() {
491 Some(block) => block,
492 None => return self.alloc_expr(Expr::Missing, syntax_node_ptr),
493 };
494 let statements = block
495 .statements()
496 .map(|s| match s {
497 ast::Stmt::LetStmt(stmt) => {
498 let pat = self.collect_pat_opt(stmt.pat());
499 let type_ref = stmt.ascribed_type().map(TypeRef::from_ast);
500 let initializer = stmt.initializer().map(|e| self.collect_expr(e));
501 Statement::Let { pat, type_ref, initializer }
502 }
503 ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())),
504 })
505 .collect();
506 let tail = block.expr().map(|e| self.collect_expr(e));
507 self.alloc_expr(Expr::Block { statements, tail }, syntax_node_ptr)
508 }
509
510 fn collect_block_opt(&mut self, expr: Option<ast::BlockExpr>) -> ExprId {
511 if let Some(block) = expr {
512 self.collect_block(block)
513 } else {
514 self.missing_expr()
515 }
516 }
517
518 fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
519 let pattern = match &pat {
520 ast::Pat::BindPat(bp) => {
521 let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
522 let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref());
523 let subpat = bp.pat().map(|subpat| self.collect_pat(subpat));
524 Pat::Bind { name, mode: annotation, subpat }
525 }
526 ast::Pat::TupleStructPat(p) => {
527 let path = p.path().and_then(Path::from_ast);
528 let args = p.args().map(|p| self.collect_pat(p)).collect();
529 Pat::TupleStruct { path, args }
530 }
531 ast::Pat::RefPat(p) => {
532 let pat = self.collect_pat_opt(p.pat());
533 let mutability = Mutability::from_mutable(p.is_mut());
534 Pat::Ref { pat, mutability }
535 }
536 ast::Pat::PathPat(p) => {
537 let path = p.path().and_then(Path::from_ast);
538 path.map(Pat::Path).unwrap_or(Pat::Missing)
539 }
540 ast::Pat::TuplePat(p) => {
541 let args = p.args().map(|p| self.collect_pat(p)).collect();
542 Pat::Tuple(args)
543 }
544 ast::Pat::PlaceholderPat(_) => Pat::Wild,
545 ast::Pat::RecordPat(p) => {
546 let path = p.path().and_then(Path::from_ast);
547 let record_field_pat_list =
548 p.record_field_pat_list().expect("every struct should have a field list");
549 let mut fields: Vec<_> = record_field_pat_list
550 .bind_pats()
551 .filter_map(|bind_pat| {
552 let ast_pat =
553 ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat");
554 let pat = self.collect_pat(ast_pat);
555 let name = bind_pat.name()?.as_name();
556 Some(RecordFieldPat { name, pat })
557 })
558 .collect();
559 let iter = record_field_pat_list.record_field_pats().filter_map(|f| {
560 let ast_pat = f.pat()?;
561 let pat = self.collect_pat(ast_pat);
562 let name = f.name()?.as_name();
563 Some(RecordFieldPat { name, pat })
564 });
565 fields.extend(iter);
566
567 Pat::Record { path, args: fields }
568 }
569
570 // FIXME: implement
571 ast::Pat::BoxPat(_) => Pat::Missing,
572 ast::Pat::LiteralPat(_) => Pat::Missing,
573 ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,
574 };
575 let ptr = AstPtr::new(&pat);
576 self.alloc_pat(pattern, Either::A(ptr))
577 }
578
579 fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
580 if let Some(pat) = pat {
581 self.collect_pat(pat)
582 } else {
583 self.missing_pat()
584 }
585 }
586}
587
588impl From<ast::BinOp> for BinaryOp {
589 fn from(ast_op: ast::BinOp) -> Self {
590 match ast_op {
591 ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or),
592 ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And),
593 ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: false }),
594 ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: true }),
595 ast::BinOp::LesserEqualTest => {
596 BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: false })
597 }
598 ast::BinOp::GreaterEqualTest => {
599 BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: false })
600 }
601 ast::BinOp::LesserTest => {
602 BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: true })
603 }
604 ast::BinOp::GreaterTest => {
605 BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: true })
606 }
607 ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add),
608 ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul),
609 ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub),
610 ast::BinOp::Division => BinaryOp::ArithOp(ArithOp::Div),
611 ast::BinOp::Remainder => BinaryOp::ArithOp(ArithOp::Rem),
612 ast::BinOp::LeftShift => BinaryOp::ArithOp(ArithOp::Shl),
613 ast::BinOp::RightShift => BinaryOp::ArithOp(ArithOp::Shr),
614 ast::BinOp::BitwiseXor => BinaryOp::ArithOp(ArithOp::BitXor),
615 ast::BinOp::BitwiseOr => BinaryOp::ArithOp(ArithOp::BitOr),
616 ast::BinOp::BitwiseAnd => BinaryOp::ArithOp(ArithOp::BitAnd),
617 ast::BinOp::Assignment => BinaryOp::Assignment { op: None },
618 ast::BinOp::AddAssign => BinaryOp::Assignment { op: Some(ArithOp::Add) },
619 ast::BinOp::DivAssign => BinaryOp::Assignment { op: Some(ArithOp::Div) },
620 ast::BinOp::MulAssign => BinaryOp::Assignment { op: Some(ArithOp::Mul) },
621 ast::BinOp::RemAssign => BinaryOp::Assignment { op: Some(ArithOp::Rem) },
622 ast::BinOp::ShlAssign => BinaryOp::Assignment { op: Some(ArithOp::Shl) },
623 ast::BinOp::ShrAssign => BinaryOp::Assignment { op: Some(ArithOp::Shr) },
624 ast::BinOp::SubAssign => BinaryOp::Assignment { op: Some(ArithOp::Sub) },
625 ast::BinOp::BitOrAssign => BinaryOp::Assignment { op: Some(ArithOp::BitOr) },
626 ast::BinOp::BitAndAssign => BinaryOp::Assignment { op: Some(ArithOp::BitAnd) },
627 ast::BinOp::BitXorAssign => BinaryOp::Assignment { op: Some(ArithOp::BitXor) },
628 }
629 }
630}