Browse Source

rename ConvertedExpression to TranslatedExpression and Convert to Translate, etc.

pull/728/head
Siegfried Pammer 11 years ago
parent
commit
bc68339ac4
  1. 12
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  2. 130
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 12
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  4. 4
      ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs
  5. 24
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs
  6. 6
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

12
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -51,15 +51,15 @@ namespace ICSharpCode.Decompiler.CSharp @@ -51,15 +51,15 @@ namespace ICSharpCode.Decompiler.CSharp
return new ExpressionWithILInstruction(expression);
}
public static ConvertedExpression WithILInstruction(this ExpressionWithResolveResult expression, ILInstruction instruction)
public static TranslatedExpression WithILInstruction(this ExpressionWithResolveResult expression, ILInstruction instruction)
{
expression.Expression.AddAnnotation(instruction);
return new ConvertedExpression(expression.Expression, expression.ResolveResult);
return new TranslatedExpression(expression.Expression, expression.ResolveResult);
}
public static ConvertedExpression WithoutILInstruction(this ExpressionWithResolveResult expression)
public static TranslatedExpression WithoutILInstruction(this ExpressionWithResolveResult expression)
{
return new ConvertedExpression(expression.Expression, expression.ResolveResult);
return new TranslatedExpression(expression.Expression, expression.ResolveResult);
}
public static ExpressionWithResolveResult WithRR(this Expression expression, ResolveResult resolveResult)
@ -68,10 +68,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -68,10 +68,10 @@ namespace ICSharpCode.Decompiler.CSharp
return new ExpressionWithResolveResult(expression, resolveResult);
}
public static ConvertedExpression WithRR(this ExpressionWithILInstruction expression, ResolveResult resolveResult)
public static TranslatedExpression WithRR(this ExpressionWithILInstruction expression, ResolveResult resolveResult)
{
expression.Expression.AddAnnotation(resolveResult);
return new ConvertedExpression(expression, resolveResult);
return new TranslatedExpression(expression, resolveResult);
}
/// <summary>

130
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <summary>
/// Translates from ILAst to C# expressions.
/// </summary>
class ExpressionBuilder : ILVisitor<ConvertedExpression>
class ExpressionBuilder : ILVisitor<TranslatedExpression>
{
internal readonly ICompilation compilation;
internal readonly NRefactoryCecilMapper cecilMapper;
@ -67,7 +67,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -67,7 +67,7 @@ namespace ICSharpCode.Decompiler.CSharp
return astType;
}
public ConvertedExpression Convert(ILInstruction inst)
public TranslatedExpression Translate(ILInstruction inst)
{
Debug.Assert(inst != null);
var cexpr = inst.AcceptVisitor(this);
@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.CSharp
return cexpr;
}
public ConvertedExpression ConvertCondition(ILInstruction condition)
public TranslatedExpression TranslateCondition(ILInstruction condition)
{
var expr = Convert(condition);
var expr = Translate(condition);
return expr.ConvertToBoolean(this);
}
@ -103,81 +103,81 @@ namespace ICSharpCode.Decompiler.CSharp @@ -103,81 +103,81 @@ namespace ICSharpCode.Decompiler.CSharp
return expr.WithRR(new ResolveResult(cecilMapper.GetType(variable.Type)));
}
ConvertedExpression IsType(IsInst inst)
TranslatedExpression IsType(IsInst inst)
{
var arg = Convert(inst.Argument);
var arg = Translate(inst.Argument);
var type = cecilMapper.GetType(inst.Type);
return new IsExpression(arg.Expression, ConvertType(type))
.WithILInstruction(inst)
.WithRR(new TypeIsResolveResult(arg.ResolveResult, type, compilation.FindType(TypeCode.Boolean)));
}
protected internal override ConvertedExpression VisitIsInst(IsInst inst)
protected internal override TranslatedExpression VisitIsInst(IsInst inst)
{
var arg = Convert(inst.Argument);
var arg = Translate(inst.Argument);
var type = cecilMapper.GetType(inst.Type);
return new AsExpression(arg.Expression, ConvertType(type))
.WithILInstruction(inst)
.WithRR(new ConversionResolveResult(type, arg.ResolveResult, Conversion.TryCast));
}
protected internal override ConvertedExpression VisitNewObj(NewObj inst)
protected internal override TranslatedExpression VisitNewObj(NewObj inst)
{
return HandleCallInstruction(inst);
}
protected internal override ConvertedExpression VisitLdcI4(LdcI4 inst)
protected internal override TranslatedExpression VisitLdcI4(LdcI4 inst)
{
return new PrimitiveExpression(inst.Value)
.WithILInstruction(inst)
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), inst.Value));
}
protected internal override ConvertedExpression VisitLdcI8(LdcI8 inst)
protected internal override TranslatedExpression VisitLdcI8(LdcI8 inst)
{
return new PrimitiveExpression(inst.Value)
.WithILInstruction(inst)
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int64), inst.Value));
}
protected internal override ConvertedExpression VisitLdcF(LdcF inst)
protected internal override TranslatedExpression VisitLdcF(LdcF inst)
{
return new PrimitiveExpression(inst.Value)
.WithILInstruction(inst)
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.Double), inst.Value));
}
protected internal override ConvertedExpression VisitLdStr(LdStr inst)
protected internal override TranslatedExpression VisitLdStr(LdStr inst)
{
return new PrimitiveExpression(inst.Value)
.WithILInstruction(inst)
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.String), inst.Value));
}
protected internal override ConvertedExpression VisitLdNull(LdNull inst)
protected internal override TranslatedExpression VisitLdNull(LdNull inst)
{
return new NullReferenceExpression()
.WithILInstruction(inst)
.WithRR(new ConstantResolveResult(SpecialType.UnknownType, null));
}
protected internal override ConvertedExpression VisitLogicNot(LogicNot inst)
protected internal override TranslatedExpression VisitLogicNot(LogicNot inst)
{
return LogicNot(ConvertCondition(inst.Argument)).WithILInstruction(inst);
return LogicNot(TranslateCondition(inst.Argument)).WithILInstruction(inst);
}
ExpressionWithResolveResult LogicNot(ConvertedExpression expr)
ExpressionWithResolveResult LogicNot(TranslatedExpression expr)
{
return new UnaryOperatorExpression(UnaryOperatorType.Not, expr.Expression)
.WithRR(new OperatorResolveResult(compilation.FindType(KnownTypeCode.Boolean), ExpressionType.Not));
}
protected internal override ConvertedExpression VisitLdLoc(LdLoc inst)
protected internal override TranslatedExpression VisitLdLoc(LdLoc inst)
{
return ConvertVariable(inst.Variable).WithILInstruction(inst);
}
protected internal override ConvertedExpression VisitLdLoca(LdLoca inst)
protected internal override TranslatedExpression VisitLdLoca(LdLoca inst)
{
var expr = ConvertVariable(inst.Variable).WithILInstruction(inst);
// Note that we put the instruction on the IdentifierExpression instead of the DirectionExpression,
@ -187,12 +187,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -187,12 +187,12 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(new ByReferenceResolveResult(expr.ResolveResult, isOut: false));
}
protected internal override ConvertedExpression VisitStLoc(StLoc inst)
protected internal override TranslatedExpression VisitStLoc(StLoc inst)
{
return Assignment(ConvertVariable(inst.Variable).WithoutILInstruction(), Convert(inst.Value)).WithILInstruction(inst);
return Assignment(ConvertVariable(inst.Variable).WithoutILInstruction(), Translate(inst.Value)).WithILInstruction(inst);
}
protected internal override ConvertedExpression VisitCeq(Ceq inst)
protected internal override TranslatedExpression VisitCeq(Ceq inst)
{
// Translate '(e as T) == null' to '!(e is T)'.
// This is necessary for correctness when T is a value type.
@ -202,8 +202,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -202,8 +202,8 @@ namespace ICSharpCode.Decompiler.CSharp
return LogicNot(IsType((IsInst)inst.Right)).WithILInstruction(inst);
}
var left = Convert(inst.Left);
var right = Convert(inst.Right);
var left = Translate(inst.Left);
var right = Translate(inst.Right);
// Remove redundant bool comparisons
if (left.Type.IsKnownType(KnownTypeCode.Boolean)) {
@ -227,30 +227,30 @@ namespace ICSharpCode.Decompiler.CSharp @@ -227,30 +227,30 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(rr);
}
protected internal override ConvertedExpression VisitClt(Clt inst)
protected internal override TranslatedExpression VisitClt(Clt inst)
{
return Comparison(inst, BinaryOperatorType.LessThan);
}
protected internal override ConvertedExpression VisitCgt(Cgt inst)
protected internal override TranslatedExpression VisitCgt(Cgt inst)
{
return Comparison(inst, BinaryOperatorType.GreaterThan);
}
protected internal override ConvertedExpression VisitClt_Un(Clt_Un inst)
protected internal override TranslatedExpression VisitClt_Un(Clt_Un inst)
{
return Comparison(inst, BinaryOperatorType.LessThan, un: true);
}
protected internal override ConvertedExpression VisitCgt_Un(Cgt_Un inst)
protected internal override TranslatedExpression VisitCgt_Un(Cgt_Un inst)
{
return Comparison(inst, BinaryOperatorType.GreaterThan, un: true);
}
ConvertedExpression Comparison(BinaryComparisonInstruction inst, BinaryOperatorType op, bool un = false)
TranslatedExpression Comparison(BinaryComparisonInstruction inst, BinaryOperatorType op, bool un = false)
{
var left = Convert(inst.Left);
var right = Convert(inst.Right);
var left = Translate(inst.Left);
var right = Translate(inst.Right);
// TODO: ensure the arguments are signed
// or with _Un: ensure the arguments are unsigned; and that float comparisons are performed unordered
return new BinaryOperatorExpression(left.Expression, op, right.Expression)
@ -260,68 +260,68 @@ namespace ICSharpCode.Decompiler.CSharp @@ -260,68 +260,68 @@ namespace ICSharpCode.Decompiler.CSharp
left.ResolveResult, right.ResolveResult));
}
ExpressionWithResolveResult Assignment(ConvertedExpression left, ConvertedExpression right)
ExpressionWithResolveResult Assignment(TranslatedExpression left, TranslatedExpression right)
{
right = right.ConvertTo(left.Type, this);
return new AssignmentExpression(left.Expression, right.Expression)
.WithRR(new OperatorResolveResult(left.Type, ExpressionType.Assign, left.ResolveResult, right.ResolveResult));
}
protected internal override ConvertedExpression VisitAdd(Add inst)
protected internal override TranslatedExpression VisitAdd(Add inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.Add);
}
protected internal override ConvertedExpression VisitSub(Sub inst)
protected internal override TranslatedExpression VisitSub(Sub inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.Subtract);
}
protected internal override ConvertedExpression VisitMul(Mul inst)
protected internal override TranslatedExpression VisitMul(Mul inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.Multiply);
}
protected internal override ConvertedExpression VisitDiv(Div inst)
protected internal override TranslatedExpression VisitDiv(Div inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.Divide);
}
protected internal override ConvertedExpression VisitRem(Rem inst)
protected internal override TranslatedExpression VisitRem(Rem inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.Modulus);
}
protected internal override ConvertedExpression VisitBitXor(BitXor inst)
protected internal override TranslatedExpression VisitBitXor(BitXor inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.ExclusiveOr);
}
protected internal override ConvertedExpression VisitBitAnd(BitAnd inst)
protected internal override TranslatedExpression VisitBitAnd(BitAnd inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.BitwiseAnd);
}
protected internal override ConvertedExpression VisitBitOr(BitOr inst)
protected internal override TranslatedExpression VisitBitOr(BitOr inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.BitwiseOr);
}
protected internal override ConvertedExpression VisitShl(Shl inst)
protected internal override TranslatedExpression VisitShl(Shl inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.ShiftLeft);
}
protected internal override ConvertedExpression VisitShr(Shr inst)
protected internal override TranslatedExpression VisitShr(Shr inst)
{
return HandleBinaryNumeric(inst, BinaryOperatorType.ShiftRight);
}
ConvertedExpression HandleBinaryNumeric(BinaryNumericInstruction inst, BinaryOperatorType op)
TranslatedExpression HandleBinaryNumeric(BinaryNumericInstruction inst, BinaryOperatorType op)
{
var resolverWithOverflowCheck = resolver.WithCheckForOverflow(inst.CheckForOverflow);
var left = Convert(inst.Left);
var right = Convert(inst.Right);
var left = Translate(inst.Left);
var right = Translate(inst.Right);
var rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult);
if (rr.IsError || rr.Type.GetStackType() != inst.ResultType
|| !IsCompatibleWithSign(left.Type, inst.Sign) || !IsCompatibleWithSign(right.Type, inst.Sign))
@ -346,9 +346,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -346,9 +346,9 @@ namespace ICSharpCode.Decompiler.CSharp
return sign == Sign.None || type.GetSign() == sign;
}
protected internal override ConvertedExpression VisitConv(Conv inst)
protected internal override TranslatedExpression VisitConv(Conv inst)
{
var arg = Convert(inst.Argument);
var arg = Translate(inst.Argument);
if (arg.Type.GetSign() != inst.Sign) {
// we need to cast the input to a type of appropriate sign
var inputType = inst.Argument.ResultType.ToKnownTypeCode(inst.Sign);
@ -361,23 +361,23 @@ namespace ICSharpCode.Decompiler.CSharp @@ -361,23 +361,23 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(rr);
}
protected internal override ConvertedExpression VisitCall(Call inst)
protected internal override TranslatedExpression VisitCall(Call inst)
{
return HandleCallInstruction(inst);
}
protected internal override ConvertedExpression VisitCallVirt(CallVirt inst)
protected internal override TranslatedExpression VisitCallVirt(CallVirt inst)
{
return HandleCallInstruction(inst);
}
ConvertedExpression HandleCallInstruction(CallInstruction inst)
TranslatedExpression HandleCallInstruction(CallInstruction inst)
{
// Used for Call, CallVirt and NewObj
var method = cecilMapper.GetMethod(inst.Method);
ConvertedExpression target;
TranslatedExpression target;
if (inst.OpCode == OpCode.NewObj) {
target = default(ConvertedExpression); // no target
target = default(TranslatedExpression); // no target
} else if (inst.Method.HasThis) {
var argInstruction = inst.Arguments[0];
if (inst.OpCode == OpCode.Call && argInstruction.MatchLdThis()) {
@ -385,7 +385,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -385,7 +385,7 @@ namespace ICSharpCode.Decompiler.CSharp
.WithILInstruction(argInstruction)
.WithRR(new ThisResolveResult(cecilMapper.GetType(inst.Method.DeclaringType), causesNonVirtualInvocation: true));
} else {
target = Convert(argInstruction);
target = Translate(argInstruction);
}
} else {
var declaringType = cecilMapper.GetType(inst.Method.DeclaringType);
@ -394,12 +394,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -394,12 +394,12 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(new TypeResolveResult(declaringType));
}
var arguments = inst.Arguments.SelectArray(Convert);
var arguments = inst.Arguments.SelectArray(Translate);
int firstParamIndex = (inst.Method.HasThis && inst.OpCode != OpCode.NewObj) ? 1 : 0;
Debug.Assert(arguments.Length == firstParamIndex + inst.Method.Parameters.Count);
ResolveResult rr;
if (method != null) {
// Convert arguments to the expected parameter types
// Translate arguments to the expected parameter types
Debug.Assert(arguments.Length == firstParamIndex + method.Parameters.Count);
for (int i = firstParamIndex; i < arguments.Length; i++) {
var parameter = method.Parameters[i - firstParamIndex];
@ -432,9 +432,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -432,9 +432,9 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
protected internal override ConvertedExpression VisitLdObj(LdObj inst)
protected internal override TranslatedExpression VisitLdObj(LdObj inst)
{
var target = Convert(inst.Target);
var target = Translate(inst.Target);
var type = cecilMapper.GetType(inst.Type);
if (target.Type.Equals(new ByReferenceType(type)) && target.Expression is DirectionExpression) {
// we can deference the managed reference by stripping away the 'ref'
@ -451,12 +451,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -451,12 +451,12 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
protected internal override ConvertedExpression VisitStObj(StObj inst)
protected internal override TranslatedExpression VisitStObj(StObj inst)
{
var target = Convert(inst.Target);
var value = Convert(inst.Value);
var target = Translate(inst.Target);
var value = Translate(inst.Value);
var type = cecilMapper.GetType(inst.Type);
ConvertedExpression result;
TranslatedExpression result;
if (target.Type.Equals(new ByReferenceType(type)) && target.Expression is DirectionExpression) {
// we can deference the managed reference by stripping away the 'ref'
result = target.UnwrapChild(((DirectionExpression)target.Expression).Expression);
@ -470,9 +470,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -470,9 +470,9 @@ namespace ICSharpCode.Decompiler.CSharp
return Assignment(result, value).WithILInstruction(inst);
}
protected internal override ConvertedExpression VisitUnboxAny(UnboxAny inst)
protected internal override TranslatedExpression VisitUnboxAny(UnboxAny inst)
{
var arg = Convert(inst.Argument);
var arg = Translate(inst.Argument);
if (arg.Type.IsReferenceType != true) {
// ensure we treat the input as a reference type
arg = arg.ConvertTo(compilation.FindType(KnownTypeCode.Object), this);
@ -482,12 +482,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -482,12 +482,12 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(new ConversionResolveResult(cecilMapper.GetType(inst.Type), arg.ResolveResult, Conversion.UnboxingConversion));
}
protected override ConvertedExpression Default(ILInstruction inst)
protected override TranslatedExpression Default(ILInstruction inst)
{
return ErrorExpression("OpCode not supported: " + inst.OpCode);
}
static ConvertedExpression ErrorExpression(string message)
static TranslatedExpression ErrorExpression(string message)
{
var e = new ErrorExpression();
e.AddChild(new Comment(message, CommentType.MultiLine), Roles.Comment);

12
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.CSharp
protected override Statement Default(ILInstruction inst)
{
return new ExpressionStatement(exprBuilder.Convert(inst));
return new ExpressionStatement(exprBuilder.Translate(inst));
}
protected internal override Statement VisitNop(Nop inst)
@ -61,12 +61,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -61,12 +61,12 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override Statement VisitVoid(ICSharpCode.Decompiler.IL.Void inst)
{
return new ExpressionStatement(exprBuilder.Convert(inst.Argument));
return new ExpressionStatement(exprBuilder.Translate(inst.Argument));
}
protected internal override Statement VisitIfInstruction(IfInstruction inst)
{
var condition = exprBuilder.ConvertCondition(inst.Condition);
var condition = exprBuilder.TranslateCondition(inst.Condition);
var trueStatement = Convert(inst.TrueInst);
var falseStatement = inst.FalseInst.OpCode == OpCode.Nop ? null : Convert(inst.FalseInst);
return new IfElseStatement(condition, trueStatement, falseStatement);
@ -79,14 +79,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -79,14 +79,14 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override Statement VisitThrow(Throw inst)
{
return new ThrowStatement(exprBuilder.Convert(inst.Argument));
return new ThrowStatement(exprBuilder.Translate(inst.Argument));
}
protected internal override Statement VisitReturn(Return inst)
{
if (inst.ReturnValue == null)
return new ReturnStatement();
return new ReturnStatement(exprBuilder.Convert(inst.ReturnValue).ConvertTo(currentMethod.ReturnType, exprBuilder));
return new ReturnStatement(exprBuilder.Translate(inst.ReturnValue).ConvertTo(currentMethod.ReturnType, exprBuilder));
}
TryCatchStatement MakeTryCatch(ILInstruction tryBlock)
@ -111,7 +111,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -111,7 +111,7 @@ namespace ICSharpCode.Decompiler.CSharp
catchClause.VariableName = handler.Variable.Name;
}
if (!handler.Filter.MatchLdcI4(1))
catchClause.Condition = exprBuilder.ConvertCondition(handler.Filter);
catchClause.Condition = exprBuilder.TranslateCondition(handler.Filter);
catchClause.Body = ConvertAsBlock(handler.Body);
tryCatch.CatchClauses.Add(catchClause);
}

4
ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs

@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
return;
// Recognize field initializers:
// Convert first statement in all ctors (if all ctors have the same statement) into a field initializer.
// Translate first statement in all ctors (if all ctors have the same statement) into a field initializer.
bool allSame;
do {
Match m = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[0].Body.FirstOrDefault());
@ -146,7 +146,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -146,7 +146,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
void HandleStaticFieldInitializers(IEnumerable<AstNode> members, TransformContext context)
{
// Convert static constructor into field initializers if the class is BeforeFieldInit
// Translate static constructor into field initializers if the class is BeforeFieldInit
var staticCtor = members.OfType<ConstructorDeclaration>().FirstOrDefault(c => (c.Modifiers & Modifiers.Static) == Modifiers.Static);
if (staticCtor != null) {
IMethod ctorMethod = staticCtor.GetSymbol() as IMethod;

24
ICSharpCode.Decompiler/CSharp/ConvertedExpression.cs → ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -86,10 +86,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -86,10 +86,10 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary>
/// <remarks>
/// The resolve result is also always available as annotation on the expression, but having
/// ConvertedExpression as a separate type is still useful to ensure that no case in the expression builder
/// TranslatedExpression as a separate type is still useful to ensure that no case in the expression builder
/// forgets to add the annotation.
/// </remarks>
struct ConvertedExpression
struct TranslatedExpression
{
public readonly Expression Expression;
@ -105,14 +105,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -105,14 +105,14 @@ namespace ICSharpCode.Decompiler.CSharp
get { return ResolveResult.Type; }
}
internal ConvertedExpression(Expression expression)
internal TranslatedExpression(Expression expression)
{
Debug.Assert(expression != null);
this.Expression = expression;
this.ResolveResult = expression.Annotation<ResolveResult>() ?? ErrorResolveResult.UnknownError;
}
internal ConvertedExpression(Expression expression, ResolveResult resolveResult)
internal TranslatedExpression(Expression expression, ResolveResult resolveResult)
{
Debug.Assert(expression != null && resolveResult != null);
Debug.Assert(expression.Annotation<ResolveResult>() == resolveResult);
@ -120,27 +120,27 @@ namespace ICSharpCode.Decompiler.CSharp @@ -120,27 +120,27 @@ namespace ICSharpCode.Decompiler.CSharp
this.Expression = expression;
}
public static implicit operator Expression(ConvertedExpression expression)
public static implicit operator Expression(TranslatedExpression expression)
{
return expression.Expression;
}
public static implicit operator ExpressionWithResolveResult(ConvertedExpression expression)
public static implicit operator ExpressionWithResolveResult(TranslatedExpression expression)
{
return new ExpressionWithResolveResult(expression.Expression, expression.ResolveResult);
}
public static implicit operator ExpressionWithILInstruction(ConvertedExpression expression)
public static implicit operator ExpressionWithILInstruction(TranslatedExpression expression)
{
return new ExpressionWithILInstruction(expression.Expression);
}
/// <summary>
/// Returns a new ConvertedExpression that represents the specified descendant expression.
/// Returns a new TranslatedExpression that represents the specified descendant expression.
/// All ILInstruction annotations from the current expression are copied to the descendant expression.
/// The descendant expression is detached from the AST.
/// </summary>
public ConvertedExpression UnwrapChild(Expression descendant)
public TranslatedExpression UnwrapChild(Expression descendant)
{
if (descendant == Expression)
return this;
@ -148,12 +148,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -148,12 +148,12 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var inst in parent.Annotations.OfType<ILInstruction>())
descendant.AddAnnotation(inst);
if (parent == Expression)
return new ConvertedExpression(descendant.Detach());
return new TranslatedExpression(descendant.Detach());
}
throw new ArgumentException("descendant must be a descendant of the current node");
}
public ConvertedExpression ConvertTo(IType targetType, ExpressionBuilder expressionBuilder)
public TranslatedExpression ConvertTo(IType targetType, ExpressionBuilder expressionBuilder)
{
var type = this.Type;
if (targetType.IsKnownType(KnownTypeCode.Boolean))
@ -180,7 +180,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -180,7 +180,7 @@ namespace ICSharpCode.Decompiler.CSharp
.WithoutILInstruction().WithRR(rr);
}
public ConvertedExpression ConvertToBoolean(ExpressionBuilder expressionBuilder)
public TranslatedExpression ConvertToBoolean(ExpressionBuilder expressionBuilder)
{
if (Type.IsKnownType(KnownTypeCode.Boolean) || Type.Kind == TypeKind.Unknown) {
return this;

6
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CSharp\Annotations.cs" />
<Compile Include="CSharp\ConvertedExpression.cs" />
<Compile Include="CSharp\TranslatedExpression.cs" />
<Compile Include="CSharp\NRefactoryCecilMapper.cs" />
<Compile Include="CSharp\CSharpDecompiler.cs" />
<Compile Include="CSharp\ExpressionBuilder.cs" />
@ -160,9 +160,7 @@ @@ -160,9 +160,7 @@
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\Transforms" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<Target Name="BeforeBuild">
<MSBuild Projects="$(MSBuildProjectDirectory)\..\BuildTools\UpdateAssemblyInfo\UpdateAssemblyInfo.csproj" Targets="Build" Properties="Configuration=Debug" />

Loading…
Cancel
Save