Browse Source

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

newNRvisualizers
Eusebiu Marcu 15 years ago
parent
commit
b33ddd3d8d
  1. 9
      ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  2. 24
      ICSharpCode.NRefactory/CSharp/Ast/AstType.cs
  3. 5
      ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
  4. 5
      ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs
  5. 10
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  6. 29
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  7. 6
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs
  8. 2
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs
  9. 14
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

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

@ -157,6 +157,15 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
/// <summary>
/// Gets all descendants of this node (including this node itself).
/// </summary>
public IEnumerable<AstNode> DescendantsAndSelf {
get {
return Utils.TreeTraversal.PreOrder(this, n => n.Children);
}
}
/// <summary> /// <summary>
/// Gets the first child with the specified role. /// Gets the first child with the specified role.
/// Returns the role's null object if the child is not found. /// Returns the role's null object if the child is not found.

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

@ -53,6 +53,30 @@ namespace ICSharpCode.NRefactory.CSharp
return new TypeReferenceExpression { Type = this }.Member(memberName); return new TypeReferenceExpression { Type = this }.Member(memberName);
} }
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>
public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
{
return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
}
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>
public InvocationExpression Invoke(string methodName, params Expression[] arguments)
{
return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
}
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>
public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
{
return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments);
}
public static AstType Create(Type type) public static AstType Create(Type type)
{ {
switch (Type.GetTypeCode(type)) { switch (Type.GetTypeCode(type)) {

5
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
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)
}} }}

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

@ -34,6 +34,11 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
return p != null ? new TypePlaceholder(p) : null; return p != null ? new TypePlaceholder(p) : null;
} }
public AstType ToType()
{
return new TypePlaceholder(this);
}
public static implicit operator Expression(Pattern p) public static implicit operator Expression(Pattern p)
{ {
return p != null ? new ExpressionPlaceholder(p) : null; return p != null ? new ExpressionPlaceholder(p) : null;
@ -64,6 +69,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
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);
}
}
} }

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

@ -57,7 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Body, value); } set { SetChildByRole (Roles.Body, value); }
} }
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole(Roles.Parameter); }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAccessor (this, data); return visitor.VisitAccessor (this, data);
} }

2
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);
} }
} }
} }

14
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -202,8 +202,20 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
WriteCommaSeparatedListInParenthesis(list.SafeCast<ParameterDeclaration, AstNode>(), spaceWithin); WriteCommaSeparatedListInParenthesis(list.SafeCast<ParameterDeclaration, AstNode>(), spaceWithin);
} }
#endif #endif
void WriteCommaSeparatedListInBrackets(IEnumerable<ParameterDeclaration> list, bool spaceWithin)
{
WriteToken("[", AstNode.Roles.LBracket);
if (list.Any()) {
Space(spaceWithin);
WriteCommaSeparatedList(list.SafeCast<ParameterDeclaration, AstNode>());
Space(spaceWithin);
}
WriteToken("]", AstNode.Roles.RBracket);
}
void WriteCommaSeparatedListInBrackets(IEnumerable<Expression> list) void WriteCommaSeparatedListInBrackets(IEnumerable<Expression> list)
{ {
WriteToken("[", AstNode.Roles.LBracket); WriteToken("[", AstNode.Roles.LBracket);
@ -1815,7 +1827,7 @@ namespace ICSharpCode.NRefactory.CSharp
WritePrivateImplementationType(indexerDeclaration.PrivateImplementationType); WritePrivateImplementationType(indexerDeclaration.PrivateImplementationType);
WriteKeyword("this"); WriteKeyword("this");
Space(policy.BeforeMethodDeclarationParentheses); Space(policy.BeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(indexerDeclaration.Parameters, policy.WithinMethodDeclarationParentheses); WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
OpenBrace(policy.PropertyBraceStyle); OpenBrace(policy.PropertyBraceStyle);
// output get/set in their original order // output get/set in their original order
foreach (AstNode node in indexerDeclaration.Children) { foreach (AstNode node in indexerDeclaration.Children) {

Loading…
Cancel
Save