### ----------------------------------------------------
### -- C::Parser
### -- Licenses: LGPL-3.0-or-later
### -- Authors: Andrew Robbins
### -- File: lib/C/Parser/Actions.rakumod
### ----------------------------------------------------
### -- Chunk 2 of 2
statement>;
    @children.unshift($<expression>.ast);
    make C::AST::Op.new(:$op, :@children);
}

# SS 6.8.5

# SS 6.8.6
method jump-statement:sym<goto>($/) {
    my $op = OpKind::goto_stmt;
    my @children = ($<ident>.ast);
    make C::AST::Op.new(:$op, :@children);
}
method jump-statement:sym<continue>($/) {
    my $op = OpKind::continue_stmt;
    make C::AST::Op.new(:$op);
}
method jump-statement:sym<break>($/) {
    my $op = OpKind::break_stmt;
    make C::AST::Op.new(:$op);
}
method jump-statement:sym<return>($/) {
    my $op = OpKind::return_stmt;
    my @children = ($<expression>.ast);
    make C::AST::Op.new(:$op, :@children);
}

# SS 6.9

method translation-unit($/) {
    my @children = map {$_.ast // ()}, @<external-declaration>;
    make C::AST::TransUnit.new(:@children);
}

method external-declaration:sym<function-definition>($/) {
    make $<function-definition>.ast;
}

method external-declaration:sym<declaration>($/) {
    make $<declaration>.ast;
}
method external-declaration:sym<__asm__>($/) {
    make Nil; #$<assembly>
}

# SS 6.9.1

method declaration-list($/) {
    make map {$_.ast}, @<declaration>;
}

method function-definition:sym<std>($/) {
    my @specs = map {$_.ast}, @<declaration-specifiers>;
    my @ancients = $<declaration-list> ?? $<declaration-list>.ast !! ();

    # TODO synthesize ancients
    # TODO synthesize type

    my $op = TyKind::function_type;
    my @children = @ancients;
    @children.push(C::AST::Specs.new(children => @specs));
    @children.push($<declarator>.ast);
    
    # TODO analyze name
    
    make C::AST::Init.new(
        type => C::AST::TypeOp.new(:$op, :@children),
        value => $<compound-statement>.ast);
}

# vim: expandtab shiftwidth=4


