Browse Source

Normalize newlines.

pull/314/merge
Daniel Grunwald 14 years ago
parent
commit
920f445da0
  1. 132
      ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs
  2. 36
      ICSharpCode.Decompiler/CecilExtensions.cs

132
ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs

@ -764,73 +764,73 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
} }
List<KeyValuePair<string, int>> BuildDictionary(List<Statement> dictCreation) List<KeyValuePair<string, int>> BuildDictionary(List<Statement> dictCreation)
{ {
if (context.Settings.ObjectOrCollectionInitializers && dictCreation.Count == 1) if (context.Settings.ObjectOrCollectionInitializers && dictCreation.Count == 1)
return BuildDictionaryFromInitializer(dictCreation[0]); return BuildDictionaryFromInitializer(dictCreation[0]);
return BuildDictionaryFromAddMethodCalls(dictCreation); return BuildDictionaryFromAddMethodCalls(dictCreation);
} }
static readonly Statement assignInitializedDictionary = new ExpressionStatement { static readonly Statement assignInitializedDictionary = new ExpressionStatement {
Expression = new AssignmentExpression { Expression = new AssignmentExpression {
Left = new AnyNode().ToExpression(), Left = new AnyNode().ToExpression(),
Right = new ObjectCreateExpression { Right = new ObjectCreateExpression {
Type = new AnyNode(), Type = new AnyNode(),
Arguments = { new Repeat(new AnyNode()) }, Arguments = { new Repeat(new AnyNode()) },
Initializer = new ArrayInitializerExpression { Initializer = new ArrayInitializerExpression {
Elements = { new Repeat(new AnyNode("dictJumpTable")) } Elements = { new Repeat(new AnyNode("dictJumpTable")) }
} }
}, },
}, },
}; };
private List<KeyValuePair<string, int>> BuildDictionaryFromInitializer(Statement statement) private List<KeyValuePair<string, int>> BuildDictionaryFromInitializer(Statement statement)
{ {
List<KeyValuePair<string, int>> dict = new List<KeyValuePair<string, int>>(); List<KeyValuePair<string, int>> dict = new List<KeyValuePair<string, int>>();
Match m = assignInitializedDictionary.Match(statement); Match m = assignInitializedDictionary.Match(statement);
if (!m.Success) if (!m.Success)
return dict; return dict;
foreach (ArrayInitializerExpression initializer in m.Get<ArrayInitializerExpression>("dictJumpTable")) { foreach (ArrayInitializerExpression initializer in m.Get<ArrayInitializerExpression>("dictJumpTable")) {
KeyValuePair<string, int> pair; KeyValuePair<string, int> pair;
if (TryGetPairFrom(initializer.Elements, out pair)) if (TryGetPairFrom(initializer.Elements, out pair))
dict.Add(pair); dict.Add(pair);
} }
return dict; return dict;
} }
private static List<KeyValuePair<string, int>> BuildDictionaryFromAddMethodCalls(List<Statement> dictCreation) private static List<KeyValuePair<string, int>> BuildDictionaryFromAddMethodCalls(List<Statement> dictCreation)
{ {
List<KeyValuePair<string, int>> dict = new List<KeyValuePair<string, int>>(); List<KeyValuePair<string, int>> dict = new List<KeyValuePair<string, int>>();
for (int i = 0; i < dictCreation.Count; i++) { for (int i = 0; i < dictCreation.Count; i++) {
ExpressionStatement es = dictCreation[i] as ExpressionStatement; ExpressionStatement es = dictCreation[i] as ExpressionStatement;
if (es == null) if (es == null)
continue; continue;
InvocationExpression ie = es.Expression as InvocationExpression; InvocationExpression ie = es.Expression as InvocationExpression;
if (ie == null) if (ie == null)
continue; continue;
KeyValuePair<string, int> pair; KeyValuePair<string, int> pair;
if (TryGetPairFrom(ie.Arguments, out pair)) if (TryGetPairFrom(ie.Arguments, out pair))
dict.Add(pair); dict.Add(pair);
} }
return dict; return dict;
} }
private static bool TryGetPairFrom(AstNodeCollection<Expression> expressions, out KeyValuePair<string, int> pair) private static bool TryGetPairFrom(AstNodeCollection<Expression> expressions, out KeyValuePair<string, int> pair)
{ {
PrimitiveExpression arg1 = expressions.ElementAtOrDefault(0) as PrimitiveExpression; PrimitiveExpression arg1 = expressions.ElementAtOrDefault(0) as PrimitiveExpression;
PrimitiveExpression arg2 = expressions.ElementAtOrDefault(1) as PrimitiveExpression; PrimitiveExpression arg2 = expressions.ElementAtOrDefault(1) as PrimitiveExpression;
if (arg1 != null && arg2 != null && arg1.Value is string && arg2.Value is int) { if (arg1 != null && arg2 != null && arg1.Value is string && arg2.Value is int) {
pair = new KeyValuePair<string, int>((string)arg1.Value, (int)arg2.Value); pair = new KeyValuePair<string, int>((string)arg1.Value, (int)arg2.Value);
return true; return true;
} }
pair = default(KeyValuePair<string, int>); pair = default(KeyValuePair<string, int>);
return false; return false;
} }
#endregion #endregion
#region Automatic Properties #region Automatic Properties

36
ICSharpCode.Decompiler/CecilExtensions.cs

@ -216,21 +216,21 @@ namespace ICSharpCode.Decompiler
return IsCompilerGeneratedOrIsInCompilerGeneratedClass(member.DeclaringType); return IsCompilerGeneratedOrIsInCompilerGeneratedClass(member.DeclaringType);
} }
public static TypeReference GetEnumUnderlyingType(this TypeDefinition type) public static TypeReference GetEnumUnderlyingType(this TypeDefinition type)
{ {
if (!type.IsEnum) if (!type.IsEnum)
throw new ArgumentException("Type must be an enum", "type"); throw new ArgumentException("Type must be an enum", "type");
var fields = type.Fields; var fields = type.Fields;
for (int i = 0; i < fields.Count; i++) for (int i = 0; i < fields.Count; i++)
{ {
var field = fields[i]; var field = fields[i];
if (!field.IsStatic) if (!field.IsStatic)
return field.FieldType; return field.FieldType;
} }
throw new NotSupportedException(); throw new NotSupportedException();
} }
public static bool IsAnonymousType(this TypeReference type) public static bool IsAnonymousType(this TypeReference type)
@ -244,9 +244,9 @@ namespace ICSharpCode.Decompiler
return false; return false;
} }
public static bool HasGeneratedName(this MemberReference member) public static bool HasGeneratedName(this MemberReference member)
{ {
return member.Name.StartsWith("<", StringComparison.Ordinal); return member.Name.StartsWith("<", StringComparison.Ordinal);
} }
public static bool ContainsAnonymousType(this TypeReference type) public static bool ContainsAnonymousType(this TypeReference type)

Loading…
Cancel
Save