3 # Copyright (c) 2008, 2010, 2012-2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
14 print "/* Generated file, do not edit */\n";
15 print "/** \\addtogroup XBT_log_cats\n";
18 # Search for calls to macros defining new channels, and prepare the tree representation
21 # $ancestor{"toto"} is the ancestor of the toto channel
22 # as declared by XBT_LOG_NEW_SUBCATEGORY and XBT_LOG_NEW_DEFAULT_SUBCATEGORY
23 # ie, when the channel toto is initialized (does not work under windows)
25 # $desc{"toto"} is its description
27 # $connected{"toto"} is defined if XBT_LOG_CONNECT("toto") is used
30 my $ctn = shift; # cleanup the content of a macro call
31 $ctn =~ s/^\s*(.*)\s*$/$1/gs;
33 print "ctn=$ctn\n" if $debug > 1;
34 if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) {
35 # Perfect, we got 0->name; 1->anc; 2->desc
39 } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) {
40 # Mmm. got no ancestor. Add the default one.
42 $elms[1] = "XBT_LOG_ROOT_CAT";
45 die "Unparsable content: $ctn\n";
47 $elms[2] =~ s/\\\\/\\/gs;
57 print "Parse $filename\n" if $debug;
58 open IN, "$filename" || die "Cannot read $filename: $!\n";
64 # Purge $data from C comments
65 $data =~ s|/\*.*?\*/||sg;
67 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
70 my $connect_data = $data; # save a copy for second parsing phase
71 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
72 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data";
74 my ($name,$anc,$desc) = cleanup_ctn($1);
76 # build the tree, checking for name conflict
77 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
78 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
79 defined ($desc{$name}) && $desc{$name} ne $desc;
80 $ancestor{$name}=$anc;
83 print " $name -> $anc\n" if $debug;
86 # Now, look for XBT_LOG_CONNECT calls
87 $data = $connect_data;
88 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
89 $data =~ s/\s*(\w+)\s*\)//s || die "unparsable macro: $data";
93 # Retrieve all the file names, and add their content to $data
95 open FILES, "find ../src/ ../tools/ ../include/ -name '*.c' -o -name '*.cpp' |" || die "Cannot search for the source file names: $!\n";
96 while (my $file=<FILES>) {
102 # Display the tree, looking for disconnected elems
105 sub display_subtree {
110 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
111 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
113 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
114 display_subtree($cat,"$indent ");
118 display_subtree("XBT_LOG_ROOT_CAT","");
121 if ($_ ne "mc_main") { # This one is not in libsimgrid
122 warn "Category $_ does not seem to be connected. Use XBT_LOG_CONNECT($_).\n";
124 } grep {!defined $connected{$_}} sort keys %ancestor;
126 warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";
127 } grep {!defined $used{$_}} sort keys %ancestor;