=head1 NAME

C99::CPPConstants Grammar -- A grammar for transforming an CPP AST to a Parrot constants file

=head1 SYNOPSYS

=head1 DESCRIPTION

=cut

#code = new 'CodeString'
#code.'emit'("    %0 = find_name '%1'", value, name)

grammar C99::CPP::Constants::ConstantsGrammar is TGE::Grammar;

transform root (C99::CPP::PAST::Node) :language('PIR') {
    .local pmc code
    code = new 'CodeString'
    code .= "# DO NOT EDIT THIS FILE.\n"
    code .= "#\n"
    code .= "# This file is generated automatically from\n"
    code .= "# ?? by c99 --constants \n"
    code .= "#\n"
    code .= "# Any changes made here will be lost.\n"
    code .= "#\n"
    $P0 = tree.get('pir', node)
    $S0 = $P0
    code .= $S0
    .return (code)
}

transform pir (C99::CPP::PAST::Node) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}

transform pir (C99::CPP::PAST::IF_SECTION) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}

transform pir(C99::CPP::PAST::IFNDEF) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}

transform pir(C99::CPP::PAST::IFDEF) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}

transform pir(C99::CPP::PAST::IF) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}

transform pir(C99::CPP::PAST::ELIF) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}

transform pir(C99::CPP::PAST::ELSE) :language('PIR') {
    .local pmc code
    .local pmc iter
    code = new 'CodeString'
    iter = node.'child_iter'()
  iter_loop:
    unless iter, iter_end
    $P0 = shift iter
    $P1 = tree.get('pir', $P0)
    code .= $P1
    goto iter_loop
  iter_end:
    .return (code)
}


transform pir(C99::CPP::PAST::DEFINE) :language('PIR') {
    .local pmc code
    code = new 'CodeString'
    $S0 = node.'name'()
    $S1 = node.'line'()
    code.'emit'("    .macro_const %0 %1", $S0, $S1)
    .return (code)
}
transform pir(C99::CPP::PAST::DEFINE_FUNCTION) :language('PIR') {
    .local pmc code
    code = new 'CodeString'
    $S0 = node.'name'()
    $S1 = node.'line'()
    code.'emit'("    .macro_const %0 = %1", $S0, $S1)
    .return (code)
}
transform pir(C99::CPP::PAST::INCLUDE) :language('PIR') {
    .local pmc code
    .return ("")
}
transform pir(C99::CPP::PAST::ERROR) :language('PIR') {
    .local pmc code
    .return ("")
}
transform pir(C99::CPP::PAST::LINE) :language('PIR') {
    .local pmc code
    .return ("")
}
transform pir(C99::CPP::PAST::PRAGMA) :language('PIR') {
    .local pmc code
    .return ("")
}
transform pir(C99::CPP::PAST::SOURCE_LINE) :language('PIR') {
    .local pmc code
    .return ("")
}
transform pir(C99::CPP::PAST::WSNWS) :language('PIR') {
    .local pmc code
    .return ("")
}

=head1 LICENSE

Copyright (C) 2006, The Perl Foundation.

This is free software; you may redistribute it and/or modify
it under the same terms as Parrot.

=head1 AUTHOR

Kevin Tew <tewk@tewk.com>

=cut
