|
|
|
@ -2,16 +2,19 @@
@@ -2,16 +2,19 @@
|
|
|
|
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.NRefactory.CSharp.PatternMatching |
|
|
|
|
{ |
|
|
|
|
// Placeholders do not store their child in the AST tree; but keep it as a separate child.
|
|
|
|
|
// This allows reusing the child in multiple placeholders; thus enabling the sharing of AST subtrees.
|
|
|
|
|
sealed class TypePlaceholder : AstType |
|
|
|
|
{ |
|
|
|
|
public static readonly Role<AstNode> ChildRole = new Role<AstNode>("Child", AstNode.Null); |
|
|
|
|
readonly AstNode child; |
|
|
|
|
|
|
|
|
|
public TypePlaceholder(AstNode child) |
|
|
|
|
{ |
|
|
|
|
AddChild(child, TypePlaceholder.ChildRole); |
|
|
|
|
this.child = child; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override NodeType NodeType { |
|
|
|
@ -20,20 +23,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
@@ -20,20 +23,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
|
|
|
|
|
|
|
|
|
|
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
|
|
|
|
{ |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data); |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected internal override bool DoMatch(AstNode other, Match match) |
|
|
|
|
{ |
|
|
|
|
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match); |
|
|
|
|
return child.DoMatch(other, match); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack) |
|
|
|
|
{ |
|
|
|
|
return child.DoMatchCollection(role, pos, match, backtrackingStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class ExpressionPlaceholder : Expression |
|
|
|
|
{ |
|
|
|
|
readonly AstNode child; |
|
|
|
|
|
|
|
|
|
public ExpressionPlaceholder(AstNode child) |
|
|
|
|
{ |
|
|
|
|
AddChild(child, TypePlaceholder.ChildRole); |
|
|
|
|
this.child = child; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override NodeType NodeType { |
|
|
|
@ -42,20 +52,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
@@ -42,20 +52,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
|
|
|
|
|
|
|
|
|
|
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
|
|
|
|
{ |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data); |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected internal override bool DoMatch(AstNode other, Match match) |
|
|
|
|
{ |
|
|
|
|
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match); |
|
|
|
|
return child.DoMatch(other, match); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack) |
|
|
|
|
{ |
|
|
|
|
return child.DoMatchCollection(role, pos, match, backtrackingStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class StatementPlaceholder : Statement |
|
|
|
|
{ |
|
|
|
|
readonly AstNode child; |
|
|
|
|
|
|
|
|
|
public StatementPlaceholder(AstNode child) |
|
|
|
|
{ |
|
|
|
|
AddChild(child, TypePlaceholder.ChildRole); |
|
|
|
|
this.child = child; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override NodeType NodeType { |
|
|
|
@ -64,20 +81,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
@@ -64,20 +81,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
|
|
|
|
|
|
|
|
|
|
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
|
|
|
|
{ |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data); |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected internal override bool DoMatch(AstNode other, Match match) |
|
|
|
|
{ |
|
|
|
|
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match); |
|
|
|
|
return child.DoMatch(other, match); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack) |
|
|
|
|
{ |
|
|
|
|
return child.DoMatchCollection(role, pos, match, backtrackingStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class BlockStatementPlaceholder : BlockStatement |
|
|
|
|
{ |
|
|
|
|
readonly AstNode child; |
|
|
|
|
|
|
|
|
|
public BlockStatementPlaceholder(AstNode child) |
|
|
|
|
{ |
|
|
|
|
AddChild(child, TypePlaceholder.ChildRole); |
|
|
|
|
this.child = child; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override NodeType NodeType { |
|
|
|
@ -86,20 +110,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
@@ -86,20 +110,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
|
|
|
|
|
|
|
|
|
|
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
|
|
|
|
{ |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data); |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected internal override bool DoMatch(AstNode other, Match match) |
|
|
|
|
{ |
|
|
|
|
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match); |
|
|
|
|
return child.DoMatch(other, match); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack) |
|
|
|
|
{ |
|
|
|
|
return child.DoMatchCollection(role, pos, match, backtrackingStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class VariablePlaceholder : VariableInitializer |
|
|
|
|
{ |
|
|
|
|
readonly AstNode child; |
|
|
|
|
|
|
|
|
|
public VariablePlaceholder(AstNode child) |
|
|
|
|
{ |
|
|
|
|
AddChild(child, TypePlaceholder.ChildRole); |
|
|
|
|
this.child = child; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override NodeType NodeType { |
|
|
|
@ -108,12 +139,17 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
@@ -108,12 +139,17 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
|
|
|
|
|
|
|
|
|
|
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
|
|
|
|
{ |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data); |
|
|
|
|
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected internal override bool DoMatch(AstNode other, Match match) |
|
|
|
|
{ |
|
|
|
|
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match); |
|
|
|
|
return child.DoMatch(other, match); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack) |
|
|
|
|
{ |
|
|
|
|
return child.DoMatchCollection(role, pos, match, backtrackingStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|