using Canon.Core.CodeGenerators; using Canon.Core.Enums; 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().Token; public IEnumerable Arguments => GetArguments(); public static ProcedureCall Create(List children) { return new ProcedureCall { Children = children }; } private IEnumerable GetArguments() { if (Children.Count == 1) { yield break; } foreach (Expression expression in Children[2].Convert().Expressions) { yield return expression; } } 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(")"); } }