Coder Social home page Coder Social logo

cxx2flow's Introduction

cxx2flow

简体中文 | English

将 C/C++ 代码转换为流程图

效果

更多效果图请参考 GALLERY

两种样式:

折线 平滑
ployline curve
inline int read() {  //快读
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

错误报告

error reporting

安装

自行编译

cargo install cxx2flow

下载预构建二进制

推荐从右侧的 Github Release 下载对应平台的二进制文件。

也可以到 GitHub ActionsNightly.link 下载最新构建的二进制,包含 Linux, Windows 和 MacOS 版本。

使用 GUI 版本

对于没有命令行使用经验的用户,推荐下载使用基于 tauri 编写的 GUI 版本。 https://github.com/Enter-tainer/cxx2flow-gui/releases

gui

使用

为了编译生成的 dot 文件,你需要安装 graphviz,并将其添加到 PATH 中。也可以将生成的结果复制进在线的 graphviz 服务中,如 http://magjac.com/graphviz-visual-editor/

Convert your C/C++ code to control flow chart

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 <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.

EXAMPLES:
    cat main.cpp | cxx2flow | dot -Tsvg -o test.svg
    cxx2flow test.cpp | dot -Tpng -o test.png
    cxx2flow main.cpp my_custom_func | dot -Tsvg -o test.svg

Please give me star if this application helps you!
如果这个应用有帮助到你,请给我点一个 star!
https://github.com/Enter-tainer/cxx2flow

限制

  • 对于预处理器的支持基于 cpp ,默认关闭,需要使用 --cpp 参数手动启用。如果 PATH 中不存在 cpp 则会失败。
  • 支持的控制流语句有:while,for,if,break,continue,break,return,switch, goto, do-while。
  • 对 range for 有基本支持。部分情况下,受到 tree-sitter-cpp 能力限制,会出现一些问题

cxx2flow's People

Contributors

dependabot[bot] avatar enter-tainer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cxx2flow's Issues

switch出现的一点问题

代码

int main(void)
{
	struct grades_list list = {NULL, NULL, 0};
	struct grades *g;
	int is_exit = 0;
	while (is_exit == 0) {
		int choice, num, i, sub_choice;
		char ID[16];
		scanf("%d", &choice);
		switch (choice) {
		case 0:
			clean_info(&list);
			is_exit = 1;
			break;
		case 1: /* 输入 */
			scanf("%d", &num);
			for (i = 0; i < num; ++i) {
				get_grades(&list);
			}
			sort_grades(&list);
			break;
		case 2: /* 输出 */
			for_each(&list, print_basic_info);
			break;
		case 3: /* 修改 */
			scanf("%s%d", ID, &sub_choice);
			g = find_grades(&list, ID);
			if (g == NULL)
				break;
			switch (sub_choice) {
			case 1:
				scanf("%d", &(g->english));
				break;
			case 2:
				scanf("%d", &(g->math));
				break;
			case 3:
				scanf("%d", &(g->physics));
				break;
			case 4:
				scanf("%d", &(g->c_lang));
				break;
			default:
				break;
			}
			count_grades(g);
			break;
		case 4: /* 统计平均 */
			for_each(&list, print_average);
			break;
		case 5: /* 输出总成绩及平均成绩 */
			for_each(&list, print_sum_and_average);
			break;
		default:
			break;
		}
	}
	return 0;
}

报错信息

% ./cxx2flow b.c -c | dot -Tpng -o a.png
Error: UnexpectedOutgoingNodes { node_index: NodeIndex(22), neighbors: [] }

dummy ast node error

The following code,

#include <stdio.h>

static void a(void)
{
	printf("a\n");
}

static void b(void)
{
	printf("b\n");
}

static void x(int y)
{
	if (y > 0) {
		return a();
	} else {
		return b();
	}
}

int main(void)
{
	int y;
	scanf("%d", &y);

	x(y);
}

With the following parameters,

cxx2flow test.c x | dot -Tpng -o test.png

Results in this output,

Error: cxx2flow::unexpected_dummy_ast

  × unexpected dummy ast node
    ╭─[test.c:15:1]
 15 │             return a();
 16 │ ╭─▶     } else {
 17 │ │           return b();
 18 │ ├─▶     }
    · ╰──── dummy ast node here
 19 │     }
    ╰────
  help: dummy node found in the ast
        this might be a bug, please report it to the author

不支持函数递归调用

目前不支持函数递归调用,希望能够完善增强一下,谢谢!

#include <bits/stdc++.h>
using namespace std;

int f(int n) {
if (n <= 2) return n;
return f(n - 1) + f(n - 2);
}

int main() {
int n, ans = 0;
cin >> n;
ans = f(n);
cout << ans << endl;
return 0;
}

命令行模式处理 if-else语句报错

您好,
命令行处理下面的代码报错“unexpected dumy ast node”,但是用图形界面gui软件就可以识别if-else语句,麻烦大神修复一下命令行的问题,谢谢!

`#include
using namespace std;

int main(){
int a = 10, b = 5;
if(a > b) {
cout << "ok";
} else {
cout << "bad";
}
return 0;
}`

1699423362166

333

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.