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


C# ParenthesizedExpression.AcceptVisitor方法代码示例

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


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

示例1: VisitUnaryOperatorExpression

        public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unary, object data)
        {
            // Remove double negation
            // !!a
            if (unary.Op == UnaryOperatorType.Not &&
                unary.Expression is UnaryOperatorExpression &&
                (unary.Expression as UnaryOperatorExpression).Op == UnaryOperatorType.Not) {
                Expression newParenth = new ParenthesizedExpression((unary.Expression as UnaryOperatorExpression).Expression);
                ReplaceCurrentNode(newParenth);
                return newParenth.AcceptVisitor(this, data);
            }

            // Basic assumtion is that we have something in form !(a)
            if (unary.Op == UnaryOperatorType.Not &&
                unary.Expression is ParenthesizedExpression) {
                ParenthesizedExpression parenth = ((ParenthesizedExpression)unary.Expression);

                // Push through two parenthesis
                // !((a))
                if (parenth.Expression is ParenthesizedExpression) {
                    parenth.Expression = new UnaryOperatorExpression(parenth.Expression, UnaryOperatorType.Not);
                    ReplaceCurrentNode(parenth);
                    return parenth.AcceptVisitor(this, data);
                }

                // Remove double negation
                // !(!a)
                if (parenth.Expression is UnaryOperatorExpression &&
                    (parenth.Expression as UnaryOperatorExpression).Op == UnaryOperatorType.Not) {
                    parenth.Expression = (parenth.Expression as UnaryOperatorExpression).Expression;
                    ReplaceCurrentNode(parenth);
                    return parenth.AcceptVisitor(this, data);
                }

                // Push through binary operation
                // !((a) op (b))
                BinaryOperatorExpression binaryOp = parenth.Expression as BinaryOperatorExpression;
                if (binaryOp != null &&
                    binaryOp.Left is ParenthesizedExpression &&
                    binaryOp.Right is ParenthesizedExpression) {

                    bool sucessful = true;
                    switch(binaryOp.Op) {
                        case BinaryOperatorType.Equality:           binaryOp.Op = BinaryOperatorType.InEquality; break;
                        case BinaryOperatorType.InEquality:         binaryOp.Op = BinaryOperatorType.Equality; break;
                        case BinaryOperatorType.GreaterThan:        binaryOp.Op = BinaryOperatorType.LessThanOrEqual; break;
                        case BinaryOperatorType.GreaterThanOrEqual: binaryOp.Op = BinaryOperatorType.LessThan; break;
                        case BinaryOperatorType.LessThanOrEqual:    binaryOp.Op = BinaryOperatorType.GreaterThan; break;
                        case BinaryOperatorType.LessThan:           binaryOp.Op = BinaryOperatorType.GreaterThanOrEqual; break;
                        default: sucessful = false; break;
                    }
                    if (sucessful) {
                        ReplaceCurrentNode(parenth);
                        return parenth.AcceptVisitor(this, data);
                    }

                    sucessful = true;
                    switch(binaryOp.Op) {
                        case BinaryOperatorType.BitwiseAnd: binaryOp.Op = BinaryOperatorType.BitwiseOr; break;
                        case BinaryOperatorType.BitwiseOr:  binaryOp.Op = BinaryOperatorType.BitwiseAnd; break;
                        case BinaryOperatorType.LogicalAnd: binaryOp.Op = BinaryOperatorType.LogicalOr; break;
                        case BinaryOperatorType.LogicalOr:  binaryOp.Op = BinaryOperatorType.LogicalAnd; break;
                        default: sucessful = false; break;
                    }
                    if (sucessful) {
                        binaryOp.Left = new UnaryOperatorExpression(binaryOp.Left, UnaryOperatorType.Not);
                        binaryOp.Right = new UnaryOperatorExpression(binaryOp.Right, UnaryOperatorType.Not);
                        ReplaceCurrentNode(parenth);
                        return parenth.AcceptVisitor(this, data);
                    }
                }
            }

            return base.VisitUnaryOperatorExpression(unary, data);
        }
开发者ID:almazik,项目名称:ILSpy,代码行数:75,代码来源:PushNegation.cs


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