2024-04-26 10:18:49 +08:00
|
|
|
|
using Canon.Core.Abstractions;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.Enums;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
using Canon.Core.LexicalParser;
|
2024-04-26 10:18:49 +08:00
|
|
|
|
using Canon.Core.SemanticParser;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public class IdentifierGeneratorEventArgs : EventArgs
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
|
|
|
|
public required IdentifierSemanticToken IdentifierToken { get; init; }
|
|
|
|
|
|
|
|
|
|
public required IdentifierList IdentifierList { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public class TypeGeneratorEventArgs : EventArgs
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
|
|
|
|
public required TypeSyntaxNode TypeSyntaxNode { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public class IdentifierList : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.IdentifierList;
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PreVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PreVisit(this);
|
|
|
|
|
RaiseEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PostVisit(this);
|
|
|
|
|
RaiseEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PascalType? _definitionType;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-26 10:18:49 +08:00
|
|
|
|
/// IdentifierList中定义的类型
|
2024-04-07 16:47:28 +08:00
|
|
|
|
/// </summary>
|
2024-04-26 10:18:49 +08:00
|
|
|
|
/// <exception cref="InvalidOperationException">尚未确定定义的类型</exception>
|
|
|
|
|
public PascalType DefinitionType
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
get
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
if (_definitionType is null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _definitionType;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
2024-04-26 10:18:49 +08:00
|
|
|
|
set
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
_definitionType = value;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否为参数中的引用参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsReference { get; set; }
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否在过程定义中使用
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsProcedure { get; set; }
|
|
|
|
|
|
2024-05-04 11:56:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否为变量定义中使用
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsVariableDefinition { get; set; }
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public event EventHandler<IdentifierGeneratorEventArgs>? OnIdentifierGenerator;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public event EventHandler<TypeGeneratorEventArgs>? OnTypeGenerator;
|
2024-04-26 10:18:49 +08:00
|
|
|
|
|
|
|
|
|
public static IdentifierList Create(List<SyntaxNodeBase> children)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
return new IdentifierList { Children = children };
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
private void RaiseEvent()
|
|
|
|
|
{
|
|
|
|
|
if (Children.Count == 2)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
OnTypeGenerator?.Invoke(this,
|
2024-05-01 21:06:27 +08:00
|
|
|
|
new TypeGeneratorEventArgs { TypeSyntaxNode = Children[1].Convert<TypeSyntaxNode>() });
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-26 10:18:49 +08:00
|
|
|
|
else
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-05-01 21:06:27 +08:00
|
|
|
|
OnIdentifierGenerator?.Invoke(this, new IdentifierGeneratorEventArgs
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
|
|
|
|
IdentifierToken = Children[1].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
|
|
|
|
|
IdentifierList = Children[2].Convert<IdentifierList>()
|
|
|
|
|
});
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-26 10:18:49 +08:00
|
|
|
|
|
|
|
|
|
OnTypeGenerator = null;
|
|
|
|
|
OnIdentifierGenerator = null;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|