当前位置: 首页>>代码示例>>C#>>正文


C# BinaryExpression.Replace方法代码示例

本文整理汇总了C#中Boo.Lang.Compiler.Ast.BinaryExpression.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpression.Replace方法的具体用法?C# BinaryExpression.Replace怎么用?C# BinaryExpression.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Boo.Lang.Compiler.Ast.BinaryExpression的用法示例。


在下文中一共展示了BinaryExpression.Replace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindNullableOperation

        bool BindNullableOperation(BinaryExpression node)
        {
            if (!IsNullableOperation(node))
                return false;

            if (BinaryOperatorType.ReferenceEquality == node.Operator)
            {
                node.Operator = BinaryOperatorType.Equality;
                return BindNullableComparison(node);
            }
            else if (BinaryOperatorType.ReferenceInequality == node.Operator)
            {
                node.Operator = BinaryOperatorType.Inequality;
                return BindNullableComparison(node);
            }

            IType lhs = GetExpressionType(node.Left);
            IType rhs = GetExpressionType(node.Right);
            bool lhsIsNullable = TypeSystemServices.IsNullable(lhs);
            bool rhsIsNullable = TypeSystemServices.IsNullable(rhs);

            if (BinaryOperatorType.Assign == node.Operator)
            {
                if (lhsIsNullable)
                {
                    if (rhsIsNullable)
                        return false;
                    BindNullableInitializer(node, node.Right, lhs);
                    return false;
                }
            }

            if (lhsIsNullable)
            {
                MemberReferenceExpression mre = new MemberReferenceExpression(node.Left, "Value");
                node.Replace(node.Left, mre);
                Visit(mre);
                mre.Annotate("nullableTarget", true);
            }
            if (rhsIsNullable)
            {
                MemberReferenceExpression mre = new MemberReferenceExpression(node.Right, "Value");
                node.Replace(node.Right, mre);
                Visit(mre);
                mre.Annotate("nullableTarget", true);
            }

            return false;
        }
开发者ID:stuman08,项目名称:boo,代码行数:49,代码来源:ProcessMethodBodies.cs

示例2: BindPointerArithmeticOperator

        bool BindPointerArithmeticOperator(BinaryExpression node, IType left, IType right)
        {
            if (!left.IsPointer || !TypeSystemServices.IsPrimitiveNumber(right))
                return false;

            switch (node.Operator)
            {
                case BinaryOperatorType.Addition:
                case BinaryOperatorType.Subtraction:
                    if (node.ContainsAnnotation("pointerSizeNormalized"))
                        return true;

                    BindExpressionType(node, left);

                    int size = TypeSystemServices.SizeOf(left);
                    if (size == 1)
                        return true; //no need for normalization

                    //normalize RHS wrt size of pointer
                    IntegerLiteralExpression literal = node.Right as IntegerLiteralExpression;
                    Expression normalizedRhs = (null != literal)
                        ? (Expression)
                            new IntegerLiteralExpression(literal.Value * size)
                        : (Expression)
                            new BinaryExpression(BinaryOperatorType.Multiply,
                                node.Right,
                                new IntegerLiteralExpression(size));
                    node.Replace(node.Right, normalizedRhs);
                    Visit(node.Right);
                    node.Annotate("pointerSizeNormalized", size);
                    return true;
            }

            return false;
        }
开发者ID:stuman08,项目名称:boo,代码行数:35,代码来源:ProcessMethodBodies.cs

示例3: BindNullableComparison

        bool BindNullableComparison(BinaryExpression node)
        {
            if (!IsNullableOperation(node))
                return false;

            if (IsNull(node.Left) || IsNull(node.Right))
            {
                Expression nullable = IsNull(node.Left) ? node.Right : node.Left;
                Expression val = new MemberReferenceExpression(nullable, "HasValue");
                node.Replace(node.Left, val);
                Visit(val);
                Expression nil = new BoolLiteralExpression(false);
                node.Replace(node.Right, nil);
                Visit(nil);
                BindExpressionType(node, TypeSystemServices.BoolType);
                return true;
            }

            BinaryExpression valueCheck = new BinaryExpression(
                (node.Operator == BinaryOperatorType.Inequality)
                    ? BinaryOperatorType.BitwiseOr
                    : BinaryOperatorType.BitwiseAnd,
                new BinaryExpression(
                    GetCorrespondingHasValueOperator(node.Operator),
                    CreateNullableHasValueOrTrueExpression(node.Left),
                    CreateNullableHasValueOrTrueExpression(node.Right)
                ),
                new BinaryExpression(
                    node.Operator,
                    CreateNullableGetValueOrDefaultExpression(node.Left),
                    CreateNullableGetValueOrDefaultExpression(node.Right)
                )
            );
            node.ParentNode.Replace(node, valueCheck);
            Visit(valueCheck);
            return true;
        }
开发者ID:stuman08,项目名称:boo,代码行数:37,代码来源:ProcessMethodBodies.cs


注:本文中的Boo.Lang.Compiler.Ast.BinaryExpression.Replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。