Skip to content

Commit

Permalink
Remove member parameter from Emit methods
Browse files Browse the repository at this point in the history
The previous commit removed the last actual usage of this parameter in
`ReturnStatement`; now it only gets passed around without ever being
used.
  • Loading branch information
stakx committed Mar 1, 2021
1 parent b184eb2 commit 93e29bf
Show file tree
Hide file tree
Showing 31 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public LocalReference DeclareLocal(Type type)
return local;
}

internal void Generate(IMemberEmitter member, ILGenerator il)
internal void Generate(ILGenerator il)
{
foreach (var local in locals)
{
Expand All @@ -61,7 +61,7 @@ internal void Generate(IMemberEmitter member, ILGenerator il)

foreach (var statement in statements)
{
statement.Emit(member, il);
statement.Emit(il);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public virtual void Generate()
return;
}

CodeBuilder.Generate(this, builder.GetILGenerator());
CodeBuilder.Generate(builder.GetILGenerator());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public virtual void Generate()
return;
}

codeBuilder.Generate(this, builder.GetILGenerator());
codeBuilder.Generate(builder.GetILGenerator());
}

private void DefineParameters(ParameterInfo[] parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public AssignArgumentStatement(ArgumentReference argument, IExpression expressio
this.expression = expression;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
ArgumentsUtil.EmitLoadOwnerAndReference(argument, gen);
expression.Emit(member, gen);
expression.Emit(gen);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public AssignArrayStatement(Reference targetArray, int targetPosition, IExpressi
this.value = value;
}

public void Emit(IMemberEmitter member, ILGenerator il)
public void Emit(ILGenerator il)
{
ArgumentsUtil.EmitLoadOwnerAndReference(targetArray, il);

il.Emit(OpCodes.Ldc_I4, targetPosition);

value.Emit(member, il);
value.Emit(il);

il.Emit(OpCodes.Stelem_Ref);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public AssignStatement(Reference target, IExpression expression)
this.expression = expression;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
ArgumentsUtil.EmitLoadOwnerAndReference(target.OwnerReference, gen);
expression.Emit(member, gen);
expression.Emit(gen);
target.StoreReference(gen);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public BindDelegateExpression(Type @delegate, IExpression owner, MethodInfo meth
this.owner = owner;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
owner.Emit(member, gen);
owner.Emit(gen);
gen.Emit(OpCodes.Dup);
if (methodToBindTo.IsFinal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public void AddStatement(IStatement statement)
statements.Add(statement);
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
foreach (var s in statements)
{
s.Emit(member, gen);
s.Emit(gen);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public ConstructorInvocationStatement(ConstructorInfo method, params IExpression
this.args = args;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.Emit(OpCodes.Ldarg_0);

foreach (var exp in args)
{
exp.Emit(member, gen);
exp.Emit(gen);
}

gen.Emit(OpCodes.Call, cmethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public ConvertExpression(Type targetType, Type fromType, IExpression right)
this.right = right;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
right.Emit(member, gen);
right.Emit(gen);

if (fromType == target)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DefaultValueExpression(Type type)
this.type = type;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
// TODO: check if this can be simplified by using more of OpCodeUtil and other existing types
if (IsPrimitiveOrClass(type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST

internal class EndExceptionBlockStatement : IStatement
{
public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.EndExceptionBlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST

internal class FinallyStatement : IStatement
{
public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.BeginFinallyBlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST

internal interface IExpressionOrStatement
{
void Emit(IMemberEmitter member, ILGenerator gen);
void Emit(ILGenerator gen);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ public IfNullExpression(IExpression expression, IExpressionOrStatement ifNull, I
this.ifNotNull = ifNotNull;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
if (reference != null)
{
ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);
}
else if (expression != null)
{
expression.Emit(member, gen);
expression.Emit(gen);
}

var notNull = gen.DefineLabel();
gen.Emit(OpCodes.Brtrue_S, notNull);
ifNull.Emit(member, gen);
ifNull.Emit(gen);
gen.MarkLabel(notNull);
if (ifNotNull != null) // yeah, I know that reads funny :)
{
ifNotNull.Emit(member, gen);
ifNotNull.Emit(gen);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LiteralIntExpression(int value)
this.value = value;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
switch (value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LoadArrayElementExpression(ConstReference index, Reference arrayReference
this.returnType = returnType;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
ArgumentsUtil.EmitLoadOwnerAndReference(arrayReference, gen);
ArgumentsUtil.EmitLoadOwnerAndReference(index, gen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public LoadRefArrayElementExpression(ConstReference index, Reference arrayRefere
this.arrayReference = arrayReference;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
ArgumentsUtil.EmitLoadOwnerAndReference(arrayReference, gen);
ArgumentsUtil.EmitLoadOwnerAndReference(index, gen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public MethodInvocationExpression(Reference owner, MethodInfo method, params IEx

public bool VirtualCall { get; set; }

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
ArgumentsUtil.EmitLoadOwnerAndReference(owner, gen);

foreach (var exp in args)
{
exp.Emit(member, gen);
exp.Emit(gen);
}

if (VirtualCall)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MethodTokenExpression(MethodInfo method)
Debug.Assert(method.DeclaringType != null); // DynamicProxy isn't using global methods nor `DynamicMethod`
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.Emit(OpCodes.Ldtoken, method);
gen.Emit(OpCodes.Ldtoken, method.DeclaringType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public NewArrayExpression(int size, Type arrayType)
this.arrayType = arrayType;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.Emit(OpCodes.Ldc_I4, size);
gen.Emit(OpCodes.Newarr, arrayType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public NewInstanceExpression(Type target)
arguments = null;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
if (arguments != null)
{
foreach (var exp in arguments)
{
exp.Emit(member, gen);
exp.Emit(gen);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST

internal class NopStatement : IStatement
{
public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.Emit(OpCodes.Nop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public NullCoalescingOperatorExpression(IExpression expression, IExpression @def
this.@default = @default;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
expression.Emit(member, gen);
expression.Emit(gen);
gen.Emit(OpCodes.Dup);
var label = gen.DefineLabel();
gen.Emit(OpCodes.Brtrue_S, label);
gen.Emit(OpCodes.Pop);
@default.Emit(member, gen);
@default.Emit(gen);
gen.MarkLabel(label);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected NullExpression()
{
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.Emit(OpCodes.Ldnull);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public virtual void Generate(ILGenerator gen)
{
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
ArgumentsUtil.EmitLoadOwnerAndReference(this, gen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ReferencesToObjectArrayExpression(params TypeReference[] args)
this.args = args;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
var local = gen.DeclareLocal(typeof(object[]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Diagnostics;
using System.Reflection.Emit;

internal class ReturnStatement : IStatement
Expand All @@ -36,19 +35,15 @@ public ReturnStatement(IExpression expression)
this.expression = expression;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
if (reference != null)
{
ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);
}
else if (expression != null)
{
expression.Emit(member, gen);
}
else
{
Debug.Assert(member.ReturnType == typeof(void));
expression.Emit(gen);
}

gen.Emit(OpCodes.Ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public ThrowStatement(Type exceptionType, string errorMessage)
this.errorMessage = errorMessage;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
var ci = exceptionType.GetConstructor(new[] { typeof(string) });
var constRef = new ConstReference(errorMessage);

var creationStmt = new NewInstanceExpression(ci, constRef);

creationStmt.Emit(member, gen);
creationStmt.Emit(gen);

gen.Emit(OpCodes.Throw);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST

internal class TryStatement : IStatement
{
public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.BeginExceptionBlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public TypeTokenExpression(Type type)
this.type = type;
}

public void Emit(IMemberEmitter member, ILGenerator gen)
public void Emit(ILGenerator gen)
{
gen.Emit(OpCodes.Ldtoken, type);
gen.Emit(OpCodes.Call, TypeMethods.GetTypeFromHandle);
Expand Down

0 comments on commit 93e29bf

Please sign in to comment.