Browse Source

Add support for char literals.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
e31a89689d
  1. 10
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 4
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  3. 1
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

10
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -514,7 +514,7 @@ namespace Decompiler
return MakeRef(new Ast.IdentifierExpression(((ParameterDefinition)operand).Name).WithAnnotation(operand)); return MakeRef(new Ast.IdentifierExpression(((ParameterDefinition)operand).Name).WithAnnotation(operand));
} }
case Code.Ldc_I4: case Code.Ldc_I4:
return PrimitiveExpression((int)operand, byteCode.InferredType); return MakePrimitive((int)operand, byteCode.InferredType);
case Code.Ldc_I8: case Code.Ldc_I8:
case Code.Ldc_R4: case Code.Ldc_R4:
case Code.Ldc_R8: case Code.Ldc_R8:
@ -763,7 +763,7 @@ namespace Decompiler
if (TypeAnalysis.IsBoolean(actualType)) if (TypeAnalysis.IsBoolean(actualType))
return expr; return expr;
if (actualIsIntegerOrEnum) { if (actualIsIntegerOrEnum) {
return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, PrimitiveExpression(0, actualType)); return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, MakePrimitive(0, actualType));
} else { } else {
return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, new NullReferenceExpression()); return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, new NullReferenceExpression());
} }
@ -771,8 +771,8 @@ namespace Decompiler
if (TypeAnalysis.IsBoolean(actualType) && requiredIsIntegerOrEnum) { if (TypeAnalysis.IsBoolean(actualType) && requiredIsIntegerOrEnum) {
return new ConditionalExpression { return new ConditionalExpression {
Condition = expr, Condition = expr,
TrueExpression = PrimitiveExpression(1, reqType), TrueExpression = MakePrimitive(1, reqType),
FalseExpression = PrimitiveExpression(0, reqType) FalseExpression = MakePrimitive(0, reqType)
}; };
} }
if (actualIsIntegerOrEnum && requiredIsIntegerOrEnum) { if (actualIsIntegerOrEnum && requiredIsIntegerOrEnum) {
@ -782,7 +782,7 @@ namespace Decompiler
} }
} }
Expression PrimitiveExpression(long val, TypeReference type) Expression MakePrimitive(long val, TypeReference type)
{ {
if (TypeAnalysis.IsBoolean(type) && val == 0) if (TypeAnalysis.IsBoolean(type) && val == 0)
return new Ast.PrimitiveExpression(false); return new Ast.PrimitiveExpression(false);

4
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -36,7 +36,7 @@ namespace Decompiler.ControlFlow
foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>().ToList()) { foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>().ToList()) {
ControlFlowGraph graph; ControlFlowGraph graph;
graph = BuildGraph(block.Body, (ILLabel)block.EntryGoto.Operand); graph = BuildGraph(block.Body, (ILLabel)block.EntryGoto.Operand);
graph.ComputeDominance(); graph.ComputeDominance(context.CancellationToken);
graph.ComputeDominanceFrontier(); graph.ComputeDominanceFrontier();
block.Body = FindLoops(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint, false); block.Body = FindLoops(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint, false);
} }
@ -49,7 +49,7 @@ namespace Decompiler.ControlFlow
// TODO: Fix // TODO: Fix
if (graph == null) if (graph == null)
continue; continue;
graph.ComputeDominance(); graph.ComputeDominance(context.CancellationToken);
graph.ComputeDominanceFrontier(); graph.ComputeDominanceFrontier();
block.Body = FindConditions(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint); block.Body = FindConditions(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint);
} }

1
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -646,6 +646,7 @@ namespace Decompiler
case MetadataType.IntPtr: case MetadataType.IntPtr:
return true; return true;
case MetadataType.Byte: case MetadataType.Byte:
case MetadataType.Char:
case MetadataType.UInt16: case MetadataType.UInt16:
case MetadataType.UInt32: case MetadataType.UInt32:
case MetadataType.UInt64: case MetadataType.UInt64:

Loading…
Cancel
Save