diff --git a/Cargo.lock b/Cargo.lock index 200546e..c2345a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cxx2flow" -version = "0.5.10" +version = "0.5.11" dependencies = [ "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index 155f27e..2a4d202 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxx2flow" -version = "0.5.10" +version = "0.5.11" edition = "2018" authors = ["mgt "] description = "Convert your C/C++ code to control flow chart" diff --git a/README-en.md b/README-en.md index 781ce79..b1d7a8b 100644 --- a/README-en.md +++ b/README-en.md @@ -58,28 +58,26 @@ For those who are not familiar with command line, I recommend the GUI version of To compile the generated dot file, you need graphviz. You can also copy the output to online graphviz services such as http://magjac.com/graphviz-visual-editor/ . ``` -cxx2flow 0.5.9 -mgt Convert your C/C++ code to control flow chart -USAGE: - cxx2flow [OPTIONS] [ARGS] - -ARGS: - Sets the path of the input file. e.g. test.cpp - If not specified, cxx2flow will read from stdin. - The function you want to convert. e.g. main [default: main] - -OPTIONS: - -c, --curly Sets the style of the flow chart. - If specified, output flow chart will have curly connection line. - --cpp Use C preprocessor. - -h, --help Print help information - -o, --output Sets the output file. - If not specified, result will be directed to stdout. - e.g. graph.dot - -t, --tikz Use tikz backend. - -V, --version Print version information +Usage: cxx2flow [OPTIONS] [INPUT] [FUNCTION] + +Arguments: + [INPUT] Sets the path of the input file. e.g. test.cpp + If not specified, cxx2flow will read from stdin. + [FUNCTION] The function you want to convert. e.g. main [default: main] + +Options: + -o, --output Sets the output file. + If not specified, result will be directed to stdout. + e.g. graph.dot + -c, --curly Sets the style of the flow chart. + If specified, output flow chart will have curly connection line. + --cpp Use C preprocessor. + -t, --tikz Use tikz backend. + -d, --dump-ast Dump AST(For debug purpose only). + -h, --help Print help information + -V, --version Print version information Note that you need to manually compile the dot file using graphviz to get SVG or PNG files. @@ -97,4 +95,4 @@ https://github.com/Enter-tainer/cxx2flow - The support of preprocessor is based on `cpp`, and is disabled by default. `--cpp` flag is needed to enable it. It will fail if `cpp` does not exist in `PATH`. - Supported control flow keyword: while,for,if,break,continue,break,return,switch, goto, do-while。 -- Very basic support for range based loop in C++ 11. \ No newline at end of file +- Very basic support for range based loop in C++ 11. diff --git a/README.md b/README.md index 5875513..5e554e9 100644 --- a/README.md +++ b/README.md @@ -59,28 +59,26 @@ cargo install cxx2flow 为了编译生成的 dot 文件,你需要安装 graphviz,并将其添加到 PATH 中。也可以将生成的结果复制进在线的 graphviz 服务中,如 http://magjac.com/graphviz-visual-editor/ 。 ``` -cxx2flow 0.5.9 -mgt Convert your C/C++ code to control flow chart -USAGE: - cxx2flow [OPTIONS] [ARGS] - -ARGS: - Sets the path of the input file. e.g. test.cpp - If not specified, cxx2flow will read from stdin. - The function you want to convert. e.g. main [default: main] - -OPTIONS: - -c, --curly Sets the style of the flow chart. - If specified, output flow chart will have curly connection line. - --cpp Use C preprocessor. - -h, --help Print help information - -o, --output Sets the output file. - If not specified, result will be directed to stdout. - e.g. graph.dot - -t, --tikz Use tikz backend. - -V, --version Print version information +Usage: cxx2flow [OPTIONS] [INPUT] [FUNCTION] + +Arguments: + [INPUT] Sets the path of the input file. e.g. test.cpp + If not specified, cxx2flow will read from stdin. + [FUNCTION] The function you want to convert. e.g. main [default: main] + +Options: + -o, --output Sets the output file. + If not specified, result will be directed to stdout. + e.g. graph.dot + -c, --curly Sets the style of the flow chart. + If specified, output flow chart will have curly connection line. + --cpp Use C preprocessor. + -t, --tikz Use tikz backend. + -d, --dump-ast Dump AST(For debug purpose only). + -h, --help Print help information + -V, --version Print version information Note that you need to manually compile the dot file using graphviz to get SVG or PNG files. diff --git a/assets/extra-semicolon.cpp b/assets/extra-semicolon.cpp new file mode 100644 index 0000000..10de299 --- /dev/null +++ b/assets/extra-semicolon.cpp @@ -0,0 +1,21 @@ +int main() { + int t; + double ans, x; + printf("Please input your salary:"); + scanf("%lf", &x); + printf("Please choose a method\n1:with if; 2:with swtch:"); + scanf("%d", &t); + if (t == 1) + ans = useif(x); + else if (t == 2) + ans = usesw(x); + else { + printf("Invalid input!\n"); + return 0; + }; + if (t == 1) + printf("calculate by if, the tax is:%.2lf\n", ans); + else + printf("calculate by switch, the tax is:%.2lf\n", ans); + return 0; +} diff --git a/src/graph.rs b/src/graph.rs index ea76dda..9b40ca1 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -468,7 +468,7 @@ pub fn from_ast(ast: Rc>, source: &str, file_name: &str) -> Result< while remove_zero_in_degree_nodes(&mut ctx.graph, source) {} while remove_single_node(&mut ctx.graph, source, |_, t| *t == GraphNodeType::Dummy)? {} let remove_empty_nodes: fn(NodeIndex, &GraphNodeType) -> bool = |_, t| match t { - GraphNodeType::Node(t) => t.is_empty(), + GraphNodeType::Node(t) => t.is_empty() || t.trim() == ";", _ => false, }; while remove_single_node(&mut ctx.graph, source, remove_empty_nodes)? {}