Browse Source

Generate PatternPlaceholder nodes

ast-source-generator
Siegfried Pammer 2 months ago
parent
commit
df1f1051d4
  1. 2
      ICSharpCode.Decompiler.Generators.Attributes/DecompilerAstNodeAttribute.cs
  2. 69
      ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs
  3. 48
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  4. 55
      ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs
  5. 46
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs
  6. 48
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs
  7. 48
      ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs
  8. 48
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs
  9. 48
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs
  10. 48
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs
  11. 48
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs
  12. 48
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs
  13. 48
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs

2
ICSharpCode.Decompiler.Generators.Attributes/DecompilerAstNodeAttribute.cs

@ -4,7 +4,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -4,7 +4,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
public sealed class DecompilerAstNodeAttribute : Attribute
{
public DecompilerAstNodeAttribute(bool hasNullNode) { }
public DecompilerAstNodeAttribute(bool hasNullNode = false, bool hasPatternPlaceholder = false) { }
}
public sealed class ExcludeFromMatchAttribute : Attribute

69
ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs

@ -14,7 +14,7 @@ namespace ICSharpCode.Decompiler.Generators; @@ -14,7 +14,7 @@ namespace ICSharpCode.Decompiler.Generators;
[Generator]
internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator
{
record AstNodeAdditions(string NodeName, bool NeedsAcceptImpls, bool NeedsVisitor, bool NeedsNullNode, int NullNodeBaseCtorParamCount, bool IsTypeNode, string VisitMethodName, string VisitMethodParamType, EquatableArray<(string Member, string TypeName, bool RecursiveMatch, bool MatchAny)>? MembersToMatch);
record AstNodeAdditions(string NodeName, bool NeedsAcceptImpls, bool NeedsVisitor, bool NeedsNullNode, bool NeedsPatternPlaceholder, int NullNodeBaseCtorParamCount, bool IsTypeNode, string VisitMethodName, string VisitMethodParamType, EquatableArray<(string Member, string TypeName, bool RecursiveMatch, bool MatchAny)>? MembersToMatch);
AstNodeAdditions GetAstNodeAdditions(GeneratorAttributeSyntaxContext context, CancellationToken ct)
{
@ -63,6 +63,7 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator @@ -63,6 +63,7 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator
return new(targetSymbol.Name, !targetSymbol.MemberNames.Contains("AcceptVisitor"),
NeedsVisitor: !targetSymbol.IsAbstract && targetSymbol.BaseType!.IsAbstract,
NeedsNullNode: (bool)attribute.ConstructorArguments[0].Value!,
NeedsPatternPlaceholder: (bool)attribute.ConstructorArguments[1].Value!,
NullNodeBaseCtorParamCount: targetSymbol.InstanceConstructors.Min(m => m.Parameters.Length),
IsTypeNode: targetSymbol.Name == "AstType" || targetSymbol.BaseType?.Name == "AstType",
visitMethodName, paramTypeName, membersToMatch?.ToEquatableArray());
@ -75,6 +76,13 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator @@ -75,6 +76,13 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator
builder.AppendLine("namespace ICSharpCode.Decompiler.CSharp.Syntax;");
builder.AppendLine();
if (source.NeedsPatternPlaceholder)
{
builder.AppendLine("using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching;");
}
builder.AppendLine();
builder.AppendLine("#nullable enable");
builder.AppendLine();
@ -140,6 +148,63 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator @@ -140,6 +148,63 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator
}
if (source.NeedsPatternPlaceholder)
{
const string toTypeReferenceCode = @"
public override Decompiler.TypeSystem.ITypeReference ToTypeReference(Resolver.NameLookupMode lookupMode, Decompiler.TypeSystem.InterningProvider? interningProvider = null)
{
throw new System.NotSupportedException();
}";
builder.Append(
$@" public static implicit operator {source.NodeName}?(PatternMatching.Pattern? pattern)
{{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}}
sealed class PatternPlaceholder : {source.NodeName}, INode
{{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{{
this.child = child;
}}
public override NodeType NodeType {{
get {{ return NodeType.Pattern; }}
}}
public override void AcceptVisitor(IAstVisitor visitor)
{{
visitor.VisitPatternPlaceholder(this, child);
}}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{{
return visitor.VisitPatternPlaceholder(this, child);
}}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{{
return visitor.VisitPatternPlaceholder(this, child, data);
}}
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{{
return child.DoMatch(other, match);
}}
bool PatternMatching.INode.DoMatchCollection(Role? role, PatternMatching.INode? pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}}{(source.NodeName == "AstType" ? toTypeReferenceCode : "")}
}}
"
);
}
if (source.NeedsAcceptImpls && source.NeedsVisitor)
{
builder.Append($@" public override void AcceptVisitor(IAstVisitor visitor)
@ -202,7 +267,7 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator @@ -202,7 +267,7 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator
builder.AppendLine("namespace ICSharpCode.Decompiler.CSharp.Syntax;");
source = source
.Concat([new("NullNode", false, true, false, 0, false, "NullNode", "AstNode", null), new("PatternPlaceholder", false, true, false, 0, false, "PatternPlaceholder", "AstNode", null)])
.Concat([new("NullNode", false, true, false, false, 0, false, "NullNode", "AstNode", null), new("PatternPlaceholder", false, true, false, false, 0, false, "PatternPlaceholder", "AstNode", null)])
.ToImmutableArray();
WriteInterface("IAstVisitor", "void", "");

48
ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs

@ -37,58 +37,12 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -37,58 +37,12 @@ using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.CSharp.Syntax
{
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public abstract partial class AstNode : AbstractAnnotatable, IFreezable, INode, ICloneable
{
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
internal static readonly Role<AstNode?> RootRole = new Role<AstNode?>("Root", null);
#region PatternPlaceholder
public static implicit operator AstNode?(PatternMatching.Pattern? pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : AstNode, INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role? role, PatternMatching.INode? pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
AstNode? parent;
AstNode? prevSibling;
AstNode? nextSibling;

55
ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs

@ -16,11 +16,9 @@ @@ -16,11 +16,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.CSharp.Syntax
@ -28,60 +26,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -28,60 +26,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <summary>
/// A type reference in the C# AST.
/// </summary>
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public abstract partial class AstType : AstNode
{
#region PatternPlaceholder
public static implicit operator AstType(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : AstType, INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider)
{
throw new NotSupportedException();
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType {
get { return NodeType.TypeReference; }
}

46
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs

@ -94,52 +94,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -94,52 +94,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
#region PatternPlaceholder
public static implicit operator ArrayInitializerExpression(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : ArrayInitializerExpression, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
}
}

48
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs

@ -27,55 +27,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -27,55 +27,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// This class is useful even though it doesn't provide any additional functionality:
/// It can be used to communicate more information in APIs, e.g. "this subnode will always be an expression"
/// </remarks>
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public abstract partial class Expression : AstNode
{
#region PatternPlaceholder
public static implicit operator Expression(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : Expression, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType {
get {
return NodeType.Expression;

48
ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs

@ -30,55 +30,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -30,55 +30,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <summary>
/// [AttributeTarget: Attributes]
/// </summary>
[DecompilerAstNode(hasNullNode: false)]
[DecompilerAstNode(hasNullNode: false, hasPatternPlaceholder: true)]
public partial class AttributeSection : AstNode
{
#region PatternPlaceholder
public static implicit operator AttributeSection(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : AttributeSection, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType {
get {
return NodeType.Unknown;

48
ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs

@ -31,57 +31,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -31,57 +31,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <summary>
/// { Statements }
/// </summary>
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public partial class BlockStatement : Statement, IEnumerable<Statement>
{
public static readonly Role<Statement> StatementRole = new Role<Statement>("Statement", Statement.Null);
#region PatternPlaceholder
public static implicit operator BlockStatement(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public CSharpTokenNode LBraceToken {
get { return GetChildByRole(Roles.LBrace); }
}

48
ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs

@ -27,55 +27,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -27,55 +27,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// This class is useful even though it doesn't provide any additional functionality:
/// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement"
/// </remarks>
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public abstract partial class Statement : AstNode
{
#region PatternPlaceholder
public static implicit operator Statement(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : Statement, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public new Statement Clone()
{
return (Statement)base.Clone();

48
ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs

@ -72,55 +72,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -72,55 +72,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
[DecompilerAstNode(hasNullNode: false)]
[DecompilerAstNode(hasNullNode: false, hasPatternPlaceholder: true)]
public partial class SwitchSection : AstNode
{
#region PatternPlaceholder
public static implicit operator SwitchSection(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : SwitchSection, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public static readonly Role<CaseLabel> CaseLabelRole = new Role<CaseLabel>("CaseLabel", null);
public override NodeType NodeType {

48
ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs

@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <summary>
/// catch (Type VariableName) { Body }
/// </summary>
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public partial class CatchClause : AstNode
{
public static readonly TokenRole CatchKeywordRole = new TokenRole("catch");
@ -80,52 +80,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -80,52 +80,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public static readonly TokenRole CondLPar = new TokenRole("(");
public static readonly TokenRole CondRPar = new TokenRole(")");
#region PatternPlaceholder
public static implicit operator CatchClause(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : CatchClause, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType {
get {
return NodeType.Unknown;

48
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs

@ -30,7 +30,7 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -30,7 +30,7 @@ using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.CSharp.Syntax
{
[DecompilerAstNode(hasNullNode: false)]
[DecompilerAstNode(hasNullNode: false, hasPatternPlaceholder: true)]
public partial class ParameterDeclaration : AstNode
{
public static readonly Role<AttributeSection> AttributeRole = EntityDeclaration.AttributeRole;
@ -42,52 +42,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -42,52 +42,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public static readonly TokenRole InModifierRole = new TokenRole("in");
public static readonly TokenRole ParamsModifierRole = new TokenRole("params");
#region PatternPlaceholder
public static implicit operator ParameterDeclaration?(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : ParameterDeclaration, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType => NodeType.Unknown;
public AstNodeCollection<AttributeSection> Attributes {

48
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs

@ -27,55 +27,9 @@ @@ -27,55 +27,9 @@
namespace ICSharpCode.Decompiler.CSharp.Syntax
{
[DecompilerAstNode(hasNullNode: true)]
[DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)]
public partial class VariableInitializer : AstNode
{
#region PatternPlaceholder
public static implicit operator VariableInitializer(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : VariableInitializer, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType {
get {
return NodeType.Unknown;

Loading…
Cancel
Save