LCOV - code coverage report
Current view: top level - core - dbc_diagnostic.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-10-20 13:34:58 Functions: 100.0 % 1 1
Branches: 100.0 % 4 4

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: MIT
       2                 :             : #ifndef DBC_DIAGNOSTIC_H
       3                 :             : #define DBC_DIAGNOSTIC_H
       4                 :             : 
       5                 :             : #include "dbc_database.h"
       6                 :             : #include <cstddef>
       7                 :             : #include <string>
       8                 :             : #include <vector>
       9                 :             : 
      10                 :             : /** @brief Warning or fatal parse error. */
      11                 :             : enum class DbcDiagnosticSeverity {
      12                 :             :     Warning,
      13                 :             :     Error
      14                 :             : };
      15                 :             : 
      16                 :             : /** Stable categories; messages provide the details. */
      17                 :             : enum class DbcDiagnosticCode {
      18                 :             :     FileOpenError,
      19                 :             :     FileReadError,
      20                 :             :     InvalidStatement,
      21                 :             :     InvalidValueDescription,
      22                 :             :     InvalidMultiplexing,
      23                 :             :     UnsupportedStatement,
      24                 :             :     InvalidAttribute,
      25                 :             :     UnsupportedAttribute
      26                 :             : };
      27                 :             : 
      28                 :             : /** @brief Diagnostic message and physical source location. */
      29                 :             : struct DbcDiagnostic {
      30                 :             :     DbcDiagnosticSeverity severity; /**< Message severity. */
      31                 :             :     DbcDiagnosticCode code;         /**< Stable diagnostic category. */
      32                 :             :     std::string filePath;           /**< Input file path. */
      33                 :             :     std::size_t lineNumber;         /**< One-based physical line; zero for file-level errors. */
      34                 :             :     std::string message;            /**< Human-readable diagnostic details. */
      35                 :             : };
      36                 :             : 
      37                 :             : /** @brief Parsed database and diagnostics; the database is empty on error. */
      38                 :             : struct DbcParseResult {
      39                 :             :     DbcDatabase database;                   /**< Parsed content, published only on success. */
      40                 :             :     std::vector<DbcDiagnostic> diagnostics; /**< Warnings and the first error, if any. */
      41                 :             : 
      42                 :             :     /** @brief Return whether any diagnostic has error severity. */
      43                 :         293 :     bool HasErrors() const {
      44         [ +  + ]:         327 :         for (const DbcDiagnostic &diagnostic: diagnostics) {
      45         [ +  + ]:         283 :             if (diagnostic.severity == DbcDiagnosticSeverity::Error)
      46                 :         249 :                 return true;
      47                 :             :         }
      48                 :          44 :         return false;
      49                 :             :     }
      50                 :             : };
      51                 :             : 
      52                 :             : #endif /* DBC_DIAGNOSTIC_H */
        

Generated by: LCOV version 2.0-1