2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.CodeGenerators;
|
|
|
|
|
using Canon.Core.Enums;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
using Canon.Core.LexicalParser;
|
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
|
|
|
|
public class ProcedureCall : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.ProcedureCall;
|
|
|
|
|
|
|
|
|
|
public IdentifierSemanticToken ProcedureId
|
|
|
|
|
=> (IdentifierSemanticToken)Children[0].Convert<TerminatedSyntaxNode>().Token;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Expression> Arguments => GetArguments();
|
|
|
|
|
|
|
|
|
|
public static ProcedureCall Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
|
|
|
|
return new ProcedureCall { Children = children };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Expression> GetArguments()
|
|
|
|
|
{
|
|
|
|
|
if (Children.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (Expression expression in Children[2].Convert<ExpressionList>().Expressions)
|
|
|
|
|
{
|
|
|
|
|
yield return expression;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
|
|
|
|
public override void GenerateCCode(CCodeBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(ProcedureId.IdentifierName + "(");
|
|
|
|
|
|
|
|
|
|
//用逗号分隔输出的expression
|
|
|
|
|
using (var enumerator = Arguments.GetEnumerator())
|
|
|
|
|
{
|
|
|
|
|
if (enumerator.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
enumerator.Current.GenerateCCode(builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (enumerator.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(", ");
|
|
|
|
|
enumerator.Current.GenerateCCode(builder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.AddString(")");
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|