本文整理汇总了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);
}