|
|
|
@ -157,15 +157,10 @@ namespace ICSharpCode.Decompiler.Ast
@@ -157,15 +157,10 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
if (!transformationsHaveRun) |
|
|
|
|
RunTransformations(); |
|
|
|
|
|
|
|
|
|
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }, null); |
|
|
|
|
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); |
|
|
|
|
var outputFormatter = new TextOutputFormatter(output); |
|
|
|
|
var formattingPolicy = new CSharpFormattingOptions(); |
|
|
|
|
// disable whitespace in front of parentheses:
|
|
|
|
|
formattingPolicy.SpaceBeforeMethodCallParentheses = false; |
|
|
|
|
formattingPolicy.SpaceBeforeMethodDeclarationParentheses = false; |
|
|
|
|
formattingPolicy.SpaceBeforeConstructorDeclarationParentheses = false; |
|
|
|
|
formattingPolicy.SpaceBeforeDelegateDeclarationParentheses = false; |
|
|
|
|
astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy), null); |
|
|
|
|
var formattingPolicy = FormattingOptionsFactory.CreateAllman(); |
|
|
|
|
astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void AddAssembly(AssemblyDefinition assemblyDefinition, bool onlyAssemblyLevel = false) |
|
|
|
@ -185,7 +180,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -185,7 +180,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, AttributedNode.AttributeRole); |
|
|
|
|
}, EntityDeclaration.AttributeRole); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConvertCustomAttributes(astCompileUnit, assemblyDefinition, "assembly"); |
|
|
|
@ -225,7 +220,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -225,7 +220,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
Arguments = { forwardedType } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, AttributedNode.AttributeRole); |
|
|
|
|
}, EntityDeclaration.AttributeRole); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -283,7 +278,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -283,7 +278,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="typeDef"></param>
|
|
|
|
|
/// <returns>TypeDeclaration or DelegateDeclaration.</returns>
|
|
|
|
|
public AttributedNode CreateType(TypeDefinition typeDef) |
|
|
|
|
public EntityDeclaration CreateType(TypeDefinition typeDef) |
|
|
|
|
{ |
|
|
|
|
// create type
|
|
|
|
|
TypeDefinition oldCurrentType = context.CurrentType; |
|
|
|
@ -313,7 +308,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -313,7 +308,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
astType.TypeParameters.AddRange(MakeTypeParameters(genericParameters)); |
|
|
|
|
astType.Constraints.AddRange(MakeConstraints(genericParameters)); |
|
|
|
|
|
|
|
|
|
AttributedNode result = astType; |
|
|
|
|
EntityDeclaration result = astType; |
|
|
|
|
if (typeDef.IsEnum) { |
|
|
|
|
long expectedEnumMemberValue = 0; |
|
|
|
|
bool forcePrintingInitializers = IsFlagsEnum(typeDef); |
|
|
|
@ -321,7 +316,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -321,7 +316,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
if (!field.IsStatic) { |
|
|
|
|
// the value__ field
|
|
|
|
|
if (field.FieldType != typeDef.Module.TypeSystem.Int32) { |
|
|
|
|
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole); |
|
|
|
|
astType.AddChild(ConvertType(field.FieldType), Roles.BaseType); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
EnumMemberDeclaration enumMember = new EnumMemberDeclaration(); |
|
|
|
@ -332,7 +327,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -332,7 +327,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
enumMember.AddChild(new PrimitiveExpression(field.Constant), EnumMemberDeclaration.InitializerRole); |
|
|
|
|
} |
|
|
|
|
expectedEnumMemberValue = memberValue + 1; |
|
|
|
|
astType.AddChild(enumMember, TypeDeclaration.MemberRole); |
|
|
|
|
astType.AddChild(enumMember, Roles.TypeMemberRole); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (typeDef.BaseType != null && typeDef.BaseType.FullName == "System.MulticastDelegate") { |
|
|
|
@ -354,10 +349,10 @@ namespace ICSharpCode.Decompiler.Ast
@@ -354,10 +349,10 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} else { |
|
|
|
|
// Base type
|
|
|
|
|
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != "System.Object") { |
|
|
|
|
astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole); |
|
|
|
|
astType.AddChild(ConvertType(typeDef.BaseType), Roles.BaseType); |
|
|
|
|
} |
|
|
|
|
foreach (var i in typeDef.Interfaces) |
|
|
|
|
astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole); |
|
|
|
|
astType.AddChild(ConvertType(i), Roles.BaseType); |
|
|
|
|
|
|
|
|
|
AddTypeMembers(astType, typeDef); |
|
|
|
|
|
|
|
|
@ -726,18 +721,18 @@ namespace ICSharpCode.Decompiler.Ast
@@ -726,18 +721,18 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
continue; |
|
|
|
|
var nestedType = CreateType(nestedTypeDef); |
|
|
|
|
SetNewModifier(nestedType); |
|
|
|
|
astType.AddChild(nestedType, TypeDeclaration.MemberRole); |
|
|
|
|
astType.AddChild(nestedType, Roles.TypeMemberRole); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add fields
|
|
|
|
|
foreach(FieldDefinition fieldDef in typeDef.Fields) { |
|
|
|
|
if (MemberIsHidden(fieldDef, context.Settings)) continue; |
|
|
|
|
astType.AddChild(CreateField(fieldDef), TypeDeclaration.MemberRole); |
|
|
|
|
astType.AddChild(CreateField(fieldDef), Roles.TypeMemberRole); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add events
|
|
|
|
|
foreach(EventDefinition eventDef in typeDef.Events) { |
|
|
|
|
astType.AddChild(CreateEvent(eventDef), TypeDeclaration.MemberRole); |
|
|
|
|
astType.AddChild(CreateEvent(eventDef), Roles.TypeMemberRole); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add properties
|
|
|
|
@ -756,7 +751,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -756,7 +751,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AttributedNode CreateMethod(MethodDefinition methodDef) |
|
|
|
|
EntityDeclaration CreateMethod(MethodDefinition methodDef) |
|
|
|
|
{ |
|
|
|
|
MethodDeclaration astMethod = new MethodDeclaration(); |
|
|
|
|
astMethod.AddAnnotation(methodDef); |
|
|
|
@ -860,7 +855,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -860,7 +855,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
astMethod.Body = CreateMethodBody(methodDef, astMethod.Parameters); |
|
|
|
|
ConvertAttributes(astMethod, methodDef); |
|
|
|
|
if (methodDef.IsStatic && methodDef.DeclaringType.IsBeforeFieldInit && !astMethod.Body.IsNull) { |
|
|
|
|
astMethod.Body.InsertChildAfter(null, new Comment(" Note: this type is marked as 'beforefieldinit'."), AstNode.Roles.Comment); |
|
|
|
|
astMethod.Body.InsertChildAfter(null, new Comment(" Note: this type is marked as 'beforefieldinit'."), Roles.Comment); |
|
|
|
|
} |
|
|
|
|
return astMethod; |
|
|
|
|
} |
|
|
|
@ -878,7 +873,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -878,7 +873,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
return m & ~Modifiers.Private; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MemberDeclaration CreateProperty(PropertyDefinition propDef) |
|
|
|
|
EntityDeclaration CreateProperty(PropertyDefinition propDef) |
|
|
|
|
{ |
|
|
|
|
PropertyDeclaration astProp = new PropertyDeclaration(); |
|
|
|
|
astProp.AddAnnotation(propDef); |
|
|
|
@ -937,7 +932,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -937,7 +932,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
ConvertCustomAttributes(astProp, propDef); |
|
|
|
|
|
|
|
|
|
MemberDeclaration member = astProp; |
|
|
|
|
EntityDeclaration member = astProp; |
|
|
|
|
if(propDef.IsIndexer()) |
|
|
|
|
member = ConvertPropertyToIndexer(astProp, propDef); |
|
|
|
|
if(!accessor.HasOverrides && !accessor.DeclaringType.IsInterface) |
|
|
|
@ -960,7 +955,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -960,7 +955,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
return astIndexer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AttributedNode CreateEvent(EventDefinition eventDef) |
|
|
|
|
EntityDeclaration CreateEvent(EventDefinition eventDef) |
|
|
|
|
{ |
|
|
|
|
if (eventDef.AddMethod != null && eventDef.AddMethod.IsAbstract) { |
|
|
|
|
// An abstract event cannot be custom
|
|
|
|
@ -1018,7 +1013,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1018,7 +1013,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
FieldDeclaration astField = new FieldDeclaration(); |
|
|
|
|
astField.AddAnnotation(fieldDef); |
|
|
|
|
VariableInitializer initializer = new VariableInitializer(CleanName(fieldDef.Name)); |
|
|
|
|
astField.AddChild(initializer, FieldDeclaration.Roles.Variable); |
|
|
|
|
astField.AddChild(initializer, Roles.Variable); |
|
|
|
|
astField.ReturnType = ConvertType(fieldDef.FieldType, fieldDef); |
|
|
|
|
astField.Modifiers = ConvertModifiers(fieldDef); |
|
|
|
|
if (fieldDef.HasConstant) { |
|
|
|
@ -1098,7 +1093,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1098,7 +1093,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region ConvertAttributes
|
|
|
|
|
void ConvertAttributes(AttributedNode attributedNode, TypeDefinition typeDefinition) |
|
|
|
|
void ConvertAttributes(EntityDeclaration attributedNode, TypeDefinition typeDefinition) |
|
|
|
|
{ |
|
|
|
|
ConvertCustomAttributes(attributedNode, typeDefinition); |
|
|
|
|
ConvertSecurityAttributes(attributedNode, typeDefinition); |
|
|
|
@ -1154,7 +1149,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1154,7 +1149,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
#endregion
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConvertAttributes(AttributedNode attributedNode, MethodDefinition methodDefinition) |
|
|
|
|
void ConvertAttributes(EntityDeclaration attributedNode, MethodDefinition methodDefinition) |
|
|
|
|
{ |
|
|
|
|
ConvertCustomAttributes(attributedNode, methodDefinition); |
|
|
|
|
ConvertSecurityAttributes(attributedNode, methodDefinition); |
|
|
|
@ -1254,7 +1249,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1254,7 +1249,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
ConvertAttributes(attributedNode, methodDefinition.MethodReturnType, methodDefinition.Module); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConvertAttributes(AttributedNode attributedNode, MethodReturnType methodReturnType, ModuleDefinition module) |
|
|
|
|
void ConvertAttributes(EntityDeclaration attributedNode, MethodReturnType methodReturnType, ModuleDefinition module) |
|
|
|
|
{ |
|
|
|
|
ConvertCustomAttributes(attributedNode, methodReturnType, "return"); |
|
|
|
|
if (methodReturnType.HasMarshalInfo) { |
|
|
|
@ -1263,7 +1258,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1263,7 +1258,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal static void ConvertAttributes(AttributedNode attributedNode, FieldDefinition fieldDefinition, string attributeTarget = null) |
|
|
|
|
internal static void ConvertAttributes(EntityDeclaration attributedNode, FieldDefinition fieldDefinition, string attributeTarget = null) |
|
|
|
|
{ |
|
|
|
|
ConvertCustomAttributes(attributedNode, fieldDefinition); |
|
|
|
|
|
|
|
|
@ -1402,14 +1397,14 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1402,14 +1397,14 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
var section = new AttributeSection(); |
|
|
|
|
section.AttributeTarget = attributeTarget; |
|
|
|
|
section.Attributes.Add(attribute); |
|
|
|
|
attributedNode.AddChild(section, AttributedNode.AttributeRole); |
|
|
|
|
attributedNode.AddChild(section, EntityDeclaration.AttributeRole); |
|
|
|
|
} |
|
|
|
|
} else if (attributes.Count > 0) { |
|
|
|
|
// use single section for all attributes
|
|
|
|
|
var section = new AttributeSection(); |
|
|
|
|
section.AttributeTarget = attributeTarget; |
|
|
|
|
section.Attributes.AddRange(attributes); |
|
|
|
|
attributedNode.AddChild(section, AttributedNode.AttributeRole); |
|
|
|
|
attributedNode.AddChild(section, EntityDeclaration.AttributeRole); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1462,14 +1457,14 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1462,14 +1457,14 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
var section = new AttributeSection(); |
|
|
|
|
section.AttributeTarget = attributeTarget; |
|
|
|
|
section.Attributes.Add(attribute); |
|
|
|
|
attributedNode.AddChild(section, AttributedNode.AttributeRole); |
|
|
|
|
attributedNode.AddChild(section, EntityDeclaration.AttributeRole); |
|
|
|
|
} |
|
|
|
|
} else if (attributes.Count > 0) { |
|
|
|
|
// use single section for all attributes
|
|
|
|
|
var section = new AttributeSection(); |
|
|
|
|
section.AttributeTarget = attributeTarget; |
|
|
|
|
section.Attributes.AddRange(attributes); |
|
|
|
|
attributedNode.AddChild(section, AttributedNode.AttributeRole); |
|
|
|
|
attributedNode.AddChild(section, EntityDeclaration.AttributeRole); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1594,7 +1589,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1594,7 +1589,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
/// Sets new modifier if the member hides some other member from a base type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="member">The node of the member which new modifier state should be determined.</param>
|
|
|
|
|
static void SetNewModifier(AttributedNode member) |
|
|
|
|
static void SetNewModifier(EntityDeclaration member) |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
bool addNewModifier = false; |
|
|
|
@ -1614,7 +1609,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -1614,7 +1609,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static bool HidesBaseMember(AttributedNode member) |
|
|
|
|
private static bool HidesBaseMember(EntityDeclaration member) |
|
|
|
|
{ |
|
|
|
|
var memberDefinition = member.Annotation<IMemberDefinition>(); |
|
|
|
|
bool addNewModifier = false; |
|
|
|
|