X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5e7db3a96e0d8c3031042633357e3c2ba4758be8..cdd4d20278cbee5a9f11f9f455bff8836410568c:/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 50ce437c56..2a0d365de6 100755 --- a/tools/doxygen/xbt_log_extract_hierarchy.pl +++ b/tools/doxygen/xbt_log_extract_hierarchy.pl @@ -1,4 +1,10 @@ -#!/usr/bin/perl +#!/usr/bin/env perl + +# Copyright (c) 2008-2019. The SimGrid Team. +# All rights reserved. + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the license (GNU LGPL) which comes with this package. use strict; use warnings; @@ -12,21 +18,16 @@ 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) +# $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 %c_ancestor; -# $c_ancestor{"toto"} is the ancestor of the toto channel, as declared by XBT_LOG_CONNECT -# ie, in a initialization function (only way to do so under windows) -# we want $ancestor{"toto"} == $c_ancestor{"toto"} for each toto, or bad things will happen under windows 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; + print STDERR "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; @@ -44,70 +45,53 @@ sub cleanup_ctn { return @elms; } - sub parse_file { my $filename = shift; - + my $data = ""; - - print "Parse $filename\n" if $debug; + + print STDERR "Parse $filename\n" if $debug; open IN, "$filename" || die "Cannot read $filename: $!\n"; while () { $data .= $_; } close IN; - # Purge $data from C comments + # Purge $data from C and C++ comments $data =~ s|/\*.*?\*/||sg; - - # 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"; # ]]); - + $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; + my ($name,$anc,$desc) = cleanup_ctn($1); - + # build the tree, checking for name conflict 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; + if defined ($ancestor{$name}) && $ancestor{$name} ne $anc && defined ($desc{$name}) && $desc{$name} ne $desc; $ancestor{$name}=$anc; $desc{$name}=$desc; - - 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 || die "unparsable macro: $data"; # ]]); - my ($name, $ignoreme, $anc) = cleanup_ctn($1); - - # build the tree, checking for name conflict - $c_ancestor{$name}=$anc; - print STDERR " $name -> $anc\n" if $debug; } } -# Retrieve all the file names, and add their content to $data -my $data; -open FILES, "find src/ tools/ include/ -name '*.c'|" || die "Cannot search for the source file names: $!\n"; +# Retrieve all the file names +my $path = $ARGV[0] // ".."; +open FILES, "find $path/src/ $path/tools/ $path/include/ -name '*.c' -o -name '*.cpp' |" || die "Cannot search for the source file names: $!\n"; while (my $file=) { chomp $file; parse_file($file); } +parse_file("$path/include/xbt/sysdep.h"); close FILES; -# Display the tree, looking for disconnected elems +# Display the tree, looking for disconnected elems my %used; - + sub display_subtree { my $name=shift; my $indent=shift; - + $used{$name} = 1; unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n"; @@ -116,23 +100,11 @@ sub display_subtree { display_subtree($cat,"$indent "); } } - + display_subtree("XBT_LOG_ROOT_CAT",""); -sub check_connection { - my $name=shift; - - foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) { - unless ($ancestor{$cat} eq "XBT_LOG_ROOT_CAT" || (defined($c_ancestor{$cat}) && $c_ancestor{$cat} eq $name)) { - warn "Category $cat will be disconnected under windows. Add the following to an initialization function:\n XBT_LOG_CONNECT($cat, $ancestor{$cat});\n"; - } else { - warn "Correctly connected, even under windows: Category $cat.\n" if $debug; - } - check_connection($cat); - } -} -check_connection("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 to the root (anc=$ancestor{$_})\n"; +} grep {!defined $used{$_}} sort keys %ancestor; - print "@}*/\n";