34 if (diagnostic.severity == DbcDiagnosticSeverity::Error) {
35 if (diagnostic.lineNumber == 0U)
36 throw std::runtime_error(diagnostic.message);
37 throw std::runtime_error(diagnostic.filePath +
":" +
38 std::to_string(diagnostic.lineNumber) +
": " + diagnostic.message);
41 return std::move(result.database);
46 std::ifstream input(filePath.c_str());
47 if (!input.is_open()) {
48 result.diagnostics.push_back({DbcDiagnosticSeverity::Error,
49 DbcDiagnosticCode::FileOpenError, filePath, 0U,
50 "Failed to open DBC file: " + filePath});
57 bool inNamespace =
false;
58 std::size_t lineNumber = 0U;
60 while (std::getline(input, line)) {
62 line = dbc_detail::TrimText(line);
66 std::istringstream tokens(line);
70 const bool hasArgument =
static_cast<bool>(tokens >> argument);
71 if (inNamespace && !hasArgument && keyword !=
"BO_" && keyword !=
"SG_" &&
72 keyword !=
"BS_" && keyword !=
"BS_:" &&
73 keyword !=
"BU_" && keyword !=
"BU_:")
75 inNamespace = keyword ==
"NS_" || keyword ==
"NS_:";
78 context.lineNumber = lineNumber;
79 if (!dispatcher.
Dispatch(line, context)) {
80 result.diagnostics.push_back({DbcDiagnosticSeverity::Warning,
81 DbcDiagnosticCode::UnsupportedStatement,
83 "Unsupported statement '" + keyword +
84 "' is ignored; decoding or metadata may be incomplete."});
86 }
catch (
const std::exception &error) {
87 result.diagnostics.push_back({DbcDiagnosticSeverity::Error,
88 StatementErrorCode(keyword), filePath,
89 lineNumber, error.what()});
94 if (input.bad() || !input.eof()) {
95 result.diagnostics.push_back({DbcDiagnosticSeverity::Error,
96 DbcDiagnosticCode::FileReadError, filePath, 0U,
97 "Failed to read DBC file: " + filePath});
102 context.ResolveValueDescriptions(filePath);
103 context.ValidateMultiplexing(filePath);
105 result.diagnostics.push_back(error.diagnostic);
108 result.database = std::move(database);