0001-01-01 02:30:17 +02:30
# dump the current parse tree
0001-01-01 02:30:17 +02:30
function element_string ( elnum ,
LOCAL , elem )
{
elem = elements [ elnum , "elem" ] ;
if ( elements [ elnum , "ptr" ] == "1" ) elem = "*" elem ;
if ( elements [ elnum , "array_len" ] != "" )
elem = elem "[" elements [ elnum , "array_len" ] "]" ;
if ( elements [ elnum , "switch" ] != "" )
elem = elem "[" elements [ elnum , "switch" ] "]" ;
return elem ;
}
function dump_element ( f , elnum ,
LOCAL , elem , type )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
type = elements [ elnum , "type" ] ;
case = elements [ elnum , "case" ] ;
elem = element_string ( elnum ) ;
if ( case != "" ) {
xprintf ( f , "\t\tcase %d %s %s;\n" , case , type , elem ) ;
} else {
xprintf ( f , "\t%s %s;\n" , type , elem ) ;
0001-01-01 02:30:17 +02:30
}
}
0001-01-01 02:30:17 +02:30
function dump_union ( f , elnum ,
0001-01-01 02:30:17 +02:30
LOCAL , i )
{
0001-01-01 02:30:17 +02:30
xprintf ( f , "\tunion %s {\n" , element_string ( elnum ) ) ;
for ( i = 0 ; i < unions [ elnum , "num_elems" ] ; i ++ ) {
dump_element ( f , unions [ elnum , i ] ) ;
}
xprintf ( f , "\t}\n" ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
function dump_elem ( f , struct_num , elem_num ,
LOCAL , enum )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
elnum = structs [ struct_num , elem_num ] ;
if ( elements [ elnum , "type" ] == "union" ) {
dump_union ( f , elnum ) ;
0001-01-01 02:30:17 +02:30
} else {
0001-01-01 02:30:17 +02:30
dump_element ( f , elnum ) ;
0001-01-01 02:30:17 +02:30
}
}
function dump_structs ( f , NIL ,
LOCAL , i , j )
{
xprintf ( f , "/* dump of parsed structures */\n\n\n" ) ;
0001-01-01 02:30:17 +02:30
for ( i = 0 ; i < num_options ; i ++ ) {
xprintf ( f , "option %s %s\n" , options [ i , "name" ] , options [ i , "value" ] ) ;
}
xprintf ( f , "\n\n" ) ;
0001-01-01 02:30:17 +02:30
for ( i = 0 ; i < num_structs ; i ++ ) {
xprintf ( f , "/* structure %d */\n" , i ) ;
xprintf ( f , "struct %s {\n" , structs [ i , "name" ] ) ;
for ( j = 0 ; j < structs [ i , "num_elems" ] ; j ++ ) {
dump_elem ( f , i , j ) ;
}
xprintf ( f , "};\n\n" ) ;
}
xprintf ( f , "/* end dump */\n\n" ) ;
}