CanonSharp/CanonSharp.Benchmark/Canon.Core/SyntaxNodes/IdentifierList.cs
jackfiled 89ce313b77 feat: CanonSharp Benchmark. (#4)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/4
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-19 14:37:34 +08:00

79 lines
2.2 KiB
C#

using CanonSharp.Benchmark.Canon.Core.Abstractions;
using CanonSharp.Benchmark.Canon.Core.Enums;
using CanonSharp.Benchmark.Canon.Core.LexicalParser;
namespace CanonSharp.Benchmark.Canon.Core.SyntaxNodes;
public class IdentifierGeneratorEventArgs : EventArgs
{
public required IdentifierSemanticToken IdentifierToken { get; init; }
public required IdentifierList IdentifierList { get; init; }
}
public class TypeGeneratorEventArgs : EventArgs
{
public required TypeSyntaxNode TypeSyntaxNode { get; init; }
}
public class IdentifierList : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.IdentifierList;
public override void PreVisit(SyntaxNodeVisitor visitor)
{
visitor.PreVisit(this);
RaiseEvent();
}
public override void PostVisit(SyntaxNodeVisitor visitor)
{
visitor.PostVisit(this);
RaiseEvent();
}
/// <summary>
/// 是否为参数中的引用参数
/// </summary>
public bool IsReference { get; set; }
/// <summary>
/// 是否在过程定义中使用
/// </summary>
public bool IsProcedure { get; set; }
/// <summary>
/// 是否为变量定义中使用
/// </summary>
public bool IsVariableDefinition { get; set; }
public event EventHandler<IdentifierGeneratorEventArgs>? OnIdentifierGenerator;
public event EventHandler<TypeGeneratorEventArgs>? OnTypeGenerator;
public static IdentifierList Create(List<SyntaxNodeBase> children)
{
return new IdentifierList { Children = children };
}
private void RaiseEvent()
{
if (Children.Count == 2)
{
OnTypeGenerator?.Invoke(this,
new TypeGeneratorEventArgs { TypeSyntaxNode = Children[1].Convert<TypeSyntaxNode>() });
}
else
{
OnIdentifierGenerator?.Invoke(this, new IdentifierGeneratorEventArgs
{
IdentifierToken = Children[1].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
IdentifierList = Children[2].Convert<IdentifierList>()
});
}
OnTypeGenerator = null;
OnIdentifierGenerator = null;
}
}