Browse Source

Delete Null Objects

ast-source-generator
Siegfried Pammer 2 months ago
parent
commit
6990c72628
  1. 39
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  2. 38
      ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs
  3. 34
      ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs
  4. 33
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs
  5. 34
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs
  6. 37
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs
  7. 33
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs
  8. 30
      ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs
  9. 38
      ICSharpCode.Decompiler/CSharp/Syntax/SimpleType.cs
  10. 32
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/BlockStatement.cs
  11. 33
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs
  12. 33
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/TryCatchStatement.cs
  13. 33
      ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs
  14. 30
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs
  15. 36
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs
  16. 33
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/VariableInitializer.cs
  17. 34
      ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs

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

@ -43,45 +43,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -43,45 +43,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
internal static readonly Role<AstNode?> RootRole = new Role<AstNode?>("Root", null);
#region 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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

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

@ -31,44 +31,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -31,44 +31,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

34
ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs

@ -37,40 +37,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -37,40 +37,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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;

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

@ -60,39 +60,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -60,39 +60,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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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); }
}

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

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.CSharp.Syntax
{
@ -31,39 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -31,39 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

37
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs

@ -1,6 +1,4 @@ @@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching;
@ -51,39 +49,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -51,39 +49,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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<InterpolatedStringContent> Role = new Role<InterpolatedStringContent>("InterpolatedStringContent", Syntax.InterpolatedStringContent.Null);
public override NodeType NodeType => NodeType.Unknown;

33
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/QueryExpression.cs

@ -23,39 +23,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -23,39 +23,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
public static readonly Role<QueryClause> ClauseRole = new Role<QueryClause>("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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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<QueryClause> Clauses {
get { return GetChildrenByRole(ClauseRole); }
}

30
ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs

@ -31,36 +31,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -31,36 +31,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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;

38
ICSharpCode.Decompiler/CSharp/Syntax/SimpleType.cs

@ -35,44 +35,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -35,44 +35,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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()
{
}

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

@ -36,38 +36,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -36,38 +36,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
public static readonly Role<Statement> StatementRole = new Role<Statement>("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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

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

@ -30,39 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -30,39 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

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

@ -95,39 +95,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -95,39 +95,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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

33
ICSharpCode.Decompiler/CSharp/Syntax/TupleAstType.cs

@ -66,39 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -66,39 +66,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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); }

30
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs

@ -34,36 +34,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -34,36 +34,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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; }
}

36
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ConstructorDeclaration.cs

@ -99,42 +99,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -99,42 +99,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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;

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

@ -30,39 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -30,39 +30,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
[DecompilerAstNode(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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> 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)
{

34
ICSharpCode.Decompiler/CSharp/Syntax/VariableDesignation.cs

@ -24,40 +24,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -24,40 +24,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
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<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNullNode(this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNullNode(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion
}
/// <summary>

Loading…
Cancel
Save