2000-05-14 18:05:10 +04:00
# dump the current parse tree
2000-05-15 17:41:05 +04:00
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 )
2000-05-14 18:05:10 +04:00
{
2000-05-15 17:41:05 +04:00
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 ) ;
2000-05-14 18:05:10 +04:00
}
}
2000-05-15 17:41:05 +04:00
function dump_union ( f , elnum ,
2000-05-14 18:05:10 +04:00
LOCAL , i )
{
2000-05-15 17:41:05 +04:00
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" ) ;
2000-05-14 18:05:10 +04:00
}
2000-05-15 17:41:05 +04:00
function dump_elem ( f , struct_num , elem_num ,
LOCAL , enum )
2000-05-14 18:05:10 +04:00
{
2000-05-15 17:41:05 +04:00
elnum = structs [ struct_num , elem_num ] ;
if ( elements [ elnum , "type" ] == "union" ) {
dump_union ( f , elnum ) ;
2000-05-14 18:05:10 +04:00
} else {
2000-05-15 17:41:05 +04:00
dump_element ( f , elnum ) ;
2000-05-14 18:05:10 +04:00
}
}
function dump_structs ( f , NIL ,
LOCAL , i , j )
{
xprintf ( f , "/* dump of parsed structures */\n\n\n" ) ;
2000-06-09 06:59:50 +04:00
for ( i = 0 ; i < num_options ; i ++ ) {
xprintf ( f , "option %s %s\n" , options [ i , "name" ] , options [ i , "value" ] ) ;
}
xprintf ( f , "\n\n" ) ;
2000-05-14 18:05:10 +04:00
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" ) ;
}