forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnaryExpression.cs
More file actions
61 lines (49 loc) · 2.06 KB
/
UnaryExpression.cs
File metadata and controls
61 lines (49 loc) · 2.06 KB
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Diagnostics;
using IronPython.Runtime.Binding;
using MSAst = System.Linq.Expressions;
namespace IronPython.Compiler.Ast {
public class UnaryExpression : Expression {
public UnaryExpression(PythonOperator op, Expression expression) {
Operator = op;
OperationKind = PythonOperatorToOperatorString(op);
Expression = expression;
EndIndex = expression.EndIndex;
}
internal UnaryExpression(PythonOperationKind op, Expression expression) {
OperationKind = op;
Expression = expression;
EndIndex = expression.EndIndex;
}
public Expression Expression { get; }
public PythonOperator Operator { get; }
internal PythonOperationKind OperationKind { get; }
public override MSAst.Expression Reduce()
=> GlobalParent.Operation(typeof(object), OperationKind, Expression);
public override void Walk(PythonWalker walker) {
if (walker.Walk(this)) {
Expression?.Walk(walker);
}
walker.PostWalk(this);
}
private static PythonOperationKind PythonOperatorToOperatorString(PythonOperator op) {
switch (op) {
// Unary
case PythonOperator.Not:
return PythonOperationKind.Not;
case PythonOperator.Pos:
return PythonOperationKind.Positive;
case PythonOperator.Invert:
return PythonOperationKind.OnesComplement;
case PythonOperator.Negate:
return PythonOperationKind.Negate;
default:
Debug.Assert(false, "Unexpected PythonOperator: " + op.ToString());
return PythonOperationKind.None;
}
}
}
}