From fe41cfeca525bdd03f0d99cd5d372592f93c840c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 15 Jun 2026 21:33:33 +0200 Subject: [PATCH] Delete the NodeType enum and other dead node members NodeType was NRefactory's coarse node category, but only three reads remained here: two checks now expressed as "is not Trivia" and one debug assert for the pattern category. Remove the enum, the abstract property, every per-node override, and the generator's emission, preserving the pattern-placeholder case through an IPatternPlaceholder marker interface the output-visitor assert checks. Also remove the unused PrimitiveExpression.AdvanceLocation helper. Assisted-by: Claude:claude-opus-4-8:Claude Code --- .../DecompilerSyntaxTreeGenerator.cs | 8 +-- .../OutputVisitor/CSharpOutputVisitor.cs | 2 +- .../InsertMissingTokensDecorator.cs | 4 +- .../CSharp/Syntax/AstNode.cs | 4 -- .../CSharp/Syntax/AstType.cs | 3 -- .../CSharp/Syntax/ComposedType.cs | 5 -- .../CSharp/Syntax/DocumentationReference.cs | 4 -- .../CSharp/Syntax/Expressions/Expression.cs | 5 -- .../InterpolatedStringExpression.cs | 1 - .../Syntax/Expressions/PrimitiveExpression.cs | 33 ------------ .../Syntax/Expressions/QueryExpression.cs | 7 --- .../Syntax/Expressions/SwitchExpression.cs | 1 - .../CSharp/Syntax/GeneralScope/Attribute.cs | 5 -- .../Syntax/GeneralScope/AttributeSection.cs | 5 -- .../CSharp/Syntax/GeneralScope/Comment.cs | 5 -- .../CSharp/Syntax/GeneralScope/Constraint.cs | 3 -- .../GeneralScope/DelegateDeclaration.cs | 3 -- .../GeneralScope/ExternAliasDeclaration.cs | 5 -- .../GeneralScope/NamespaceDeclaration.cs | 6 --- .../GeneralScope/PreProcessorDirective.cs | 5 -- .../Syntax/GeneralScope/TypeDeclaration.cs | 3 -- .../GeneralScope/TypeParameterDeclaration.cs | 4 -- .../GeneralScope/UsingAliasDeclaration.cs | 6 --- .../Syntax/GeneralScope/UsingDeclaration.cs | 6 --- .../CSharp/Syntax/Identifier.cs | 5 -- .../CSharp/Syntax/NodeType.cs | 54 ------------------- .../PatternMatching/IPatternPlaceholder.cs | 28 ++++++++++ .../CSharp/Syntax/Statements/Statement.cs | 3 -- .../Syntax/Statements/SwitchStatement.cs | 12 ----- .../Syntax/Statements/TryCatchStatement.cs | 6 --- .../CSharp/Syntax/SyntaxTree.cs | 6 --- .../CSharp/Syntax/TupleAstType.cs | 1 - .../CSharp/Syntax/TypeMembers/Accessor.cs | 3 -- .../TypeMembers/ConstructorDeclaration.cs | 6 --- .../Syntax/TypeMembers/EntityDeclaration.cs | 4 -- .../TypeMembers/FixedVariableInitializer.cs | 5 -- .../TypeMembers/ParameterDeclaration.cs | 2 - .../Syntax/TypeMembers/VariableInitializer.cs | 5 -- .../CSharp/Syntax/VariableDesignation.cs | 1 - .../ICSharpCode.Decompiler.csproj | 2 +- 40 files changed, 33 insertions(+), 243 deletions(-) delete mode 100644 ICSharpCode.Decompiler/CSharp/Syntax/NodeType.cs create mode 100644 ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IPatternPlaceholder.cs diff --git a/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs b/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs index 7312e0386..5dd97d844 100644 --- a/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs +++ b/ICSharpCode.Decompiler.Generators/DecompilerSyntaxTreeGenerator.cs @@ -174,8 +174,6 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator 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) @@ -228,7 +226,7 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator return pattern != null ? new PatternPlaceholder(pattern) : null{forgive}; }} - sealed class PatternPlaceholder : {source.NodeName}, INode + sealed class PatternPlaceholder : {source.NodeName}, INode, PatternMatching.IPatternPlaceholder {{ readonly PatternMatching.Pattern child; @@ -237,10 +235,6 @@ internal class DecompilerSyntaxTreeGenerator : IIncrementalGenerator this.child = child; }} - public override NodeType NodeType {{ - get {{ return NodeType.Pattern; }} - }} - public override void AcceptVisitor(IAstVisitor visitor) {{ visitor.VisitPatternPlaceholder(this, child); diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index f8316a4b9..e455af233 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { // Ensure that nodes are visited in the proper nested order. // Jumps to different subtrees are allowed only for the child of a placeholder node. - Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek() || containerStack.Peek().NodeType == NodeType.Pattern); + Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek() || containerStack.Peek() is IPatternPlaceholder); containerStack.Push(node); writer.StartNode(node); foreach (var trivia in node.LeadingTrivia) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs index 02e5b62f6..3f503da3e 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs @@ -59,7 +59,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { // ignore whitespace: these don't need to be processed. // StartNode/EndNode is only called for them to support folding of comments. - if (node.NodeType != NodeType.Whitespace) + if (node is not Trivia) { currentList.Add(node); nodes.Push(currentList); @@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor { // ignore whitespace: these don't need to be processed. // StartNode/EndNode is only called for them to support folding of comments. - if (node.NodeType != NodeType.Whitespace) + if (node is not Trivia) { // A node that printed no tokens of its own collapses to a zero-width span here. if (nodesAwaitingStart.Remove(node)) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs b/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs index c78a3365f..aa49d2028 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs @@ -57,10 +57,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax const uint roleIndexMask = (1u << Role.RoleIndexBits) - 1; protected const int AstNodeFlagsUsedBits = Role.RoleIndexBits; - public abstract NodeType NodeType { - get; - } - public virtual bool IsNull { get { return false; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs index 9d8de1256..aec98518e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs @@ -29,9 +29,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] public abstract partial class AstType : AstNode { - public override NodeType NodeType { - get { return NodeType.TypeReference; } - } public new AstType Clone() { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs index a98b6e4a9..a462c87df 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs @@ -137,11 +137,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class ArraySpecifier : AstNode { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } public ArraySpecifier() { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs b/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs index bd782db48..ff5f01a25 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs @@ -75,10 +75,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public override NodeType NodeType { - get { return NodeType.Unknown; } - } - /// /// Gets/Sets the declaring type. /// diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs index f73e50549..e86d8ad4f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs @@ -30,11 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] public abstract partial class Expression : AstNode { - public override NodeType NodeType { - get { - return NodeType.Expression; - } - } public new Expression Clone() { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs index 3e2b43a3f..dd826fc3d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs @@ -38,7 +38,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { public new static readonly Role Role = new Role("InterpolatedStringContent", Syntax.InterpolatedStringContent.Null); - public override NodeType NodeType => NodeType.Unknown; } /// diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs index e73c589bb..a0ffd0c6f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs @@ -100,39 +100,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.format = format; } - unsafe static TextLocation AdvanceLocation(TextLocation startLocation, string str) - { - int line = startLocation.Line; - int col = startLocation.Column; - fixed (char* start = str) - { - char* p = start; - char* endPtr = start + str.Length; - while (p < endPtr) - { - var nl = NewLine.GetDelimiterLength(*p, () => { - char* nextp = p + 1; - if (nextp < endPtr) - return *nextp; - return '\0'; - }); - if (nl > 0) - { - line++; - col = 1; - if (nl == 2) - p++; - } - else - { - col++; - } - p++; - } - } - return new TextLocation(line, col); - } - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { PrimitiveExpression o = other as PrimitiveExpression; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs index 465b92222..3bf5ab2e5 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs @@ -32,9 +32,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public abstract class QueryClause : AstNode { - public override NodeType NodeType { - get { return NodeType.QueryClause; } - } } /// @@ -229,10 +226,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public readonly static TokenRole AscendingKeywordRole = new TokenRole("ascending"); public readonly static TokenRole DescendingKeywordRole = new TokenRole("descending"); - public override NodeType NodeType { - get { return NodeType.Unknown; } - } - [Slot("Roles.Expression")] public partial Expression Expression { get; set; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs index 1c114198a..0e84510fd 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/SwitchExpression.cs @@ -50,6 +50,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [Slot("BodyRole")] public partial Expression Body { get; set; } - public override NodeType NodeType => NodeType.Unknown; } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs index 3ea559f25..6bb1d1ddc 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Attribute.cs @@ -34,11 +34,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class Attribute : AstNode { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } [Slot("Roles.Type")] public partial AstType Type { get; set; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs index 7362996cb..20ae7a33a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/AttributeSection.cs @@ -32,11 +32,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false, hasPatternPlaceholder: true)] public partial class AttributeSection : AstNode { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } public string AttributeTarget { get { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs index e76e83ec3..66c13afb9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Comment.cs @@ -56,11 +56,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class Comment : Trivia { - public override NodeType NodeType { - get { - return NodeType.Whitespace; - } - } CommentType commentType; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs index daecdae21..7c3b338b2 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/Constraint.cs @@ -33,9 +33,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true)] public partial class Constraint : AstNode { - public override NodeType NodeType { - get { return NodeType.Unknown; } - } [Slot("Roles.ConstraintTypeParameter")] public partial SimpleType TypeParameter { get; set; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs index 8316ce1f3..fa9143692 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/DelegateDeclaration.cs @@ -34,9 +34,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class DelegateDeclaration : EntityDeclaration { - public override NodeType NodeType { - get { return NodeType.TypeDeclaration; } - } public override SymbolKind SymbolKind { get { return SymbolKind.TypeDefinition; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs index 1c78956cc..fd7bed8fc 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/ExternAliasDeclaration.cs @@ -32,11 +32,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class ExternAliasDeclaration : AstNode { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } public string Name { get { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs index 10aa86523..efe7100ad 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs @@ -42,12 +42,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly Role MemberRole = SyntaxTree.MemberRole; public static readonly Role NamespaceNameRole = new Role("NamespaceName", AstType.Null); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - public bool IsFileScoped { get; set; } [Slot("NamespaceNameRole")] diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs index 23706508e..f1073b0b1 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/PreProcessorDirective.cs @@ -106,11 +106,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class PreProcessorDirective : Trivia { - public override NodeType NodeType { - get { - return NodeType.Whitespace; - } - } public PreProcessorDirectiveType Type { get; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs index 64eae5dd4..de9ad3b97 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs @@ -50,9 +50,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class TypeDeclaration : EntityDeclaration { - public override NodeType NodeType { - get { return NodeType.TypeDeclaration; } - } public override SymbolKind SymbolKind { get { return SymbolKind.TypeDefinition; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs index dcda355c4..d6e119e50 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeParameterDeclaration.cs @@ -33,10 +33,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole OutVarianceKeywordRole = new TokenRole("out"); public static readonly TokenRole InVarianceKeywordRole = new TokenRole("in"); - public override NodeType NodeType { - get { return NodeType.Unknown; } - } - [Slot("AttributeRole")] public partial AstNodeCollection Attributes { get; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs index 1d90d4bc5..b501a0480 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingAliasDeclaration.cs @@ -36,12 +36,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly Role AliasRole = new Role("Alias", Identifier.Null); public static readonly Role ImportRole = UsingDeclaration.ImportRole; - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - public string Alias { get { return AliasToken.Name; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs index eb06843a2..1c45901bc 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/UsingDeclaration.cs @@ -43,12 +43,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole UsingKeywordRole = new TokenRole("using"); public static readonly Role ImportRole = new Role("Import", AstType.Null); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - [Slot("ImportRole")] public partial AstType Import { get; set; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs index 54fddaf33..b01f791e9 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs @@ -40,11 +40,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true)] public partial class Identifier : AstNode { - public override NodeType NodeType { - get { - return NodeType.Token; - } - } string name; public string Name { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/NodeType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/NodeType.cs deleted file mode 100644 index 9797a8cc6..000000000 --- a/ICSharpCode.Decompiler/CSharp/Syntax/NodeType.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// NodeType.cs -// -// Author: -// Mike Krüger -// -// Copyright (c) 2009 Novell, Inc (http://www.novell.com) -// -// 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 -{ - public enum NodeType - { - Unknown, - /// - /// AstType - /// - TypeReference, - /// - /// Type or delegate declaration - /// - TypeDeclaration, - Member, - Statement, - Expression, - Token, - QueryClause, - /// - /// Comment or whitespace or pre-processor directive - /// - Whitespace, - /// - /// Placeholder for a pattern - /// - Pattern - } -} diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IPatternPlaceholder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IPatternPlaceholder.cs new file mode 100644 index 000000000..1b8f9e70a --- /dev/null +++ b/ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/IPatternPlaceholder.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2011-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.PatternMatching +{ + /// + /// Marker for the generated node that wraps a so it can occupy an AST slot + /// (one per node type, each a sealed subclass of its own node, so they share no common node base). + /// + public interface IPatternPlaceholder + { + } +} diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs index 49f87dfaa..55a50804e 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs @@ -42,8 +42,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node)); } - public override NodeType NodeType { - get { return NodeType.Statement; } - } } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs index 9c89d035d..8a508660a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/SwitchStatement.cs @@ -50,12 +50,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { public static readonly Role CaseLabelRole = new Role("CaseLabel", null); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - [Slot("CaseLabelRole")] public partial AstNodeCollection CaseLabels { get; } @@ -72,12 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole CaseKeywordRole = new TokenRole("case"); public static readonly TokenRole DefaultKeywordRole = new TokenRole("default"); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - /// /// Gets or sets the expression. The expression can be null - if the expression is null, it's the default switch section. /// diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs index 740255c57..5d249343d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs @@ -60,12 +60,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole CondLPar = new TokenRole("("); public static readonly TokenRole CondRPar = new TokenRole(")"); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - [Slot("Roles.Type")] public partial AstType Type { get; set; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs b/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs index e82228e36..9fd2e4c22 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs @@ -38,12 +38,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax { public static readonly Role MemberRole = new Role("Member", AstNode.Null); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - [Slot("MemberRole")] public partial AstNodeCollection Members { get; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs index 7b5e3b0f9..d1e1be331 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs @@ -49,6 +49,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [Slot("Roles.Identifier")] public partial Identifier NameToken { get; set; } - public override NodeType NodeType => NodeType.Unknown; } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs index 30c49b336..b97ff458a 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs @@ -46,9 +46,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true)] public partial class Accessor : EntityDeclaration { - public override NodeType NodeType { - get { return NodeType.Unknown; } - } public override SymbolKind SymbolKind { get { return SymbolKind.Method; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs index 751f4c4e7..9a3d06110 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs @@ -74,12 +74,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole BaseKeywordRole = new TokenRole("base"); public static readonly TokenRole ThisKeywordRole = new TokenRole("this"); - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } - public ConstructorInitializerType ConstructorInitializerType { get; set; diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs index d353cc987..931e2d7da 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs @@ -33,10 +33,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole ModifierRole = new TokenRole("modifier"); public static readonly Role PrivateImplementationTypeRole = new Role("PrivateImplementationType", AstType.Null); - public override NodeType NodeType { - get { return NodeType.Member; } - } - public abstract SymbolKind SymbolKind { get; } public virtual AstNodeCollection Attributes { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs index 42d5cc1bc..90c74ceaa 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/FixedVariableInitializer.cs @@ -32,11 +32,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: false)] public partial class FixedVariableInitializer : AstNode { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } public FixedVariableInitializer() { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs index c464f2717..da9d6176d 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs @@ -46,8 +46,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly TokenRole InModifierRole = new TokenRole("in"); public static readonly TokenRole ParamsModifierRole = new TokenRole("params"); - public override NodeType NodeType => NodeType.Unknown; - [Slot("AttributeRole")] public partial AstNodeCollection Attributes { get; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs index f00575000..f1056817f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs @@ -32,11 +32,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true, hasPatternPlaceholder: true)] public partial class VariableInitializer : AstNode { - public override NodeType NodeType { - get { - return NodeType.Unknown; - } - } public VariableInitializer() { diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs b/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs index 2ecaa817b..e60b966f5 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs @@ -21,7 +21,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax [DecompilerAstNode(hasNullNode: true)] public abstract partial class VariableDesignation : AstNode { - public override NodeType NodeType => NodeType.Unknown; } /// diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 0b0de28b7..1d42c0d2b 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -251,13 +251,13 @@ - +