Closed homui closed 4 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
源文件:
// 定义车辆状态枚举类型 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; } } }
}
Originally posted by @homui in https://github.com/Enter-tainer/cxx2flow/issues/47#issuecomment-2188421986
上游parser的问题,如果你把 sensor_data.obstacle_distance < 0 改成 sensor_data.obstacle_distance 就没事了
sensor_data.obstacle_distance < 0
sensor_data.obstacle_distance
https://github.com/Enter-tainer/cxx2flow/commit/1bc135017284856e73a5115f4b79ae2bbb3fca93 这个commit修掉了
执行 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; }
}
Originally posted by @homui in https://github.com/Enter-tainer/cxx2flow/issues/47#issuecomment-2188421986