Skip to content

Commit 4cbde53

Browse files
authored
Merge pull request #709 from stakx/refactor/simple-ast-reference-type
Refactor `SimpleAST`'s `Reference`s to be typed
2 parents 61eed01 + 895f612 commit 4cbde53

24 files changed

+80
-108
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -129,7 +129,7 @@ private void EmitCustomGetObjectData(CodeBuilder codeBuilder, ArgumentReference
129129
var getObjectData = new MethodInvocationExpression(
130130
null,
131131
FormatterServicesMethods.GetObjectData,
132-
SelfReference.Self,
132+
ThisExpression.Instance,
133133
members);
134134
codeBuilder.AddStatement(new AssignStatement(data, getObjectData));
135135

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -122,7 +122,7 @@ private MethodBuilder CreateCallbackMethod(ClassEmitter emitter, MethodInfo meth
122122

123123
callBackMethod.CodeBuilder.AddStatement(
124124
new ReturnStatement(
125-
new MethodInvocationExpression(SelfReference.Self,
125+
new MethodInvocationExpression(ThisExpression.Instance,
126126
targetMethod,
127127
callBackMethod.Arguments)));
128128

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -119,7 +119,7 @@ private MethodInfo CreateCallbackMethod(ClassEmitter emitter, MethodInfo methodI
119119

120120
callBackMethod.CodeBuilder.AddStatement(
121121
new ReturnStatement(
122-
new MethodInvocationExpression(SelfReference.Self, targetMethod, callBackMethod.Arguments)));
122+
new MethodInvocationExpression(ThisExpression.Instance, targetMethod, callBackMethod.Arguments)));
123123

124124
return callBackMethod.MethodBuilder;
125125
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ namespace Castle.DynamicProxy.Contributors
2525
/// </summary>
2626
internal sealed class ProxyTargetAccessorContributor : ITypeContributor
2727
{
28-
private readonly Func<Reference> getTargetReference;
28+
private readonly Func<IExpression> getTarget;
2929
private readonly Type targetType;
3030

31-
public ProxyTargetAccessorContributor(Func<Reference> getTargetReference, Type targetType)
31+
public ProxyTargetAccessorContributor(Func<IExpression> getTarget, Type targetType)
3232
{
33-
this.getTargetReference = getTargetReference;
33+
this.getTarget = getTarget;
3434
this.targetType = targetType;
3535
}
3636

@@ -41,17 +41,17 @@ public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model)
4141
public void Generate(ClassEmitter emitter)
4242
{
4343
var interceptorsField = emitter.GetField("__interceptors");
44-
var targetReference = getTargetReference();
44+
var target = getTarget();
4545

4646
var dynProxyGetTarget = emitter.CreateMethod(nameof(IProxyTargetAccessor.DynProxyGetTarget), typeof(object));
4747

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

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

5353
// we can only change the target of the interface proxy
54-
if (targetReference is FieldReference targetField)
54+
if (target is FieldReference targetField)
5555
{
5656
dynProxySetTarget.CodeBuilder.AddStatement(
5757
new AssignStatement(targetField,

src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(INamingSco
5151
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
5252
{
5353
return new ProxyTargetAccessorContributor(
54-
getTargetReference: () => SelfReference.Self,
54+
getTarget: () => ThisExpression.Instance,
5555
targetType);
5656
}
5757
}

src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(INamingSco
6565
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
6666
{
6767
return new ProxyTargetAccessorContributor(
68-
getTargetReference: () => targetField,
68+
getTarget: () => targetField,
6969
targetType);
7070
}
7171

src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ protected override void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invoca
6262
{
6363
invokeMethodOnTarget.CodeBuilder.AddStatement(
6464
new MethodInvocationExpression(
65-
SelfReference.Self,
65+
ThisExpression.Instance,
6666
InvocationMethods.CompositionInvocationEnsureValidTarget));
6767

6868
base.ImplementInvokeMethodOnTarget(invocation, parameters, invokeMethodOnTarget, targetField);

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ArgumentReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
2121
using System.Reflection.Emit;
2222

2323
[DebuggerDisplay("argument {Type}")]
24-
internal class ArgumentReference : TypeReference
24+
internal class ArgumentReference : Reference
2525
{
2626
public ArgumentReference(Type argumentType)
2727
: base(argumentType)

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeReference.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal class AsTypeReference : Reference
2727
private readonly Type type;
2828

2929
public AsTypeReference(Reference reference, Type type)
30+
: base(type)
3031
{
3132
this.reference = reference;
3233
this.type = type;

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ByRefReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
2222

2323

2424
[DebuggerDisplay("&{localReference}")]
25-
internal class ByRefReference : TypeReference
25+
internal class ByRefReference : Reference
2626
{
2727
private readonly LocalReference localReference;
2828

0 commit comments

Comments
 (0)