From 3f62b31798556613df50416ed8cc27135984141b Mon Sep 17 00:00:00 2001 From: Dominique Schuppli Date: Mon, 1 Mar 2021 02:04:16 +0100 Subject: [PATCH] Delete 3 superfluous SimpleAST node types --- .../Generators/Emitters/MethodEmitter.cs | 1 - .../SimpleAST/BindDelegateExpression.cs | 59 ------------------- .../SimpleAST/LoadArrayElementExpression.cs | 45 -------------- .../Emitters/SimpleAST/NopStatement.cs | 26 -------- 4 files changed, 131 deletions(-) delete mode 100644 src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BindDelegateExpression.cs delete mode 100644 src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadArrayElementExpression.cs delete mode 100644 src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NopStatement.cs diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs index 442f985977..3d51910c36 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs @@ -125,7 +125,6 @@ public virtual void EnsureValidCodeBlock() { if (ImplementedByRuntime == false && CodeBuilder.IsEmpty) { - CodeBuilder.AddStatement(new NopStatement()); if (ReturnType == typeof(void)) { CodeBuilder.AddStatement(new ReturnStatement()); diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BindDelegateExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BindDelegateExpression.cs deleted file mode 100644 index c803eff247..0000000000 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BindDelegateExpression.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST -{ - using System; - using System.Reflection; - using System.Reflection.Emit; - - using Castle.DynamicProxy.Internal; - - internal class BindDelegateExpression : IExpression - { - private readonly ConstructorInfo delegateCtor; - private readonly MethodInfo methodToBindTo; - private readonly IExpression owner; - - public BindDelegateExpression(Type @delegate, IExpression owner, MethodInfo methodToBindTo, - GenericTypeParameterBuilder[] genericTypeParams) - { - delegateCtor = @delegate.GetConstructors()[0]; - this.methodToBindTo = methodToBindTo; - if (@delegate.IsGenericTypeDefinition) - { - var genericTypeParameters = genericTypeParams.AsTypeArray(); - var closedDelegate = @delegate.MakeGenericType(genericTypeParameters); - delegateCtor = TypeBuilder.GetConstructor(closedDelegate, delegateCtor); - this.methodToBindTo = methodToBindTo.MakeGenericMethod(genericTypeParameters); - } - this.owner = owner; - } - - public void Emit(ILGenerator gen) - { - owner.Emit(gen); - gen.Emit(OpCodes.Dup); - if (methodToBindTo.IsFinal) - { - gen.Emit(OpCodes.Ldftn, methodToBindTo); - } - else - { - gen.Emit(OpCodes.Ldvirtftn, methodToBindTo); - } - gen.Emit(OpCodes.Newobj, delegateCtor); - } - } -} \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadArrayElementExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadArrayElementExpression.cs deleted file mode 100644 index eaf74fc075..0000000000 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadArrayElementExpression.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST -{ - using System; - using System.Reflection.Emit; - - internal class LoadArrayElementExpression : IExpression - { - private readonly Reference arrayReference; - private readonly ConstReference index; - private readonly Type returnType; - - public LoadArrayElementExpression(int index, Reference arrayReference, Type returnType) - : this(new ConstReference(index), arrayReference, returnType) - { - } - - public LoadArrayElementExpression(ConstReference index, Reference arrayReference, Type returnType) - { - this.index = index; - this.arrayReference = arrayReference; - this.returnType = returnType; - } - - public void Emit(ILGenerator gen) - { - ArgumentsUtil.EmitLoadOwnerAndReference(arrayReference, gen); - ArgumentsUtil.EmitLoadOwnerAndReference(index, gen); - gen.Emit(OpCodes.Ldelem, returnType); - } - } -} \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NopStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NopStatement.cs deleted file mode 100644 index 2c148a547e..0000000000 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NopStatement.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST -{ - using System.Reflection.Emit; - - internal class NopStatement : IStatement - { - public void Emit(ILGenerator gen) - { - gen.Emit(OpCodes.Nop); - } - } -} \ No newline at end of file