Commit aa1411f
authored
Fix removing parentheses when using deducing assignement (#331)
The issue is caused by `emit(expression_list_node)` that skips parentheses
when node is inside initializer - that serves cases like:
```cpp
v : std::vector<int> = (1,2,3);
```
Where it generates:
```cpp
std::vector<int> v{1,2,3};
```
When `:=` is used in the following cases:
```cpp
d := (1 + 2) * (3 + 4) * (5 + 6);
```
It removes first parentheses and we end up with:
```cpp
auto d = {1 + 2 * (3 + 4) * ( 5 + 6)};
```
This change corrects this behaviour on the parsing side. After parsing
expression list it checks if the next lexeme is `Semicolon`. If it is it
means that we are on the initializer of the form:
```cpp
d1 := ((2 + 1) * (4 - 1) * (8 - 3));
d3 := (move d2);
v : std::vector<int> = ();
```
And we can suppres printing of parentheses - as there will be braces:
```cpp
auto d1 {(2 + 1) * (4 - 1) * (8 - 3)};
auto d3 {std::move(d2)};
std::vector<int> v {};
```
When next lexeme is not `Semicolon` it means that we are in initializer
of the form:
```cpp
d2 := (2 + 1) * (4 - 1) * (8 - 3);
d4 : _ = (1 + 2) * (3 + 4) * (5 + 6);
d5 : int = (1 + 2) * (3 + 4) * (5 + 6);
```
And we need to keep all the parentheses and it will be generates to:
```cpp
auto d2 {(2 + 1) * (4 - 1) * (8 - 3)};
auto d4 {(1 + 2) * (3 + 4) * (5 + 6)};
int d5 {(1 + 2) * (3 + 4) * (5 + 6)};
```1 parent ef6b1a0 commit aa1411f
1 file changed
+6
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2852 | 2852 | | |
2853 | 2853 | | |
2854 | 2854 | | |
2855 | | - | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
2856 | 2858 | | |
2857 | 2859 | | |
2858 | 2860 | | |
| |||
2870 | 2872 | | |
2871 | 2873 | | |
2872 | 2874 | | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
2873 | 2878 | | |
2874 | 2879 | | |
2875 | 2880 | | |
| |||
0 commit comments