Browse Source

Implemented support for undocumented expressions.

pull/150/head
Daniel Grunwald 14 years ago
parent
commit
c869e7cf02
  1. 17
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 13
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  3. 13
      ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
  4. 1
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  5. 26
      ICSharpCode.Decompiler/Tests/UndocumentedExpressions.cs

17
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -739,14 +739,17 @@ namespace ICSharpCode.Decompiler.Ast @@ -739,14 +739,17 @@ namespace ICSharpCode.Decompiler.Ast
getterModifiers = ConvertModifiers(propDef.GetMethod);
setterModifiers = ConvertModifiers(propDef.SetMethod);
astProp.Modifiers = FixUpVisibility(getterModifiers | setterModifiers);
if (accessor.IsVirtual && !accessor.IsNewSlot && (propDef.GetMethod == null || propDef.SetMethod == null))
foreach (var basePropDef in TypesHierarchyHelpers.FindBaseProperties(propDef))
if (accessor.IsVirtual && !accessor.IsNewSlot && (propDef.GetMethod == null || propDef.SetMethod == null)) {
foreach (var basePropDef in TypesHierarchyHelpers.FindBaseProperties(propDef)) {
if (basePropDef.GetMethod != null && basePropDef.SetMethod != null) {
var propVisibilityModifiers = ConvertModifiers(basePropDef.GetMethod) | ConvertModifiers(basePropDef.SetMethod);
astProp.Modifiers = FixUpVisibility((astProp.Modifiers & ~Modifiers.VisibilityMask) | (propVisibilityModifiers & Modifiers.VisibilityMask));
break;
} else if ((basePropDef.GetMethod ?? basePropDef.SetMethod).IsNewSlot)
break;
var propVisibilityModifiers = ConvertModifiers(basePropDef.GetMethod) | ConvertModifiers(basePropDef.SetMethod);
astProp.Modifiers = FixUpVisibility((astProp.Modifiers & ~Modifiers.VisibilityMask) | (propVisibilityModifiers & Modifiers.VisibilityMask));
break;
} else if ((basePropDef.GetMethod ?? basePropDef.SetMethod).IsNewSlot) {
break;
}
}
}
if (accessor.IsVirtual ^ !accessor.IsNewSlot) {
if (TypesHierarchyHelpers.FindBaseProperties(propDef).Any())
astProp.Modifiers |= Modifiers.New;

13
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -608,6 +608,17 @@ namespace ICSharpCode.Decompiler.Ast @@ -608,6 +608,17 @@ namespace ICSharpCode.Decompiler.Ast
return InlineAssembly(byteCode, args);
}
}
case ILCode.Refanytype:
return new UndocumentedExpression {
UndocumentedExpressionType = UndocumentedExpressionType.RefType,
Arguments = { arg1 }
}.Member("TypeHandle");
case ILCode.Refanyval:
return MakeRef(
new UndocumentedExpression {
UndocumentedExpressionType = UndocumentedExpressionType.RefValue,
Arguments = { arg1, new TypeReferenceExpression(operandAsTypeRef) }
});
case ILCode.Newobj: {
Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType;
if (declaringType is ArrayType) {
@ -644,8 +655,6 @@ namespace ICSharpCode.Decompiler.Ast @@ -644,8 +655,6 @@ namespace ICSharpCode.Decompiler.Ast
case ILCode.Nop: return null;
case ILCode.Pop: return arg1;
case ILCode.Readonly: return InlineAssembly(byteCode, args);
case ILCode.Refanytype: return InlineAssembly(byteCode, args);
case ILCode.Refanyval: return InlineAssembly(byteCode, args);
case ILCode.Ret:
if (methodDef.ReturnType.FullName != "System.Void") {
return new Ast.ReturnStatement { Expression = arg1 };

13
ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs

@ -14,6 +14,14 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -14,6 +14,14 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
/// </summary>
public class ReplaceMethodCallsWithOperators : DepthFirstAstVisitor<object, object>, IAstTransform
{
static readonly MemberReferenceExpression typeHandleOnTypeOfPattern = new MemberReferenceExpression {
Target = new Choice {
new TypeOfExpression(new AnyNode()),
new UndocumentedExpression { UndocumentedExpressionType = UndocumentedExpressionType.RefType, Arguments = { new AnyNode() } }
},
MemberName = "TypeHandle"
};
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
base.VisitInvocationExpression(invocationExpression, data);
@ -38,9 +46,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -38,9 +46,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
switch (methodRef.FullName) {
case "System.Type System.Type::GetTypeFromHandle(System.RuntimeTypeHandle)":
if (arguments.Length == 1) {
MemberReferenceExpression mre = arguments[0] as MemberReferenceExpression;
if (mre != null && mre.Target is TypeOfExpression && mre.MemberName == "TypeHandle") {
invocationExpression.ReplaceWith(mre.Target);
if (typeHandleOnTypeOfPattern.IsMatch(arguments[0])) {
invocationExpression.ReplaceWith(((MemberReferenceExpression)arguments[0]).Target);
return null;
}
}

1
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
<Compile Include="IncrementDecrement.cs" />
<Compile Include="QueryExpressions.cs" />
<Compile Include="Switch.cs" />
<Compile Include="UndocumentedExpressions.cs" />
<Compile Include="UnsafeCode.cs" />
<Compile Include="Types\S_TypeDeclarations.cs" />
<Compile Include="YieldReturn.cs" />

26
ICSharpCode.Decompiler/Tests/UndocumentedExpressions.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
public class UndocumentedExpressions
{
public static int GetArgCount(__arglist)
{
ArgIterator argIterator = new ArgIterator(__arglist);
return argIterator.GetRemainingCount();
}
public static void MakeTypedRef(object o)
{
TypedReference tr = __makeref(o);
UndocumentedExpressions.AcceptTypedRef(tr);
}
static void AcceptTypedRef(TypedReference tr)
{
Console.WriteLine("Value is: " + __refvalue(tr, object).ToString());
Console.WriteLine("Type is: " + __reftype(tr).Name);
__refvalue(tr, object) = 1;
}
}
Loading…
Cancel
Save