This commit is contained in:
deeaitch committed 2026-10-11 06:19:42 -04:00
1 parent bce707daf6
commit 51fcdb88ac
174 files changed
+5220 -2213

No files matched your search

+66 -7
View File
@@ -126,7 +126,7 @@ Doxyfile API documentation configuration
| Component | Source files |
| --- | --- |
| Parsed metadata | `core/dbc_database.h`, `core/frame_info.h`, `core/signal_info.h` |
| Parser and dispatch | `core/dbc_parser.*`, `core/dbc_statement_handler.*`, `core/typefactory.h` |
| Parser and dispatch | `core/dbc_parser.*`, `core/dbc_diagnostic.h`, `core/dbc_statement_handler.*`, `core/typefactory.h` |
| UI tree | `core/tree_node.*`, `core/dbc_tree_builder.*` |
| Runtime database | `core/decode_database.h`, `core/dbc_decode_builder.*` |
| Decoder | `core/dbc_decoder.*` |
@@ -470,6 +470,61 @@ The current parser supports the following DBC elements:
- `VAL_` signal value descriptions
- basic `M` / `mN` multiplexing
### Structured diagnostics
`ParseFileWithDiagnostics(path)` returns `DbcParseResult` containing `database`
and `diagnostics`. Each `DbcDiagnostic` has `severity`, `code`, `filePath`,
`lineNumber`, and `message`. Paths preserve the caller's supplied spelling.
Lines are one-based physical lines, including blank lines; file-level errors use zero.
```cpp
const DbcParser parser;
const DbcParseResult result = parser.ParseFileWithDiagnostics("example.dbc");
for (const DbcDiagnostic &diagnostic : result.diagnostics) {
std::cerr << diagnostic.filePath << ":" << diagnostic.lineNumber
<< ": " << diagnostic.message << '\n';
}
if (!result.HasErrors()) {
const DecodeDatabase runtime = DbcDecodeBuilder().Build(result.database);
// Inspect warnings before relying on decoding results.
}
```
| Severity / code | Meaning |
| --- | --- |
| `Error` / `FileOpenError` | Input cannot be opened |
| `Error` / `FileReadError` | Input cannot be read completely |
| `Error` / `InvalidStatement` | Invalid frame/signal definition, duplicate, or payload violation |
| `Error` / `InvalidValueDescription` | Invalid `VAL_` syntax, duplicate value, or unresolved reference |
| `Error` / `InvalidMultiplexing` | Selector, branch range, or signal overlap validation failed |
| `Warning` / `UnsupportedStatement` | Unregistered statement skipped; decoding or metadata may be incomplete |
| `Error` / `UnsupportedStatement` | Extended multiplexing (`SG_MUL_VAL_`) rejected |
Parsing stops at the first error and returns an empty database, together with
any preceding warnings and the error. Deferred `VAL_` and multiplexing errors
retain their original source lines. Invalid signal markers use `InvalidStatement`.
`HasErrors()` checks severity; warnings alone do not make a parse fail.
Unknown statements are reported conservatively, including `SIG_VALTYPE_`,
attributes (`BA_`, `BA_DEF_`, defaults and relation forms), signal types/references,
environment variables, named `VAL_TABLE_` tables, and vendor extensions. For
example, ignoring `SIG_VALTYPE_` may decode a floating-point signal as an integer.
The parser does not implement the warned features; consumers should review warnings.
Common `VERSION`, `NS_`, `BS_`, and `BU_` headers produce no diagnostics.
Single-token symbols inside the `NS_` declaration list are quiet regardless of
indentation, even when they name unsupported syntax. Frame, signal, bus, and
node definitions or a line with arguments end the list. Actual unsupported
statements outside that list are reported.
Node and bus metadata are not stored. Other comment forms (`CM_`, `CM_ BU_`,
`CM_ EV_`) are ignored by the comment handler; comments only attach to already
parsed frames/signals. Supported statements currently require one physical line.
`ParseFile(path)` remains compatible: it returns the database, discards warnings,
and throws `std::runtime_error` on the first error with the existing `path:line:`
format. Use `ParseFileWithDiagnostics` to see skipped syntax. Resource failures
such as allocation errors may still throw.
---
## Supported DBC Syntax
@@ -516,7 +571,8 @@ example.dbc:3: Invalid CAN ID: invalid
```
Frame and signal definitions are validated as described here; comprehensive
DBC grammar coverage is still planned. File-open errors contain the path but have no line number.
DBC grammar coverage is still planned. File-open exceptions contain the path but
no line number. The structured diagnostic API uses line zero for file-level errors.
---
@@ -566,7 +622,7 @@ rejected. Minimum must not exceed maximum. Zero and negative factors are allowed
Basic multiplexing markers `M` and `mN` are supported as described below.
Overlapping signals are rejected unless their branch values differ.
Duplicate frame/signal name detection remains separate work.
Duplicate frame keys and signal names within a frame are rejected.
Invalid signal definitions stop parsing with `path:line: description`, including
when the signal exceeds the declared payload length.
@@ -857,6 +913,7 @@ lines:
- `CM_` → `DbcCommentHandler`
- `VAL_` → `DbcValueDescriptionHandler`
- `SG_MUL_VAL_` → `DbcUnsupportedMultiplexingHandler`
- `VERSION`, `NS_`, `BS_`, `BU_` → `DbcHeaderHandler` (also accepts attached colons)
Grammar implementations live in `core/dbc_statement_handler.cpp`; their interface,
context, and dispatcher live in `core/dbc_statement_handler.h`. `core/typefactory.h`
@@ -878,8 +935,8 @@ RegisterType<MyCustomHandler>("CUSTOM_"); // after implementing MyCustomHandler
Registration creates one handler; replacing a registration replaces that instance.
Register during initialization before dispatching. A line is routed using its
full first whitespace-delimited keyword, so `BO_TX_BU_` cannot match `BO_`.
Unregistered keywords remain ignored. `SG_` and `CM_` accept spaces and tabs
after their keywords.
Unregistered keywords produce `UnsupportedStatement` warnings through
`ParseFileWithDiagnostics`. `SG_` and `CM_` accept spaces and tabs after their keywords.
This factory handles statements inside DBC files. A separate format-level
factory can be introduced when another file format is implemented. The decoder
@@ -953,7 +1010,9 @@ Not supported yet:
- extended and nested multiplexing (`SG_MUL_VAL_`, `mNM`)
- named `VAL_TABLE_` tables and environment-variable value descriptions
- `BA_` attributes
- `BA_DEF_` definitions
- `BA_DEF_` definitions and attribute defaults
- `SIG_VALTYPE_` floating-point signal types
- signal types/references (`SGTYPE_`, `SIG_TYPE_REF_`) and environment variables
- advanced comment handling
- full DBC grammar coverage
- full J1939 validation
@@ -961,7 +1020,7 @@ Not supported yet:
Additional behavior to account for:
- unregistered DBC keywords are ignored
- unregistered DBC keywords are skipped with warnings in the diagnostic API
- an `SG_` statement before the first frame is rejected
- duplicate frame keys (normalized CAN ID and frame type) and repeated signal
names within a frame are rejected at their definition lines; manually created