Browse Source

Add pattern matching support to the NRefactory C# AST.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
1b99074a8e
  1. 44
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstComparer.cs
  2. 26
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  3. 22
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs
  4. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs
  5. 13
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs
  6. 7
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs
  7. 12
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs
  8. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs
  9. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs
  10. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs
  11. 11
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs
  12. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs
  13. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs
  14. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BaseReferenceExpression.cs
  15. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs
  16. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs
  17. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs
  18. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs
  19. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs
  20. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs
  21. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs
  22. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs
  23. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs
  24. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs
  25. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IsExpression.cs
  26. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs
  27. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs
  28. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs
  29. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs
  30. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs
  31. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs
  32. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs
  33. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs
  34. 23
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs
  35. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs
  36. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/StackAllocExpression.cs
  37. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ThisReferenceExpression.cs
  38. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs
  39. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs
  40. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs
  41. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs
  42. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs
  43. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs
  44. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Comment.cs
  45. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs
  46. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs
  47. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs
  48. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs
  49. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs
  50. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs
  51. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs
  52. 3
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/NodeType.cs
  53. 26
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/AnyNode.cs
  54. 25
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Backreference.cs
  55. 30
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Match.cs
  56. 29
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/NamedGroup.cs
  57. 39
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  58. 119
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  59. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs
  60. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs
  61. 11
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs
  62. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/BreakStatement.cs
  63. 17
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ExpressionStatement.cs
  64. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/IfElseStatement.cs
  65. 10
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs
  66. 12
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs
  67. 12
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs
  68. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs
  69. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs
  70. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs
  71. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  72. 6
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs
  73. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs
  74. 8
      NRefactory/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

44
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstComparer.cs

@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// 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
{
/// <summary>
/// Compares whether two ASTs are structurally identical.
/// </summary>
public static class AstComparer
{
static HashSet<Type> nodeTypesWithoutExtraInfo = new HashSet<Type> {
typeof(IdentifierExpression)
};
public static bool? AreEqual(AstNode node1, AstNode node2)
{
if (node1 == node2)
return true;
if (node1 == null || node1.IsNull || node2 == null || node2.IsNull)
return false;
Type nodeType = node1.GetType();
if (nodeType != node2.GetType())
return false;
if (node1.Role != node2.Role)
return false;
AstNode child1 = node1.FirstChild;
AstNode child2 = node2.FirstChild;
bool? result = true;
while (result != false && (child1 != null || child2 != null)) {
result &= AreEqual(child1, child2);
child1 = child1.NextSibling;
child2 = child2.NextSibling;
}
if (nodeTypesWithoutExtraInfo.Contains(nodeType))
return result;
if (nodeType == typeof(Identifier))
return ((Identifier)node1).Name == ((Identifier)node2).Name;
return null;
}
}
}

26
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs

@ -25,11 +25,14 @@ @@ -25,11 +25,14 @@
// THE SOFTWARE.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp
{
public abstract class AstNode
@ -55,6 +58,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,6 +58,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion
@ -569,6 +577,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -569,6 +577,24 @@ namespace ICSharpCode.NRefactory.CSharp
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data);
#region Pattern Matching
public Match Match(AstNode other)
{
Match match = new Match();
if (DoMatch(other, match))
return match;
else
return null;
}
protected static bool MatchString(string name1, string name2)
{
return string.IsNullOrEmpty(name1) || name1 == name2;
}
protected internal abstract bool DoMatch(AstNode other, Match match);
#endregion
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
static readonly Role<AstNode> RootRole = new Role<AstNode>("Root");

22
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs

@ -5,13 +5,14 @@ using System; @@ -5,13 +5,14 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// Represents the children of an AstNode that have a specific role.
/// </summary>
public struct AstNodeCollection<T> : ICollection<T> where T : AstNode
public class AstNodeCollection<T> : ICollection<T> where T : AstNode
{
readonly AstNode node;
readonly Role<T> role;
@ -152,5 +153,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -152,5 +153,24 @@ namespace ICSharpCode.NRefactory.CSharp
return !(left.role == right.role && left.node == right.node);
}
#endregion
internal bool DoMatch(AstNodeCollection<T> other, Match match)
{
AstNode cur1 = this.node.FirstChild;
AstNode cur2 = other.node.FirstChild;
while (true) {
while (cur1 != null && cur1.Role != role)
cur1 = cur1.NextSibling;
while (cur2 != null && cur2.Role != role)
cur2 = cur2.NextSibling;
if (cur1 == null || cur2 == null)
break;
if (!cur1.DoMatch(cur2, match))
return false;
cur1 = cur1.NextSibling;
cur2 = cur2.NextSibling;
}
return cur1 == null && cur2 == null;
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
@ -22,6 +23,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -22,6 +23,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion

13
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// TokenNode.cs
//
// Author:
@ -46,6 +46,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -46,6 +46,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
@ -80,6 +85,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -80,6 +85,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitCSharpTokenNode (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CSharpTokenNode o = other as CSharpTokenNode;
return o != null;
}
public override string ToString ()
{
return string.Format ("[CSharpTokenNode: StartLocation={0}, EndLocation={1}, Role={2}]", StartLocation, EndLocation, Role);

7
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs

@ -42,6 +42,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -42,6 +42,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CompilationUnit o = other as CompilationUnit;
return o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match);
}
public AstNode GetNodeAt (int line, int column)
{
return GetNodeAt (new AstLocation (line, column));
@ -99,7 +105,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -99,7 +105,6 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitCompilationUnit (this, data);
}
}
}

12
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs

@ -76,6 +76,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -76,6 +76,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitComposedType (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ComposedType o = other as ComposedType;
return o != null && this.HasNullableSpecifier == o.HasNullableSpecifier && this.PointerRank == o.PointerRank && this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match);
}
public override string ToString()
{
StringBuilder b = new StringBuilder();
@ -156,6 +162,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -156,6 +162,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitArraySpecifier(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ArraySpecifier o = other as ArraySpecifier;
return o != null && this.Dimensions == o.Dimensions;
}
public override string ToString()
{
return "[" + new string(',', this.Dimensions - 1) + "]";

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs

@ -64,5 +64,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,5 +64,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitAnonymousMethodExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
AnonymousMethodExpression o = other as AnonymousMethodExpression;
return o != null && this.HasParameterList == o.HasParameterList && this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs

@ -57,6 +57,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,6 +57,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitArgListExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ArgListExpression o = other as ArgListExpression;
return o != null && this.IsAccess == o.IsAccess && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs

@ -37,5 +37,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -37,5 +37,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitArrayCreateExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ArrayCreateExpression o = other as ArrayCreateExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.Initializer.DoMatch(o.Initializer, match);
}
}
}

11
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs

@ -48,6 +48,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +48,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion
@ -67,6 +72,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -67,6 +72,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitArrayInitializerExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ArrayInitializerExpression o = other as ArrayInitializerExpression;
return o != null && this.Elements.DoMatch(o.Elements, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AssignmentExpression.cs
//
// Author:
@ -72,6 +72,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,6 +72,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitAssignmentExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
AssignmentExpression o = other as AssignmentExpression;
return o != null && this.Left.DoMatch(o.Left, match) && this.Operator == o.Operator && this.Right.DoMatch(o.Right, match);
}
public static string GetOperatorSymbol(AssignmentOperatorType op)
{
switch (op) {

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BaseReferenceExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// BinaryOperatorExpression.cs
//
// Author:
@ -72,6 +72,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,6 +72,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitBinaryOperatorExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
BinaryOperatorExpression o = other as BinaryOperatorExpression;
return o != null && this.Left.DoMatch(o.Left, match) && this.Operator == o.Operator && this.Right.DoMatch(o.Right, match);
}
public static string GetOperatorSymbol(BinaryOperatorType op)
{
switch (op) {

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs

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

5
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs

@ -31,6 +31,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,6 +31,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs

@ -64,5 +64,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,5 +64,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitIdentifierExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
IdentifierExpression o = other as IdentifierExpression;
return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs

@ -54,5 +54,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,5 +54,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitIndexerExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
IndexerExpression o = other as IndexerExpression;
return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs

@ -54,5 +54,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,5 +54,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitInvocationExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
InvocationExpression o = other as InvocationExpression;
return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IsExpression.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// TypeOfIsExpression.cs
//
// Author:
@ -49,6 +49,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,6 +49,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitIsExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
IsExpression o = other as IsExpression;
return o != null && this.Expression.DoMatch(o.Expression, match) && this.Type.DoMatch(o.Type, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs

@ -53,5 +53,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,5 +53,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitLambdaExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
LambdaExpression o = other as LambdaExpression;
return o != null && this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs

@ -63,5 +63,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -63,5 +63,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitMemberReferenceExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
MemberReferenceExpression o = other as MemberReferenceExpression;
return o != null && this.Target.DoMatch(o.Target, match) && MatchString(this.MemberName, o.MemberName) && this.TypeArguments.DoMatch(o.TypeArguments, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs

@ -28,5 +28,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -28,5 +28,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitNamedArgumentExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
NamedArgumentExpression o = other as NamedArgumentExpression;
return o != null && MatchString(this.Identifier, o.Identifier) && this.Expression.DoMatch(o.Expression, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs

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

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs

@ -65,5 +65,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,5 +65,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitObjectCreateExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ObjectCreateExpression o = other as ObjectCreateExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.Initializer.DoMatch(o.Initializer, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs

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

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs

@ -57,5 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,5 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitPointerReferenceExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
PointerReferenceExpression o = other as PointerReferenceExpression;
return o != null && MatchString(this.MemberName, o.MemberName) && this.TypeArguments.DoMatch(o.TypeArguments, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs

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

23
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs

@ -25,6 +25,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -25,6 +25,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion
@ -36,6 +41,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,6 +41,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryExpression o = other as QueryExpression;
return o != null && this.Clauses.DoMatch(o.Clauses, match);
}
}
public abstract class QueryClause : AstNode
@ -43,6 +54,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,6 +54,12 @@ namespace ICSharpCode.NRefactory.CSharp
public override NodeType NodeType {
get { return NodeType.QueryClause; }
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryClause o = other as QueryClause;
throw new NotImplementedException();
}
}
/// <summary>
@ -293,6 +310,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -293,6 +310,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryOrdering (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryOrdering o = other as QueryOrdering;
return o != null && this.Direction == o.Direction && this.Expression.DoMatch(o.Expression, match);
}
}
public enum QueryOrderingDirection

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/StackAllocExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ThisReferenceExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs

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

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UnaryOperatorExpression.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// UnaryOperatorExpression.cs
//
// Author:
@ -64,6 +64,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,6 +64,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitUnaryOperatorExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
UnaryOperatorExpression o = other as UnaryOperatorExpression;
return o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match);
}
public static string GetOperatorSymbol(UnaryOperatorType op)
{
switch (op) {

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs

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

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs

@ -52,5 +52,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,5 +52,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitAttribute (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Attribute o = other as Attribute;
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs

@ -58,6 +58,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,6 +58,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitAttributeSection (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
AttributeSection o = other as AttributeSection;
return o != null && this.AttributeTarget == o.AttributeTarget && this.Attributes.DoMatch(o.Attributes, match);
}
public static string GetAttributeTargetName(AttributeTarget attributeTarget)
{
switch (attributeTarget) {

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Comment.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// Comment.cs
//
// Author:
@ -86,6 +86,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -86,6 +86,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitComment (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Comment o = other as Comment;
return o != null && this.CommentType == o.CommentType && MatchString(this.Content, o.Content);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs

@ -61,6 +61,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -61,6 +61,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitConstraint (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Constraint o = other as Constraint;
return o != null && MatchString(this.TypeParameter, o.TypeParameter) && this.BaseTypes.DoMatch(o.BaseTypes, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs

@ -100,5 +100,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -100,5 +100,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitNamespaceDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
NamespaceDeclaration o = other as NamespaceDeclaration;
return o != null && MatchString(this.Name, o.Name) && this.Members.DoMatch(o.Members, match);
}
}
};

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs

@ -38,5 +38,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -38,5 +38,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitTypeParameterDeclaration(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
TypeParameterDeclaration o = other as TypeParameterDeclaration;
return o != null && this.Variance == o.Variance && MatchString(this.Name, o.Name);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs

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

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs

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

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs

@ -60,6 +60,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,6 +60,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitMemberType (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
MemberType o = other as MemberType;
return o != null && this.IsDoubleColon == o.IsDoubleColon && MatchString(this.MemberName, o.MemberName) && this.Target.DoMatch(o.Target, match);
}
public override string ToString()
{
StringBuilder b = new StringBuilder();

3
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/NodeType.cs

@ -43,7 +43,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,7 +43,8 @@ namespace ICSharpCode.NRefactory.CSharp
Statement,
Expression,
Token,
QueryClause
QueryClause,
Pattern
}
}

26
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/AnyNode.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
/// <summary>
/// Matches any node.
/// </summary>
public class AnyNode : Pattern
{
readonly string groupName;
public AnyNode(string groupName = null)
{
this.groupName = groupName;
}
protected internal override bool DoMatch(AstNode other, Match match)
{
match.Add(this.groupName, other);
return other != null && !other.IsNull;
}
}
}

25
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Backreference.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
public class Backreference : Pattern
{
readonly string referencedGroupName;
public Backreference(string referencedGroupName)
{
if (referencedGroupName == null)
throw new ArgumentNullException("referencedGroupName");
this.referencedGroupName = referencedGroupName;
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return match[referencedGroupName].Last().Match(other) != null;
}
}
}

30
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Match.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
public class Match
{
List<KeyValuePair<string, AstNode>> results = new List<KeyValuePair<string, AstNode>>();
public IEnumerable<AstNode> this[string groupName] {
get {
foreach (var pair in results) {
if (pair.Key == groupName)
yield return pair.Value;
}
}
}
public void Add(string groupName, AstNode node)
{
if (groupName != null && node != null) {
results.Add(new KeyValuePair<string, AstNode>(groupName, node));
}
}
}
}

29
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/NamedGroup.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
/// <summary>
/// Represents a named node within a pattern.
/// </summary>
public class NamedNode : Pattern
{
public static readonly Role<AstNode> ElementRole = new Role<AstNode>("Element", AstNode.Null);
readonly string groupName;
public NamedNode(string groupName, AstNode childNode)
{
this.groupName = groupName;
AddChild(childNode, ElementRole);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
match.Add(this.groupName, other);
return GetChildByRole(ElementRole).DoMatch(other, match);
}
}
}

39
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
public abstract class Pattern : AstNode
{
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return default(S);
}
public AstType ToType()
{
return new TypePlaceholder(this);
}
public Expression ToExpression()
{
return new ExpressionPlaceholder(this);
}
public BlockStatement ToBlock()
{
return new BlockStatementPlaceholder(this);
}
public VariableInitializer ToVariable()
{
return new VariablePlaceholder(this);
}
}
}

119
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs

@ -0,0 +1,119 @@ @@ -0,0 +1,119 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
sealed class TypePlaceholder : AstType
{
public static readonly Role<Pattern> PatternRole = new Role<Pattern>("Pattern");
public TypePlaceholder(Pattern pattern)
{
AddChild(pattern, TypePlaceholder.PatternRole);
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return default(S);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match);
}
}
sealed class ExpressionPlaceholder : Expression
{
public ExpressionPlaceholder(Pattern pattern)
{
AddChild(pattern, TypePlaceholder.PatternRole);
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return default(S);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match);
}
}
sealed class StatementPlaceholder : Statement
{
public StatementPlaceholder(Pattern pattern)
{
AddChild(pattern, TypePlaceholder.PatternRole);
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return default(S);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match);
}
}
sealed class BlockStatementPlaceholder : BlockStatement
{
public BlockStatementPlaceholder(Pattern pattern)
{
AddChild(pattern, TypePlaceholder.PatternRole);
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return default(S);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match);
}
}
sealed class VariablePlaceholder : VariableInitializer
{
public VariablePlaceholder(Pattern pattern)
{
AddChild(pattern, TypePlaceholder.PatternRole);
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return default(S);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// FullTypeName.cs
//
// Author:
@ -65,6 +65,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,6 +65,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitPrimitiveType (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
PrimitiveType o = other as PrimitiveType;
return o != null && MatchString(this.Keyword, o.Keyword);
}
public override string ToString()
{
return Keyword ?? base.ToString();

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs

@ -65,6 +65,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,6 +65,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitSimpleType (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
SimpleType o = other as SimpleType;
return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match);
}
public override string ToString()
{
StringBuilder b = new StringBuilder(this.Identifier);

11
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs

@ -49,6 +49,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,6 +49,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion
@ -69,6 +74,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -69,6 +74,12 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitBlockStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
BlockStatement o = other as BlockStatement;
return o != null && this.Statements.DoMatch(o.Statements, match);
}
#region Builder methods
public void AddStatement(Statement statement)
{

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

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

17
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Statements/ExpressionStatement.cs

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

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

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

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

@ -29,6 +29,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -29,6 +29,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion
@ -47,5 +52,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,5 +52,10 @@ 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();
}
}
}

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

@ -93,6 +93,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -93,6 +93,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitSwitchSection (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
SwitchSection o = other as SwitchSection;
return o != null && this.CaseLabels.DoMatch(o.CaseLabels, match) && this.Statements.DoMatch(o.Statements, match);
}
}
public class CaseLabel : AstNode
@ -112,5 +118,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -112,5 +118,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitCaseLabel (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CaseLabel o = other as CaseLabel;
return o != null && this.Expression.DoMatch(o.Expression, match);
}
}
}

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

@ -66,6 +66,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -66,6 +66,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitTryCatchStatement (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
TryCatchStatement o = other as TryCatchStatement;
return o != null && this.TryBlock.DoMatch(o.TryBlock, match) && this.CatchClauses.DoMatch(o.CatchClauses, match) && this.FinallyBlock.DoMatch(o.FinallyBlock, match);
}
}
/// <summary>
@ -115,5 +121,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -115,5 +121,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitCatchClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CatchClause o = other as CatchClause;
return o != null && this.Type.DoMatch(o.Type, match) && MatchString(this.VariableName, o.VariableName) && this.Body.DoMatch(o.Body, match);
}
}
}

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

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

9
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// PropertyDeclaration.cs
//
// Author:
@ -24,6 +24,8 @@ @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
@ -59,5 +61,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,5 +61,10 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitAccessor (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
throw new NotImplementedException();
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
@ -56,5 +57,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -56,5 +57,10 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
}
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.CSharp.PatternMatching.Match match)
{
throw new NotImplementedException();
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs

@ -112,5 +112,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -112,5 +112,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitConstructorInitializer (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ConstructorInitializer o = other as ConstructorInitializer;
return o != null && this.ConstructorInitializerType == o.ConstructorInitializerType && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

6
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs

@ -81,6 +81,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -81,6 +81,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitParameterDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ParameterDeclaration o = other as ParameterDeclaration;
return o != null && this.Attributes.DoMatch(o.Attributes, match) && this.ParameterModifier == o.ParameterModifier && MatchString(this.Name, o.Name) && this.DefaultExpression.DoMatch(o.DefaultExpression, match);
}
}
}

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs

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

8
NRefactory/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -55,7 +55,6 @@ @@ -55,7 +55,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CSharp\Ast\AstComparer.cs" />
<Compile Include="CSharp\Ast\AstNodeCollection.cs" />
<Compile Include="CSharp\Ast\Expressions\TypeReferenceExpression.cs" />
<Compile Include="CSharp\Ast\IAstVisitor.cs" />
@ -96,6 +95,12 @@ @@ -96,6 +95,12 @@
<Compile Include="CSharp\Ast\Expressions\UncheckedExpression.cs" />
<Compile Include="CSharp\Ast\GeneralScope\TypeParameterDeclaration.cs" />
<Compile Include="CSharp\Ast\MemberType.cs" />
<Compile Include="CSharp\Ast\PatternMatching\AnyNode.cs" />
<Compile Include="CSharp\Ast\PatternMatching\Backreference.cs" />
<Compile Include="CSharp\Ast\PatternMatching\Match.cs" />
<Compile Include="CSharp\Ast\PatternMatching\NamedGroup.cs" />
<Compile Include="CSharp\Ast\PatternMatching\Pattern.cs" />
<Compile Include="CSharp\Ast\PatternMatching\Placeholder.cs" />
<Compile Include="CSharp\Ast\PrimitiveType.cs" />
<Compile Include="CSharp\Ast\GeneralScope\Attribute.cs" />
<Compile Include="CSharp\Ast\GeneralScope\AttributeSection.cs" />
@ -334,6 +339,7 @@ @@ -334,6 +339,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />
<Folder Include="CSharp\Ast\PatternMatching" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

Loading…
Cancel
Save