public override BoundNode VisitPointerElementAccess(BoundPointerElementAccess node)
        {
            BoundExpression rewrittenExpression = LowerReceiverOfPointerElementAccess(node.Expression);
            BoundExpression rewrittenIndex      = VisitExpression(node.Index);

            return(RewritePointerElementAccess(node, rewrittenExpression, rewrittenIndex));
        }
        private BoundExpression RewritePointerElementAccess(BoundPointerElementAccess node, BoundExpression rewrittenExpression, BoundExpression rewrittenIndex)
        {
            // Optimization: p[0] == *p
            if (rewrittenIndex.IsDefaultValue())
            {
                return(new BoundPointerIndirectionOperator(
                           node.Syntax,
                           rewrittenExpression,
                           node.Type));
            }

            BinaryOperatorKind additionKind = BinaryOperatorKind.Addition;

            switch (rewrittenIndex.Type.SpecialType)
            {
            case SpecialType.System_Int32:
                additionKind |= BinaryOperatorKind.PointerAndInt32Addition;
                break;

            case SpecialType.System_UInt32:
                additionKind |= BinaryOperatorKind.PointerAndUInt32Addition;
                break;

            case SpecialType.System_Int64:
                additionKind |= BinaryOperatorKind.PointerAndInt64Addition;
                break;

            case SpecialType.System_UInt64:
                additionKind |= BinaryOperatorKind.PointerAndUInt64Addition;
                break;

            default:
                throw ExceptionUtilities.UnexpectedValue(rewrittenIndex.Type.SpecialType);
            }

            if (node.Checked)
            {
                additionKind |= BinaryOperatorKind.Checked;
            }

            return(new BoundPointerIndirectionOperator(
                       node.Syntax,
                       MakeBinaryOperator(
                           node.Syntax,
                           additionKind,
                           rewrittenExpression,
                           rewrittenIndex,
                           rewrittenExpression.Type,
                           method: null,
                           isPointerElementAccess: true), //see RewriterPointerNumericOperator
                       node.Type));
        }
Exemplo n.º 3
0
        public override BoundNode VisitPointerElementAccess(BoundPointerElementAccess node)
        {
            BoundSpillSequenceBuilder builder = null;
            var             index             = VisitExpression(ref builder, node.Index);
            BoundExpression expression;

            if (builder == null)
            {
                expression = VisitExpression(ref builder, node.Expression);
            }
            else
            {
                var expressionBuilder = new BoundSpillSequenceBuilder();
                expression = VisitExpression(ref expressionBuilder, node.Expression);
                expression = Spill(expressionBuilder, expression);
                expressionBuilder.Include(builder);
                builder = expressionBuilder;
            }

            return(UpdateExpression(builder, node.Update(expression, index, node.Checked, node.Type)));
        }
Exemplo n.º 4
0
 public override BoundNode VisitPointerElementAccess(BoundPointerElementAccess node)
 {
     NoteUnsafe(node);
     return(base.VisitPointerElementAccess(node));
 }
Exemplo n.º 5
0
 private static BoundExpression VisitPointerElementAccess(BoundPointerElementAccess node)
 {
     // error should have been reported earlier
     // Diagnostics.Add(ErrorCode.ERR_ExpressionTreeContainsPointerOp, node.Syntax.Location);
     return(new BoundBadExpression(node.Syntax, default(LookupResultKind), ImmutableArray <Symbol> .Empty, ImmutableArray.Create <BoundExpression>(node), node.Type));
 }