C# Class ICSharpCode.NRefactory.CSharp.InsertParenthesesVisitor

Inserts the parentheses into the AST that are needed to ensure the AST can be printed correctly. For example, if the AST contains BinaryOperatorExpresson(2, Mul, BinaryOperatorExpression(1, Add, 1))); printing that AST would incorrectly result in "2 * 1 + 1". By running InsertParenthesesVisitor, the necessary parentheses are inserted: "2 * (1 + 1)".
Inheritance: DepthFirstAstVisitor
Show file Open project: icsharpcode/NRefactory

Public Methods

Method Description
VisitAsExpression ( AsExpression asExpression ) : void
VisitAssignmentExpression ( AssignmentExpression assignmentExpression ) : void
VisitBinaryOperatorExpression ( BinaryOperatorExpression binaryOperatorExpression ) : void
VisitCastExpression ( CastExpression castExpression ) : void
VisitConditionalExpression ( ConditionalExpression conditionalExpression ) : void
VisitIndexerExpression ( IndexerExpression indexerExpression ) : void
VisitInvocationExpression ( InvocationExpression invocationExpression ) : void
VisitIsExpression ( IsExpression isExpression ) : void
VisitMemberReferenceExpression ( MemberReferenceExpression memberReferenceExpression ) : void
VisitNamedExpression ( NamedExpression namedExpression ) : void
VisitPointerReferenceExpression ( PointerReferenceExpression pointerReferenceExpression ) : void
VisitQueryExpression ( QueryExpression queryExpression ) : void
VisitUnaryOperatorExpression ( UnaryOperatorExpression unaryOperatorExpression ) : void

Private Methods

Method Description
GetBinaryOperatorType ( Expression expr ) : BinaryOperatorType?
GetPrecedence ( Expression expr ) : int

Gets the row number in the C# 4.0 spec operator precedence table.

Parenthesize ( Expression expr ) : void
ParenthesizeIfRequired ( Expression expr, int minimumPrecedence ) : void

Parenthesizes the expression if it does not have the minimum required precedence.

TypeCanBeMisinterpretedAsExpression ( AstType type ) : bool

Method Details

VisitAsExpression() public method

public VisitAsExpression ( AsExpression asExpression ) : void
asExpression AsExpression
return void

VisitAssignmentExpression() public method

public VisitAssignmentExpression ( AssignmentExpression assignmentExpression ) : void
assignmentExpression AssignmentExpression
return void

VisitBinaryOperatorExpression() public method

public VisitBinaryOperatorExpression ( BinaryOperatorExpression binaryOperatorExpression ) : void
binaryOperatorExpression BinaryOperatorExpression
return void

VisitCastExpression() public method

public VisitCastExpression ( CastExpression castExpression ) : void
castExpression CastExpression
return void

VisitConditionalExpression() public method

public VisitConditionalExpression ( ConditionalExpression conditionalExpression ) : void
conditionalExpression ConditionalExpression
return void

VisitIndexerExpression() public method

public VisitIndexerExpression ( IndexerExpression indexerExpression ) : void
indexerExpression IndexerExpression
return void

VisitInvocationExpression() public method

public VisitInvocationExpression ( InvocationExpression invocationExpression ) : void
invocationExpression InvocationExpression
return void

VisitIsExpression() public method

public VisitIsExpression ( IsExpression isExpression ) : void
isExpression IsExpression
return void

VisitMemberReferenceExpression() public method

public VisitMemberReferenceExpression ( MemberReferenceExpression memberReferenceExpression ) : void
memberReferenceExpression MemberReferenceExpression
return void

VisitNamedExpression() public method

public VisitNamedExpression ( NamedExpression namedExpression ) : void
namedExpression NamedExpression
return void

VisitPointerReferenceExpression() public method

public VisitPointerReferenceExpression ( PointerReferenceExpression pointerReferenceExpression ) : void
pointerReferenceExpression PointerReferenceExpression
return void

VisitQueryExpression() public method

public VisitQueryExpression ( QueryExpression queryExpression ) : void
queryExpression QueryExpression
return void

VisitUnaryOperatorExpression() public method

public VisitUnaryOperatorExpression ( UnaryOperatorExpression unaryOperatorExpression ) : void
unaryOperatorExpression UnaryOperatorExpression
return void