public override Expression CloneExpressionOnly() { BoxExpression result = new BoxExpression(this.BoxedExpression.CloneExpressionOnly(), theTypeSystem, this.BoxedAs, null) { IsAutoBox = this.IsAutoBox }; return(result); }
public override Expression Clone() { BoxExpression result = new BoxExpression(this.BoxedExpression.Clone(), theTypeSystem, this.BoxedAs, instructions) { IsAutoBox = this.IsAutoBox }; return(result); }
public override bool Equals(Expression other) { BoxExpression otherBox = other as BoxExpression; if (otherBox == null) { return(false); } if (this.BoxedExpression.Equals(otherBox.BoxedExpression)) { return(this.BoxedAs.FullName == otherBox.BoxedAs.FullName); } return(false); }
public override ICodeNode VisitBoxExpression(BoxExpression node) { node = (BoxExpression)base.VisitBoxExpression(node); TypeDefinition boxedAs = node.BoxedAs.Resolve(); if (boxedAs != null && boxedAs.IsEnum && !node.BoxedAs.IsArray) { if (node.BoxedExpression is LiteralExpression) { node.BoxedExpression = EnumHelper.GetEnumExpression(boxedAs, node.BoxedExpression as LiteralExpression, typeSystem); } } return node; }
public override void VisitBoxExpression(BoxExpression node) { Stack<Expression> removedExpressions = new Stack<Expression>(); removedExpressions.Push(parentExpressions.Pop());// pop the box expression if (parentExpressions.Count > 0) { Expression containingExpression = parentExpressions.Peek(); if (containingExpression is MemberReferenceExpresion) { MemberReferenceExpresion memberExpression = parentExpressions.Pop() as MemberReferenceExpresion; removedExpressions.Push(memberExpression); if (memberExpression.Member is MethodReference) { //The box expression is the method target. // This is automatically handled by C#/VB compilers. node.IsAutoBox = true; } } else if (containingExpression is MethodInvocationExpression || containingExpression is FieldReferenceExpression || containingExpression is PropertyReferenceExpression) { // The boxed expression is an argument to a method call. // This is automatically handled by C#/VB compilers. node.IsAutoBox = true; } else if (containingExpression is BinaryExpression) { BinaryExpression binary = containingExpression as BinaryExpression; // Check for expressions of the type: // a = B; // where a is of type object and B is the boxed expression. if (binary.IsAssignmentExpression && binary.Right.Equals(node)) { node.IsAutoBox = true; } // check for expressions of the type: // X == null // X != null // null == X // null != X // where X is the boxed expression and X is of some generic parameter type T if (binary.IsComparisonExpression && node.BoxedAs.IsGenericParameter) { if (binary.Left == node) { if (binary.Right is LiteralExpression && (binary.Right as LiteralExpression).Value == null) { node.IsAutoBox = true; } } if (binary.Right == node) { if (binary.Left is LiteralExpression && (binary.Left as LiteralExpression).Value == null) { node.IsAutoBox = true; } } } } else if (containingExpression is ReturnExpression) { if (context.Method.ReturnType.FullName == "System.Object") { node.IsAutoBox = true; } else { TypeDefinition type = node.BoxedExpression.ExpressionType.Resolve(); if (type != null && type.IsValueType) { node.IsAutoBox = true; } } } else if (containingExpression is YieldReturnExpression) { YieldReturnExpression yieldReturn = containingExpression as YieldReturnExpression; if (yieldReturn.Expression.Equals(node)) { node.IsAutoBox = true; } } } // push back the popped expressions while (removedExpressions.Count > 0) { parentExpressions.Push(removedExpressions.Pop()); } base.VisitBoxExpression(node); }
public override ICodeNode VisitBoxExpression(BoxExpression node) { base.VisitBoxExpression(node); if (node.BoxedExpression.CodeNodeType == CodeNodeType.LiteralExpression && node.BoxedAs.FullName == currentTypeSystem.Boolean.FullName) { FixBooleanLiteral(node.BoxedExpression as LiteralExpression); return node.BoxedExpression.CloneAndAttachInstructions(node.MappedInstructions); } if (node.BoxedExpression.CodeNodeType == CodeNodeType.CastExpression && ((CastExpression)node.BoxedExpression).Expression.CodeNodeType == CodeNodeType.CastExpression) { // double cast in a boxed expression; CastExpression outerCast = node.BoxedExpression as CastExpression; CastExpression innerCast = outerCast.Expression as CastExpression; if (outerCast.TargetType.FullName == currentTypeSystem.Char.FullName && innerCast.TargetType.FullName == currentTypeSystem.UInt16.FullName) { // Remove the outer cast, as it is produced by the box expression and doesn't have any instructions mapped. // The inner cast contains the instruction, converting the stack value to 2-byte integer (which at this point is known to be char, not ushort). innerCast.TargetType = currentTypeSystem.Char; node.BoxedExpression = innerCast; } } return node; }
public override void VisitBoxExpression(BoxExpression node) { if (!node.IsAutoBox) { WriteToken("("); WriteReferenceAndNamespaceIfInCollision(node.ExpressionType); // the cast to object WriteToken(")"); } bool isComplexCastTarget = IsComplexTarget(node.BoxedExpression); if (isComplexCastTarget && !node.IsAutoBox) { WriteToken("("); } Visit(node.BoxedExpression); if (isComplexCastTarget && !node.IsAutoBox) { WriteToken(")"); } }
public override Expression CloneExpressionOnly() { BoxExpression result = new BoxExpression(this.BoxedExpression.CloneExpressionOnly(), theTypeSystem, this.BoxedAs, null) { IsAutoBox = this.IsAutoBox }; return result; }
public override Expression Clone() { BoxExpression result = new BoxExpression(this.BoxedExpression.Clone(), theTypeSystem, this.BoxedAs, instructions) { IsAutoBox = this.IsAutoBox }; return result; }
public virtual void VisitBoxExpression(BoxExpression node) { Visit(node.BoxedExpression); }
public override Expression CloneExpressionOnly() { stackVariable8 = new BoxExpression(this.get_BoxedExpression().CloneExpressionOnly(), this.theTypeSystem, this.get_BoxedAs(), null); stackVariable8.set_IsAutoBox(this.get_IsAutoBox()); return(stackVariable8); }
public override Expression Clone() { stackVariable9 = new BoxExpression(this.get_BoxedExpression().Clone(), this.theTypeSystem, this.get_BoxedAs(), this.instructions); stackVariable9.set_IsAutoBox(this.get_IsAutoBox()); return(stackVariable9); }