diff --git a/Directory.Packages.props b/Directory.Packages.props index 4aa51ddaf..822b0c4f0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -14,8 +14,11 @@ + + + diff --git a/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs b/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs new file mode 100644 index 000000000..08b9c19d2 --- /dev/null +++ b/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs @@ -0,0 +1,384 @@ +using System.Collections; +using System.Collections.Immutable; +using System.Text; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; + +namespace ICSharpCode.Decompiler.Generators; + +[Generator] +internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator +{ + 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) + { + var targetSymbol = (INamedTypeSymbol)context.TargetSymbol; + var attribute = context.Attributes.SingleOrDefault(ad => ad.AttributeClass?.Name == "DecompilerAstNodeAttribute")!; + var (visitMethodName, paramTypeName) = targetSymbol.Name switch { + "ErrorExpression" => ("ErrorNode", "AstNode"), + string s when s.Contains("AstType") => (s.Replace("AstType", "Type"), s), + _ => (targetSymbol.Name, targetSymbol.Name), + }; + + List<(string Member, string TypeName, bool RecursiveMatch, bool MatchAny)>? membersToMatch = null; + + if (!targetSymbol.MemberNames.Contains("DoMatch")) + { + membersToMatch = new(); + + var astNodeType = (INamedTypeSymbol)context.SemanticModel.GetSpeculativeSymbolInfo(context.TargetNode.Span.Start, SyntaxFactory.ParseTypeName("AstNode"), SpeculativeBindingOption.BindAsTypeOrNamespace).Symbol!; + + if (targetSymbol.BaseType!.MemberNames.Contains("MatchAttributesAndModifiers")) + membersToMatch.Add(("MatchAttributesAndModifiers", null!, false, false)); + + foreach (var m in targetSymbol.GetMembers()) + { + if (m is not IPropertySymbol property || property.IsIndexer || property.IsOverride) + continue; + if (property.GetAttributes().Any(a => a.AttributeClass?.Name == "ExcludeFromMatchAttribute")) + continue; + if (property.Type.MetadataName is "CSharpTokenNode" or "TextLocation") + continue; + switch (property.Type) + { + case INamedTypeSymbol named when named.IsDerivedFrom(astNodeType) || named.MetadataName == "AstNodeCollection`1": + membersToMatch.Add((property.Name, named.Name, true, false)); + break; + case INamedTypeSymbol { TypeKind: TypeKind.Enum } named when named.GetMembers().Any(_ => _.Name == "Any"): + membersToMatch.Add((property.Name, named.Name, false, true)); + break; + default: + membersToMatch.Add((property.Name, property.Type.Name, false, false)); + break; + } + } + } + + 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()); + } + + void WriteGeneratedMembers(SourceProductionContext context, AstNodeAdditions source) + { + var builder = new StringBuilder(); + + 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(); + + builder.AppendLine($"partial class {source.NodeName}"); + builder.AppendLine("{"); + + if (source.NeedsNullNode) + { + bool needsNew = source.NodeName != "AstNode"; + + builder.AppendLine($" {(needsNew ? "new " : "")}public static readonly {source.NodeName} Null = new Null{source.NodeName}();"); + + builder.AppendLine($@" + sealed class Null{source.NodeName} : {source.NodeName} + {{ + public override NodeType NodeType => NodeType.Unknown; + + public override bool IsNull => true; + + public override void AcceptVisitor(IAstVisitor visitor) + {{ + visitor.VisitNullNode(this); + }} + + public override T AcceptVisitor(IAstVisitor visitor) + {{ + return visitor.VisitNullNode(this); + }} + + public override S AcceptVisitor(IAstVisitor visitor, T data) + {{ + return visitor.VisitNullNode(this, data); + }} + + protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match) + {{ + return other == null || other.IsNull; + }}"); + + if (source.IsTypeNode) + { + builder.AppendLine( + $@" + + public override Decompiler.TypeSystem.ITypeReference ToTypeReference(Resolver.NameLookupMode lookupMode, Decompiler.TypeSystem.InterningProvider? interningProvider = null) + {{ + return Decompiler.TypeSystem.SpecialType.UnknownType; + }}" + ); + } + + if (source.NullNodeBaseCtorParamCount > 0) + { + builder.AppendLine($@" + + public Null{source.NodeName}() : base({string.Join(", ", Enumerable.Repeat("default", source.NullNodeBaseCtorParamCount))}) {{ }}"); + } + + builder.AppendLine($@" + }} + +"); + + } + + 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(IAstVisitor visitor) + {{ + return visitor.VisitPatternPlaceholder(this, child); + }} + + public override S AcceptVisitor(IAstVisitor 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) + {{ + visitor.Visit{source.VisitMethodName}(this); + }} + + public override T AcceptVisitor(IAstVisitor visitor) + {{ + return visitor.Visit{source.VisitMethodName}(this); + }} + + public override S AcceptVisitor(IAstVisitor visitor, T data) + {{ + return visitor.Visit{source.VisitMethodName}(this, data); + }} +"); + } + + if (source.MembersToMatch != null) + { + builder.Append($@" protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match) + {{ + return other is {source.NodeName} o && !o.IsNull"); + + foreach (var (member, typeName, recursive, hasAny) in source.MembersToMatch) + { + if (member == "MatchAttributesAndModifiers") + { + builder.Append($"\r\n\t\t\t&& this.MatchAttributesAndModifiers(o, match)"); + } + else if (recursive) + { + builder.Append($"\r\n\t\t\t&& this.{member}.DoMatch(o.{member}, match)"); + } + else if (hasAny) + { + builder.Append($"\r\n\t\t\t&& (this.{member} == {typeName}.Any || this.{member} == o.{member})"); + } + else if (typeName == "String") + { + builder.Append($"\r\n\t\t\t&& MatchString(this.{member}, o.{member})"); + } + else + { + builder.Append($"\r\n\t\t\t&& this.{member} == o.{member}"); + } + } + + builder.Append(@"; + } +"); + } + + builder.AppendLine("}"); + + context.AddSource(source.NodeName + ".g.cs", SourceText.From(builder.ToString(), Encoding.UTF8)); + } + + void WriteVisitors(SourceProductionContext context, ImmutableArray source) + { + var builder = new StringBuilder(); + + builder.AppendLine("namespace ICSharpCode.Decompiler.CSharp.Syntax;"); + + source = source + .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", ""); + WriteInterface("IAstVisitor", "S", ""); + WriteInterface("IAstVisitor", "S", ", T data"); + + context.AddSource("IAstVisitor.g.cs", SourceText.From(builder.ToString(), Encoding.UTF8)); + + void WriteInterface(string name, string ret, string param) + { + builder.AppendLine($"public interface {name}"); + builder.AppendLine("{"); + + foreach (var type in source.OrderBy(t => t.VisitMethodName)) + { + if (!type.NeedsVisitor) + continue; + + string extParams, paramName; + if (type.VisitMethodName == "PatternPlaceholder") + { + paramName = "placeholder"; + extParams = ", PatternMatching.Pattern pattern" + param; + } + else + { + paramName = char.ToLowerInvariant(type.VisitMethodName[0]) + type.VisitMethodName.Substring(1); + extParams = param; + } + + builder.AppendLine($"\t{ret} Visit{type.VisitMethodName}({type.VisitMethodParamType} {paramName}{extParams});"); + } + + builder.AppendLine("}"); + } + } + + public void Initialize(IncrementalGeneratorInitializationContext context) + { + var astNodeAdditions = context.SyntaxProvider.ForAttributeWithMetadataName( + "ICSharpCode.Decompiler.CSharp.Syntax.DecompilerAstNodeAttribute", + (n, ct) => n is ClassDeclarationSyntax, + GetAstNodeAdditions); + + var visitorMembers = astNodeAdditions.Collect(); + + context + .RegisterPostInitializationOutput(i => i.AddSource("DecompilerSyntaxTreeGeneratorAttributes.g.cs", @" + +using System; + +namespace Microsoft.CodeAnalysis +{ + internal sealed partial class EmbeddedAttribute : global::System.Attribute + { + } +} + +namespace ICSharpCode.Decompiler.CSharp.Syntax +{ + [global::Microsoft.CodeAnalysis.EmbeddedAttribute] + sealed class DecompilerAstNodeAttribute : global::System.Attribute + { + public DecompilerAstNodeAttribute(bool hasNullNode = false, bool hasPatternPlaceholder = false) { } + } + + [global::Microsoft.CodeAnalysis.EmbeddedAttribute] + sealed class ExcludeFromMatchAttribute : global::System.Attribute + { + } +} + +")); + + context.RegisterSourceOutput(astNodeAdditions, WriteGeneratedMembers); + context.RegisterSourceOutput(visitorMembers, WriteVisitors); + } +} + +readonly struct EquatableArray : IEquatable>, IEnumerable + where T : IEquatable +{ + readonly T[] array; + + public EquatableArray(T[] array) + { + this.array = array ?? throw new ArgumentNullException(nameof(array)); + } + + public bool Equals(EquatableArray other) + { + return other.array.AsSpan().SequenceEqual(this.array); + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)array).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return array.GetEnumerator(); + } +} + +static class EquatableArrayExtensions +{ + public static EquatableArray ToEquatableArray(this List array) where T : IEquatable + { + return new EquatableArray(array.ToArray()); + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Generators/ICSharpCode.Decompiler.Generators.csproj b/ICSharpCode.Decompiler.Generators/ICSharpCode.Decompiler.Generators.csproj new file mode 100644 index 000000000..fc882407c --- /dev/null +++ b/ICSharpCode.Decompiler.Generators/ICSharpCode.Decompiler.Generators.csproj @@ -0,0 +1,16 @@ + + + + netstandard2.0 + enable + enable + true + 12 + + + + + + + + diff --git a/ICSharpCode.Decompiler.Generators/IsExternalInit.cs b/ICSharpCode.Decompiler.Generators/IsExternalInit.cs new file mode 100644 index 000000000..7bac4c969 --- /dev/null +++ b/ICSharpCode.Decompiler.Generators/IsExternalInit.cs @@ -0,0 +1,3 @@ +namespace System.Runtime.CompilerServices; + +class IsExternalInit { } diff --git a/ICSharpCode.Decompiler.Generators/RoslynHelpers.cs b/ICSharpCode.Decompiler.Generators/RoslynHelpers.cs new file mode 100644 index 000000000..fa4747f76 --- /dev/null +++ b/ICSharpCode.Decompiler.Generators/RoslynHelpers.cs @@ -0,0 +1,32 @@ +using Microsoft.CodeAnalysis; + +namespace ICSharpCode.Decompiler.Generators; + +public static class RoslynHelpers +{ + public static IEnumerable GetTopLevelTypes(this IAssemblySymbol assembly) + { + foreach (var ns in TreeTraversal.PreOrder(assembly.GlobalNamespace, ns => ns.GetNamespaceMembers())) + { + foreach (var t in ns.GetTypeMembers()) + { + yield return t; + } + } + } + + public static bool IsDerivedFrom(this INamedTypeSymbol type, INamedTypeSymbol baseType) + { + INamedTypeSymbol? t = type; + + while (t != null) + { + if (SymbolEqualityComparer.Default.Equals(t, baseType)) + return true; + + t = t.BaseType; + } + + return false; + } +} diff --git a/ICSharpCode.Decompiler.Generators/TreeTraversal.cs b/ICSharpCode.Decompiler.Generators/TreeTraversal.cs new file mode 100644 index 000000000..4c194383a --- /dev/null +++ b/ICSharpCode.Decompiler.Generators/TreeTraversal.cs @@ -0,0 +1,125 @@ +#nullable enable +// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +namespace ICSharpCode.Decompiler.Generators; + +/// +/// Static helper methods for traversing trees. +/// +internal static class TreeTraversal +{ + /// + /// Converts a tree data structure into a flat list by traversing it in pre-order. + /// + /// The root element of the tree. + /// The function that gets the children of an element. + /// Iterator that enumerates the tree structure in pre-order. + public static IEnumerable PreOrder(T root, Func?> recursion) + { + return PreOrder(new T[] { root }, recursion); + } + + /// + /// Converts a tree data structure into a flat list by traversing it in pre-order. + /// + /// The root elements of the forest. + /// The function that gets the children of an element. + /// Iterator that enumerates the tree structure in pre-order. + public static IEnumerable PreOrder(IEnumerable input, Func?> recursion) + { + Stack> stack = new Stack>(); + try + { + stack.Push(input.GetEnumerator()); + while (stack.Count > 0) + { + while (stack.Peek().MoveNext()) + { + T element = stack.Peek().Current; + yield return element; + IEnumerable? children = recursion(element); + if (children != null) + { + stack.Push(children.GetEnumerator()); + } + } + stack.Pop().Dispose(); + } + } + finally + { + while (stack.Count > 0) + { + stack.Pop().Dispose(); + } + } + } + + /// + /// Converts a tree data structure into a flat list by traversing it in post-order. + /// + /// The root element of the tree. + /// The function that gets the children of an element. + /// Iterator that enumerates the tree structure in post-order. + public static IEnumerable PostOrder(T root, Func?> recursion) + { + return PostOrder(new T[] { root }, recursion); + } + + /// + /// Converts a tree data structure into a flat list by traversing it in post-order. + /// + /// The root elements of the forest. + /// The function that gets the children of an element. + /// Iterator that enumerates the tree structure in post-order. + public static IEnumerable PostOrder(IEnumerable input, Func?> recursion) + { + Stack> stack = new Stack>(); + try + { + stack.Push(input.GetEnumerator()); + while (stack.Count > 0) + { + while (stack.Peek().MoveNext()) + { + T element = stack.Peek().Current; + IEnumerable? children = recursion(element); + if (children != null) + { + stack.Push(children.GetEnumerator()); + } + else + { + yield return element; + } + } + stack.Pop().Dispose(); + if (stack.Count > 0) + yield return stack.Peek().Current; + } + } + finally + { + while (stack.Count > 0) + { + stack.Pop().Dispose(); + } + } + } +} diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs b/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs index b11edf399..605f6b8e7 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs @@ -37,96 +37,12 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public abstract class AstNode : AbstractAnnotatable, IFreezable, INode, ICloneable + [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 RootRole = new Role("Root", null); - #region Null - public static readonly AstNode Null = new NullAstNode(); - - sealed class NullAstNode : AstNode - { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs index a8b8da53a..a8f5cdc97 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs @@ -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,97 +26,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// A type reference in the C# AST. /// - public abstract class AstType : AstNode + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public abstract partial class AstType : AstNode { - #region Null - public new static readonly AstType Null = new NullAstType(); - - sealed class NullAstType : AstType - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - - public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider) - { - return SpecialType.UnknownType; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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; } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs index fbe31464d..d295a515b 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs @@ -31,7 +31,8 @@ using ICSharpCode.Decompiler.CSharp.OutputVisitor; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class CSharpModifierToken : CSharpTokenNode + [DecompilerAstNode(hasNullNode: false)] + public partial class CSharpModifierToken : CSharpTokenNode { Modifiers modifier; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs index 6bbf8a546..e458f1fbc 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs @@ -34,42 +34,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// In all non null c# token nodes the Role of a CSharpToken must be a TokenRole. /// - public class CSharpTokenNode : AstNode + [DecompilerAstNode(hasNullNode: true)] + public partial class CSharpTokenNode : AstNode { - public static new readonly CSharpTokenNode Null = new NullCSharpTokenNode(); - class NullCSharpTokenNode : CSharpTokenNode - { - public override bool IsNull { - get { - return true; - } - } - - public NullCSharpTokenNode() : base(TextLocation.Empty, null) - { - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - public override NodeType NodeType { get { return NodeType.Token; @@ -117,21 +84,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return string.Empty; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCSharpTokenNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCSharpTokenNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCSharpTokenNode(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CSharpTokenNode o = other as CSharpTokenNode; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs index c042a2ca9..33ade4c83 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs @@ -34,7 +34,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class ComposedType : AstType + [DecompilerAstNode(hasNullNode: false)] + public partial class ComposedType : AstType { public static readonly Role AttributeRole = EntityDeclaration.AttributeRole; public static readonly TokenRole RefRole = new TokenRole("ref"); @@ -129,21 +130,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(PointerRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitComposedType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitComposedType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitComposedType(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ComposedType o = other as ComposedType; @@ -230,7 +216,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// [,,,] /// - public class ArraySpecifier : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class ArraySpecifier : AstNode { public override NodeType NodeType { get { @@ -272,21 +259,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBracket); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitArraySpecifier(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitArraySpecifier(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitArraySpecifier(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ArraySpecifier o = other as ArraySpecifier; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs b/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs index 893f015fc..550e913ec 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs @@ -23,7 +23,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Represents a 'cref' reference in XML documentation. /// - public class DocumentationReference : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class DocumentationReference : AstNode { public static readonly Role DeclaringTypeRole = new Role("DeclaringType", AstType.Null); public static readonly Role ConversionOperatorReturnTypeRole = new Role("ConversionOperatorReturnType", AstType.Null); @@ -133,20 +134,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } return this.Parameters.DoMatch(o.Parameters, match); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDocumentationReference(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDocumentationReference(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDocumentationReference(this, data); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs index 633073b36..964a4fd2a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs @@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// [async] delegate(Parameters) {Body} /// - public class AnonymousMethodExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class AnonymousMethodExpression : Expression { public readonly static TokenRole DelegateKeywordRole = new TokenRole("delegate"); public readonly static TokenRole AsyncModifierRole = LambdaExpression.AsyncModifierRole; @@ -93,27 +94,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public AnonymousMethodExpression(BlockStatement body, params ParameterDeclaration[] parameters) : this(body, (IEnumerable)parameters) { } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAnonymousMethodExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAnonymousMethodExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAnonymousMethodExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - AnonymousMethodExpression o = other as AnonymousMethodExpression; - return o != null && this.IsAsync == o.IsAsync && this.HasParameterList == o.HasParameterList - && this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousTypeCreateExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousTypeCreateExpression.cs index e74e2e1af..0160c3b25 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousTypeCreateExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousTypeCreateExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// new { [ExpressionList] } /// - public class AnonymousTypeCreateExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class AnonymousTypeCreateExpression : Expression { public readonly static TokenRole NewKeywordRole = new TokenRole("new"); @@ -65,27 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public AnonymousTypeCreateExpression(params Expression[] initializer) : this((IEnumerable)initializer) { } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAnonymousTypeCreateExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAnonymousTypeCreateExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAnonymousTypeCreateExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - var o = other as AnonymousTypeCreateExpression; - return o != null && this.Initializers.DoMatch(o.Initializers, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs index e4314f001..de1a58ff7 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs @@ -16,13 +16,13 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// new Type[Dimensions] /// - public class ArrayCreateExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ArrayCreateExpression : Expression { public readonly static TokenRole NewKeywordRole = new TokenRole("new"); public readonly static Role AdditionalArraySpecifierRole = new Role("AdditionalArraySpecifier", null); @@ -53,29 +53,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(InitializerRole); } set { SetChildByRole(InitializerRole, value); } } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitArrayCreateExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitArrayCreateExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitArrayCreateExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - ArrayCreateExpression o = other as ArrayCreateExpression; - return o != null && this.Type.DoMatch(o.Type, match) - && this.Arguments.DoMatch(o.Arguments, match) - && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) - && this.Initializer.DoMatch(o.Initializer, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs index f9ce09152..3702f18cb 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs @@ -31,20 +31,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// { Elements } /// - public class ArrayInitializerExpression : Expression + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public partial class ArrayInitializerExpression : Expression { - /// - /// For ease of use purposes in the resolver the ast representation - /// of { a, b, c } is { {a}, {b}, {c} }. - /// If IsSingleElement is true then this array initializer expression is a generated one. - /// That has no meaning in the source code (and contains no brace tokens). - /// - public virtual bool IsSingleElement { - get { - return false; - } - } - public ArrayInitializerExpression() { } @@ -59,39 +48,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.Elements.AddRange(elements); } - #region Null - public new static readonly ArrayInitializerExpression Null = new NullArrayInitializerExpression(); - - sealed class NullArrayInitializerExpression : ArrayInitializerExpression - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - public CSharpTokenNode LBraceToken { get { return GetChildByRole(Roles.LBrace); } } @@ -103,90 +59,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public CSharpTokenNode RBraceToken { get { return GetChildByRole(Roles.RBrace); } } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitArrayInitializerExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitArrayInitializerExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitArrayInitializerExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - ArrayInitializerExpression o = other as ArrayInitializerExpression; - return o != null && this.Elements.DoMatch(o.Elements, match); - } - - public static ArrayInitializerExpression CreateSingleElementInitializer() - { - return new SingleArrayInitializerExpression(); - } - /// - /// Single elements in array initializers are represented with this special class. - /// - class SingleArrayInitializerExpression : ArrayInitializerExpression - { - public override bool IsSingleElement { - get { - return true; - } - } - - } - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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 } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AsExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AsExpression.cs index b01fd4f86..13666c173 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AsExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AsExpression.cs @@ -23,14 +23,13 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.Collections.Generic; - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// Expression as TypeReference /// - public class AsExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class AsExpression : Expression { public readonly static TokenRole AsKeywordRole = new TokenRole("as"); @@ -57,27 +56,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(expression, Roles.Expression); AddChild(type, Roles.Type); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAsExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAsExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAsExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - AsExpression o = other as AsExpression; - return o != null && this.Expression.DoMatch(o.Expression, match) && this.Type.DoMatch(o.Type, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AssignmentExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AssignmentExpression.cs index 378b33bfa..56c4eba2a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AssignmentExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AssignmentExpression.cs @@ -25,7 +25,6 @@ // THE SOFTWARE. using System; -using System.Collections.Generic; using System.Linq.Expressions; namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -33,7 +32,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Left Operator= Right /// - public class AssignmentExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class AssignmentExpression : Expression { // reuse roles from BinaryOperatorExpression public readonly static Role LeftRole = BinaryOperatorExpression.LeftRole; @@ -88,28 +88,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(RightRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAssignmentExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAssignmentExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAssignmentExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - AssignmentExpression o = other as AssignmentExpression; - 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 TokenRole GetOperatorRole(AssignmentOperatorType op) { switch (op) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BaseReferenceExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BaseReferenceExpression.cs index 5084d0e04..ace2c05d9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BaseReferenceExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BaseReferenceExpression.cs @@ -24,13 +24,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// base /// - public class BaseReferenceExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class BaseReferenceExpression : Expression { public TextLocation Location { get; @@ -47,26 +47,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return new TextLocation(Location.Line, Location.Column + "base".Length); } } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitBaseReferenceExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitBaseReferenceExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitBaseReferenceExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - BaseReferenceExpression o = other as BaseReferenceExpression; - return o != null; - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BinaryOperatorExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BinaryOperatorExpression.cs index 1386e1029..af73340e4 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BinaryOperatorExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BinaryOperatorExpression.cs @@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Left Operator Right /// - public class BinaryOperatorExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class BinaryOperatorExpression : Expression { public readonly static TokenRole BitwiseAndRole = new TokenRole("&"); public readonly static TokenRole BitwiseOrRole = new TokenRole("|"); @@ -90,28 +91,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(RightRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitBinaryOperatorExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitBinaryOperatorExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitBinaryOperatorExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - BinaryOperatorExpression o = other as BinaryOperatorExpression; - 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 TokenRole GetOperatorRole(BinaryOperatorType op) { switch (op) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CastExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CastExpression.cs index f3bd22ec2..b8d05a715 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CastExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CastExpression.cs @@ -23,14 +23,13 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.Collections.Generic; - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// (CastTo)Expression /// - public class CastExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class CastExpression : Expression { public CSharpTokenNode LParToken { get { return GetChildByRole(Roles.LPar); } @@ -59,27 +58,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(castToType, Roles.Type); AddChild(expression, Roles.Expression); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCastExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCastExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCastExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - CastExpression o = other as CastExpression; - return o != null && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CheckedExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CheckedExpression.cs index baff6c51a..dacceb8c9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CheckedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CheckedExpression.cs @@ -24,13 +24,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// checked(Expression) /// - public class CheckedExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class CheckedExpression : Expression { public readonly static TokenRole CheckedKeywordRole = new TokenRole("checked"); @@ -59,26 +59,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { AddChild(expression, Roles.Expression); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCheckedExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCheckedExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCheckedExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - CheckedExpression o = other as CheckedExpression; - return o != null && this.Expression.DoMatch(o.Expression, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ConditionalExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ConditionalExpression.cs index a1576e5cc..809312b9e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ConditionalExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ConditionalExpression.cs @@ -23,14 +23,13 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.Collections.Generic; - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// Condition ? TrueExpression : FalseExpression /// - public class ConditionalExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ConditionalExpression : Expression { public readonly static Role ConditionRole = Roles.Condition; public readonly static TokenRole QuestionMarkRole = new TokenRole("?"); @@ -71,26 +70,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(trueExpression, TrueRole); AddChild(falseExpression, FalseRole); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitConditionalExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitConditionalExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitConditionalExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - ConditionalExpression o = other as ConditionalExpression; - return o != null && this.Condition.DoMatch(o.Condition, match) && this.TrueExpression.DoMatch(o.TrueExpression, match) && this.FalseExpression.DoMatch(o.FalseExpression, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DeclarationExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DeclarationExpression.cs index 558456524..c24382f8d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DeclarationExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DeclarationExpression.cs @@ -16,14 +16,13 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// TypeName VariableDesignation /// - public class DeclarationExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class DeclarationExpression : Expression { public AstType Type { get { return GetChildByRole(Roles.Type); } @@ -34,27 +33,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.VariableDesignationRole); } set { SetChildByRole(Roles.VariableDesignationRole, value); } } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDeclarationExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDeclarationExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDeclarationExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, Match match) - { - return other is DeclarationExpression o - && Type.DoMatch(o.Type, match) - && Designation.DoMatch(o.Designation, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DecompilerAstNodeAttribute.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DecompilerAstNodeAttribute.cs new file mode 100644 index 000000000..a0dd2b2ae --- /dev/null +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DecompilerAstNodeAttribute.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2017 Siegfried Pammer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + + + + + + + +namespace ICSharpCode.Decompiler.CSharp.Syntax +{ + class DecompilerAstNodeAttribute : System.Attribute + { + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DefaultValueExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DefaultValueExpression.cs index 372325a40..6e310505e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DefaultValueExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DefaultValueExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// default(Type) /// - public class DefaultValueExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class DefaultValueExpression : Expression { public readonly static TokenRole DefaultKeywordRole = new TokenRole("default"); @@ -59,27 +60,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { AddChild(type, Roles.Type); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDefaultValueExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDefaultValueExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDefaultValueExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - DefaultValueExpression o = other as DefaultValueExpression; - return o != null && this.Type.DoMatch(o.Type, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DirectionExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DirectionExpression.cs index e92115530..9f07667ee 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DirectionExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/DirectionExpression.cs @@ -38,7 +38,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// ref Expression /// - public class DirectionExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class DirectionExpression : Expression { public readonly static TokenRole RefKeywordRole = new TokenRole("ref"); public readonly static TokenRole OutKeywordRole = new TokenRole("out"); @@ -77,26 +78,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.FieldDirection = direction; AddChild(expression, Roles.Expression); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDirectionExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDirectionExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDirectionExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - DirectionExpression o = other as DirectionExpression; - return o != null && this.FieldDirection == o.FieldDirection && this.Expression.DoMatch(o.Expression, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ErrorExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ErrorExpression.cs index 89f9fcfdd..956ec76b7 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ErrorExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ErrorExpression.cs @@ -23,11 +23,10 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; - namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class ErrorExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ErrorExpression : Expression { public TextLocation Location { get; set; } @@ -43,11 +42,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public string Error { - get; - private set; - } - public ErrorExpression() { } @@ -56,27 +50,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { AddChild(new Comment(error, CommentType.MultiLine), Roles.Comment); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitErrorNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitErrorNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitErrorNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - var o = other as ErrorExpression; - return o != null; - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs index c5d73352e..f73e50549 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System; -using System.Collections.Generic; namespace ICSharpCode.Decompiler.CSharp.Syntax { @@ -28,87 +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" /// - public abstract class Expression : AstNode + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public abstract partial class Expression : AstNode { - #region Null - public new static readonly Expression Null = new NullExpression(); - - sealed class NullExpression : Expression - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IdentifierExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IdentifierExpression.cs index 76fc8c2a5..e6da3ddd6 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IdentifierExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IdentifierExpression.cs @@ -26,7 +26,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class IdentifierExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class IdentifierExpression : Expression { public IdentifierExpression() { @@ -63,26 +64,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public AstNodeCollection TypeArguments { get { return GetChildrenByRole(Roles.TypeArgument); } } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitIdentifierExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitIdentifierExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitIdentifierExpression(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - IdentifierExpression o = other as IdentifierExpression; - return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IndexerExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IndexerExpression.cs index e688b2a74..3d3d01420 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IndexerExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IndexerExpression.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Target[Arguments] /// - public class IndexerExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class IndexerExpression : Expression { public Expression Target { get { return GetChildByRole(Roles.TargetExpression); } @@ -70,21 +71,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitIndexerExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitIndexerExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitIndexerExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { IndexerExpression o = other as IndexerExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs index 562755a0a..b790676f5 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class InterpolatedStringExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class InterpolatedStringExpression : Expression { public static readonly TokenRole OpenQuote = new TokenRole("$\""); public static readonly TokenRole CloseQuote = new TokenRole("\""); @@ -25,21 +24,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Content.AddRange(content); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitInterpolatedStringExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitInterpolatedStringExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitInterpolatedStringExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { InterpolatedStringExpression o = other as InterpolatedStringExpression; @@ -47,41 +31,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public abstract class InterpolatedStringContent : AstNode + [DecompilerAstNode(hasNullNode: true)] + public abstract partial class InterpolatedStringContent : AstNode { - #region Null - public new static readonly InterpolatedStringContent Null = new NullInterpolatedStringContent(); - - sealed class NullInterpolatedStringContent : InterpolatedStringContent - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - public new static readonly Role Role = new Role("InterpolatedStringContent", Syntax.InterpolatedStringContent.Null); public override NodeType NodeType => NodeType.Unknown; @@ -90,7 +42,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// { Expression , Alignment : Suffix } /// - public class Interpolation : InterpolatedStringContent + [DecompilerAstNode(hasNullNode: false)] + public partial class Interpolation : InterpolatedStringContent { public static readonly TokenRole LBrace = new TokenRole("{"); public static readonly TokenRole RBrace = new TokenRole("}"); @@ -124,21 +77,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Suffix = suffix; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitInterpolation(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitInterpolation(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitInterpolation(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { Interpolation o = other as Interpolation; @@ -146,7 +84,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class InterpolatedStringText : InterpolatedStringContent + [DecompilerAstNode(hasNullNode: false)] + public partial class InterpolatedStringText : InterpolatedStringContent { public string Text { get; set; } @@ -160,21 +99,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Text = text; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitInterpolatedStringText(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitInterpolatedStringText(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitInterpolatedStringText(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { InterpolatedStringText o = other as InterpolatedStringText; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InvocationExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InvocationExpression.cs index 3ed91cefc..41e0c782a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InvocationExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InvocationExpression.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Target(Arguments) /// - public class InvocationExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class InvocationExpression : Expression { public Expression Target { get { return GetChildByRole(Roles.TargetExpression); } @@ -50,21 +51,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RPar); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitInvocationExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitInvocationExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitInvocationExpression(this, data); - } - public InvocationExpression() { } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IsExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IsExpression.cs index fa1bea0bc..5624ec68b 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IsExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/IsExpression.cs @@ -23,14 +23,13 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.Collections.Generic; - namespace ICSharpCode.Decompiler.CSharp.Syntax { /// /// Expression is Type /// - public class IsExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class IsExpression : Expression { public readonly static TokenRole IsKeywordRole = new TokenRole("is"); @@ -58,22 +57,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(type, Roles.Type); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitIsExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitIsExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitIsExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { IsExpression o = other as IsExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/LambdaExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/LambdaExpression.cs index 8782aa1d8..2b49a1569 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/LambdaExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/LambdaExpression.cs @@ -29,7 +29,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// [async] Parameters => Body /// - public class LambdaExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class LambdaExpression : Expression { public static readonly Role AttributeRole = new Role("Attribute", null); public readonly static TokenRole AsyncModifierRole = new TokenRole("async"); @@ -67,21 +68,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(BodyRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitLambdaExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitLambdaExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitLambdaExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { LambdaExpression o = other as LambdaExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/MemberReferenceExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/MemberReferenceExpression.cs index fcda03b54..656710e61 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/MemberReferenceExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/MemberReferenceExpression.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Target.MemberName /// - public class MemberReferenceExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class MemberReferenceExpression : Expression { public Expression Target { get { @@ -97,21 +98,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitMemberReferenceExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitMemberReferenceExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitMemberReferenceExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { MemberReferenceExpression o = other as MemberReferenceExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedArgumentExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedArgumentExpression.cs index 5f3fb3627..cce206d08 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedArgumentExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedArgumentExpression.cs @@ -23,7 +23,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// Represents a named argument passed to a method or attribute. /// name: expression /// - public class NamedArgumentExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class NamedArgumentExpression : Expression { public NamedArgumentExpression() { @@ -62,21 +63,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNamedArgumentExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNamedArgumentExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNamedArgumentExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { NamedArgumentExpression o = other as NamedArgumentExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedExpression.cs index d8fe23df8..87d278d13 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NamedExpression.cs @@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// This isn't the same as 'assign' even though it has the same syntax. /// This expression is used in object initializers and for named attribute arguments [Attr(FieldName = value)]. /// - public class NamedExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class NamedExpression : Expression { public NamedExpression() { @@ -71,21 +72,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNamedExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNamedExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNamedExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { var o = other as NamedExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NullReferenceExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NullReferenceExpression.cs index ee67fb20f..a136fc800 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NullReferenceExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/NullReferenceExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// null /// - public class NullReferenceExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class NullReferenceExpression : Expression { TextLocation location; public override TextLocation StartLocation { @@ -60,21 +61,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.location = location; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullReferenceExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullReferenceExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullReferenceExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { NullReferenceExpression o = other as NullReferenceExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ObjectCreateExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ObjectCreateExpression.cs index f559f6a89..c96b9428e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ObjectCreateExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ObjectCreateExpression.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// new Type(Arguments) { Initializer } /// - public class ObjectCreateExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ObjectCreateExpression : Expression { public readonly static TokenRole NewKeywordRole = new TokenRole("new"); public readonly static Role InitializerRole = ArrayCreateExpression.InitializerRole; @@ -82,21 +83,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitObjectCreateExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitObjectCreateExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitObjectCreateExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ObjectCreateExpression o = other as ObjectCreateExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/OutVarDeclarationExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/OutVarDeclarationExpression.cs index 022987e80..28fb3692d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/OutVarDeclarationExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/OutVarDeclarationExpression.cs @@ -21,7 +21,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// out type expression /// - public class OutVarDeclarationExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class OutVarDeclarationExpression : Expression { public readonly static TokenRole OutKeywordRole = DirectionExpression.OutKeywordRole; @@ -49,21 +50,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.Variable = new VariableInitializer(name); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitOutVarDeclarationExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitOutVarDeclarationExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitOutVarDeclarationExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { var o = other as OutVarDeclarationExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ParenthesizedExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ParenthesizedExpression.cs index b662ab3d4..cf17f350e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ParenthesizedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ParenthesizedExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// ( Expression ) /// - public class ParenthesizedExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ParenthesizedExpression : Expression { public CSharpTokenNode LParToken { get { return GetChildByRole(Roles.LPar); } @@ -54,21 +55,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Expression = expr; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitParenthesizedExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitParenthesizedExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitParenthesizedExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ParenthesizedExpression o = other as ParenthesizedExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PointerReferenceExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PointerReferenceExpression.cs index d678cdaf8..5417245d2 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PointerReferenceExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PointerReferenceExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Target->MemberName /// - public class PointerReferenceExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class PointerReferenceExpression : Expression { public readonly static TokenRole ArrowRole = new TokenRole("->"); @@ -65,21 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(Roles.TypeArgument); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitPointerReferenceExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitPointerReferenceExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitPointerReferenceExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { PointerReferenceExpression o = other as PointerReferenceExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs index a1e8fcc3b..153493737 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs @@ -24,8 +24,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; - using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -48,7 +46,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Represents a literal value. /// - public class PrimitiveExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class PrimitiveExpression : Expression { public static readonly object AnyValue = new object(); @@ -95,21 +94,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.format = format; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitPrimitiveExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitPrimitiveExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitPrimitiveExpression(this, data); - } - unsafe static TextLocation AdvanceLocation(TextLocation startLocation, string str) { int line = startLocation.Line; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs index 87315b01f..46fc9c106 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs @@ -18,62 +18,15 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class QueryExpression : Expression + [DecompilerAstNode(hasNullNode: true)] + public partial class QueryExpression : Expression { public static readonly Role ClauseRole = new Role("Clause", null); - #region Null - public new static readonly QueryExpression Null = new NullQueryExpression(); - - sealed class NullQueryExpression : QueryExpression - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - public AstNodeCollection Clauses { get { return GetChildrenByRole(ClauseRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryExpression o = other as QueryExpression; @@ -106,7 +59,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// new QuerySelectClause(e) /// } /// - public class QueryContinuationClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryContinuationClause : QueryClause { public static readonly Role PrecedingQueryRole = new Role("PrecedingQuery", QueryExpression.Null); public static readonly TokenRole IntoKeywordRole = new TokenRole("into"); @@ -133,21 +87,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Identifier); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryContinuationClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryContinuationClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryContinuationClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryContinuationClause o = other as QueryContinuationClause; @@ -155,7 +94,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class QueryFromClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryFromClause : QueryClause { public static readonly TokenRole FromKeywordRole = new TokenRole("from"); public static readonly TokenRole InKeywordRole = new TokenRole("in"); @@ -191,21 +131,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryFromClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryFromClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryFromClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryFromClause o = other as QueryFromClause; @@ -214,7 +139,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class QueryLetClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryLetClause : QueryClause { public readonly static TokenRole LetKeywordRole = new TokenRole("let"); @@ -244,21 +170,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryLetClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryLetClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryLetClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryLetClause o = other as QueryLetClause; @@ -267,7 +178,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } - public class QueryWhereClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryWhereClause : QueryClause { public readonly static TokenRole WhereKeywordRole = new TokenRole("where"); @@ -280,21 +192,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Condition, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryWhereClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryWhereClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryWhereClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryWhereClause o = other as QueryWhereClause; @@ -305,7 +202,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Represents a join or group join clause. /// - public class QueryJoinClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryJoinClause : QueryClause { public static readonly TokenRole JoinKeywordRole = new TokenRole("join"); public static readonly Role TypeRole = Roles.Type; @@ -389,21 +287,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(IntoIdentifierRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryJoinClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryJoinClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryJoinClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryJoinClause o = other as QueryJoinClause; @@ -415,7 +298,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class QueryOrderClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryOrderClause : QueryClause { public static readonly TokenRole OrderbyKeywordRole = new TokenRole("orderby"); public static readonly Role OrderingRole = new Role("Ordering", null); @@ -428,21 +312,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(OrderingRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryOrderClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryOrderClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryOrderClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryOrderClause o = other as QueryOrderClause; @@ -450,7 +319,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class QueryOrdering : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryOrdering : AstNode { public readonly static TokenRole AscendingKeywordRole = new TokenRole("ascending"); public readonly static TokenRole DescendingKeywordRole = new TokenRole("descending"); @@ -473,21 +343,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return Direction == QueryOrderingDirection.Ascending ? GetChildByRole(AscendingKeywordRole) : GetChildByRole(DescendingKeywordRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryOrdering(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryOrdering(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryOrdering(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryOrdering o = other as QueryOrdering; @@ -502,7 +357,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Descending } - public class QuerySelectClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QuerySelectClause : QueryClause { public readonly static TokenRole SelectKeywordRole = new TokenRole("select"); @@ -515,21 +371,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQuerySelectClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQuerySelectClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQuerySelectClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QuerySelectClause o = other as QuerySelectClause; @@ -537,7 +378,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class QueryGroupClause : QueryClause + [DecompilerAstNode(hasNullNode: false)] + public partial class QueryGroupClause : QueryClause { public static readonly TokenRole GroupKeywordRole = new TokenRole("group"); public static readonly Role ProjectionRole = new Role("Projection", Expression.Null); @@ -562,21 +404,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(KeyRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitQueryGroupClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitQueryGroupClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitQueryGroupClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { QueryGroupClause o = other as QueryGroupClause; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/RecursivePatternExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/RecursivePatternExpression.cs index 3a26d735b..7d5a06552 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/RecursivePatternExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/RecursivePatternExpression.cs @@ -20,7 +20,8 @@ using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class RecursivePatternExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class RecursivePatternExpression : Expression { public static readonly Role SubPatternRole = new Role("SubPattern", Syntax.Expression.Null); @@ -40,21 +41,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public bool IsPositional { get; set; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitRecursivePatternExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitRecursivePatternExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitRecursivePatternExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is RecursivePatternExpression o diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SizeOfExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SizeOfExpression.cs index b5daa0a9f..817c6c208 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SizeOfExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SizeOfExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// sizeof(Type) /// - public class SizeOfExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class SizeOfExpression : Expression { public readonly static TokenRole SizeofKeywordRole = new TokenRole("sizeof"); @@ -60,21 +61,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(type, Roles.Type); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSizeOfExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSizeOfExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSizeOfExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { SizeOfExpression o = other as SizeOfExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/StackAllocExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/StackAllocExpression.cs index f3c1c9b85..86a6c4812 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/StackAllocExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/StackAllocExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// stackalloc Type[Count] /// - public class StackAllocExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class StackAllocExpression : Expression { public readonly static TokenRole StackallocKeywordRole = new TokenRole("stackalloc"); public readonly static Role InitializerRole = new Role("Initializer", ArrayInitializerExpression.Null); @@ -62,21 +63,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(InitializerRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitStackAllocExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitStackAllocExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitStackAllocExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { StackAllocExpression o = other as StackAllocExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs index ca66a0796..c319e8f2f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs @@ -22,7 +22,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Expression switch { SwitchSections } /// - public class SwitchExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class SwitchExpression : Expression { public static readonly TokenRole SwitchKeywordRole = new TokenRole("switch"); public static readonly Role SwitchSectionRole = new Role("SwitchSection", null); @@ -48,21 +49,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBrace); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSwitchExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSwitchExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSwitchExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { SwitchExpression o = other as SwitchExpression; @@ -73,7 +59,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Pattern => Expression /// - public class SwitchExpressionSection : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class SwitchExpressionSection : AstNode { public static readonly Role PatternRole = new Role("Pattern", Expression.Null); public static readonly Role BodyRole = new Role("Body", Expression.Null); @@ -94,21 +81,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public override NodeType NodeType => NodeType.Unknown; - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSwitchExpressionSection(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSwitchExpressionSection(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSwitchExpressionSection(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { SwitchExpressionSection o = other as SwitchExpressionSection; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThisReferenceExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThisReferenceExpression.cs index db61e2dad..53b9aafde 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThisReferenceExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThisReferenceExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// this /// - public class ThisReferenceExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ThisReferenceExpression : Expression { public TextLocation Location { get; @@ -48,21 +49,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitThisReferenceExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitThisReferenceExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitThisReferenceExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ThisReferenceExpression o = other as ThisReferenceExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThrowExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThrowExpression.cs index 736d2da6d..5bd7b19cf 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThrowExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ThrowExpression.cs @@ -21,7 +21,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// throw Expression /// - public class ThrowExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class ThrowExpression : Expression { public static readonly TokenRole ThrowKeywordRole = ThrowStatement.ThrowKeywordRole; @@ -43,21 +44,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(expression, Roles.Expression); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitThrowExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitThrowExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitThrowExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ThrowExpression o = other as ThrowExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TupleExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TupleExpression.cs index 143726af4..14aa07d04 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TupleExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TupleExpression.cs @@ -16,33 +16,17 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; - using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class TupleExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class TupleExpression : Expression { public AstNodeCollection Elements { get { return GetChildrenByRole(Roles.Expression); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTupleExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTupleExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTupleExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is TupleExpression tuple diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeOfExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeOfExpression.cs index b6605ab63..6bdd47a1f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeOfExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeOfExpression.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// typeof(Type) /// - public class TypeOfExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class TypeOfExpression : Expression { public readonly static TokenRole TypeofKeywordRole = new TokenRole("typeof"); @@ -61,21 +62,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(type, Roles.Type); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTypeOfExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTypeOfExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTypeOfExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { TypeOfExpression o = other as TypeOfExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeReferenceExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeReferenceExpression.cs index 57c8ea9fa..bf874b2d2 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeReferenceExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/TypeReferenceExpression.cs @@ -23,28 +23,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// Represents an AstType as an expression. /// This is used when calling a method on a primitive type: "int.Parse()" /// - public class TypeReferenceExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class TypeReferenceExpression : Expression { public AstType Type { get { return GetChildByRole(Roles.Type); } set { SetChildByRole(Roles.Type, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTypeReferenceExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTypeReferenceExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTypeReferenceExpression(this, data); - } - public TypeReferenceExpression() { } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UnaryOperatorExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UnaryOperatorExpression.cs index 460f9a421..6d3cb7972 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UnaryOperatorExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UnaryOperatorExpression.cs @@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Operator Expression /// - public class UnaryOperatorExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class UnaryOperatorExpression : Expression { public readonly static TokenRole NotRole = new TokenRole("!"); public readonly static TokenRole BitNotRole = new TokenRole("~"); @@ -72,21 +73,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUnaryOperatorExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUnaryOperatorExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUnaryOperatorExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UnaryOperatorExpression o = other as UnaryOperatorExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UncheckedExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UncheckedExpression.cs index aa8160127..8cbe40f89 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UncheckedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UncheckedExpression.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// unchecked(Expression) /// - public class UncheckedExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class UncheckedExpression : Expression { public readonly static TokenRole UncheckedKeywordRole = new TokenRole("unchecked"); @@ -60,21 +61,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(expression, Roles.Expression); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUncheckedExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUncheckedExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUncheckedExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UncheckedExpression o = other as UncheckedExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UndocumentedExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UndocumentedExpression.cs index 7de290d8d..489613a64 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UndocumentedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/UndocumentedExpression.cs @@ -39,7 +39,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Represents undocumented expressions. /// - public class UndocumentedExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class UndocumentedExpression : Expression { public readonly static TokenRole ArglistKeywordRole = new TokenRole("__arglist"); public readonly static TokenRole RefvalueKeywordRole = new TokenRole("__refvalue"); @@ -80,21 +81,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RPar); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUndocumentedExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUndocumentedExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUndocumentedExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UndocumentedExpression o = other as UndocumentedExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/WithInitializerExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/WithInitializerExpression.cs index 809dfb367..3a780b4a3 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/WithInitializerExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/WithInitializerExpression.cs @@ -23,7 +23,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Expression with Initializer /// - public class WithInitializerExpression : Expression + [DecompilerAstNode(hasNullNode: false)] + public partial class WithInitializerExpression : Expression { public readonly static TokenRole WithKeywordRole = new TokenRole("with"); public readonly static Role InitializerRole = ArrayCreateExpression.InitializerRole; @@ -42,21 +43,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(InitializerRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitWithInitializerExpression(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitWithInitializerExpression(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitWithInitializerExpression(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is WithInitializerExpression o diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/FunctionPointerAstType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/FunctionPointerAstType.cs index 96aee3ee9..743bbbe06 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/FunctionPointerAstType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/FunctionPointerAstType.cs @@ -31,7 +31,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class FunctionPointerAstType : AstType + [DecompilerAstNode(hasNullNode: false)] + public partial class FunctionPointerAstType : AstType { public static readonly TokenRole PointerRole = new TokenRole("*"); public static readonly Role CallingConventionRole = new Role("CallConv", AstType.Null); @@ -51,21 +52,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Type, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitFunctionPointerType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitFunctionPointerType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFunctionPointerType(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { return other is FunctionPointerAstType o diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs index b07bca2b2..2d2704df5 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Attribute(Arguments) /// - public class Attribute : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class Attribute : AstNode { public override NodeType NodeType { get { @@ -62,21 +63,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAttribute(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAttribute(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAttribute(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { Attribute o = other as Attribute; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs index cf8658fe0..2b74052b1 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs @@ -30,54 +30,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// [AttributeTarget: Attributes] /// - public class AttributeSection : AstNode + [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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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; @@ -114,21 +69,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBracket); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAttributeSection(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAttributeSection(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAttributeSection(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { AttributeSection o = other as AttributeSection; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs index b2a84f0ff..c2aa2691d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs @@ -51,7 +51,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax MultiLineDocumentation } - public class Comment : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class Comment : AstNode { public override NodeType NodeType { get { @@ -128,21 +129,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.endLocation = endLocation; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitComment(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitComment(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitComment(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { Comment o = other as Comment; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs index 4b0c18618..ee2a78ad1 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs @@ -33,7 +33,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// new(), struct and class constraints are represented using a PrimitiveType "new", "struct" or "class" /// - public class Constraint : AstNode + [DecompilerAstNode(hasNullNode: true)] + public partial class Constraint : AstNode { public override NodeType NodeType { get { return NodeType.Unknown; } @@ -58,21 +59,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitConstraint(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitConstraint(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitConstraint(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { Constraint o = other as Constraint; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs index 0d85f5a59..72246b096 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// delegate ReturnType Name<TypeParameters>(Parameters) where Constraints; /// - public class DelegateDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class DelegateDeclaration : EntityDeclaration { public override NodeType NodeType { get { return NodeType.TypeDeclaration; } @@ -65,21 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(Roles.Constraint); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDelegateDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDelegateDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDelegateDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { DelegateDeclaration o = other as DelegateDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs index 353e71f2c..ca82555b3 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// extern alias IDENTIFIER; /// - public class ExternAliasDeclaration : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class ExternAliasDeclaration : AstNode { public override NodeType NodeType { get { @@ -68,21 +69,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitExternAliasDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitExternAliasDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitExternAliasDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { var o = other as ExternAliasDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs index b41e9f882..0b319e65c 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// namespace Name { Members } /// - public class NamespaceDeclaration : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class NamespaceDeclaration : AstNode { public static readonly Role MemberRole = SyntaxTree.MemberRole; public static readonly Role NamespaceNameRole = new Role("NamespaceName", AstType.Null); @@ -135,21 +136,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(child, MemberRole); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNamespaceDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNamespaceDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNamespaceDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { NamespaceDeclaration o = other as NamespaceDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs index a1b175d1c..3ba9af307 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs @@ -46,7 +46,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Line = 12 } - public class LinePreprocessorDirective : PreProcessorDirective + [DecompilerAstNode(hasNullNode: false)] + public partial class LinePreprocessorDirective : PreProcessorDirective { public int LineNumber { get; @@ -67,7 +68,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class PragmaWarningPreprocessorDirective : PreProcessorDirective + [DecompilerAstNode(hasNullNode: false)] + public partial class PragmaWarningPreprocessorDirective : PreProcessorDirective { public static readonly Role WarningRole = new Role("Warning", null); @@ -125,7 +127,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class PreProcessorDirective : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class PreProcessorDirective : AstNode { public override NodeType NodeType { get { @@ -178,21 +181,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.Argument = argument; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitPreProcessorDirective(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitPreProcessorDirective(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitPreProcessorDirective(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { PreProcessorDirective o = other as PreProcessorDirective; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs index a60d12843..32d00fdb4 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs @@ -47,7 +47,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// class Name<TypeParameters> : BaseTypes where Constraints; /// - public class TypeDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class TypeDeclaration : EntityDeclaration { public override NodeType NodeType { get { return NodeType.TypeDeclaration; } @@ -132,21 +133,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBrace); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTypeDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTypeDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTypeDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { TypeDeclaration o = other as TypeDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs index db5c622cf..eba6864a8 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs @@ -27,7 +27,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// Note: mirroring the C# syntax, constraints are not part of the type parameter declaration, but belong /// to the parent type or method. /// - public class TypeParameterDeclaration : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class TypeParameterDeclaration : AstNode { public static readonly Role AttributeRole = EntityDeclaration.AttributeRole; public static readonly TokenRole OutVarianceKeywordRole = new TokenRole("out"); @@ -89,21 +90,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Name = name; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTypeParameterDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTypeParameterDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTypeParameterDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { TypeParameterDeclaration o = other as TypeParameterDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs index 1b3ab140f..2a90d0023 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// using Alias = Import; /// - public class UsingAliasDeclaration : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class UsingAliasDeclaration : AstNode { public static readonly TokenRole UsingKeywordRole = new TokenRole("using"); public static readonly Role AliasRole = new Role("Alias", Identifier.Null); @@ -84,21 +85,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(import, ImportRole); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUsingAliasDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUsingAliasDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUsingAliasDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UsingAliasDeclaration o = other as UsingAliasDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs index d7246003c..f337e3466 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs @@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// using Import; /// - public class UsingDeclaration : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class UsingDeclaration : AstNode { public static readonly TokenRole UsingKeywordRole = new TokenRole("using"); public static readonly Role ImportRole = new Role("Import", AstType.Null); @@ -100,21 +101,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(import, ImportRole); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUsingDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUsingDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUsingDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UsingDeclaration o = other as UsingDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/IAstVisitor.cs b/ICSharpCode.Decompiler/CSharp/Syntax/IAstVisitor.cs deleted file mode 100644 index 37dfd40a3..000000000 --- a/ICSharpCode.Decompiler/CSharp/Syntax/IAstVisitor.cs +++ /dev/null @@ -1,468 +0,0 @@ -// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - - -namespace ICSharpCode.Decompiler.CSharp.Syntax -{ - /// - /// AST visitor. - /// - public interface IAstVisitor - { - void VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression); - void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression); - void VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression); - void VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression); - void VisitAsExpression(AsExpression asExpression); - void VisitAssignmentExpression(AssignmentExpression assignmentExpression); - void VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression); - void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression); - void VisitCastExpression(CastExpression castExpression); - void VisitCheckedExpression(CheckedExpression checkedExpression); - void VisitConditionalExpression(ConditionalExpression conditionalExpression); - void VisitDeclarationExpression(DeclarationExpression declarationExpression); - void VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression); - void VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression); - void VisitDirectionExpression(DirectionExpression directionExpression); - void VisitIdentifierExpression(IdentifierExpression identifierExpression); - void VisitIndexerExpression(IndexerExpression indexerExpression); - void VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression); - void VisitInvocationExpression(InvocationExpression invocationExpression); - void VisitIsExpression(IsExpression isExpression); - void VisitLambdaExpression(LambdaExpression lambdaExpression); - void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression); - void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression); - void VisitNamedExpression(NamedExpression namedExpression); - void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression); - void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression); - void VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression); - void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression); - void VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression); - void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression); - void VisitSizeOfExpression(SizeOfExpression sizeOfExpression); - void VisitStackAllocExpression(StackAllocExpression stackAllocExpression); - void VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression); - void VisitThrowExpression(ThrowExpression throwExpression); - void VisitTupleExpression(TupleExpression tupleExpression); - void VisitTypeOfExpression(TypeOfExpression typeOfExpression); - void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression); - void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression); - void VisitUncheckedExpression(UncheckedExpression uncheckedExpression); - void VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression); - void VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression); - - void VisitQueryExpression(QueryExpression queryExpression); - void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause); - void VisitQueryFromClause(QueryFromClause queryFromClause); - void VisitQueryLetClause(QueryLetClause queryLetClause); - void VisitQueryWhereClause(QueryWhereClause queryWhereClause); - void VisitQueryJoinClause(QueryJoinClause queryJoinClause); - void VisitQueryOrderClause(QueryOrderClause queryOrderClause); - void VisitQueryOrdering(QueryOrdering queryOrdering); - void VisitQuerySelectClause(QuerySelectClause querySelectClause); - void VisitQueryGroupClause(QueryGroupClause queryGroupClause); - - void VisitAttribute(Attribute attribute); - void VisitAttributeSection(AttributeSection attributeSection); - void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration); - void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration); - void VisitTypeDeclaration(TypeDeclaration typeDeclaration); - void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration); - void VisitUsingDeclaration(UsingDeclaration usingDeclaration); - void VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration); - - void VisitBlockStatement(BlockStatement blockStatement); - void VisitBreakStatement(BreakStatement breakStatement); - void VisitCheckedStatement(CheckedStatement checkedStatement); - void VisitContinueStatement(ContinueStatement continueStatement); - void VisitDoWhileStatement(DoWhileStatement doWhileStatement); - void VisitEmptyStatement(EmptyStatement emptyStatement); - void VisitExpressionStatement(ExpressionStatement expressionStatement); - void VisitFixedStatement(FixedStatement fixedStatement); - void VisitForeachStatement(ForeachStatement foreachStatement); - void VisitForStatement(ForStatement forStatement); - void VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement); - void VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement); - void VisitGotoStatement(GotoStatement gotoStatement); - void VisitIfElseStatement(IfElseStatement ifElseStatement); - void VisitLabelStatement(LabelStatement labelStatement); - void VisitLockStatement(LockStatement lockStatement); - void VisitReturnStatement(ReturnStatement returnStatement); - void VisitSwitchStatement(SwitchStatement switchStatement); - void VisitSwitchSection(SwitchSection switchSection); - void VisitCaseLabel(CaseLabel caseLabel); - void VisitSwitchExpression(SwitchExpression switchExpression); - void VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection); - void VisitThrowStatement(ThrowStatement throwStatement); - void VisitTryCatchStatement(TryCatchStatement tryCatchStatement); - void VisitCatchClause(CatchClause catchClause); - void VisitUncheckedStatement(UncheckedStatement uncheckedStatement); - void VisitUnsafeStatement(UnsafeStatement unsafeStatement); - void VisitUsingStatement(UsingStatement usingStatement); - void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement); - void VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement); - void VisitWhileStatement(WhileStatement whileStatement); - void VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement); - void VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement); - - void VisitAccessor(Accessor accessor); - void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration); - void VisitConstructorInitializer(ConstructorInitializer constructorInitializer); - void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration); - void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration); - void VisitEventDeclaration(EventDeclaration eventDeclaration); - void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration); - void VisitFieldDeclaration(FieldDeclaration fieldDeclaration); - void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration); - void VisitMethodDeclaration(MethodDeclaration methodDeclaration); - void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration); - void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration); - void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration); - void VisitVariableInitializer(VariableInitializer variableInitializer); - void VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration); - void VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer); - - void VisitSyntaxTree(SyntaxTree syntaxTree); - void VisitSimpleType(SimpleType simpleType); - void VisitMemberType(MemberType memberType); - void VisitTupleType(TupleAstType tupleType); - void VisitTupleTypeElement(TupleTypeElement tupleTypeElement); - void VisitFunctionPointerType(FunctionPointerAstType functionPointerType); - void VisitInvocationType(InvocationAstType invocationType); - void VisitComposedType(ComposedType composedType); - void VisitArraySpecifier(ArraySpecifier arraySpecifier); - void VisitPrimitiveType(PrimitiveType primitiveType); - - void VisitComment(Comment comment); - void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective); - void VisitDocumentationReference(DocumentationReference documentationReference); - - void VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration); - void VisitConstraint(Constraint constraint); - void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode); - void VisitIdentifier(Identifier identifier); - - void VisitInterpolation(Interpolation interpolation); - void VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText); - - void VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation); - void VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation); - - void VisitNullNode(AstNode nullNode); - void VisitErrorNode(AstNode errorNode); - void VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern); - } - - /// - /// AST visitor. - /// - public interface IAstVisitor - { - S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression); - S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression); - S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression); - S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression); - S VisitAsExpression(AsExpression asExpression); - S VisitAssignmentExpression(AssignmentExpression assignmentExpression); - S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression); - S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression); - S VisitCastExpression(CastExpression castExpression); - S VisitCheckedExpression(CheckedExpression checkedExpression); - S VisitConditionalExpression(ConditionalExpression conditionalExpression); - S VisitDeclarationExpression(DeclarationExpression declarationExpression); - S VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression); - S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression); - S VisitDirectionExpression(DirectionExpression directionExpression); - S VisitIdentifierExpression(IdentifierExpression identifierExpression); - S VisitIndexerExpression(IndexerExpression indexerExpression); - S VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression); - S VisitInvocationExpression(InvocationExpression invocationExpression); - S VisitIsExpression(IsExpression isExpression); - S VisitLambdaExpression(LambdaExpression lambdaExpression); - S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression); - S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression); - S VisitNamedExpression(NamedExpression namedExpression); - S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression); - S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression); - S VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression); - S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression); - S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression); - S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression); - S VisitSizeOfExpression(SizeOfExpression sizeOfExpression); - S VisitStackAllocExpression(StackAllocExpression stackAllocExpression); - S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression); - S VisitThrowExpression(ThrowExpression throwExpression); - S VisitTupleExpression(TupleExpression tupleExpression); - S VisitTypeOfExpression(TypeOfExpression typeOfExpression); - S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression); - S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression); - S VisitUncheckedExpression(UncheckedExpression uncheckedExpression); - S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression); - S VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression); - - S VisitQueryExpression(QueryExpression queryExpression); - S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause); - S VisitQueryFromClause(QueryFromClause queryFromClause); - S VisitQueryLetClause(QueryLetClause queryLetClause); - S VisitQueryWhereClause(QueryWhereClause queryWhereClause); - S VisitQueryJoinClause(QueryJoinClause queryJoinClause); - S VisitQueryOrderClause(QueryOrderClause queryOrderClause); - S VisitQueryOrdering(QueryOrdering queryOrdering); - S VisitQuerySelectClause(QuerySelectClause querySelectClause); - S VisitQueryGroupClause(QueryGroupClause queryGroupClause); - - S VisitAttribute(Attribute attribute); - S VisitAttributeSection(AttributeSection attributeSection); - S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration); - S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration); - S VisitTypeDeclaration(TypeDeclaration typeDeclaration); - S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration); - S VisitUsingDeclaration(UsingDeclaration usingDeclaration); - S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration); - - S VisitBlockStatement(BlockStatement blockStatement); - S VisitBreakStatement(BreakStatement breakStatement); - S VisitCheckedStatement(CheckedStatement checkedStatement); - S VisitContinueStatement(ContinueStatement continueStatement); - S VisitDoWhileStatement(DoWhileStatement doWhileStatement); - S VisitEmptyStatement(EmptyStatement emptyStatement); - S VisitExpressionStatement(ExpressionStatement expressionStatement); - S VisitFixedStatement(FixedStatement fixedStatement); - S VisitForeachStatement(ForeachStatement foreachStatement); - S VisitForStatement(ForStatement forStatement); - S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement); - S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement); - S VisitGotoStatement(GotoStatement gotoStatement); - S VisitIfElseStatement(IfElseStatement ifElseStatement); - S VisitLabelStatement(LabelStatement labelStatement); - S VisitLockStatement(LockStatement lockStatement); - S VisitReturnStatement(ReturnStatement returnStatement); - S VisitSwitchStatement(SwitchStatement switchStatement); - S VisitSwitchSection(SwitchSection switchSection); - S VisitCaseLabel(CaseLabel caseLabel); - S VisitSwitchExpression(SwitchExpression switchExpression); - S VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection); - S VisitThrowStatement(ThrowStatement throwStatement); - S VisitTryCatchStatement(TryCatchStatement tryCatchStatement); - S VisitCatchClause(CatchClause catchClause); - S VisitUncheckedStatement(UncheckedStatement uncheckedStatement); - S VisitUnsafeStatement(UnsafeStatement unsafeStatement); - S VisitUsingStatement(UsingStatement usingStatement); - S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement); - S VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement); - S VisitWhileStatement(WhileStatement whileStatement); - S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement); - S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement); - - S VisitAccessor(Accessor accessor); - S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration); - S VisitConstructorInitializer(ConstructorInitializer constructorInitializer); - S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration); - S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration); - S VisitEventDeclaration(EventDeclaration eventDeclaration); - S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration); - S VisitFieldDeclaration(FieldDeclaration fieldDeclaration); - S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration); - S VisitMethodDeclaration(MethodDeclaration methodDeclaration); - S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration); - S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration); - S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration); - S VisitVariableInitializer(VariableInitializer variableInitializer); - S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration); - S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer); - - S VisitSyntaxTree(SyntaxTree syntaxTree); - S VisitSimpleType(SimpleType simpleType); - S VisitMemberType(MemberType memberType); - S VisitTupleType(TupleAstType tupleType); - S VisitTupleTypeElement(TupleTypeElement tupleTypeElement); - S VisitFunctionPointerType(FunctionPointerAstType functionPointerType); - S VisitInvocationType(InvocationAstType invocationType); - S VisitComposedType(ComposedType composedType); - S VisitArraySpecifier(ArraySpecifier arraySpecifier); - S VisitPrimitiveType(PrimitiveType primitiveType); - - S VisitComment(Comment comment); - S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective); - S VisitDocumentationReference(DocumentationReference documentationReference); - - S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration); - S VisitConstraint(Constraint constraint); - S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode); - S VisitIdentifier(Identifier identifier); - - S VisitInterpolation(Interpolation interpolation); - S VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText); - - S VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation); - S VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation); - - S VisitNullNode(AstNode nullNode); - S VisitErrorNode(AstNode errorNode); - S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern); - } - - /// - /// AST visitor. - /// - public interface IAstVisitor - { - S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data); - S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data); - S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data); - S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data); - S VisitAsExpression(AsExpression asExpression, T data); - S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); - S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data); - S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data); - S VisitCastExpression(CastExpression castExpression, T data); - S VisitCheckedExpression(CheckedExpression checkedExpression, T data); - S VisitConditionalExpression(ConditionalExpression conditionalExpression, T data); - S VisitDeclarationExpression(DeclarationExpression declarationExpression, T data); - S VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T data); - S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data); - S VisitDirectionExpression(DirectionExpression directionExpression, T data); - S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); - S VisitIndexerExpression(IndexerExpression indexerExpression, T data); - S VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression, T data); - S VisitInvocationExpression(InvocationExpression invocationExpression, T data); - S VisitIsExpression(IsExpression isExpression, T data); - S VisitLambdaExpression(LambdaExpression lambdaExpression, T data); - S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data); - S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data); - S VisitNamedExpression(NamedExpression namedExpression, T data); - S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data); - S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data); - S VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression, T data); - S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); - S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data); - S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); - S VisitSizeOfExpression(SizeOfExpression sizeOfExpression, T data); - S VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data); - S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data); - S VisitThrowExpression(ThrowExpression throwExpression, T data); - S VisitTupleExpression(TupleExpression tupleExpression, T data); - S VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data); - S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); - S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data); - S VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data); - S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data); - S VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data); - - S VisitQueryExpression(QueryExpression queryExpression, T data); - S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data); - S VisitQueryFromClause(QueryFromClause queryFromClause, T data); - S VisitQueryLetClause(QueryLetClause queryLetClause, T data); - S VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data); - S VisitQueryJoinClause(QueryJoinClause queryJoinClause, T data); - S VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data); - S VisitQueryOrdering(QueryOrdering queryOrdering, T data); - S VisitQuerySelectClause(QuerySelectClause querySelectClause, T data); - S VisitQueryGroupClause(QueryGroupClause queryGroupClause, T data); - - S VisitAttribute(Attribute attribute, T data); - S VisitAttributeSection(AttributeSection attributeSection, T data); - S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data); - S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data); - S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data); - S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, T data); - S VisitUsingDeclaration(UsingDeclaration usingDeclaration, T data); - S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration, T data); - - S VisitBlockStatement(BlockStatement blockStatement, T data); - S VisitBreakStatement(BreakStatement breakStatement, T data); - S VisitCheckedStatement(CheckedStatement checkedStatement, T data); - S VisitContinueStatement(ContinueStatement continueStatement, T data); - S VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data); - S VisitEmptyStatement(EmptyStatement emptyStatement, T data); - S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); - S VisitFixedStatement(FixedStatement fixedStatement, T data); - S VisitForeachStatement(ForeachStatement foreachStatement, T data); - S VisitForStatement(ForStatement forStatement, T data); - S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data); - S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data); - S VisitGotoStatement(GotoStatement gotoStatement, T data); - S VisitIfElseStatement(IfElseStatement ifElseStatement, T data); - S VisitLabelStatement(LabelStatement labelStatement, T data); - S VisitLockStatement(LockStatement lockStatement, T data); - S VisitReturnStatement(ReturnStatement returnStatement, T data); - S VisitSwitchStatement(SwitchStatement switchStatement, T data); - S VisitSwitchSection(SwitchSection switchSection, T data); - S VisitCaseLabel(CaseLabel caseLabel, T data); - S VisitSwitchExpression(SwitchExpression switchExpression, T data); - S VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection, T data); - S VisitThrowStatement(ThrowStatement throwStatement, T data); - S VisitTryCatchStatement(TryCatchStatement tryCatchStatement, T data); - S VisitCatchClause(CatchClause catchClause, T data); - S VisitUncheckedStatement(UncheckedStatement uncheckedStatement, T data); - S VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data); - S VisitUsingStatement(UsingStatement usingStatement, T data); - S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data); - S VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement, T data); - S VisitWhileStatement(WhileStatement whileStatement, T data); - S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data); - S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data); - - S VisitAccessor(Accessor accessor, T data); - S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); - S VisitConstructorInitializer(ConstructorInitializer constructorInitializer, T data); - S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data); - S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data); - S VisitEventDeclaration(EventDeclaration eventDeclaration, T data); - S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration, T data); - S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); - S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data); - S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); - S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data); - S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data); - S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); - S VisitVariableInitializer(VariableInitializer variableInitializer, T data); - S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data); - S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer, T data); - - S VisitSyntaxTree(SyntaxTree syntaxTree, T data); - S VisitSimpleType(SimpleType simpleType, T data); - S VisitMemberType(MemberType memberType, T data); - S VisitTupleType(TupleAstType tupleType, T data); - S VisitTupleTypeElement(TupleTypeElement tupleTypeElement, T data); - S VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T data); - S VisitInvocationType(InvocationAstType invocationType, T data); - S VisitComposedType(ComposedType composedType, T data); - S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); - S VisitPrimitiveType(PrimitiveType primitiveType, T data); - - S VisitComment(Comment comment, T data); - S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data); - S VisitDocumentationReference(DocumentationReference documentationReference, T data); - - S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data); - S VisitConstraint(Constraint constraint, T data); - S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data); - S VisitIdentifier(Identifier identifier, T data); - - S VisitInterpolation(Interpolation interpolation, T data); - S VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText, T data); - - S VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T data); - S VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation, T data); - - S VisitNullNode(AstNode nullNode, T data); - S VisitErrorNode(AstNode errorNode, T data); - S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data); - } -} diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs index 726c939fb..b99e4d2b6 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs @@ -28,38 +28,9 @@ using System; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class Identifier : AstNode + [DecompilerAstNode(hasNullNode: true)] + public partial class Identifier : AstNode { - public new static readonly Identifier Null = new NullIdentifier(); - sealed class NullIdentifier : Identifier - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - public override NodeType NodeType { get { return NodeType.Token; @@ -149,21 +120,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return new Identifier(name, location); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitIdentifier(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitIdentifier(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitIdentifier(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { Identifier o = other as Identifier; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/InvocationAstType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/InvocationAstType.cs index 5dddbfb56..ec3e7616e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/InvocationAstType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/InvocationAstType.cs @@ -17,8 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System; -using System.Collections.Generic; -using System.Text; using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; @@ -29,7 +27,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// BaseType "(" Argument { "," Argument } ")" /// - public class InvocationAstType : AstType + [DecompilerAstNode(hasNullNode: false)] + public partial class InvocationAstType : AstType { public AstNodeCollection Arguments { get { return GetChildrenByRole(Roles.Expression); } @@ -40,21 +39,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Type, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitInvocationType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitInvocationType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitInvocationType(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is InvocationAstType o diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/MemberType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/MemberType.cs index 00abace78..3ac178878 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/MemberType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/MemberType.cs @@ -32,7 +32,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class MemberType : AstType + [DecompilerAstNode(hasNullNode: false)] + public partial class MemberType : AstType { public static readonly Role TargetRole = new Role("Target", AstType.Null); @@ -97,21 +98,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitMemberType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitMemberType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitMemberType(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { MemberType o = other as MemberType; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/IdentifierExpressionBackreference.cs b/ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IdentifierExpressionBackreference.cs similarity index 84% rename from ICSharpCode.Decompiler/CSharp/Syntax/IdentifierExpressionBackreference.cs rename to ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IdentifierExpressionBackreference.cs index 78ee9359d..0975b686a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/IdentifierExpressionBackreference.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IdentifierExpressionBackreference.cs @@ -19,12 +19,12 @@ using System; using System.Linq; -namespace ICSharpCode.Decompiler.CSharp.Syntax +namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching { /// /// Matches identifier expressions that have the same identifier as the referenced variable/type definition/method definition. /// - public class IdentifierExpressionBackreference : PatternMatching.Pattern + public class IdentifierExpressionBackreference : Pattern { readonly string referencedGroupName; @@ -39,12 +39,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.referencedGroupName = referencedGroupName; } - public override bool DoMatch(PatternMatching.INode other, PatternMatching.Match match) + public override bool DoMatch(INode other, Match match) { - IdentifierExpression ident = other as IdentifierExpression; + var ident = other as IdentifierExpression; if (ident == null || ident.TypeArguments.Any()) return false; - AstNode referenced = (AstNode)match.Get(referencedGroupName).Last(); + var referenced = (AstNode)match.Get(referencedGroupName).Last(); if (referenced == null) return false; return ident.Identifier == referenced.GetChildByRole(Roles.Identifier).Name; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/PrimitiveType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/PrimitiveType.cs index a6f112542..bbf30fd36 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/PrimitiveType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/PrimitiveType.cs @@ -33,7 +33,8 @@ using ICSharpCode.Decompiler.TypeSystem.Implementation; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class PrimitiveType : AstType + [DecompilerAstNode(hasNullNode: false)] + public partial class PrimitiveType : AstType { TextLocation location; string keyword = string.Empty; @@ -85,21 +86,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitPrimitiveType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitPrimitiveType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitPrimitiveType(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { PrimitiveType o = other as PrimitiveType; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Role.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Role.cs index 2411a2652..aec5a1f0c 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Role.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Role.cs @@ -88,15 +88,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return node is T; } - [Obsolete("Use the other overload explicitly specifying the nullObject.")] - public Role(string name) - { - if (name == null) - throw new ArgumentNullException(nameof(name)); - this.name = name; - this.nullObject = null!; - } - public Role(string name, T nullObject) { this.name = name ?? throw new ArgumentNullException(nameof(name)); diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/SimpleType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/SimpleType.cs index 17a19e345..28f55b587 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/SimpleType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/SimpleType.cs @@ -32,46 +32,9 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class SimpleType : AstType + [DecompilerAstNode(hasNullNode: true)] + public partial class SimpleType : AstType { - #region Null - public new static readonly SimpleType Null = new NullSimpleType(); - - sealed class NullSimpleType : SimpleType - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - - public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider) - { - return SpecialType.UnknownType; - } - } - #endregion - public SimpleType() { } @@ -126,21 +89,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(Roles.TypeArgument); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSimpleType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSimpleType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSimpleType(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { SimpleType o = other as SimpleType; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs index 9965c7af9..e57fa6ad9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs @@ -31,88 +31,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// { Statements } /// - public class BlockStatement : Statement, IEnumerable + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public partial class BlockStatement : Statement, IEnumerable { public static readonly Role StatementRole = new Role("Statement", Statement.Null); - #region Null - public static readonly new BlockStatement Null = new NullBlockStatement(); - sealed class NullBlockStatement : BlockStatement - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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); } } @@ -125,21 +48,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBrace); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitBlockStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitBlockStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitBlockStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { BlockStatement o = other as BlockStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BreakStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BreakStatement.cs index df8732e81..88b2b3238 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BreakStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/BreakStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// break; /// - public class BreakStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class BreakStatement : Statement { public static readonly TokenRole BreakKeywordRole = new TokenRole("break"); @@ -42,21 +43,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitBreakStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitBreakStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitBreakStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { BreakStatement o = other as BreakStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/CheckedStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/CheckedStatement.cs index c701dcfc5..9af92d1d4 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/CheckedStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/CheckedStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// checked BodyBlock /// - public class CheckedStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class CheckedStatement : Statement { public static readonly TokenRole CheckedKeywordRole = new TokenRole("checked"); @@ -52,21 +53,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(body, Roles.Body); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCheckedStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCheckedStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCheckedStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CheckedStatement o = other as CheckedStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ContinueStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ContinueStatement.cs index a4b8abacf..57a1251a1 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ContinueStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ContinueStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// continue; /// - public class ContinueStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class ContinueStatement : Statement { public static readonly TokenRole ContinueKeywordRole = new TokenRole("continue"); @@ -42,21 +43,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitContinueStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitContinueStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitContinueStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ContinueStatement o = other as ContinueStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/DoWhileStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/DoWhileStatement.cs index ce05ff6b6..6319fab85 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/DoWhileStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/DoWhileStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// "do EmbeddedStatement while(Condition);" /// - public class DoWhileStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class DoWhileStatement : Statement { public static readonly TokenRole DoKeywordRole = new TokenRole("do"); public static readonly TokenRole WhileKeywordRole = new TokenRole("while"); @@ -65,21 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDoWhileStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDoWhileStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDoWhileStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { DoWhileStatement o = other as DoWhileStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/EmptyStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/EmptyStatement.cs index c76016963..4da13ae7b 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/EmptyStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/EmptyStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// ; /// - public class EmptyStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class EmptyStatement : Statement { public TextLocation Location { get; @@ -49,21 +50,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitEmptyStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitEmptyStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitEmptyStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { EmptyStatement o = other as EmptyStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ExpressionStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ExpressionStatement.cs index 5a4f2a413..563fcc63e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ExpressionStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ExpressionStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Expression; /// - public class ExpressionStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class ExpressionStatement : Statement { public Expression Expression { get { return GetChildByRole(Roles.Expression); } @@ -41,21 +42,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitExpressionStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitExpressionStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitExpressionStatement(this, data); - } - public ExpressionStatement() { } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/FixedStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/FixedStatement.cs index 3b34ea2fb..ff098821a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/FixedStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/FixedStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// fixed (Type Variables) EmbeddedStatement /// - public class FixedStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class FixedStatement : Statement { public static readonly TokenRole FixedKeywordRole = new TokenRole("fixed"); @@ -60,21 +61,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.EmbeddedStatement, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitFixedStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitFixedStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFixedStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { FixedStatement o = other as FixedStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForStatement.cs index 91784f0d4..97aef87c7 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// for (Initializers; Condition; Iterators) EmbeddedStatement /// - public class ForStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class ForStatement : Statement { public static readonly TokenRole ForKeywordRole = new TokenRole("for"); public readonly static Role InitializerRole = new Role("Initializer", Statement.Null); @@ -71,21 +72,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.EmbeddedStatement, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitForStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitForStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitForStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ForStatement o = other as ForStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForeachStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForeachStatement.cs index a01bc05de..e447f805a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForeachStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ForeachStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// foreach (Type VariableName in InExpression) EmbeddedStatement /// - public class ForeachStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class ForeachStatement : Statement { public static readonly TokenRole AwaitRole = UnaryOperatorExpression.AwaitRole; public static readonly TokenRole ForeachKeywordRole = new TokenRole("foreach"); @@ -81,21 +82,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.EmbeddedStatement, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitForeachStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitForeachStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitForeachStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ForeachStatement o = other as ForeachStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/GotoStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/GotoStatement.cs index b1b064c01..d5a538c12 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/GotoStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/GotoStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// "goto Label;" /// - public class GotoStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class GotoStatement : Statement { public static readonly TokenRole GotoKeywordRole = new TokenRole("goto"); @@ -63,21 +64,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitGotoStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitGotoStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitGotoStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { GotoStatement o = other as GotoStatement; @@ -88,7 +74,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// or "goto case LabelExpression;" /// - public class GotoCaseStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class GotoCaseStatement : Statement { public static readonly TokenRole GotoKeywordRole = new TokenRole("goto"); public static readonly TokenRole CaseKeywordRole = new TokenRole("case"); @@ -113,21 +100,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitGotoCaseStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitGotoCaseStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitGotoCaseStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { GotoCaseStatement o = other as GotoCaseStatement; @@ -138,7 +110,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// or "goto default;" /// - public class GotoDefaultStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class GotoDefaultStatement : Statement { public static readonly TokenRole GotoKeywordRole = new TokenRole("goto"); public static readonly TokenRole DefaultKeywordRole = new TokenRole("default"); @@ -155,21 +128,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitGotoDefaultStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitGotoDefaultStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitGotoDefaultStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { GotoDefaultStatement o = other as GotoDefaultStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/IfElseStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/IfElseStatement.cs index fece09f10..b76511bbc 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/IfElseStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/IfElseStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// if (Condition) TrueStatement else FalseStatement /// - public class IfElseStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class IfElseStatement : Statement { public readonly static TokenRole IfKeywordRole = new TokenRole("if"); public readonly static Role ConditionRole = Roles.Condition; @@ -69,21 +70,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(FalseRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitIfElseStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitIfElseStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitIfElseStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { IfElseStatement o = other as IfElseStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LabelStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LabelStatement.cs index ca56ec478..55ce57682 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LabelStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LabelStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Label: /// - public class LabelStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class LabelStatement : Statement { public string Label { get { @@ -50,21 +51,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Colon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitLabelStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitLabelStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitLabelStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { LabelStatement o = other as LabelStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LocalFunctionDeclarationStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LocalFunctionDeclarationStatement.cs index da2d1550f..052e7877f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LocalFunctionDeclarationStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LocalFunctionDeclarationStatement.cs @@ -20,7 +20,8 @@ using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class LocalFunctionDeclarationStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class LocalFunctionDeclarationStatement : Statement { public static readonly Role MethodDeclarationRole = new Role("Method", null); @@ -34,21 +35,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(methodDeclaration, MethodDeclarationRole); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitLocalFunctionDeclarationStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitLocalFunctionDeclarationStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitLocalFunctionDeclarationStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is LocalFunctionDeclarationStatement o && Declaration.DoMatch(o.Declaration, match); diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LockStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LockStatement.cs index a8f25c579..3151920c8 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LockStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/LockStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// lock (Expression) EmbeddedStatement; /// - public class LockStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class LockStatement : Statement { public static readonly TokenRole LockKeywordRole = new TokenRole("lock"); @@ -56,21 +57,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.EmbeddedStatement, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitLockStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitLockStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitLockStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { LockStatement o = other as LockStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ReturnStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ReturnStatement.cs index 75b96f4fe..51ac889c7 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ReturnStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ReturnStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// return Expression; /// - public class ReturnStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class ReturnStatement : Statement { public static readonly TokenRole ReturnKeywordRole = new TokenRole("return"); @@ -56,21 +57,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(returnExpression, Roles.Expression); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitReturnStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitReturnStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitReturnStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ReturnStatement o = other as ReturnStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs index b278d1e3f..49f87dfaa 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs @@ -27,87 +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" /// - public abstract class Statement : AstNode + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public abstract partial class Statement : AstNode { - #region Null - public new static readonly Statement Null = new NullStatement(); - - sealed class NullStatement : Statement - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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(); diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs index a3412d1c8..53af944eb 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// switch (Expression) { SwitchSections } /// - public class SwitchStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class SwitchStatement : Statement { public static readonly TokenRole SwitchKeywordRole = new TokenRole("switch"); public static readonly Role SwitchSectionRole = new Role("SwitchSection", null); @@ -64,21 +65,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBrace); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSwitchStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSwitchStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSwitchStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { SwitchStatement o = other as SwitchStatement; @@ -86,54 +72,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class SwitchSection : AstNode + [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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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 CaseLabelRole = new Role("CaseLabel", null); public override NodeType NodeType { @@ -150,21 +91,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(Roles.EmbeddedStatement); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSwitchSection(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSwitchSection(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSwitchSection(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { SwitchSection o = other as SwitchSection; @@ -172,7 +98,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class CaseLabel : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class CaseLabel : AstNode { public static readonly TokenRole CaseKeywordRole = new TokenRole("case"); public static readonly TokenRole DefaultKeywordRole = new TokenRole("default"); @@ -204,21 +131,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.Expression = expression; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCaseLabel(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCaseLabel(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCaseLabel(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CaseLabel o = other as CaseLabel; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ThrowStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ThrowStatement.cs index a16d67a34..7c5dde36c 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ThrowStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/ThrowStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// throw Expression; /// - public class ThrowStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class ThrowStatement : Statement { public static readonly TokenRole ThrowKeywordRole = new TokenRole("throw"); @@ -56,21 +57,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(expression, Roles.Expression); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitThrowStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitThrowStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitThrowStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ThrowStatement o = other as ThrowStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs index f3ad325bc..1a21e7c13 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// try TryBlock CatchClauses finally FinallyBlock /// - public class TryCatchStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class TryCatchStatement : Statement { public static readonly TokenRole TryKeywordRole = new TokenRole("try"); public static readonly Role TryBlockRole = new Role("TryBlock", BlockStatement.Null); @@ -60,21 +61,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(FinallyBlockRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTryCatchStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTryCatchStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTryCatchStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { TryCatchStatement o = other as TryCatchStatement; @@ -85,7 +71,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// catch (Type VariableName) { Body } /// - public class CatchClause : AstNode + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public partial class CatchClause : AstNode { public static readonly TokenRole CatchKeywordRole = new TokenRole("catch"); public static readonly TokenRole WhenKeywordRole = new TokenRole("when"); @@ -93,85 +80,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole CondLPar = new TokenRole("("); public static readonly TokenRole CondRPar = new TokenRole(")"); - #region Null - public new static readonly CatchClause Null = new NullCatchClause(); - - sealed class NullCatchClause : CatchClause - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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; @@ -236,21 +144,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Body, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCatchClause(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCatchClause(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCatchClause(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CatchClause o = other as CatchClause; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UncheckedStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UncheckedStatement.cs index f24f7213e..47f03ccd1 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UncheckedStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UncheckedStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// unchecked BodyBlock /// - public class UncheckedStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class UncheckedStatement : Statement { public static readonly TokenRole UncheckedKeywordRole = new TokenRole("unchecked"); @@ -52,21 +53,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax AddChild(body, Roles.Body); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUncheckedStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUncheckedStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUncheckedStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UncheckedStatement o = other as UncheckedStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UnsafeStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UnsafeStatement.cs index 1a977d5b9..f98a1a372 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UnsafeStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UnsafeStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// unsafe { Body } /// - public class UnsafeStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class UnsafeStatement : Statement { public static readonly TokenRole UnsafeKeywordRole = new TokenRole("unsafe"); @@ -43,21 +44,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Body, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUnsafeStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUnsafeStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUnsafeStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UnsafeStatement o = other as UnsafeStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UsingStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UsingStatement.cs index 33bf9d839..71843602d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UsingStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/UsingStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// [ await ] using (ResourceAcquisition) EmbeddedStatement /// - public class UsingStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class UsingStatement : Statement { public static readonly TokenRole UsingKeywordRole = new TokenRole("using"); public static readonly TokenRole AwaitRole = UnaryOperatorExpression.AwaitRole; @@ -72,21 +73,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.EmbeddedStatement, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitUsingStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitUsingStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitUsingStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { UsingStatement o = other as UsingStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/VariableDeclarationStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/VariableDeclarationStatement.cs index 1a6066f17..d523f6069 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/VariableDeclarationStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/VariableDeclarationStatement.cs @@ -27,7 +27,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class VariableDeclarationStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class VariableDeclarationStatement : Statement { public static readonly Role ModifierRole = EntityDeclaration.ModifierRole; @@ -64,21 +65,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return Variables.FirstOrNullObject(vi => vi.Name == name); } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitVariableDeclarationStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitVariableDeclarationStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitVariableDeclarationStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { VariableDeclarationStatement o = other as VariableDeclarationStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/WhileStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/WhileStatement.cs index 3e852e35d..29f8233e9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/WhileStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/WhileStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// "while (Condition) EmbeddedStatement" /// - public class WhileStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class WhileStatement : Statement { public static readonly TokenRole WhileKeywordRole = new TokenRole("while"); @@ -56,21 +57,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.EmbeddedStatement, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitWhileStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitWhileStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitWhileStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { WhileStatement o = other as WhileStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldBreakStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldBreakStatement.cs index 4a777afa9..db5dbf34a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldBreakStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldBreakStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// yield break; /// - public class YieldBreakStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class YieldBreakStatement : Statement { public static readonly TokenRole YieldKeywordRole = new TokenRole("yield"); public static readonly TokenRole BreakKeywordRole = new TokenRole("break"); @@ -47,21 +48,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitYieldBreakStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitYieldBreakStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitYieldBreakStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { YieldBreakStatement o = other as YieldBreakStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldReturnStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldReturnStatement.cs index 235201ab2..aea77e7a2 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldReturnStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/YieldReturnStatement.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// yield return Expression; /// - public class YieldReturnStatement : Statement + [DecompilerAstNode(hasNullNode: false)] + public partial class YieldReturnStatement : Statement { public static readonly TokenRole YieldKeywordRole = new TokenRole("yield"); public static readonly TokenRole ReturnKeywordRole = new TokenRole("return"); @@ -52,21 +53,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.Semicolon); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitYieldReturnStatement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitYieldReturnStatement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitYieldReturnStatement(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { YieldReturnStatement o = other as YieldReturnStatement; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs b/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs index 92e3bb63d..f5d0294ae 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs @@ -26,12 +26,12 @@ using System.Collections.Generic; -using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class SyntaxTree : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class SyntaxTree : AstNode { public static readonly Role MemberRole = new Role("Member", AstNode.Null); @@ -122,20 +122,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax SyntaxTree o = other as SyntaxTree; return o != null && this.Members.DoMatch(o.Members, match); } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSyntaxTree(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSyntaxTree(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSyntaxTree(this, data); - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs index 16f5cd4aa..3601518b9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs @@ -16,7 +16,6 @@ // 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.Immutable; using System.Linq; @@ -26,7 +25,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class TupleAstType : AstType + [DecompilerAstNode(hasNullNode: false)] + public partial class TupleAstType : AstType { public static readonly Role ElementRole = new Role("Element", TupleTypeElement.Null); @@ -34,21 +34,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(ElementRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTupleType(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTupleType(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTupleType(this, data); - } - public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { return new TupleTypeReference( @@ -63,41 +48,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class TupleTypeElement : AstNode + [DecompilerAstNode(hasNullNode: true)] + public partial class TupleTypeElement : AstNode { - #region Null - public new static readonly TupleTypeElement Null = new TupleTypeElement(); - - sealed class NullTupleTypeElement : TupleTypeElement - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - public AstType Type { get { return GetChildByRole(Roles.Type); } set { SetChildByRole(Roles.Type, value); } @@ -115,21 +68,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public override NodeType NodeType => NodeType.Unknown; - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitTupleTypeElement(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitTupleTypeElement(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitTupleTypeElement(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is TupleTypeElement o diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs index def135ba9..bbdb172fd 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs @@ -24,45 +24,28 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#nullable enable + using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { + public enum AccessorKind + { + Any, + Getter, + Setter, + Init, + Adder, + Remover + } + /// /// get/set/init/add/remove /// - public class Accessor : EntityDeclaration + [DecompilerAstNode(hasNullNode: true)] + public partial class Accessor : EntityDeclaration { - public static readonly new Accessor Null = new NullAccessor(); - sealed class NullAccessor : Accessor - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - public override NodeType NodeType { get { return NodeType.Unknown; } } @@ -71,21 +54,15 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return SymbolKind.Method; } } + public AccessorKind Kind { get; set; } + /// /// Gets the 'get'/'set'/'init'/'add'/'remove' keyword /// public CSharpTokenNode Keyword { get { - for (AstNode child = this.FirstChild; child != null; child = child.NextSibling) - { - if (child.Role == PropertyDeclaration.GetKeywordRole || child.Role == PropertyDeclaration.SetKeywordRole - || child.Role == PropertyDeclaration.InitKeywordRole - || child.Role == CustomEventDeclaration.AddKeywordRole || child.Role == CustomEventDeclaration.RemoveKeywordRole) - { - return (CSharpTokenNode)child; - } - } - return CSharpTokenNode.Null; + var role = GetAccessorKeywordRole(Kind); + return role == null ? CSharpTokenNode.Null : GetChildByRole(role); } } @@ -94,25 +71,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Body, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitAccessor(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitAccessor(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitAccessor(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + public static TokenRole? GetAccessorKeywordRole(AccessorKind kind) { - Accessor o = other as Accessor; - return o != null && !o.IsNull && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match); + return kind switch { + AccessorKind.Getter => PropertyDeclaration.GetKeywordRole, + AccessorKind.Setter => PropertyDeclaration.SetKeywordRole, + AccessorKind.Init => PropertyDeclaration.InitKeywordRole, + AccessorKind.Adder => CustomEventDeclaration.AddKeywordRole, + AccessorKind.Remover => CustomEventDeclaration.RemoveKeywordRole, + _ => null, + }; } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs index 890b77088..bb0832b38 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs @@ -28,7 +28,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class ConstructorDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class ConstructorDeclaration : EntityDeclaration { public static readonly Role InitializerRole = new Role("Initializer", ConstructorInitializer.Null); @@ -62,21 +63,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Body, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitConstructorDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitConstructorDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitConstructorDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ConstructorDeclaration o = other as ConstructorDeclaration; @@ -92,47 +78,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax This } - public class ConstructorInitializer : AstNode + [DecompilerAstNode(hasNullNode: true)] + public partial class ConstructorInitializer : AstNode { public static readonly TokenRole BaseKeywordRole = new TokenRole("base"); public static readonly TokenRole ThisKeywordRole = new TokenRole("this"); - public static readonly new ConstructorInitializer Null = new NullConstructorInitializer(); - class NullConstructorInitializer : ConstructorInitializer - { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - public override NodeType NodeType { get { return NodeType.Unknown; @@ -165,21 +116,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RPar); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitConstructorInitializer(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitConstructorInitializer(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitConstructorInitializer(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ConstructorInitializer o = other as ConstructorInitializer; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/DestructorDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/DestructorDeclaration.cs index 5039831ee..ca18b395f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/DestructorDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/DestructorDeclaration.cs @@ -28,7 +28,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class DestructorDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class DestructorDeclaration : EntityDeclaration { public static readonly TokenRole TildeRole = new TokenRole("~"); @@ -52,21 +53,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Body, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitDestructorDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitDestructorDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitDestructorDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { DestructorDeclaration o = other as DestructorDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs index 28cfb0798..b2670a956 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs @@ -16,6 +16,7 @@ // 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 System.Linq; @@ -33,6 +34,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return NodeType.Member; } } + [Obsolete] public abstract SymbolKind SymbolKind { get; } public AstNodeCollection Attributes { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EnumMemberDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EnumMemberDeclaration.cs index cbf983454..6344464a1 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EnumMemberDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EnumMemberDeclaration.cs @@ -28,7 +28,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class EnumMemberDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class EnumMemberDeclaration : EntityDeclaration { public static readonly Role InitializerRole = new Role("Initializer", Expression.Null); @@ -45,21 +46,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(InitializerRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitEnumMemberDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitEnumMemberDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitEnumMemberDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { EnumMemberDeclaration o = other as EnumMemberDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EventDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EventDeclaration.cs index 1abb7c739..62957aafd 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EventDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EventDeclaration.cs @@ -31,7 +31,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class EventDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class EventDeclaration : EntityDeclaration { public static readonly TokenRole EventKeywordRole = new TokenRole("event"); @@ -61,21 +62,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { throw new NotSupportedException(); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitEventDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitEventDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitEventDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { EventDeclaration o = other as EventDeclaration; @@ -84,7 +70,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public class CustomEventDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class CustomEventDeclaration : EntityDeclaration { public static readonly TokenRole EventKeywordRole = new TokenRole("event"); public static readonly TokenRole AddKeywordRole = new TokenRole("add"); @@ -124,21 +111,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBrace); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitCustomEventDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitCustomEventDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitCustomEventDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { CustomEventDeclaration o = other as CustomEventDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FieldDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FieldDeclaration.cs index 548b0333e..ea0de51be 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FieldDeclaration.cs @@ -31,7 +31,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class FieldDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class FieldDeclaration : EntityDeclaration { public override SymbolKind SymbolKind { get { return SymbolKind.Field; } @@ -55,21 +56,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { throw new NotSupportedException(); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitFieldDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitFieldDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFieldDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { FieldDeclaration o = other as FieldDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedFieldDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedFieldDeclaration.cs index 2d31d86ab..a829b05f3 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedFieldDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedFieldDeclaration.cs @@ -27,7 +27,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class FixedFieldDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class FixedFieldDeclaration : EntityDeclaration { public static readonly TokenRole FixedKeywordRole = new TokenRole("fixed"); public static readonly Role VariableRole = new Role("FixedVariable", null); @@ -44,21 +45,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildrenByRole(VariableRole); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitFixedFieldDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitFixedFieldDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFixedFieldDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { var o = other as FixedFieldDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs index 56c602300..4ef6867cd 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs @@ -30,7 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// Name [ CountExpression ] /// - public class FixedVariableInitializer : AstNode + [DecompilerAstNode(hasNullNode: false)] + public partial class FixedVariableInitializer : AstNode { public override NodeType NodeType { get { @@ -79,21 +80,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RBracket); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitFixedVariableInitializer(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitFixedVariableInitializer(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitFixedVariableInitializer(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { var o = other as FixedVariableInitializer; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs index bad5ce81b..e2300b4ef 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs @@ -31,7 +31,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class IndexerDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class IndexerDeclaration : EntityDeclaration { public static readonly TokenRole ThisKeywordRole = new TokenRole("this"); public static readonly Role GetterRole = PropertyDeclaration.GetterRole; @@ -101,21 +102,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(ExpressionBodyRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitIndexerDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitIndexerDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitIndexerDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { IndexerDeclaration o = other as IndexerDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/MethodDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/MethodDeclaration.cs index d01822868..61f4def45 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/MethodDeclaration.cs @@ -28,7 +28,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class MethodDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class MethodDeclaration : EntityDeclaration { public override SymbolKind SymbolKind { get { return SymbolKind.Method; } @@ -75,21 +76,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitMethodDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitMethodDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitMethodDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { MethodDeclaration o = other as MethodDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/OperatorDeclaration.cs index 9ffc9058b..a6ec8eb50 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/OperatorDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/OperatorDeclaration.cs @@ -76,7 +76,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax CheckedExplicit } - public class OperatorDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class OperatorDeclaration : EntityDeclaration { public static readonly TokenRole OperatorKeywordRole = new TokenRole("operator"); public static readonly TokenRole CheckedKeywordRole = new TokenRole("checked"); @@ -327,21 +328,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return names[(int)type][0]; } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitOperatorDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitOperatorDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitOperatorDeclaration(this, data); - } - public override string Name { get { return GetName(this.OperatorType); } set { throw new NotSupportedException(); } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs index 98a86fd69..d9d0cf1fa 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs @@ -30,7 +30,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class ParameterDeclaration : AstNode + [DecompilerAstNode(hasNullNode: false, hasPatternPlaceholder: true)] + public partial class ParameterDeclaration : AstNode { public static readonly Role AttributeRole = EntityDeclaration.AttributeRole; public static readonly TokenRole ThisModifierRole = new TokenRole("this"); @@ -41,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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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 Attributes { @@ -173,21 +128,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitParameterDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitParameterDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitParameterDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match) { var o = other as ParameterDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/PropertyDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/PropertyDeclaration.cs index f7fd87434..93ab7edcb 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/PropertyDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/PropertyDeclaration.cs @@ -28,7 +28,8 @@ using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class PropertyDeclaration : EntityDeclaration + [DecompilerAstNode(hasNullNode: false)] + public partial class PropertyDeclaration : EntityDeclaration { public static readonly TokenRole GetKeywordRole = new TokenRole("get"); public static readonly TokenRole SetKeywordRole = new TokenRole("set"); @@ -82,21 +83,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(ExpressionBodyRole, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitPropertyDeclaration(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitPropertyDeclaration(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitPropertyDeclaration(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { PropertyDeclaration o = other as PropertyDeclaration; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs index d5b74faa8..ee2d6166c 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs @@ -27,87 +27,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { - public class VariableInitializer : AstNode + [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] + public partial class VariableInitializer : AstNode { - #region Null - public new static readonly VariableInitializer Null = new NullVariableInitializer(); - - sealed class NullVariableInitializer : VariableInitializer - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - - #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(IAstVisitor visitor) - { - return visitor.VisitPatternPlaceholder(this, child); - } - - public override S AcceptVisitor(IAstVisitor 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; @@ -151,21 +73,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Expression, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitVariableInitializer(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitVariableInitializer(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitVariableInitializer(this, data); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { VariableInitializer o = other as VariableInitializer; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index 119185bc5..07ef4484c 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -2082,22 +2082,24 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax decl.Modifiers = ModifierFromAccessibility(accessor.Accessibility, UsePrivateProtectedAccessibility); if (this.ShowModifiers && accessor.HasReadonlyModifier()) decl.Modifiers |= Modifiers.Readonly; - TokenRole keywordRole = kind switch { - MethodSemanticsAttributes.Getter => PropertyDeclaration.GetKeywordRole, - MethodSemanticsAttributes.Setter => PropertyDeclaration.SetKeywordRole, - MethodSemanticsAttributes.Adder => CustomEventDeclaration.AddKeywordRole, - MethodSemanticsAttributes.Remover => CustomEventDeclaration.RemoveKeywordRole, - _ => null + AccessorKind accessorKind = kind switch { + MethodSemanticsAttributes.Getter => AccessorKind.Getter, + MethodSemanticsAttributes.Setter => AccessorKind.Setter, + MethodSemanticsAttributes.Adder => AccessorKind.Adder, + MethodSemanticsAttributes.Remover => AccessorKind.Remover, + _ => AccessorKind.Any }; if (kind == MethodSemanticsAttributes.Setter && SupportInitAccessors && accessor.IsInitOnly) { - keywordRole = PropertyDeclaration.InitKeywordRole; + accessorKind = AccessorKind.Init; } - if (keywordRole != null) + decl.Kind = accessorKind; + if (accessorKind != AccessorKind.Any) { - decl.AddChild(new CSharpTokenNode(TextLocation.Empty, keywordRole), keywordRole); + var tokenKind = Accessor.GetAccessorKeywordRole(accessorKind); + decl.AddChild(new CSharpTokenNode(TextLocation.Empty, tokenKind), tokenKind); } - if (accessor.IsInitOnly && keywordRole != PropertyDeclaration.InitKeywordRole) + if (accessor.IsInitOnly && accessorKind != AccessorKind.Init) { decl.AddChild(new Comment("init", CommentType.MultiLine), Roles.Comment); } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs b/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs index 8d7991dec..a4234f3aa 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs @@ -20,51 +20,18 @@ using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; namespace ICSharpCode.Decompiler.CSharp.Syntax { - public abstract class VariableDesignation : AstNode + [DecompilerAstNode(hasNullNode: true)] + public abstract partial class VariableDesignation : AstNode { public override NodeType NodeType => NodeType.Unknown; - - #region Null - public new static readonly VariableDesignation Null = new NullVariableDesignation(); - - sealed class NullVariableDesignation : VariableDesignation - { - public override bool IsNull { - get { - return true; - } - } - - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitNullNode(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitNullNode(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitNullNode(this, data); - } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - return other == null || other.IsNull; - } - } - #endregion - } /// /// Identifier /// - public class SingleVariableDesignation : VariableDesignation + [DecompilerAstNode(hasNullNode: false)] + public partial class SingleVariableDesignation : VariableDesignation { - public string Identifier { get { return GetChildByRole(Roles.Identifier).Name; } set { SetChildByRole(Roles.Identifier, Syntax.Identifier.Create(value)); } @@ -75,21 +42,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax set { SetChildByRole(Roles.Identifier, value); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitSingleVariableDesignation(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitSingleVariableDesignation(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitSingleVariableDesignation(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is SingleVariableDesignation o && MatchString(this.Identifier, o.Identifier); @@ -99,7 +51,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// /// ( VariableDesignation (, VariableDesignation)* ) /// - public class ParenthesizedVariableDesignation : VariableDesignation + [DecompilerAstNode(hasNullNode: false)] + public partial class ParenthesizedVariableDesignation : VariableDesignation { public CSharpTokenNode LParToken { @@ -114,21 +67,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax get { return GetChildByRole(Roles.RPar); } } - public override void AcceptVisitor(IAstVisitor visitor) - { - visitor.VisitParenthesizedVariableDesignation(this); - } - - public override T AcceptVisitor(IAstVisitor visitor) - { - return visitor.VisitParenthesizedVariableDesignation(this); - } - - public override S AcceptVisitor(IAstVisitor visitor, T data) - { - return visitor.VisitParenthesizedVariableDesignation(this, data); - } - protected internal override bool DoMatch(AstNode other, Match match) { return other is ParenthesizedVariableDesignation o && VariableDesignations.DoMatch(o.VariableDesignations, match); diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 0a11c17b9..32c6a1937 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -28,7 +28,7 @@ False false - 11 + 13 true True ICSharpCode.Decompiler.snk @@ -99,6 +99,10 @@ + + + + @@ -109,6 +113,11 @@ + + True + True + Instructions.tt + @@ -227,9 +236,8 @@ - - + @@ -507,11 +515,6 @@ - - True - True - Instructions.tt - diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index 4094f9c9e..90cbcc525 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -3790,7 +3790,7 @@ namespace ICSharpCode.Decompiler.IL public bool DelayExceptions; // NullReferenceException/IndexOutOfBoundsException only occurs when the reference is dereferenced readonly IField field; /// Returns the field operand. - public IField Field { get { return field; } } + public IField Field { get { return this.field; } } public override StackType ResultType { get { return target.ResultType.IsIntegerType() ? StackType.I : StackType.Ref; } } protected override InstructionFlags ComputeFlags() { @@ -3844,7 +3844,7 @@ namespace ICSharpCode.Decompiler.IL public override StackType ResultType { get { return StackType.Ref; } } readonly IField field; /// Returns the field operand. - public IField Field { get { return field; } } + public IField Field { get { return this.field; } } public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { WriteILRange(output, options); diff --git a/ICSharpCode.Decompiler/IL/Instructions.tt b/ICSharpCode.Decompiler/IL/Instructions.tt index 8c2a5bf5e..28f40fc27 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.tt +++ b/ICSharpCode.Decompiler/IL/Instructions.tt @@ -862,7 +862,8 @@ namespace ICSharpCode.Decompiler.IL opCode.PerformMatchConditions.Add("Patterns.ListMatch.DoMatch(this." + argProp + ", o." + argProp + ", ref match)"); if (i == 0) opCode.WriteArguments.Add("bool first = true;"); - opCode.WriteArguments.Add("foreach (var " + arg + " in " + argProp + ") {"); + opCode.WriteArguments.Add("foreach (var " + arg + " in " + argProp + ")"); + opCode.WriteArguments.Add("{"); if (i > 0) opCode.WriteArguments.Add("\toutput.Write(\", \");"); else @@ -1087,7 +1088,7 @@ protected override void Disconnected() opCode.MatchParameters.Add(new MatchParamInfo { TypeName = "IField", Name = "field", FieldName = "Field" }); opCode.PerformMatchConditions.Add("field.Equals(o.field)"); opCode.Members.Add("/// Returns the field operand." + Environment.NewLine - + "public IField Field { get { return field; } }"); + + "public IField Field { get { return this.field; } }"); opCode.GenerateWriteTo = true; opCode.WriteOperand.Add("output.Write(' ');"); opCode.WriteOperand.Add("field.WriteTo(output);"); diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs index 103c77d79..32fcb73d3 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs @@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms private readonly IField field; private ILVariable declaredVariable; - public string Name => field.Name; + public string Name => @field.Name; public bool CanPropagate { get; private set; } public bool UsesInitialValue { get; set; } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs index 632a3e4cc..03e9c5e6c 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs @@ -187,7 +187,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation foreach (FieldDefinitionHandle h in fieldCollection) { var field = metadata.GetFieldDefinition(h); - var attr = field.Attributes; + var attr = @field.Attributes; if (module.IsVisible(attr)) { fieldList.Add(module.GetDefinition(h)); diff --git a/ICSharpCode.Decompiler/packages.lock.json b/ICSharpCode.Decompiler/packages.lock.json index 90d8e948b..5f400a344 100644 --- a/ICSharpCode.Decompiler/packages.lock.json +++ b/ICSharpCode.Decompiler/packages.lock.json @@ -91,6 +91,9 @@ "type": "Transitive", "resolved": "6.0.0", "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + }, + "icsharpcode.decompiler.generators.attributes": { + "type": "Project" } } } diff --git a/ILSpy.sln b/ILSpy.sln index 27a5a1fd6..17884f664 100644 --- a/ILSpy.sln +++ b/ILSpy.sln @@ -44,6 +44,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler.Generators", "ICSharpCode.Decompiler.Generators\ICSharpCode.Decompiler.Generators.csproj", "{0792B524-622B-4B9D-8027-3531ED6A42EB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -102,6 +104,10 @@ Global {81A30182-3378-4952-8880-F44822390040}.Debug|Any CPU.Build.0 = Debug|Any CPU {81A30182-3378-4952-8880-F44822390040}.Release|Any CPU.ActiveCfg = Release|Any CPU {81A30182-3378-4952-8880-F44822390040}.Release|Any CPU.Build.0 = Release|Any CPU + {0792B524-622B-4B9D-8027-3531ED6A42EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0792B524-622B-4B9D-8027-3531ED6A42EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0792B524-622B-4B9D-8027-3531ED6A42EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0792B524-622B-4B9D-8027-3531ED6A42EB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE