Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BinaryExpression.cs
Go to the documentation of this file.
7
9
10[DebuggerTypeProxy(typeof(BinaryExpressionProxy))]
12{
13 public override bool CanReduce => IsOpAssignment(NodeType);
14
15 public Expression Right { get; }
16
17 public Expression Left { get; }
18
20
22
23 public bool IsLifted
24 {
25 get
26 {
27 if (NodeType == ExpressionType.Coalesce || NodeType == ExpressionType.Assign)
28 {
29 return false;
30 }
31 if (Left.Type.IsNullableType())
32 {
34 if (!(method == null))
35 {
36 return !TypeUtils.AreEquivalent(method.GetParametersCached()[0].ParameterType.GetNonRefType(), Left.Type);
37 }
38 return true;
39 }
40 return false;
41 }
42 }
43
44 public bool IsLiftedToNull
45 {
46 get
47 {
48 if (IsLifted)
49 {
50 return Type.IsNullableType();
51 }
52 return false;
53 }
54 }
55
56 internal bool IsLiftedLogical
57 {
58 get
59 {
63 ExpressionType nodeType = NodeType;
64 if ((nodeType == ExpressionType.AndAlso || nodeType == ExpressionType.OrElse) && TypeUtils.AreEquivalent(type2, type) && type.IsNullableType() && method != null)
65 {
66 return TypeUtils.AreEquivalent(method.ReturnType, type.GetNonNullableType());
67 }
68 return false;
69 }
70 }
71
73 {
74 get
75 {
79 ExpressionType nodeType = NodeType;
80 if ((nodeType == ExpressionType.Equal || nodeType == ExpressionType.NotEqual) && method == null && !type.IsValueType)
81 {
82 return !type2.IsValueType;
83 }
84 return false;
85 }
86 }
87
89 {
90 Left = left;
91 Right = right;
92 }
93
94 private static bool IsOpAssignment(ExpressionType op)
95 {
96 if ((uint)(op - 63) <= 13u)
97 {
98 return true;
99 }
100 return false;
101 }
102
103 internal virtual MethodInfo GetMethod()
104 {
105 return null;
106 }
107
109 {
110 if (left == Left && right == Right && conversion == Conversion)
111 {
112 return this;
113 }
115 {
116 if (NodeType == ExpressionType.Equal)
117 {
118 return Expression.ReferenceEqual(left, right);
119 }
120 return Expression.ReferenceNotEqual(left, right);
121 }
123 }
124
125 public override Expression Reduce()
126 {
128 {
129 return Left.NodeType switch
130 {
131 ExpressionType.MemberAccess => ReduceMember(),
132 ExpressionType.Index => ReduceIndex(),
133 _ => ReduceVariable(),
134 };
135 }
136 return this;
137 }
138
140 {
141 return op switch
142 {
143 ExpressionType.AddAssign => ExpressionType.Add,
144 ExpressionType.AddAssignChecked => ExpressionType.AddChecked,
145 ExpressionType.SubtractAssign => ExpressionType.Subtract,
146 ExpressionType.SubtractAssignChecked => ExpressionType.SubtractChecked,
147 ExpressionType.MultiplyAssign => ExpressionType.Multiply,
148 ExpressionType.MultiplyAssignChecked => ExpressionType.MultiplyChecked,
149 ExpressionType.DivideAssign => ExpressionType.Divide,
150 ExpressionType.ModuloAssign => ExpressionType.Modulo,
151 ExpressionType.PowerAssign => ExpressionType.Power,
152 ExpressionType.AndAssign => ExpressionType.And,
153 ExpressionType.OrAssign => ExpressionType.Or,
154 ExpressionType.RightShiftAssign => ExpressionType.RightShift,
155 ExpressionType.LeftShiftAssign => ExpressionType.LeftShift,
156 ExpressionType.ExclusiveOrAssign => ExpressionType.ExclusiveOr,
157 _ => throw ContractUtils.Unreachable,
158 };
159 }
160
172
195
197 {
202 builder.UncheckedAdd(parameterExpression);
204 int argumentCount = indexExpression.ArgumentCount;
206 for (int i = 0; i < argumentCount; i++)
207 {
208 Expression argument = indexExpression.GetArgument(i);
210 builder.UncheckedAdd(parameterExpression2);
211 builder3.UncheckedAdd(parameterExpression2);
213 }
218 if (conversion != null)
219 {
221 }
223 builder.UncheckedAdd(parameterExpression3);
225 builder2.UncheckedAdd(Expression.Assign(left, parameterExpression3));
226 return Expression.Block(builder.ToReadOnly(), builder2.ToReadOnly());
227 }
228
230 {
231 return null;
232 }
233
234 protected internal override Expression Accept(ExpressionVisitor visitor)
235 {
236 return visitor.VisitBinary(this);
237 }
238
240 {
241 if (conversion != null)
242 {
243 return new CoalesceConversionBinaryExpression(left, right, conversion);
244 }
245 if (method != null)
246 {
247 return new MethodBinaryExpression(nodeType, left, right, type, method);
248 }
249 if (type == typeof(bool))
250 {
251 return new LogicalBinaryExpression(nodeType, left, right);
252 }
253 return new SimpleBinaryExpression(nodeType, left, right, type);
254 }
255
264
265 [DynamicDependency("GetValueOrDefault", typeof(Nullable<>))]
266 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The method will be preserved by the DynamicDependency.")]
268 {
269 return Expression.Call(nullable, "GetValueOrDefault", null);
270 }
271
272 [DynamicDependency("HasValue", typeof(Nullable<>))]
273 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The property will be preserved by the DynamicDependency.")]
278}
void Add(TKey key, TValue value)
static bool AreEquivalent(Type t1, Type t2)
Definition TypeUtils.cs:664
static MethodInfo GetBooleanOperator(Type type, string name)
Definition TypeUtils.cs:640
static bool IsOpAssignment(ExpressionType op)
static MethodCallExpression CallGetValueOrDefault(ParameterExpression nullable)
BinaryExpression(Expression left, Expression right)
static ExpressionType GetBinaryOpFromAssignmentOp(ExpressionType op)
static MemberExpression GetHasValueProperty(ParameterExpression nullable)
override Expression Accept(ExpressionVisitor visitor)
static BinaryExpression Create(ExpressionType nodeType, Expression left, Expression right, Type type, MethodInfo method, LambdaExpression conversion)
BinaryExpression Update(Expression left, LambdaExpression? conversion, Expression right)
static ConstantExpression Constant(object? value)
static BlockExpression Block(Expression arg0, Expression arg1)
static MethodCallExpression Call(MethodInfo method)
static BinaryExpression Assign(Expression left, Expression right)
static ParameterExpression Parameter(Type type)
static MemberExpression MakeMemberAccess(Expression? expression, MemberInfo member)
static BinaryExpression ReferenceEqual(Expression left, Expression right)
static IndexExpression Property(Expression instance, string propertyName, params Expression[]? arguments)
virtual ExpressionType NodeType
static ConditionalExpression Condition(Expression test, Expression ifTrue, Expression ifFalse)
static UnaryExpression Convert(Expression expression, Type type)
static BinaryExpression MakeBinary(ExpressionType binaryType, Expression left, Expression right)
static BinaryExpression ReferenceNotEqual(Expression left, Expression right)
static IndexExpression MakeIndex(Expression instance, PropertyInfo? indexer, IEnumerable< Expression >? arguments)
static ParameterExpression Variable(Type type)
static InvocationExpression Invoke(Expression expression)