Browse Source

Implement pattern matching for statements.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
01cc3ecd38
  1. 7
      ICSharpCode.Decompiler/Ast/CommentStatement.cs
  2. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs
  3. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ContinueStatement.cs
  4. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs
  5. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/EmptyStatement.cs
  6. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs
  7. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForeachStatement.cs
  8. 38
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/GotoStatement.cs
  9. 12
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/LabelStatement.cs
  10. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/LockStatement.cs
  11. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs
  12. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs
  13. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs
  14. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs
  15. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs
  16. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/UnsafeStatement.cs
  17. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs
  18. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs
  19. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs

7
ICSharpCode.Decompiler/Ast/CommentStatement.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
namespace Decompiler
{
@ -34,5 +35,11 @@ namespace Decompiler @@ -34,5 +35,11 @@ namespace Decompiler
cs.Remove();
}
}
protected override bool DoMatch(AstNode other, Match match)
{
CommentStatement o = other as CommentStatement;
return o != null && MatchString(comment, o.comment);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// CheckedStatement.cs
//
// Author:
@ -44,5 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,5 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitCheckedStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CheckedStatement o = other as CheckedStatement;
return o != null && this.Body.DoMatch(o.Body, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ContinueStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// ContinueStatement.cs
//
// Author:
@ -39,5 +39,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,5 +39,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitContinueStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ContinueStatement o = other as ContinueStatement;
return o != null;
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// DoWhileStatement.cs
//
// Author:
@ -68,6 +68,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -68,6 +68,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitDoWhileStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
DoWhileStatement o = other as DoWhileStatement;
return o != null && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match) && this.Condition.DoMatch(o.Condition, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/EmptyStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// EmptyStatement.cs
//
// Author:
@ -52,5 +52,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,5 +52,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitEmptyStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
EmptyStatement o = other as EmptyStatement;
return o != null;
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs

@ -63,5 +63,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -63,5 +63,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitFixedStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
FixedStatement o = other as FixedStatement;
return o != null && this.Variables.DoMatch(o.Variables, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match);
}
}
}

9
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForeachStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// ForeachStatement.cs
//
// Author:
@ -75,5 +75,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -75,5 +75,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitForeachStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ForeachStatement o = other as ForeachStatement;
return o != null && this.VariableType.DoMatch(o.VariableType, match) && MatchString(this.VariableName, o.VariableName)
&& this.InExpression.DoMatch(o.InExpression, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match);
}
}
}

38
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/GotoStatement.cs

@ -56,14 +56,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -56,14 +56,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
/// <summary>
/// Used for "goto case LabelExpression;"
/// </summary>
public Expression LabelExpression {
get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole (Roles.Expression, value); }
}
public CSharpTokenNode SemicolonToken {
get { return GetChildByRole (Roles.Semicolon); }
}
@ -72,6 +64,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,6 +64,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitGotoStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
GotoStatement o = other as GotoStatement;
return o != null && MatchString(this.Label, o.Label);
}
}
/// <summary>
@ -89,18 +87,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -89,18 +87,6 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (CaseKeywordRole); }
}
public string Label {
get {
return GetChildByRole (Roles.Identifier).Name;
}
set {
if (string.IsNullOrEmpty(value))
SetChildByRole(Roles.Identifier, null);
else
SetChildByRole(Roles.Identifier, new Identifier(value, AstLocation.Empty));
}
}
/// <summary>
/// Used for "goto case LabelExpression;"
/// </summary>
@ -117,6 +103,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -117,6 +103,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitGotoCaseStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
GotoCaseStatement o = other as GotoCaseStatement;
return o != null && this.LabelExpression.DoMatch(o.LabelExpression, match);
}
}
/// <summary>
@ -142,5 +134,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -142,5 +134,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitGotoDefaultStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
GotoDefaultStatement o = other as GotoDefaultStatement;
return o != null;
}
}
}

12
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/LabelStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// LabelStatement.cs
//
// Author:
@ -40,9 +40,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,9 +40,19 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public CSharpTokenNode Colon {
get { return GetChildByRole (Roles.Colon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitLabelStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
LabelStatement o = other as LabelStatement;
return o != null && MatchString(this.Label, o.Label);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/LockStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// LockStatement.cs
//
// Author:
@ -57,5 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,5 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitLockStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
LockStatement o = other as LockStatement;
return o != null && this.Expression.DoMatch(o.Expression, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// ReturnStatement.cs
//
// Author:
@ -48,5 +48,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,5 +48,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitReturnStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ReturnStatement o = other as ReturnStatement;
return o != null && this.Expression.DoMatch(o.Expression, match);
}
}
}

5
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs

@ -52,10 +52,5 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,10 +52,5 @@ namespace ICSharpCode.NRefactory.CSharp
public override NodeType NodeType {
get { return NodeType.Statement; }
}
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.CSharp.PatternMatching.Match match)
{
throw new NotImplementedException();
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs

@ -69,6 +69,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -69,6 +69,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitSwitchStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
SwitchStatement o = other as SwitchStatement;
return o != null && this.Expression.DoMatch(o.Expression, match) && this.SwitchSections.DoMatch(o.SwitchSections, match);
}
}
public class SwitchSection : AstNode

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// ThrowStatement.cs
//
// Author:
@ -48,5 +48,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,5 +48,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitThrowStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ThrowStatement o = other as ThrowStatement;
return o != null && this.Expression.DoMatch(o.Expression, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// UncheckedStatement.cs
//
// Author:
@ -44,5 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,5 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitUncheckedStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
UncheckedStatement o = other as UncheckedStatement;
return o != null && this.Body.DoMatch(o.Body, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/UnsafeStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// UnsafeStatement.cs
//
// Author:
@ -44,5 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,5 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitUnsafeStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
UnsafeStatement o = other as UnsafeStatement;
return o != null && this.Body.DoMatch(o.Body, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// WhileStatement.cs
//
// Author:
@ -59,5 +59,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,5 +59,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitWhileStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
WhileStatement o = other as WhileStatement;
return o != null && this.Condition.DoMatch(o.Condition, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// YieldBreakStatement.cs
//
// Author:
@ -50,5 +50,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -50,5 +50,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitYieldBreakStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
YieldBreakStatement o = other as YieldBreakStatement;
return o != null;
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// YieldStatement.cs
//
// Author:
@ -55,5 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,5 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitYieldStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
YieldStatement o = other as YieldStatement;
return o != null && this.Expression.DoMatch(o.Expression, match);
}
}
}

Loading…
Cancel
Save