X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f95d18a77d4a399455342cef52cdfe13d167acce..0e9c0448c6566825b170b98ecff716b098bda10e:/tools/doxygen/xbt_log_extract_hierarchy.pl diff --git a/tools/doxygen/xbt_log_extract_hierarchy.pl b/tools/doxygen/xbt_log_extract_hierarchy.pl index 7eabb2472b..8544ab92d1 100755 --- a/tools/doxygen/xbt_log_extract_hierarchy.pl +++ b/tools/doxygen/xbt_log_extract_hierarchy.pl @@ -1,16 +1,47 @@ -#! /usr/bin/perl +#!/usr/bin/perl use strict; use warnings; my $debug = 0; +print "/* Generated file, do not edit */\n"; +print "/** \\addtogroup XBT_log_cats\n"; +print " \@{\n"; # Search for calls to macros defining new channels, and prepare the tree representation my %ancestor; my %desc; # $ancestor{"toto"} is the ancestor of the toto channel +# as declared by XBT_LOG_NEW_SUBCATEGORY and XBT_LOG_NEW_DEFAULT_SUBCATEGORY +# ie, when the channel toto is initialized (does not work under windows) + # $desc{"toto"} is its description +my %connected; +# $connected{"toto"} is defined if XBT_LOG_CONNECT("toto") is used + +sub cleanup_ctn { + my $ctn = shift; # cleanup the content of a macro call + $ctn =~ s/^\s*(.*)\s*$/$1/gs; + my @elms; + print "ctn=$ctn\n" if $debug > 1; + if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) { + # Perfect, we got 0->name; 1->anc; 2->desc + $elms[0] = $1; + $elms[1] = $2; + $elms[2] = $3; + } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) { + # Mmm. got no ancestor. Add the default one. + $elms[0] = $1; + $elms[1] = "XBT_LOG_ROOT_CAT"; + $elms[2] = $2; + } else { + die "Unparsable content: $ctn\n"; + } + $elms[2] =~ s/\\\\/\\/gs; + return @elms; +} + sub parse_file { my $filename = shift; @@ -30,52 +61,14 @@ sub parse_file { # C++ comments are forbiden in SG for portability reasons, but deal with it anyway $data =~ s|//.*$||mg; + my $connect_data = $data; # save a copy for second parsing phase while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) { - $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; # ]]); - my $ctn = $1; - - # cleanup the content - $ctn =~ s/ *\n//gs; - $ctn =~ s/,\s*"/,"/gs; - $ctn =~ s/"\s*$/"/gs; - $ctn =~ s/,\s*/,/gs; - my @elms_tmp=split (/,/,$ctn); - my @elms; - print "ctn=$ctn\n" if $debug > 1; - # There may be some ',' in the description. Remerge the stuff like: "description, really" - while (1) { - my $acc = shift @elms_tmp; - last unless defined $acc; - if ($acc =~ /^"/) { # ") { - while (shift @elms_tmp) { - $acc .= $_; - } - die "Unparsable content: $ctn\n" - unless ($acc =~ s/^"(.*)"$/$1/); - } - print " seen $acc\n" if $debug > 1; - push @elms, $acc; - } - - my ($name,$anc,$desc); + $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; + + my ($name,$anc,$desc) = cleanup_ctn($1); + # build the tree, checking for name conflict - if (scalar(@elms) eq 3) { - $name = $elms[0]; - $anc = $elms[1]; - $desc = $elms[2]; - } elsif (scalar(@elms) eq 2) { - $name = $elms[0]; - $anc = "XBT_LOG_ROOT_CAT"; - $desc = $elms[1]; - } else { - my $l = scalar(@elms); - my $s = ""; - map {$s .= $_;} @elms; - die "Unparsable content: $ctn (length=$l) (content=$s)\n"; - } - $name =~ s/^\s*(\S*)\s*$/$1/; # trim - $anc =~ s/^\s*(\S*)\s*$/$1/; # trim - die "ERROR: Category name conflict: $name used several times\n" + die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n" if defined ($ancestor{$name}) && $ancestor{$name} ne $anc && defined ($desc{$name}) && $desc{$name} ne $desc; $ancestor{$name}=$anc; @@ -83,10 +76,17 @@ sub parse_file { print " $name -> $anc\n" if $debug; } + + # Now, look for XBT_LOG_CONNECT calls + $data = $connect_data; + while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) { + $data =~ s/\s*(\w+)\s*\)//s || die "unparsable macro: $data"; + $connected{$1} = 1; + } } # Retrieve all the file names, and add their content to $data my $data; -open FILES, "find -name '*.c'|" || die "Cannot search for the source file names; $!\n"; +open FILES, "find ../src/ ../tools/ ../include/ -name '*.c'|" || die "Cannot search for the source file names: $!\n"; while (my $file=) { chomp $file; parse_file($file); @@ -95,7 +95,7 @@ close FILES; # Display the tree, looking for disconnected elems my %used; - + sub display_subtree { my $name=shift; my $indent=shift; @@ -111,4 +111,12 @@ sub display_subtree { display_subtree("XBT_LOG_ROOT_CAT",""); -map {warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";} grep {!defined $used{$_}} sort keys %ancestor; +map { + warn "Category $_ does not seem to be connected. Use XBT_LOG_CONNECT($_).\n"; +} grep {!defined $connected{$_}} sort keys %ancestor; +map { + warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n"; +} grep {!defined $used{$_}} sort keys %ancestor; + + +print "@}*/\n";