Skip to content

Commit d6c4bec

Browse files
gpetrouslozier
authored andcommitted
Use null propagation (#595)
1 parent 8ed996e commit d6c4bec

40 files changed

Lines changed: 148 additions & 362 deletions

Src/IronPython/Compiler/Ast/AndExpression.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ public override Type Type {
7272

7373
public override void Walk(PythonWalker walker) {
7474
if (walker.Walk(this)) {
75-
if (_left != null) {
76-
_left.Walk(walker);
77-
}
78-
if (_right != null) {
79-
_right.Walk(walker);
80-
}
75+
_left?.Walk(walker);
76+
_right?.Walk(walker);
8177
}
8278
walker.PostWalk(this);
8379
}

Src/IronPython/Compiler/Ast/Arg.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ internal Argument GetArgumentInfo() {
4646

4747
public override void Walk(PythonWalker walker) {
4848
if (walker.Walk(this)) {
49-
if (_expression != null) {
50-
_expression.Walk(walker);
51-
}
49+
_expression?.Walk(walker);
5250
}
5351
walker.PostWalk(this);
5452
}

Src/IronPython/Compiler/Ast/AugmentedAssignStatement.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ private static PythonOperationKind PythonOperatorToAction(PythonOperator op) {
7272

7373
public override void Walk(PythonWalker walker) {
7474
if (walker.Walk(this)) {
75-
if (_left != null) {
76-
_left.Walk(walker);
77-
}
78-
if (_right != null) {
79-
_right.Walk(walker);
80-
}
75+
_left?.Walk(walker);
76+
_right?.Walk(walker);
8177
}
8278
walker.PostWalk(this);
8379
}

Src/IronPython/Compiler/Ast/BackQuoteExpression.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public override MSAst.Expression Reduce() {
3131

3232
public override void Walk(PythonWalker walker) {
3333
if (walker.Walk(this)) {
34-
if (_expression != null) {
35-
_expression.Walk(walker);
36-
}
34+
_expression?.Walk(walker);
3735
}
3836
walker.PostWalk(this);
3937
}

Src/IronPython/Compiler/Ast/ClassDefinition.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,8 @@ public override void Walk(PythonWalker walker) {
288288
b.Walk(walker);
289289
}
290290
}
291-
if (_body != null) {
292-
_body.Walk(walker);
293-
}
291+
292+
_body?.Walk(walker);
294293
}
295294
walker.PostWalk(this);
296295
}

Src/IronPython/Compiler/Ast/Comprehension.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ public override string NodeName {
106106

107107
public override void Walk(PythonWalker walker) {
108108
if (walker.Walk(this)) {
109-
if (_item != null) {
110-
_item.Walk(walker);
111-
}
109+
_item?.Walk(walker);
112110
if (_iterators != null) {
113111
foreach (ComprehensionIterator ci in _iterators) {
114112
ci.Walk(walker);
@@ -169,9 +167,7 @@ public override string NodeName {
169167

170168
public override void Walk(PythonWalker walker) {
171169
if (walker.Walk(this)) {
172-
if (_item != null) {
173-
_item.Walk(walker);
174-
}
170+
_item?.Walk(walker);
175171
if (_iterators != null) {
176172
foreach (ComprehensionIterator ci in _iterators) {
177173
ci.Walk(walker);
@@ -244,12 +240,8 @@ public override string NodeName {
244240

245241
public override void Walk(PythonWalker walker) {
246242
if (walker.Walk(this)) {
247-
if (_key != null) {
248-
_key.Walk(walker);
249-
}
250-
if (_value != null) {
251-
_value.Walk(walker);
252-
}
243+
_key?.Walk(walker);
244+
_value?.Walk(walker);
253245
if (_iterators != null) {
254246
foreach (ComprehensionIterator ci in _iterators) {
255247
ci.Walk(walker);

Src/IronPython/Compiler/Ast/ComprehensionFor.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ internal override MSAst.Expression Transform(MSAst.Expression body) {
3939

4040
public override void Walk(PythonWalker walker) {
4141
if (walker.Walk(this)) {
42-
if (_lhs != null) {
43-
_lhs.Walk(walker);
44-
}
45-
if (_list != null) {
46-
_list.Walk(walker);
47-
}
42+
_lhs?.Walk(walker);
43+
_list?.Walk(walker);
4844
}
4945
walker.PostWalk(this);
5046
}

Src/IronPython/Compiler/Ast/ComprehensionIf.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ internal override MSAst.Expression Transform(MSAst.Expression body) {
3434

3535
public override void Walk(PythonWalker walker) {
3636
if (walker.Walk(this)) {
37-
if (_test != null) {
38-
_test.Walk(walker);
39-
}
37+
_test?.Walk(walker);
4038
}
4139
walker.PostWalk(this);
4240
}

Src/IronPython/Compiler/Ast/ConditionalExpression.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,9 @@ public override MSAst.Expression Reduce() {
5050

5151
public override void Walk(PythonWalker walker) {
5252
if (walker.Walk(this)) {
53-
if (_testExpr != null) {
54-
_testExpr.Walk(walker);
55-
}
56-
if (_trueExpr != null) {
57-
_trueExpr.Walk(walker);
58-
}
59-
if (_falseExpr != null) {
60-
_falseExpr.Walk(walker);
61-
}
53+
_testExpr?.Walk(walker);
54+
_trueExpr?.Walk(walker);
55+
_falseExpr?.Walk(walker);
6256
}
6357
walker.PostWalk(this);
6458
}

Src/IronPython/Compiler/Ast/ExecStatement.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ public override MSAst.Expression Reduce() {
6565

6666
public override void Walk(PythonWalker walker) {
6767
if (walker.Walk(this)) {
68-
if (_code != null) {
69-
_code.Walk(walker);
70-
}
71-
if (_locals != null) {
72-
_locals.Walk(walker);
73-
}
74-
if (_globals != null) {
75-
_globals.Walk(walker);
76-
}
68+
_code?.Walk(walker);
69+
_locals?.Walk(walker);
70+
_globals?.Walk(walker);
7771
}
7872
walker.PostWalk(this);
7973
}

0 commit comments

Comments
 (0)