Browse Source

Add support for 'any' operator and fix a bug in pattern matching.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
38faf8415d
  1. 3
      ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs
  2. 6
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs
  3. 10
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/BinaryOperatorExpression.cs
  4. 4
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/PrimitiveExpression.cs

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

@ -187,7 +187,8 @@ namespace ICSharpCode.NRefactory.CSharp
success = cur1.DoMatch(cur2, match); success = cur1.DoMatch(cur2, match);
} }
cur1 = cur1.NextSibling; cur1 = cur1.NextSibling;
cur2 = cur2.NextSibling; if (cur2 != null)
cur2 = cur2.NextSibling;
} }
while (cur2 != null && cur2.Role != role) while (cur2 != null && cur2.Role != role)
cur2 = cur2.NextSibling; cur2 = cur2.NextSibling;

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

@ -75,7 +75,8 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
AssignmentExpression o = other as AssignmentExpression; AssignmentExpression o = other as AssignmentExpression;
return o != null && this.Left.DoMatch(o.Left, match) && this.Operator == o.Operator && this.Right.DoMatch(o.Right, match); return o != null && (this.Operator == AssignmentOperatorType.Any || this.Operator == o.Operator)
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match);
} }
public static string GetOperatorSymbol(AssignmentOperatorType op) public static string GetOperatorSymbol(AssignmentOperatorType op)
@ -136,5 +137,8 @@ namespace ICSharpCode.NRefactory.CSharp
BitwiseOr, BitwiseOr,
/// <summary>left ^= right</summary> /// <summary>left ^= right</summary>
ExclusiveOr, ExclusiveOr,
/// <summary>Any operator (for pattern matching)</summary>
Any
} }
} }

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

@ -75,7 +75,8 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
BinaryOperatorExpression o = other as BinaryOperatorExpression; BinaryOperatorExpression o = other as BinaryOperatorExpression;
return o != null && this.Left.DoMatch(o.Left, match) && this.Operator == o.Operator && this.Right.DoMatch(o.Right, match); return o != null && (this.Operator == BinaryOperatorType.Any || this.Operator == o.Operator)
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match);
} }
public static string GetOperatorSymbol(BinaryOperatorType op) public static string GetOperatorSymbol(BinaryOperatorType op)
@ -173,6 +174,11 @@ namespace ICSharpCode.NRefactory.CSharp
ShiftRight, ShiftRight,
/// <summary>left ?? right</summary> /// <summary>left ?? right</summary>
NullCoalescing NullCoalescing,
/// <summary>
/// Any binary operator (used in pattern matching)
/// </summary>
Any
} }
} }

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

@ -31,6 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class PrimitiveExpression : Expression public class PrimitiveExpression : Expression
{ {
public static readonly object AnyValue = new object();
AstLocation startLocation; AstLocation startLocation;
public override AstLocation StartLocation { public override AstLocation StartLocation {
get { get {
@ -70,7 +72,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
PrimitiveExpression o = other as PrimitiveExpression; PrimitiveExpression o = other as PrimitiveExpression;
return o != null && object.Equals(this.Value, o.Value); return o != null && (this.Value == AnyValue || object.Equals(this.Value, o.Value));
} }
} }
} }

Loading…
Cancel
Save