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 as declared by XBT_LOG_NEW_SUBCATEGORY and
22 # XBT_LOG_NEW_DEFAULT_SUBCATEGORY ie, when the channel toto is initialized (does not work under windows)
24 # $desc{"toto"} is its description
26 # $connected{"toto"} is defined if XBT_LOG_CONNECT("toto") is used
29 my $ctn = shift; # cleanup the content of a macro call
30 $ctn =~ s/^\s*(.*)\s*$/$1/gs;
32 print "ctn=$ctn\n" if $debug > 1;
33 if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) {
34 # Perfect, we got 0->name; 1->anc; 2->desc
38 } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) {
39 # Mmm. got no ancestor. Add the default one.
41 $elms[1] = "XBT_LOG_ROOT_CAT";
44 die "Unparsable content: $ctn\n";
46 $elms[2] =~ s/\\\\/\\/gs;
55 print "Parse $filename\n" if $debug;
56 open IN, "$filename" || die "Cannot read $filename: $!\n";
62 # Purge $data from C comments
63 $data =~ s|/\*.*?\*/||sg;
65 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
68 my $connect_data = $data; # save a copy for second parsing phase
69 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
70 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data";
72 my ($name,$anc,$desc) = cleanup_ctn($1);
74 # build the tree, checking for name conflict
75 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
76 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc && defined ($desc{$name}) && $desc{$name} ne $desc;
77 $ancestor{$name}=$anc;
80 print " $name -> $anc\n" if $debug;
83 # Now, look for XBT_LOG_CONNECT calls
84 $data = $connect_data;
85 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
86 $data =~ s/\s*(\w+)\s*\)//s || die "unparsable macro: $data";
90 # Retrieve all the file names, and add their content to $data
92 open FILES, "find ../src/ ../tools/ ../include/ -name '*.c' -o -name '*.cpp' |" || die "Cannot search for the source file names: $!\n";
93 while (my $file=<FILES>) {
99 # Display the tree, looking for disconnected elems
102 sub display_subtree {
107 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
108 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
110 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
111 display_subtree($cat,"$indent ");
115 display_subtree("XBT_LOG_ROOT_CAT","");
118 if ($_ ne "mc_main") { # This one is not in libsimgrid
119 warn "Category $_ does not seem to be connected. Use XBT_LOG_CONNECT($_).\n";
121 } grep {!defined $connected{$_}} sort keys %ancestor;
123 warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";
124 } grep {!defined $used{$_}} sort keys %ancestor;