diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-17 16:57:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-17 16:57:02 +0100 |
commit | 5a2a97c7e8cfac690a00505d8644be30f7ee863a (patch) | |
tree | eba980071d5c8941fdd3adc11fc5525d243ba2b3 /crates/ra_syntax | |
parent | d15cf2c9600e0464b9bcd0273e7845efbf7bdeb5 (diff) | |
parent | 189d879659f4e44c3343023d6455bed7cdf0e7c9 (diff) |
Merge #1694
1694: Implement initial type-inference support for Index r=flodiebold a=matklad
This doesn't actually infer indexing types, but at least it walks sub-expressions!
Initially, I wanted to make `Index` just a new kind of `BinOp` (b/c indexing is kind of a binary op), so I've refactoring binop handing a bit.
However, in the end I've decided to add a separate expr kind for Index, because `foo[0]`, `&foo[1]` and `&mut foo[1]` all seem to need slightly different handing, which is not binop-like
r? @flodiebold
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 8284f1b25..cf5b6f251 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -102,10 +102,6 @@ pub enum BinOp { | |||
102 | BitwiseOr, | 102 | BitwiseOr, |
103 | /// The `&` operator for bitwise AND | 103 | /// The `&` operator for bitwise AND |
104 | BitwiseAnd, | 104 | BitwiseAnd, |
105 | /// The `..` operator for right-open ranges | ||
106 | RangeRightOpen, | ||
107 | /// The `..=` operator for right-closed ranges | ||
108 | RangeRightClosed, | ||
109 | /// The `=` operator for assignment | 105 | /// The `=` operator for assignment |
110 | Assignment, | 106 | Assignment, |
111 | /// The `+=` operator for assignment after addition | 107 | /// The `+=` operator for assignment after addition |
@@ -132,41 +128,40 @@ pub enum BinOp { | |||
132 | 128 | ||
133 | impl ast::BinExpr { | 129 | impl ast::BinExpr { |
134 | fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { | 130 | fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { |
135 | self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| match c | 131 | self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| { |
136 | .kind() | 132 | let bin_op = match c.kind() { |
137 | { | 133 | T![||] => BinOp::BooleanOr, |
138 | T![||] => Some((c, BinOp::BooleanOr)), | 134 | T![&&] => BinOp::BooleanAnd, |
139 | T![&&] => Some((c, BinOp::BooleanAnd)), | 135 | T![==] => BinOp::EqualityTest, |
140 | T![==] => Some((c, BinOp::EqualityTest)), | 136 | T![!=] => BinOp::NegatedEqualityTest, |
141 | T![!=] => Some((c, BinOp::NegatedEqualityTest)), | 137 | T![<=] => BinOp::LesserEqualTest, |
142 | T![<=] => Some((c, BinOp::LesserEqualTest)), | 138 | T![>=] => BinOp::GreaterEqualTest, |
143 | T![>=] => Some((c, BinOp::GreaterEqualTest)), | 139 | T![<] => BinOp::LesserTest, |
144 | T![<] => Some((c, BinOp::LesserTest)), | 140 | T![>] => BinOp::GreaterTest, |
145 | T![>] => Some((c, BinOp::GreaterTest)), | 141 | T![+] => BinOp::Addition, |
146 | T![+] => Some((c, BinOp::Addition)), | 142 | T![*] => BinOp::Multiplication, |
147 | T![*] => Some((c, BinOp::Multiplication)), | 143 | T![-] => BinOp::Subtraction, |
148 | T![-] => Some((c, BinOp::Subtraction)), | 144 | T![/] => BinOp::Division, |
149 | T![/] => Some((c, BinOp::Division)), | 145 | T![%] => BinOp::Remainder, |
150 | T![%] => Some((c, BinOp::Remainder)), | 146 | T![<<] => BinOp::LeftShift, |
151 | T![<<] => Some((c, BinOp::LeftShift)), | 147 | T![>>] => BinOp::RightShift, |
152 | T![>>] => Some((c, BinOp::RightShift)), | 148 | T![^] => BinOp::BitwiseXor, |
153 | T![^] => Some((c, BinOp::BitwiseXor)), | 149 | T![|] => BinOp::BitwiseOr, |
154 | T![|] => Some((c, BinOp::BitwiseOr)), | 150 | T![&] => BinOp::BitwiseAnd, |
155 | T![&] => Some((c, BinOp::BitwiseAnd)), | 151 | T![=] => BinOp::Assignment, |
156 | T![..] => Some((c, BinOp::RangeRightOpen)), | 152 | T![+=] => BinOp::AddAssign, |
157 | T![..=] => Some((c, BinOp::RangeRightClosed)), | 153 | T![/=] => BinOp::DivAssign, |
158 | T![=] => Some((c, BinOp::Assignment)), | 154 | T![*=] => BinOp::MulAssign, |
159 | T![+=] => Some((c, BinOp::AddAssign)), | 155 | T![%=] => BinOp::RemAssign, |
160 | T![/=] => Some((c, BinOp::DivAssign)), | 156 | T![>>=] => BinOp::ShrAssign, |
161 | T![*=] => Some((c, BinOp::MulAssign)), | 157 | T![<<=] => BinOp::ShlAssign, |
162 | T![%=] => Some((c, BinOp::RemAssign)), | 158 | T![-=] => BinOp::SubAssign, |
163 | T![>>=] => Some((c, BinOp::ShrAssign)), | 159 | T![|=] => BinOp::BitOrAssign, |
164 | T![<<=] => Some((c, BinOp::ShlAssign)), | 160 | T![&=] => BinOp::BitAndAssign, |
165 | T![-=] => Some((c, BinOp::SubAssign)), | 161 | T![^=] => BinOp::BitXorAssign, |
166 | T![|=] => Some((c, BinOp::BitOrAssign)), | 162 | _ => return None, |
167 | T![&=] => Some((c, BinOp::BitAndAssign)), | 163 | }; |
168 | T![^=] => Some((c, BinOp::BitXorAssign)), | 164 | Some((c, bin_op)) |
169 | _ => None, | ||
170 | }) | 165 | }) |
171 | } | 166 | } |
172 | 167 | ||
@@ -194,6 +189,15 @@ impl ast::BinExpr { | |||
194 | } | 189 | } |
195 | } | 190 | } |
196 | 191 | ||
192 | impl ast::IndexExpr { | ||
193 | pub fn base(&self) -> Option<ast::Expr> { | ||
194 | children(self).nth(0) | ||
195 | } | ||
196 | pub fn index(&self) -> Option<ast::Expr> { | ||
197 | children(self).nth(1) | ||
198 | } | ||
199 | } | ||
200 | |||
197 | pub enum ArrayExprKind { | 201 | pub enum ArrayExprKind { |
198 | Repeat { initializer: Option<ast::Expr>, repeat: Option<ast::Expr> }, | 202 | Repeat { initializer: Option<ast::Expr>, repeat: Option<ast::Expr> }, |
199 | ElementList(AstChildren<ast::Expr>), | 203 | ElementList(AstChildren<ast::Expr>), |