Beispiel #1
0
        public bool WriteExpressionInParenthesesIfNeeded(Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var parenthesis = expression is ArrayCreation ||
                              expression is DelegateCreationExpression || expression is BinaryOperator ||
                              expression is UnaryOperator || expression is UnaryAssignmentOperator || expression is ConditionalOperator ||
                              expression is AssignmentOperator || expression is PointerIndirectionOperator;

            var conversion = expression as Conversion;

            if (conversion != null && (conversion.ConversionKind == ConversionKind.PointerToInteger ||
                                       conversion.ConversionKind == ConversionKind.IntegerToPointer ||
                                       conversion.ConversionKind == ConversionKind.PointerToPointer))
            {
                parenthesis = true;
            }

            if (parenthesis)
            {
                this.TextSpan("(");
            }

            expression.WriteTo(this);

            if (parenthesis)
            {
                this.TextSpan(")");
            }

            return(parenthesis);
        }
Beispiel #2
0
        public bool WriteWrappedExpressionIfNeeded(Expression expression, bool useEnumUnderlyingType = false)
        {
            if (expression.IsStaticOrSupportedVolatileWrapperCall())
            {
                new Cast {
                    Type = expression.Type, Operand = expression, CCast = true, UseEnumUnderlyingType = useEnumUnderlyingType,
                }.WriteTo(this);
                return(true);
            }

            this.WriteExpressionInParenthesesIfNeeded(expression);
            return(false);
        }
Beispiel #3
0
        public void WriteAccess(Expression expression)
        {
            var effectiveExpression = expression;

            this.WriteExpressionInParenthesesIfNeeded(effectiveExpression);

            if (effectiveExpression.IsReference)
            {
                if (effectiveExpression is BaseReference)
                {
                    this.TextSpan("::");
                    return;
                }

                this.TextSpan("->");
                return;
            }

            var elementAccessExpression = effectiveExpression as ElementAccessExpression;

            if (elementAccessExpression != null && elementAccessExpression.Operand.Type.TypeKind == TypeKind.Pointer)
            {
                this.TextSpan("->");
                return;
            }

            var expressionType = effectiveExpression.Type;

            if (expressionType.TypeKind == TypeKind.Struct || expressionType.TypeKind == TypeKind.Enum)
            {
                if (!effectiveExpression.IsStaticOrSupportedVolatileWrapperCall())
                {
                    this.TextSpan(".");
                    return;
                }
            }

            // default for Templates
            this.TextSpan("->");
        }