aspclassic-core/AspClassic.Parser/BlockDeclaration.cs
Jelle Luteijn 484dbfc9d9 progress
2022-05-15 11:19:49 +02:00

65 lines
1.9 KiB
C#

#define DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for a block declaration.
/// </summary>
public abstract class BlockDeclaration : ModifiedDeclaration
{
private readonly Location _KeywordLocation;
private readonly SimpleName _Name;
private readonly DeclarationCollection _Declarations;
private readonly EndBlockDeclaration _EndDeclaration;
/// <summary>
/// The location of the keyword.
/// </summary>
public Location KeywordLocation => _KeywordLocation;
/// <summary>
/// The name of the declaration.
/// </summary>
public SimpleName Name => _Name;
/// <summary>
/// The declarations in the block.
/// </summary>
public DeclarationCollection Declarations => _Declarations;
/// <summary>
/// The End statement for the block.
/// </summary>
public EndBlockDeclaration EndDeclaration => _EndDeclaration;
protected BlockDeclaration(TreeType type, AttributeBlockCollection attributes, ModifierCollection modifiers, Location keywordLocation, SimpleName name, DeclarationCollection declarations, EndBlockDeclaration endDeclaration, Span span, IList<Comment> comments)
: base(type, attributes, modifiers, span, comments)
{
Debug.Assert(type == TreeType.ClassDeclaration || type == TreeType.ModuleDeclaration || type == TreeType.InterfaceDeclaration || type == TreeType.StructureDeclaration || type == TreeType.EnumDeclaration);
if (name == null)
{
throw new ArgumentNullException("name");
}
SetParent(name);
SetParent(declarations);
SetParent(endDeclaration);
_KeywordLocation = keywordLocation;
_Name = name;
_Declarations = declarations;
_EndDeclaration = endDeclaration;
}
protected override void GetChildTrees(IList<Tree> childList)
{
base.GetChildTrees(childList);
Tree.AddChild(childList, Name);
Tree.AddChild(childList, Declarations);
Tree.AddChild(childList, EndDeclaration);
}
}