Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy into Debugger

newNRvisualizers
Eusebiu Marcu 15 years ago
parent
commit
9e3e3022ae
  1. 2
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Backreference.cs
  2. 18
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Choice.cs
  3. 20
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Match.cs
  4. 5
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  5. 52
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  6. 3
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

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

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
{ {
return match[referencedGroupName].Last().Match(other) != null; return match.Get(referencedGroupName).Last().Match(other) != null;
} }
} }
} }

18
ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Choice.cs

@ -2,20 +2,25 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System; using System;
using System.Collections;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{ {
/// <summary> /// <summary>
/// Matches one of several alternatives. /// Matches one of several alternatives.
/// </summary> /// </summary>
public class Choice : Pattern public class Choice : Pattern, IEnumerable
{ {
public static readonly Role<AstNode> AlternativeRole = new Role<AstNode>("Alternative", AstNode.Null); public static readonly Role<AstNode> AlternativeRole = new Role<AstNode>("Alternative", AstNode.Null);
public Choice(params AstNode[] alternatives) public void Add(string name, AstNode alternative)
{ {
foreach (AstNode node in alternatives) AddChild(new NamedNode(name, alternative), AlternativeRole);
AddChild(node, AlternativeRole); }
public void Add(AstNode alternative)
{
AddChild(alternative, AlternativeRole);
} }
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
@ -29,5 +34,10 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
} }
return false; return false;
} }
IEnumerator IEnumerable.GetEnumerator()
{
return GetChildrenByRole(AlternativeRole).GetEnumerator();
}
} }
} }

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

@ -24,13 +24,29 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
results.RemoveRange(checkPoint, results.Count - checkPoint); results.RemoveRange(checkPoint, results.Count - checkPoint);
} }
public IEnumerable<AstNode> this[string groupName] { public IEnumerable<AstNode> Get(string groupName)
get { {
foreach (var pair in results) { foreach (var pair in results) {
if (pair.Key == groupName) if (pair.Key == groupName)
yield return pair.Value; yield return pair.Value;
} }
} }
public IEnumerable<T> Get<T>(string groupName) where T : AstNode
{
foreach (var pair in results) {
if (pair.Key == groupName)
yield return (T)pair.Value;
}
}
public bool Has(string groupName)
{
foreach (var pair in results) {
if (pair.Key == groupName)
return true;
}
return false;
} }
public void Add(string groupName, AstNode node) public void Add(string groupName, AstNode node)

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

@ -29,6 +29,11 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
return new ExpressionPlaceholder(this); return new ExpressionPlaceholder(this);
} }
public Statement ToStatement()
{
return new StatementPlaceholder(this);
}
public BlockStatement ToBlock() public BlockStatement ToBlock()
{ {
return new BlockStatementPlaceholder(this); return new BlockStatementPlaceholder(this);

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

@ -7,113 +7,113 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{ {
sealed class TypePlaceholder : AstType sealed class TypePlaceholder : AstType
{ {
public static readonly Role<Pattern> PatternRole = new Role<Pattern>("Pattern"); public static readonly Role<AstNode> ChildRole = new Role<AstNode>("Child", AstNode.Null);
public TypePlaceholder(Pattern pattern) public TypePlaceholder(AstNode child)
{ {
AddChild(pattern, TypePlaceholder.PatternRole); AddChild(child, TypePlaceholder.ChildRole);
} }
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.Pattern; } get { return GetChildByRole(TypePlaceholder.ChildRole).NodeType; }
} }
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return default(S); return GetChildByRole(TypePlaceholder.ChildRole).AcceptVisitor(visitor, data);
} }
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
{ {
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match); return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
} }
} }
sealed class ExpressionPlaceholder : Expression sealed class ExpressionPlaceholder : Expression
{ {
public ExpressionPlaceholder(Pattern pattern) public ExpressionPlaceholder(AstNode child)
{ {
AddChild(pattern, TypePlaceholder.PatternRole); AddChild(child, TypePlaceholder.ChildRole);
} }
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.Pattern; } get { return GetChildByRole(TypePlaceholder.ChildRole).NodeType; }
} }
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return default(S); return GetChildByRole(TypePlaceholder.ChildRole).AcceptVisitor(visitor, data);
} }
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
{ {
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match); return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
} }
} }
sealed class StatementPlaceholder : Statement sealed class StatementPlaceholder : Statement
{ {
public StatementPlaceholder(Pattern pattern) public StatementPlaceholder(AstNode child)
{ {
AddChild(pattern, TypePlaceholder.PatternRole); AddChild(child, TypePlaceholder.ChildRole);
} }
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.Pattern; } get { return GetChildByRole(TypePlaceholder.ChildRole).NodeType; }
} }
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return default(S); return GetChildByRole(TypePlaceholder.ChildRole).AcceptVisitor(visitor, data);
} }
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
{ {
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match); return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
} }
} }
sealed class BlockStatementPlaceholder : BlockStatement sealed class BlockStatementPlaceholder : BlockStatement
{ {
public BlockStatementPlaceholder(Pattern pattern) public BlockStatementPlaceholder(AstNode child)
{ {
AddChild(pattern, TypePlaceholder.PatternRole); AddChild(child, TypePlaceholder.ChildRole);
} }
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.Pattern; } get { return GetChildByRole(TypePlaceholder.ChildRole).NodeType; }
} }
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return default(S); return GetChildByRole(TypePlaceholder.ChildRole).AcceptVisitor(visitor, data);
} }
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
{ {
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match); return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
} }
} }
sealed class VariablePlaceholder : VariableInitializer sealed class VariablePlaceholder : VariableInitializer
{ {
public VariablePlaceholder(Pattern pattern) public VariablePlaceholder(AstNode child)
{ {
AddChild(pattern, TypePlaceholder.PatternRole); AddChild(child, TypePlaceholder.ChildRole);
} }
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.Pattern; } get { return GetChildByRole(TypePlaceholder.ChildRole).NodeType; }
} }
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return default(S); return GetChildByRole(TypePlaceholder.ChildRole).AcceptVisitor(visitor, data);
} }
protected internal override bool DoMatch(AstNode other, Match match) protected internal override bool DoMatch(AstNode other, Match match)
{ {
return GetChildByRole(TypePlaceholder.PatternRole).DoMatch(other, match); return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
} }
} }
} }

3
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -1689,6 +1689,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteModifiers(eventDeclaration.ModifierTokens); WriteModifiers(eventDeclaration.ModifierTokens);
WriteKeyword("event"); WriteKeyword("event");
eventDeclaration.ReturnType.AcceptVisitor(this, data); eventDeclaration.ReturnType.AcceptVisitor(this, data);
Space();
WriteCommaSeparatedList(eventDeclaration.Variables); WriteCommaSeparatedList(eventDeclaration.Variables);
Semicolon(); Semicolon();
return EndNode(eventDeclaration); return EndNode(eventDeclaration);
@ -1700,6 +1701,8 @@ namespace ICSharpCode.NRefactory.CSharp
WriteAttributes(customEventDeclaration.Attributes); WriteAttributes(customEventDeclaration.Attributes);
WriteModifiers(customEventDeclaration.ModifierTokens); WriteModifiers(customEventDeclaration.ModifierTokens);
WriteKeyword("event"); WriteKeyword("event");
customEventDeclaration.ReturnType.AcceptVisitor(this, data);
Space();
WritePrivateImplementationType(customEventDeclaration.PrivateImplementationType); WritePrivateImplementationType(customEventDeclaration.PrivateImplementationType);
WriteIdentifier(customEventDeclaration.Name); WriteIdentifier(customEventDeclaration.Name);
OpenBrace(policy.EventBraceStyle); OpenBrace(policy.EventBraceStyle);

Loading…
Cancel
Save