Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Using named parameter syntax when passing literals in System.Linq.Expressions #13046

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static AssemblyGen Assembly
{
if (s_assembly == null)
{
Interlocked.CompareExchange(ref s_assembly, new AssemblyGen(), null);
Interlocked.CompareExchange(ref s_assembly, new AssemblyGen(), comparand: null);
}
return s_assembly;
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public partial class Expression
/// <returns>The created <see cref="CatchBlock"/>.</returns>
public static CatchBlock Catch(Type type, Expression body)
{
return MakeCatchBlock(type, null, body, null);
return MakeCatchBlock(type, null, body, filter: null);
}

/// <summary>
Expand All @@ -94,7 +94,7 @@ public static CatchBlock Catch(Type type, Expression body)
public static CatchBlock Catch(ParameterExpression variable, Expression body)
{
ContractUtils.RequiresNotNull(variable, nameof(variable));
return MakeCatchBlock(variable.Type, variable, body, null);
return MakeCatchBlock(variable.Type, variable, body, filter: null);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal HoistedLocals(HoistedLocals parent, ReadOnlyCollection<ParameterExpress
indexes.Add(vars[i], i);
}

SelfVariable = Expression.Variable(typeof(object[]), null);
SelfVariable = Expression.Variable(typeof(object[]), name: null);
Parent = parent;
Variables = vars;
Indexes = new ReadOnlyDictionary<Expression, int>(indexes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void AddressOf(BinaryExpression node, Type type)
Type indexType = TypeUtils.GetNonNullableType(rightType);
if (indexType != typeof(int))
{
_ilg.EmitConvertToType(indexType, typeof(int), true);
_ilg.EmitConvertToType(indexType, typeof(int), isChecked: true);
}
_ilg.Emit(OpCodes.Ldelema, node.Type);
}
Expand Down Expand Up @@ -290,7 +290,7 @@ private WriteBack AddressOfWriteBackCore(MemberExpression node)
PropertyInfo pi = (PropertyInfo)node.Member;

// emit the get
EmitCall(instanceType, pi.GetGetMethod(true));
EmitCall(instanceType, pi.GetGetMethod(nonPublic: true));

// emit the address of the value
LocalBuilder valueLocal = GetLocal(node.Type);
Expand All @@ -308,7 +308,7 @@ private WriteBack AddressOfWriteBackCore(MemberExpression node)
}
@this._ilg.Emit(OpCodes.Ldloc, valueLocal);
@this.FreeLocal(valueLocal);
@this.EmitCall(instanceLocal?.LocalType, pi.GetSetMethod(true));
@this.EmitCall(instanceLocal?.LocalType, pi.GetSetMethod(nonPublic: true));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ private void EmitBinaryMethod(BinaryExpression b, CompilationFlags flags)
{
if (b.IsLifted)
{
ParameterExpression p1 = Expression.Variable(TypeUtils.GetNonNullableType(b.Left.Type), null);
ParameterExpression p2 = Expression.Variable(TypeUtils.GetNonNullableType(b.Right.Type), null);
ParameterExpression p1 = Expression.Variable(TypeUtils.GetNonNullableType(b.Left.Type), name: null);
ParameterExpression p2 = Expression.Variable(TypeUtils.GetNonNullableType(b.Right.Type), name: null);
MethodCallExpression mc = Expression.Call(null, b.Method, p1, p2);
Type resultType = null;
if (b.IsLiftedToNull)
Expand Down Expand Up @@ -549,7 +549,7 @@ private void EmitLiftedRelational(ExpressionType op, Type leftType, Type rightTy
TypeUtils.GetNonNullableType(leftType),
TypeUtils.GetNonNullableType(rightType),
TypeUtils.GetNonNullableType(resultType),
false
liftedToNull: false
);

if (!liftedToNull)
Expand All @@ -559,7 +559,7 @@ private void EmitLiftedRelational(ExpressionType op, Type leftType, Type rightTy

if (!TypeUtils.AreEquivalent(resultType, TypeUtils.GetNonNullableType(resultType)))
{
_ilg.EmitConvertToType(TypeUtils.GetNonNullableType(resultType), resultType, true);
_ilg.EmitConvertToType(TypeUtils.GetNonNullableType(resultType), resultType, isChecked: true);
}

if (liftedToNull)
Expand Down Expand Up @@ -632,7 +632,7 @@ private void EmitLiftedBinaryArithmetic(ExpressionType op, Type leftType, Type r
FreeLocal(locLeft);
FreeLocal(locRight);

EmitBinaryOperator(op, TypeUtils.GetNonNullableType(leftType), TypeUtils.GetNonNullableType(rightType), TypeUtils.GetNonNullableType(resultType), false);
EmitBinaryOperator(op, TypeUtils.GetNonNullableType(leftType), TypeUtils.GetNonNullableType(rightType), TypeUtils.GetNonNullableType(resultType), liftedToNull: false);

// construct result type
ConstructorInfo ci = resultType.GetConstructor(new Type[] { TypeUtils.GetNonNullableType(resultType) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void EmitGetIndexCall(IndexExpression node, Type objectType)
if (node.Indexer != null)
{
// For indexed properties, just call the getter
MethodInfo method = node.Indexer.GetGetMethod(true);
MethodInfo method = node.Indexer.GetGetMethod(nonPublic: true);
EmitCall(objectType, method);
}
else
Expand Down Expand Up @@ -319,7 +319,7 @@ private void EmitSetIndexCall(IndexExpression node, Type objectType)
if (node.Indexer != null)
{
// For indexed properties, just call the setter
MethodInfo method = node.Indexer.GetSetMethod(true);
MethodInfo method = node.Indexer.GetSetMethod(nonPublic: true);
EmitCall(objectType, method);
}
else
Expand Down Expand Up @@ -800,7 +800,7 @@ private void EmitMemberAssignment(BinaryExpression node, CompilationFlags flags)
// MemberExpression.Member can only be a FieldInfo or a PropertyInfo
Debug.Assert(member is PropertyInfo);
var prop = (PropertyInfo)member;
EmitCall(objectType, prop.GetSetMethod(true));
EmitCall(objectType, prop.GetSetMethod(nonPublic: true));
}

if (emitAs != CompilationFlags.EmitAsVoidType)
Expand Down Expand Up @@ -846,7 +846,7 @@ private void EmitMemberGet(MemberInfo member, Type objectType)
// MemberExpression.Member or MemberBinding.Member can only be a FieldInfo or a PropertyInfo
Debug.Assert(member is PropertyInfo);
var prop = (PropertyInfo)member;
EmitCall(objectType, prop.GetGetMethod(true));
EmitCall(objectType, prop.GetGetMethod(nonPublic: true));
}
}

Expand All @@ -858,7 +858,7 @@ private static bool TryGetRawConstantValue(FieldInfo fi, out object value)

try
{
value = fi.GetValue(null);
value = fi.GetValue(obj: null);
return true;
}
catch
Expand Down Expand Up @@ -908,7 +908,7 @@ private void EmitNewArrayExpression(Expression expr)
{
Expression x = expressions[i];
EmitExpression(x);
_ilg.EmitConvertToType(x.Type, typeof(int), true);
_ilg.EmitConvertToType(x.Type, typeof(int), isChecked: true);
}
_ilg.EmitArray(node.Type);
}
Expand Down Expand Up @@ -968,7 +968,7 @@ private void EmitMemberAssignment(MemberAssignment binding, Type objectType)
PropertyInfo pi = binding.Member as PropertyInfo;
if (pi != null)
{
EmitCall(objectType, pi.GetSetMethod(true));
EmitCall(objectType, pi.GetSetMethod(nonPublic: true));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void EmitNullableCoalesce(BinaryExpression b)
{
_ilg.Emit(OpCodes.Ldloca, loc);
_ilg.EmitGetValueOrDefault(b.Left.Type);
_ilg.EmitConvertToType(nnLeftType, b.Type, true);
_ilg.EmitConvertToType(nnLeftType, b.Type, isChecked: true);
}
else
{
Expand All @@ -165,7 +165,7 @@ private void EmitNullableCoalesce(BinaryExpression b)
EmitExpression(b.Right);
if (!TypeUtils.AreEquivalent(b.Right.Type, b.Type))
{
_ilg.EmitConvertToType(b.Right.Type, b.Type, true);
_ilg.EmitConvertToType(b.Right.Type, b.Type, isChecked: true);
}
_ilg.MarkLabel(labEnd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ private void EmitCatchStart(CatchBlock cb)
// begin the catch, clear the exception, we've
// already saved it
_ilg.MarkLabel(endFilter);
_ilg.BeginCatchBlock(null);
_ilg.BeginCatchBlock(exceptionType: null);
_ilg.Emit(OpCodes.Pop);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ private void EmitUnary(UnaryExpression node, CompilationFlags flags)
LocalBuilder loc = GetLocal(node.Operand.Type);
_ilg.Emit(OpCodes.Stloc, loc);
_ilg.EmitInt(0);
_ilg.EmitConvertToType(typeof(int), node.Operand.Type, false);
_ilg.EmitConvertToType(typeof(int), node.Operand.Type, isChecked: false);
_ilg.Emit(OpCodes.Ldloc, loc);
FreeLocal(loc);
EmitBinaryOperator(ExpressionType.SubtractChecked, node.Operand.Type, node.Operand.Type, node.Type, false);
EmitBinaryOperator(ExpressionType.SubtractChecked, node.Operand.Type, node.Operand.Type, node.Type, liftedToNull: false);
}
else
{
Expand Down Expand Up @@ -366,12 +366,12 @@ private void EmitUnaryMethod(UnaryExpression node, CompilationFlags flags)
{
if (node.IsLifted)
{
ParameterExpression v = Expression.Variable(TypeUtils.GetNonNullableType(node.Operand.Type), null);
ParameterExpression v = Expression.Variable(TypeUtils.GetNonNullableType(node.Operand.Type), name: null);
MethodCallExpression mc = Expression.Call(node.Method, v);

Type resultType = TypeUtils.GetNullableType(mc.Type);
EmitLift(node.NodeType, resultType, mc, new ParameterExpression[] { v }, new Expression[] { node.Operand });
_ilg.EmitConvertToType(resultType, node.Type, false);
_ilg.EmitConvertToType(resultType, node.Type, isChecked: false);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected Expression(ExpressionType nodeType, Type type)
Interlocked.CompareExchange(
ref s_legacyCtorSupportTable,
new ConditionalWeakTable<Expression, ExtensionInfo>(),
null
comparand: null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ private static bool IsCompatible(PropertyInfo pi, Expression[] args)
{
MethodInfo mi;

mi = pi.GetGetMethod(true);
mi = pi.GetGetMethod(nonPublic: true);
ParameterInfo[] parms;
if (mi != null)
{
parms = mi.GetParametersCached();
}
else
{
mi = pi.GetSetMethod(true);
mi = pi.GetSetMethod(nonPublic: true);
//The setter has an additional parameter for the value to set,
//need to remove the last type to match the arguments.
parms = mi.GetParametersCached().RemoveLast();
Expand Down Expand Up @@ -366,14 +366,14 @@ private static void ValidateIndexedProperty(Expression instance, PropertyInfo pr
if (property.PropertyType == typeof(void)) throw Error.PropertyTypeCannotBeVoid(nameof(property));

ParameterInfo[] getParameters = null;
MethodInfo getter = property.GetGetMethod(true);
MethodInfo getter = property.GetGetMethod(nonPublic: true);
if (getter != null)
{
getParameters = getter.GetParametersCached();
ValidateAccessor(instance, getter, getParameters, ref argList, nameof(property));
}

MethodInfo setter = property.GetSetMethod(true);
MethodInfo setter = property.GetSetMethod(nonPublic: true);
if (setter != null)
{
ParameterInfo[] setParameters = setter.GetParametersCached();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LoadStaticFieldInstruction(FieldInfo field)

public override int Run(InterpretedFrame frame)
{
frame.Push(_field.GetValue(null));
frame.Push(_field.GetValue(obj: null));
return +1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public InstructionArray ToArray()

public void EmitLoad(object value)
{
EmitLoad(value, null);
EmitLoad(value, type: null);
}

public void EmitLoad(bool value)
Expand Down
Loading