Skip to content

Commit 662317c

Browse files
committed
ReferenceExpression is no longer needed
because `Reference` can simply implement `IExpression` instead.
1 parent 2626f1f commit 662317c

19 files changed

+66
-124
lines changed

src/Castle.Core/DynamicProxy/Contributors/ClassProxySerializableContributor.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ protected override void CustomizeGetObjectData(CodeBuilder codebuilder, Argument
9696
new MethodInvocationExpression(
9797
serializationInfo,
9898
SerializationInfoMethods.AddValue_Bool,
99-
new ConstReference("__delegateToBase").ToExpression(),
100-
new ConstReference(delegateToBaseGetObjectData).ToExpression()));
99+
new ConstReference("__delegateToBase"),
100+
new ConstReference(delegateToBaseGetObjectData)));
101101

102102
if (delegateToBaseGetObjectData == false)
103103
{
@@ -123,21 +123,21 @@ private void EmitCustomGetObjectData(CodeBuilder codebuilder, ArgumentReference
123123
var callSort = new MethodInvocationExpression(
124124
null,
125125
TypeUtilMethods.Sort,
126-
members.ToExpression());
126+
members);
127127
codebuilder.AddStatement(new AssignStatement(members, callSort));
128128

129129
var getObjectData = new MethodInvocationExpression(
130130
null,
131131
FormatterServicesMethods.GetObjectData,
132-
SelfReference.Self.ToExpression(),
133-
members.ToExpression());
132+
SelfReference.Self,
133+
members);
134134
codebuilder.AddStatement(new AssignStatement(data, getObjectData));
135135

136136
var addValue = new MethodInvocationExpression(
137137
serializationInfo,
138138
SerializationInfoMethods.AddValue_Object,
139-
new ConstReference("__data").ToExpression(),
140-
data.ToExpression());
139+
new ConstReference("__data"),
140+
data);
141141
codebuilder.AddStatement(addValue);
142142
}
143143

@@ -150,8 +150,8 @@ private void EmitCallToBaseGetObjectData(CodeBuilder codebuilder, ArgumentRefere
150150
codebuilder.AddStatement(
151151
new MethodInvocationExpression(
152152
baseGetObjectData,
153-
serializationInfo.ToExpression(),
154-
streamingContext.ToExpression()));
153+
serializationInfo,
154+
streamingContext));
155155
}
156156

157157
private void Constructor(ClassEmitter emitter)
@@ -172,14 +172,14 @@ private void GenerateSerializationConstructor(ClassEmitter emitter)
172172

173173
ctor.CodeBuilder.AddStatement(
174174
new ConstructorInvocationStatement(serializationConstructor,
175-
serializationInfo.ToExpression(),
176-
streamingContext.ToExpression()));
175+
serializationInfo,
176+
streamingContext));
177177

178178
foreach (var field in serializedFields)
179179
{
180180
var getValue = new MethodInvocationExpression(serializationInfo,
181181
SerializationInfoMethods.GetValue,
182-
new ConstReference(field.Reference.Name).ToExpression(),
182+
new ConstReference(field.Reference.Name),
183183
new TypeTokenExpression(field.Reference.FieldType));
184184
ctor.CodeBuilder.AddStatement(new AssignStatement(
185185
field,

src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,13 @@ private MethodBuilder CreateCallbackMethod(ClassEmitter emitter, MethodInfo meth
115115
targetMethod = targetMethod.MakeGenericMethod(callBackMethod.GenericTypeParams.AsTypeArray());
116116
}
117117

118-
var exps = new IExpression[callBackMethod.Arguments.Length];
119-
for (var i = 0; i < callBackMethod.Arguments.Length; i++)
120-
{
121-
exps[i] = callBackMethod.Arguments[i].ToExpression();
122-
}
123-
124118
// invocation on base class
125119

126120
callBackMethod.CodeBuilder.AddStatement(
127121
new ReturnStatement(
128122
new MethodInvocationExpression(SelfReference.Self,
129123
targetMethod,
130-
exps)));
124+
callBackMethod.Arguments)));
131125

132126
return callBackMethod.MethodBuilder;
133127
}

src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEm
7676
return new MethodWithInvocationGenerator(method,
7777
@class.GetField("__interceptors"),
7878
invocation,
79-
(c, m) => c.GetField("__target").ToExpression(),
79+
(c, m) => c.GetField("__target"),
8080
overrideMethod,
8181
null);
8282
}
@@ -151,7 +151,7 @@ private MethodGenerator IndirectlyCalledMethodGenerator(MetaMethod method, Class
151151
return new MethodWithInvocationGenerator(method,
152152
proxy.GetField("__interceptors"),
153153
invocation,
154-
(c, m) => c.GetField("__target").ToExpression(),
154+
(c, m) => c.GetField("__target"),
155155
overrideMethod,
156156
contributor);
157157
}

src/Castle.Core/DynamicProxy/Contributors/InterfaceProxySerializableContributor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ protected override void CustomizeGetObjectData(CodeBuilder codebuilder, Argument
3838
new MethodInvocationExpression(
3939
serializationInfo,
4040
SerializationInfoMethods.AddValue_Object,
41-
new ConstReference("__targetFieldType").ToExpression(),
42-
new ConstReference(targetField.Reference.FieldType.AssemblyQualifiedName).ToExpression()));
41+
new ConstReference("__targetFieldType"),
42+
new ConstReference(targetField.Reference.FieldType.AssemblyQualifiedName)));
4343

4444
codebuilder.AddStatement(
4545
new MethodInvocationExpression(
4646
serializationInfo,
4747
SerializationInfoMethods.AddValue_Object,
48-
new ConstReference("__theInterface").ToExpression(),
49-
new ConstReference(targetType.AssemblyQualifiedName).ToExpression()));
48+
new ConstReference("__theInterface"),
49+
new ConstReference(targetType.AssemblyQualifiedName)));
5050
}
5151
}
5252
}

src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyTargetContributor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEm
6868
return new MethodWithInvocationGenerator(method,
6969
@class.GetField("__interceptors"),
7070
invocation,
71-
(c, m) => c.GetField("__target").ToExpression(),
71+
(c, m) => c.GetField("__target"),
7272
overrideMethod,
7373
null);
7474
}

src/Castle.Core/DynamicProxy/Contributors/InvocationWithDelegateContributor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ConstructorEmitter CreateConstructor(ArgumentReference[] baseCtorArgument
4646
var constructor = invocation.CreateConstructor(arguments);
4747

4848
var delegateField = invocation.CreateField("delegate", delegateType);
49-
constructor.CodeBuilder.AddStatement(new AssignStatement(delegateField, new ReferenceExpression(arguments[0])));
49+
constructor.CodeBuilder.AddStatement(new AssignStatement(delegateField, arguments[0]));
5050
return constructor;
5151
}
5252

@@ -68,7 +68,7 @@ public MethodInvocationExpression GetCallbackMethodInvocation(AbstractTypeEmitte
6868
public IExpression[] GetConstructorInvocationArguments(IExpression[] arguments, ClassEmitter proxy)
6969
{
7070
var allArguments = new IExpression[arguments.Length + 1];
71-
allArguments[0] = new ReferenceExpression(BuildDelegateToken(proxy));
71+
allArguments[0] = BuildDelegateToken(proxy);
7272
Array.Copy(arguments, 0, allArguments, 1, arguments.Length);
7373
return allArguments;
7474
}
@@ -92,7 +92,7 @@ private IExpression[] GetAllArgs(IExpression[] args, Reference targetField)
9292
{
9393
var allArgs = new IExpression[args.Length + 1];
9494
args.CopyTo(allArgs, 1);
95-
allArgs[0] = new ConvertExpression(targetType, targetField.ToExpression());
95+
allArgs[0] = new ConvertExpression(targetType, targetField);
9696
return allArgs;
9797
}
9898

src/Castle.Core/DynamicProxy/Contributors/InvocationWithGenericDelegateContributor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ private Reference GetDelegate(AbstractTypeEmitter invocation, MethodEmitter invo
6868
var closedDelegateType = delegateType.MakeGenericType(genericTypeParameters);
6969
var localReference = invokeMethodOnTarget.CodeBuilder.DeclareLocal(closedDelegateType);
7070
var closedMethodOnTarget = method.MethodOnTarget.MakeGenericMethod(genericTypeParameters);
71-
var localTarget = new ReferenceExpression(targetReference);
7271
invokeMethodOnTarget.CodeBuilder.AddStatement(
73-
SetDelegate(localReference, localTarget, closedDelegateType, closedMethodOnTarget));
72+
SetDelegate(localReference, targetReference, closedDelegateType, closedMethodOnTarget));
7473
return localReference;
7574
}
7675

77-
private AssignStatement SetDelegate(LocalReference localDelegate, ReferenceExpression localTarget,
76+
private AssignStatement SetDelegate(LocalReference localDelegate, Reference localTarget,
7877
Type closedDelegateType, MethodInfo closedMethodOnTarget)
7978
{
8079
var delegateCreateDelegate = new MethodInvocationExpression(

src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ private GetTargetExpressionDelegate BuildGetTargetExpression()
111111
{
112112
if (!canChangeTarget)
113113
{
114-
return (c, m) => fields[m.DeclaringType].ToExpression();
114+
return (c, m) => fields[m.DeclaringType];
115115
}
116116

117117
return (c, m) => new NullCoalescingOperatorExpression(
118-
new AsTypeReference(c.GetField("__target"), m.DeclaringType).ToExpression(),
119-
fields[m.DeclaringType].ToExpression());
118+
new AsTypeReference(c.GetField("__target"), m.DeclaringType),
119+
fields[m.DeclaringType]);
120120
}
121121

122122
private FieldReference BuildTargetField(ClassEmitter @class, Type type)

src/Castle.Core/DynamicProxy/Contributors/ProxyTargetAccessorContributor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void Generate(ClassEmitter emitter)
4646
var dynProxyGetTarget = emitter.CreateMethod(nameof(IProxyTargetAccessor.DynProxyGetTarget), typeof(object));
4747

4848
dynProxyGetTarget.CodeBuilder.AddStatement(
49-
new ReturnStatement(new ConvertExpression(typeof(object), targetType, targetReference.ToExpression())));
49+
new ReturnStatement(new ConvertExpression(typeof(object), targetType, targetReference)));
5050

5151
var dynProxySetTarget = emitter.CreateMethod(nameof(IProxyTargetAccessor.DynProxySetTarget), typeof(void), typeof(object));
5252

@@ -55,7 +55,7 @@ public void Generate(ClassEmitter emitter)
5555
{
5656
dynProxySetTarget.CodeBuilder.AddStatement(
5757
new AssignStatement(targetField,
58-
new ConvertExpression(targetField.Fieldbuilder.FieldType, dynProxySetTarget.Arguments[0].ToExpression())));
58+
new ConvertExpression(targetField.Fieldbuilder.FieldType, dynProxySetTarget.Arguments[0])));
5959
}
6060
else
6161
{

src/Castle.Core/DynamicProxy/Contributors/SerializableContributor.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ protected void ImplementGetObjectData(ClassEmitter emitter)
5757
new MethodInvocationExpression(
5858
null,
5959
TypeMethods.StaticGetType,
60-
new ConstReference(typeof(ProxyObjectReference).AssemblyQualifiedName).ToExpression(),
61-
new ConstReference(1).ToExpression(),
62-
new ConstReference(0).ToExpression())));
60+
new ConstReference(typeof(ProxyObjectReference).AssemblyQualifiedName),
61+
new ConstReference(1),
62+
new ConstReference(0))));
6363

6464
getObjectData.CodeBuilder.AddStatement(
6565
new MethodInvocationExpression(
6666
info,
6767
SerializationInfoMethods.SetType,
68-
typeLocal.ToExpression()));
68+
typeLocal));
6969

7070
foreach (var field in emitter.GetAllFields())
7171
{
@@ -93,36 +93,36 @@ protected void ImplementGetObjectData(ClassEmitter emitter)
9393
new AssignArrayStatement(
9494
interfacesLocal,
9595
i,
96-
new ConstReference(interfaces[i].AssemblyQualifiedName).ToExpression()));
96+
new ConstReference(interfaces[i].AssemblyQualifiedName)));
9797
}
9898

9999
getObjectData.CodeBuilder.AddStatement(
100100
new MethodInvocationExpression(
101101
info,
102102
SerializationInfoMethods.AddValue_Object,
103-
new ConstReference("__interfaces").ToExpression(),
104-
interfacesLocal.ToExpression()));
103+
new ConstReference("__interfaces"),
104+
interfacesLocal));
105105

106106
getObjectData.CodeBuilder.AddStatement(
107107
new MethodInvocationExpression(
108108
info,
109109
SerializationInfoMethods.AddValue_Object,
110-
new ConstReference("__baseType").ToExpression(),
111-
new ConstReference(emitter.BaseType.AssemblyQualifiedName).ToExpression()));
110+
new ConstReference("__baseType"),
111+
new ConstReference(emitter.BaseType.AssemblyQualifiedName)));
112112

113113
getObjectData.CodeBuilder.AddStatement(
114114
new MethodInvocationExpression(
115115
info,
116116
SerializationInfoMethods.AddValue_Object,
117-
new ConstReference("__proxyGenerationOptions").ToExpression(),
118-
emitter.GetField("proxyGenerationOptions").ToExpression()));
117+
new ConstReference("__proxyGenerationOptions"),
118+
emitter.GetField("proxyGenerationOptions")));
119119

120120
getObjectData.CodeBuilder.AddStatement(
121121
new MethodInvocationExpression(
122122
info,
123123
SerializationInfoMethods.AddValue_Object,
124-
new ConstReference("__proxyTypeId").ToExpression(),
125-
new ConstReference(proxyTypeId).ToExpression()));
124+
new ConstReference("__proxyTypeId"),
125+
new ConstReference(proxyTypeId)));
126126

127127
CustomizeGetObjectData(getObjectData.CodeBuilder, info, getObjectData.Arguments[1], emitter);
128128

@@ -136,8 +136,8 @@ protected virtual void AddAddValueInvocation(ArgumentReference serializationInfo
136136
new MethodInvocationExpression(
137137
serializationInfo,
138138
SerializationInfoMethods.AddValue_Object,
139-
new ConstReference(field.Reference.Name).ToExpression(),
140-
field.ToExpression()));
139+
new ConstReference(field.Reference.Name),
140+
field));
141141
return;
142142
}
143143

0 commit comments

Comments
 (0)