diff --git a/ICSharpCode.Decompiler/DynamicCallSites.cs b/ICSharpCode.Decompiler/DynamicCallSites.cs deleted file mode 100644 index 26c61f21ff..0000000000 --- a/ICSharpCode.Decompiler/DynamicCallSites.cs +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2011 Kevin Gadd -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using ICSharpCode.Decompiler.FlowAnalysis; -using Mono.Cecil; - -namespace ICSharpCode.Decompiler.ILAst { - public class DynamicCallSites { - public readonly DecompilerContext Context; - - public DynamicCallSites (DecompilerContext context) { - Context = context; - } - - public static bool IsCallSite (TypeReference type) { - if (type.FullName.Contains("Runtime.CompilerServices.CallSite")) - return true; - - return false; - } - - public static bool IsCallSiteBinder (TypeReference type) { - if (type.FullName.Contains("Runtime.CompilerServices.CallSiteBinder")) - return true; - - return false; - } - - public static bool IsCallSiteTarget (TypeReference type) { - var declaringType = type as IGenericInstance; - - if ( - (declaringType != null) && - (declaringType.GenericArguments.Count > 1) && - IsCallSite(declaringType.GenericArguments[0]) - ) { - return true; - } - - return false; - } - - public static bool IsCallSiteStorage (FieldReference field) { - var declaringType = field.DeclaringType; - - bool isMsCallSite = ( - field.Name.Contains("__Site") && - declaringType.FullName.Contains("__SiteContainer") - ); - - bool isMonoCallSite = ( - field.Name.Contains("Site") && - declaringType.FullName.Contains("__DynamicSite") - ); - - if (isMsCallSite || isMonoCallSite) - return true; - else - return false; - } - - /// - /// Finds individual instructions within the block that represent higher level concepts related to dynamic call sites. - /// This enables FindDynamicCallSites to locate and transform call sites in a single pass. - /// - public bool AnalyzeInstructions(List body, ILExpression expr, int pos) { - bool result = false; - - var newInstruction = AnalyzeInstruction(expr, ref result); - if (newInstruction != expr) - body[pos] = newInstruction; - - return result; - } - - protected ILExpression AnalyzeInstruction (ILExpression expr, ref bool modified) { - var result = expr; - - switch (expr.Code) { - case ILCode.Ldsfld: { - var field = expr.Operand as FieldReference; - if (IsCallSiteStorage(field)) { - result = new ILExpression( - ILCode.GetCallSite, expr.Operand, expr.Arguments - ); - modified = true; - } - - break; - } - case ILCode.Stsfld: { - var field = expr.Operand as FieldReference; - if ( - (expr.Arguments[0].Code == ILCode.Call) && - IsCallSiteStorage(field) - ) { - var method = expr.Arguments[0].Operand as MethodReference; - if (IsCallSite(method.DeclaringType) && (method.Name == "Create")) { - result = new ILExpression( - ILCode.CreateCallSite, expr.Operand, expr.Arguments - ); - modified = true; - } - } - - break; - } - case ILCode.Call: { - var method = expr.Operand as MethodReference; - if (IsCallSiteBinder(method.ReturnType)) { - result = new ILExpression( - ILCode.GetCallSiteBinder, expr.Operand, expr.Arguments - ); - modified = true; - } - - break; - } - case ILCode.Callvirt: { - // Detect SiteContainer.callSite.Target.Invoke(callSite, ...) - var method = expr.Operand as MethodReference; - if (IsCallSiteTarget(method.DeclaringType)) { - result = new ILExpression( - ILCode.InvokeCallSiteTarget, expr.Operand, expr.Arguments - ); - modified = true; - } - - break; - } - } - - for (int i = 0, c = result.Arguments.Count; i < c; i++) { - var arg = result.Arguments[i]; - var newArg = AnalyzeInstruction(arg, ref modified); - - if (newArg != arg) - result.Arguments[i] = newArg; - } - - return result; - } - } -} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 792e69a233..5aef069633 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -85,7 +85,6 @@ - diff --git a/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs b/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs index 4d9adbe2e2..947678c2c1 100644 --- a/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs +++ b/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs @@ -56,7 +56,6 @@ public enum ILAstOptimizationStep IntroducePostIncrement, InlineExpressionTreeParameterDeclarations, InlineVariables2, - FindDynamicCallSites, FindLoops, FindConditions, FlattenNestedMovableBlocks, @@ -195,17 +194,7 @@ public void Optimize(DecompilerContext context, ILBlock method, ILAstOptimizatio } while(modified); } - if (abortBeforeStep == ILAstOptimizationStep.FindDynamicCallSites) return; - foreach (ILBlock block in method.GetSelfAndChildrenRecursive()) { - var dcs = new DynamicCallSites(context); - - bool modified; - do { - modified = block.RunOptimization(dcs.AnalyzeInstructions); - } while (modified); - } - - if (abortBeforeStep == ILAstOptimizationStep.FindLoops) return; + if (abortBeforeStep == ILAstOptimizationStep.FindLoops) return; foreach(ILBlock block in method.GetSelfAndChildrenRecursive()) { new LoopsAndConditions(context).FindLoops(block); } diff --git a/ICSharpCode.Decompiler/ILAst/ILCodes.cs b/ICSharpCode.Decompiler/ILAst/ILCodes.cs index a3a215fa82..5ca063b752 100644 --- a/ICSharpCode.Decompiler/ILAst/ILCodes.cs +++ b/ICSharpCode.Decompiler/ILAst/ILCodes.cs @@ -334,22 +334,6 @@ public enum ILCode /// assignments to the ParameterExpression variables. /// ExpressionTreeParameterDeclarations, - /// - /// Represents an invocation expression on the target of a dynamic call site. - /// - InvokeCallSiteTarget, - /// - /// Represents an expression that produces a runtime call site binder. Used as an argument to CreateCallSite. - /// - GetCallSiteBinder, - /// - /// Represents the creation of a call site and a store into its storage field. - /// - CreateCallSite, - /// - /// Represents a load of a call site from its storage field. - /// - GetCallSite, /// /// C# 5 await /// diff --git a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs index ad20addac6..c5a52337fd 100644 --- a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs +++ b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs @@ -318,8 +318,6 @@ TypeReference DoInferTypeForExpression(ILExpression expr, TypeReference expected case ILCode.CallvirtGetter: case ILCode.CallSetter: case ILCode.CallvirtSetter: - case ILCode.GetCallSiteBinder: - case ILCode.InvokeCallSiteTarget: { MethodReference method = (MethodReference)expr.Operand; if (forceInferChildren) { @@ -362,7 +360,6 @@ TypeReference DoInferTypeForExpression(ILExpression expr, TypeReference expected } return GetFieldType((FieldReference)expr.Operand); case ILCode.Ldsfld: - case ILCode.GetCallSite: return GetFieldType((FieldReference)expr.Operand); case ILCode.Ldflda: if (forceInferChildren) { @@ -378,7 +375,6 @@ TypeReference DoInferTypeForExpression(ILExpression expr, TypeReference expected } return GetFieldType((FieldReference)expr.Operand); case ILCode.Stsfld: - case ILCode.CreateCallSite: if (forceInferChildren) InferTypeForExpression(expr.Arguments[0], GetFieldType((FieldReference)expr.Operand)); return GetFieldType((FieldReference)expr.Operand);