Canon/Canon.Core/SyntaxNodes/CompoundStatement.cs
jackfiled 3a584751dc feat: 针对C的代码生成 (#50)
Co-authored-by: Lan_G <2911328695@qq.com>
Reviewed-on: PostGuard/Canon#50
2024-04-21 22:24:35 +08:00

29 lines
801 B
C#

using Canon.Core.CodeGenerators;
using Canon.Core.Enums;
namespace Canon.Core.SyntaxNodes;
public class CompoundStatement : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.CompoundStatement;
public IEnumerable<Statement> Statements => Children[1].Convert<StatementList>().Statements;
public static CompoundStatement Create(List<SyntaxNodeBase> children)
{
return new CompoundStatement { Children = children };
}
public override void GenerateCCode(CCodeBuilder builder)
{
foreach (var statement in Statements.Reverse())
{
if (statement.Children.Count > 0)
{
statement.GenerateCCode(builder);
builder.AddString(";");
}
}
}
}