Enter-tainer / cxx2flow

将 C/C++ 代码转换成流程图 / Turn your C/C++ code into flowchart
MIT License
737 stars 61 forks source link

可否只生成简化的流程图,只包含一些决策分支 #47

Closed homui closed 5 months ago

homui commented 5 months ago

比如流程图里只包含if else这些分支选项

Enter-tainer commented 5 months ago

能举个例子吗

homui commented 5 months ago

你好,我遇到一个问题 执行 cxx2flow --cpp -c src/auto.cpp autonomous_driving_decision 报错: 20 errors generated. Error: cxx2flow::target_function_not_found

× target function not found ╭──── 1 │ autonomous_driving_decision · ─────────────┬───────────── · ╰── this is the name of your target function ╰──── help: maybe you have a typo, or source code is incomplete, please check your input

源文件:

include

include

// 定义车辆状态枚举类型 typedef enum { NORMAL, EMERGENCY_BRAKE, MAINTAIN_SPEED, SLOW_DOWN, STOP } VehicleState;

// 定义传感器输入结构体 typedef struct { int obstacle_distance; // 障碍物距离(单位:米) int speed; // 车速(单位:千米/小时) bool is_traffic_light_green; // 交通灯状态(true表示绿灯,false表示红灯) bool is_pedestrian_nearby; // 附近是否有行人 } SensorInput;

// 自动驾驶行为决策函数 VehicleState autonomous_driving_decision(SensorInput sensor_data) { if (sensor_data.obstacle_distance < 0 || sensor_data.speed < 0) { printf("Error: Invalid sensor data.\n"); return STOP; }

if (sensor_data.is_traffic_light_green)
{
    if (sensor_data.obstacle_distance > 50 && sensor_data.speed > 60)
    {
        return MAINTAIN_SPEED;
    }
    else if (sensor_data.obstacle_distance <= 50 && sensor_data.speed > 40)
    {
        return SLOW_DOWN;
    }
    else
    {
        if (sensor_data.is_pedestrian_nearby &&
            sensor_data.obstacle_distance > 10)
        {
            return SLOW_DOWN;
        }
        else
        {
            return NORMAL;
        }
    }
}
else
{
    if (sensor_data.obstacle_distance > 30 && sensor_data.speed > 30)
    {
        return MAINTAIN_SPEED;
    }
    else if (sensor_data.obstacle_distance <= 10)
    {
        return EMERGENCY_BRAKE;
    }
    else
    {
        if (sensor_data.is_pedestrian_nearby &&
            sensor_data.obstacle_distance > 20)
        {
            return EMERGENCY_BRAKE;
        }
        else
        {
            return NORMAL;
        }
    }
}

}