Browse Source

Add support for Modifiers.Any (for pattern-matching) and for AttributeSection patterns.

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
8484a21767
  1. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
  2. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs
  3. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  4. 29
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  5. 2
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs

5
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs

@ -72,7 +72,10 @@ namespace ICSharpCode.NRefactory.CSharp
new KeyValuePair<Modifiers, int>(Modifiers.Volatile, "volatile".Length), new KeyValuePair<Modifiers, int>(Modifiers.Volatile, "volatile".Length),
new KeyValuePair<Modifiers, int>(Modifiers.Extern, "extern".Length), new KeyValuePair<Modifiers, int>(Modifiers.Extern, "extern".Length),
new KeyValuePair<Modifiers, int>(Modifiers.Partial, "partial".Length), new KeyValuePair<Modifiers, int>(Modifiers.Partial, "partial".Length),
new KeyValuePair<Modifiers, int>(Modifiers.Const, "const".Length) new KeyValuePair<Modifiers, int>(Modifiers.Const, "const".Length),
// even though it's used for patterns only, it needs to be in this table to be usable in the AST
new KeyValuePair<Modifiers, int>(Modifiers.Any, "any".Length)
}; };
public static IEnumerable<Modifiers> AllModifiers { public static IEnumerable<Modifiers> AllModifiers {

5
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs

@ -66,4 +66,9 @@ namespace ICSharpCode.NRefactory.CSharp
//Final = 0x400000, //Final = 0x400000,
//Literal = 0x800000, //Literal = 0x800000,
VisibilityMask = Private | Internal | Protected | Public, VisibilityMask = Private | Internal | Protected | Public,
/// <summary>
/// Special value used to match any modifiers during pattern matching.
/// </summary>
Any = unchecked((int)0x80000000)
}} }}

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

@ -64,6 +64,11 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
return p != null ? new VariablePlaceholder(p) : null; return p != null ? new VariablePlaceholder(p) : null;
} }
public static implicit operator AttributeSection(Pattern p)
{
return p != null ? new AttributeSectionPlaceholder(p) : null;
}
// Make debugging easier by giving Patterns a ToString() implementation // Make debugging easier by giving Patterns a ToString() implementation
public override string ToString() public override string ToString()
{ {

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

@ -152,4 +152,33 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
return child.DoMatchCollection(role, pos, match, backtrackingStack); return child.DoMatchCollection(role, pos, match, backtrackingStack);
} }
} }
sealed class AttributeSectionPlaceholder : AttributeSection
{
readonly AstNode child;
public AttributeSectionPlaceholder(AstNode child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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);
}
}
} }

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

@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match) protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match)
{ {
return this.Modifiers == o.Modifiers && this.Attributes.DoMatch(o.Attributes, match); return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch(o.Attributes, match);
} }
} }
} }

Loading…
Cancel
Save