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-05-01 21:06:27 +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 ParameterGeneratorEventArgs : EventArgs
|
2024-04-28 22:02:29 +08:00
|
|
|
|
{
|
|
|
|
|
public required ExpressionList Parameters { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public class NoParameterGeneratorEventArgs : EventArgs;
|
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public class ProcedureCall : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.ProcedureCall;
|
|
|
|
|
|
2024-05-04 11:56:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 调用函数的名称
|
|
|
|
|
/// </summary>
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public IdentifierSemanticToken ProcedureId
|
2024-04-28 22:02:29 +08:00
|
|
|
|
=> Children[0].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>();
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-05-04 11:56:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 调用函数的参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<Expression> Parameters { get; } = [];
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 调用函数时含有参数的事件
|
|
|
|
|
/// </summary>
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public event EventHandler<ParameterGeneratorEventArgs>? OnParameterGenerator;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 调用函数是没有参数的事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<NoParameterGeneratorEventArgs>? OnNoParameterGenerator;
|
|
|
|
|
|
|
|
|
|
private PascalType? _pascalType;
|
|
|
|
|
|
|
|
|
|
public PascalType ReturnType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_pascalType is null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _pascalType;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_pascalType = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PreVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PreVisit(this);
|
2024-04-28 22:02:29 +08:00
|
|
|
|
RaiseEvent();
|
2024-04-26 10:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PostVisit(this);
|
2024-04-28 22:02:29 +08:00
|
|
|
|
RaiseEvent();
|
2024-04-26 10:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public static ProcedureCall Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
2024-05-04 11:56:06 +08:00
|
|
|
|
ProcedureCall result = new() { Children = children };
|
|
|
|
|
|
|
|
|
|
if (children.Count == 4)
|
|
|
|
|
{
|
|
|
|
|
result.Parameters.AddRange(children[2].Convert<ExpressionList>().Expressions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
private void RaiseEvent()
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
if (Children.Count == 4)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-05-01 21:06:27 +08:00
|
|
|
|
OnParameterGenerator?.Invoke(this, new ParameterGeneratorEventArgs
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
Parameters = Children[2].Convert<ExpressionList>()
|
|
|
|
|
});
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-05-01 21:06:27 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OnNoParameterGenerator?.Invoke(this, new NoParameterGeneratorEventArgs());
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
OnParameterGenerator = null;
|
2024-05-01 21:06:27 +08:00
|
|
|
|
OnNoParameterGenerator = null;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|