diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-02-10 15:26:03 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-02-10 15:26:03 +0200 |
commit | b85e6151264722dcaf7dcd1ec2a75bcee295512c (patch) | |
tree | f30c25a60b37097cff69cee25f0deb54d7954145 | |
parent | b4038ea16c1709367f5c84939919785686481b55 (diff) | |
download | cflow-b85e6151264722dcaf7dcd1ec2a75bcee295512c.tar.gz cflow-b85e6151264722dcaf7dcd1ec2a75bcee295512c.tar.bz2 |
Finish implementation of --all
* doc/cflow.1: Document the --all --all behavior
* doc/cflow.texi: Likewise.
* src/main.c: Increment all_functions for each -A option.
* src/output.c (tree_output): If one --all option is used, output graphs
for all top-level functions (i.e. functions, not reachable from other ones).
If used twice, output graphs for all global function.
* tests/all.at: New test.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
-rw-r--r-- | doc/cflow.1 | 7 | ||||
-rw-r--r-- | doc/cflow.texi | 8 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/output.c | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/all.at | 300 | ||||
-rw-r--r-- | tests/struct.at | 16 | ||||
-rw-r--r-- | tests/testsuite.at | 3 |
8 files changed, 334 insertions, 7 deletions
diff --git a/doc/cflow.1 b/doc/cflow.1 index 917eb42..f0aa298 100644 --- a/doc/cflow.1 +++ b/doc/cflow.1 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Cflow. If not, see <http://www.gnu.org/licenses/>. -.TH CFLOW 1 "February 8, 2019" "CFLOW" +.TH CFLOW 1 "February 10, 2019" "CFLOW" .SH NAME cflow \- generate a C-language flowgraph .SH SYNOPSIS @@ -180,10 +180,13 @@ Produce graphs for all global functions in the program. Use this option if your program contains functions which are not directly reachable from \fBmain()\fR. .sp -The output consist of separate flow graphs for each global function +The output consist of separate flow graphs for each top-level function defined in the program. These graphs will be placed after the graph for \fBmain()\fR (if it exists), and will be ordered lexicographically by the function name. +.sp +If used twice, graphs for all global functions (whether top-level or +not) will be displayed. .TP \fB\-b\fR, \fB\-\-brief\fR Brief output. diff --git a/doc/cflow.texi b/doc/cflow.texi index f4a71f4..1b164f4 100644 --- a/doc/cflow.texi +++ b/doc/cflow.texi @@ -235,10 +235,16 @@ Many programs (such as libraries or interpreters) define functions that are not directly reachable from the main function. To produce flow graph for all functions in the program, use the @option{--all} (@option{-A}) option. The output will then include separate flow -graphs for each global function defined in the program. These graphs +graphs for each top-level function defined in the program. These graphs will be placed after the graph for @code{main} (if it exists), and will be ordered lexicographically by the function name. +When @option{--all} is used twice, graphs for all global functions +(whether top-level or not) will be displayed. + +To disable special handling of the @code{main} function, use the +@option{--no-main} option. + @node Direct and Reverse @chapter Two Types of Flow Graphs. @cindex @option{--reverse} @@ -518,7 +518,7 @@ parse_opt (int key, char *arg, struct argp_state *state) switch (key) { case 'A': - all_functions = 1; + all_functions++; break; case 'a': strict_ansi = 1; diff --git a/src/output.c b/src/output.c index bf5af1f..625d29e 100644 --- a/src/output.c +++ b/src/output.c @@ -395,7 +395,7 @@ tree_output() if ((main_sym = start_name ? lookup(start_name) : NULL) != NULL) { direct_tree(0, 0, main_sym); separator(); - } else { + } else if (!all_functions) { all_functions = 1; } @@ -403,7 +403,7 @@ tree_output() for (i = 0; i < num; i++) { if (main_sym != symbols[i] && symbols[i]->source - && symbols[i]->caller == NULL) { + && (all_functions > 1 || symbols[i]->caller == NULL)) { direct_tree(0, 0, symbols[i]); separator(); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 2dfe751..1c35368 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,6 +39,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac ## ------------ ## TESTSUITE_AT = \ + all.at\ attr.at\ awrapper.at\ bartest.at\ diff --git a/tests/all.at b/tests/all.at new file mode 100644 index 0000000..44d8e3f --- /dev/null +++ b/tests/all.at @@ -0,0 +1,300 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2005-2019 Sergey Poznyakoff +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +AT_BANNER([all-functions mode]) + +# Default case: in the absense of mail, --all is assumed +CFLOW_TEST([default], +[all all-default all00], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +], +[bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +]) + +# Default case: if main is present, only functions directly reachable from it +# are displayed. +CFLOW_TEST([default (main present)], +[all all-default-main all01], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +int +main(void) +{ + zuuq(); +} +], +[main() <int main (void) at prog:17>: + zuuq() +]) + +# If --main is supplied, only this function and calls reachable from it are +# output. +CFLOW_OPT([--main=foo],[ +CFLOW_TEST([the --main option], +[all all--main all02], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +], +[foo() <int foo (void) at prog:2>: + baz() +]) +]) + +# Single --all option: print all top-level functions and functions reachable +# from them. +CFLOW_OPT([--all],[ +CFLOW_TEST([the --all option], +[all all--all all03], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +], +[bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +]) +]) + +# Double --all options print all global functions, no matter whether reachable +# from others. +CFLOW_OPT([--all --all],[ +CFLOW_TEST([the --all --all option], +[all all--all--all all04], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +], +[bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +qux() <void qux (void) at prog:12>: + boom() +]) +]) + +# The --all option applied to a source with main function: main graph is placed +# on top. +CFLOW_OPT([--all],[ +CFLOW_TEST([the --all option with main], +[all all--all-main all05], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +int +main(void) +{ + zuuq(); +} +], +[main() <int main (void) at prog:17>: + zuuq() +bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +]) +]) + +# Double --all option applied to a source with main function: main graph is +# placed on top, followed by graphs for all global functions. +CFLOW_OPT([--all --all],[ +CFLOW_TEST([the --all --all option with main], +[all all--all--all-main all06], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +int +main(void) +{ + zuuq(); +} +], +[main() <int main (void) at prog:17>: + zuuq() +bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +qux() <void qux (void) at prog:12>: + boom() +]) +]) + +# The --no-main option is similar to --all, if the function main() is not +# defined. +CFLOW_OPT([--no-main],[ +CFLOW_TEST([the --no-main option], +[all all--no-main all07], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +], +[bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +]) +]) + +# If main() is defined, --no-main has the same effect as --all, except that +# the graph for main() is placed according to the global lexicographic +# ordering. +CFLOW_OPT([--no-main],[ +CFLOW_TEST([the --no-main option with main], +[all all--no-main-main all08], +[int +foo(void) +{ + baz(); +} +int +bar(void) +{ + qux(); +} +void +qux(void) +{ + boom(); +} +int +main(void) +{ + zuuq(); +} +], +[bar() <int bar (void) at prog:7>: + qux() <void qux (void) at prog:12>: + boom() +foo() <int foo (void) at prog:2>: + baz() +main() <int main (void) at prog:17>: + zuuq() +]) +]) + + diff --git a/tests/struct.at b/tests/struct.at index aed1a9c..0114257 100644 --- a/tests/struct.at +++ b/tests/struct.at @@ -1,3 +1,19 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2005-2019 Sergey Poznyakoff +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + AT_BANNER([struct]) CFLOW_TEST([struct definition followed by attribute], diff --git a/tests/testsuite.at b/tests/testsuite.at index 8d3ba47..e6a1947 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -15,7 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # We need a recent Autotest. -m4_version_prereq([2.52g]) +m4_version_prereq([2.69]) m4_define([TEST_CFLOW_OPTIONS],[]) @@ -78,5 +78,6 @@ m4_include([memberof.at]) m4_include([struct.at]) m4_include([typedef.at]) +m4_include([all.at]) # End of testsuite.at |