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 @@ -15,3 +15,3 @@ .\" 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 @@ -182,3 +182,3 @@ 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 @@ -186,2 +186,5 @@ 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 diff --git a/doc/cflow.texi b/doc/cflow.texi index f4a71f4..1b164f4 100644 --- a/doc/cflow.texi +++ b/doc/cflow.texi @@ -237,3 +237,3 @@ 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 @@ -241,2 +241,8 @@ 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 @@ -520,3 +520,3 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'A': - all_functions = 1; + all_functions++; break; diff --git a/src/output.c b/src/output.c index bf5af1f..625d29e 100644 --- a/src/output.c +++ b/src/output.c @@ -397,3 +397,3 @@ tree_output() separator(); - } else { + } else if (!all_functions) { all_functions = 1; @@ -405,3 +405,3 @@ tree_output() && symbols[i]->source - && symbols[i]->caller == NULL) { + && (all_functions > 1 || symbols[i]->caller == NULL)) { direct_tree(0, 0, symbols[i]); diff --git a/tests/Makefile.am b/tests/Makefile.am index 2dfe751..1c35368 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,2 +41,3 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac TESTSUITE_AT = \ + all.at\ attr.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 +1,17 @@ +# 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]) diff --git a/tests/testsuite.at b/tests/testsuite.at index 8d3ba47..e6a1947 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -17,3 +17,3 @@ # We need a recent Autotest. -m4_version_prereq([2.52g]) +m4_version_prereq([2.69]) @@ -80,2 +80,3 @@ m4_include([struct.at]) m4_include([typedef.at]) +m4_include([all.at]) |