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

36
ICSharpCode.Decompiler/CecilExtensions.cs

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

Loading…
Cancel
Save