| {{- /* |
| -------------------------------------------------------------------------------- |
| Template file for use with tools/src/cmd/gen to generate diagnostic_control.cc |
| |
| See: |
| * tools/src/cmd/gen for structures used by this template |
| * https://golang.org/pkg/text/template/ for documentation on the template syntax |
| -------------------------------------------------------------------------------- |
| */ -}} |
| |
| {{- Import "src/tint/templates/enums.tmpl.inc" -}} |
| |
| #include "src/tint/ast/diagnostic_control.h" |
| |
| #include <string> |
| |
| #include "src/tint/ast/identifier.h" |
| #include "src/tint/ast/templated_identifier.h" |
| |
| namespace tint::ast { |
| |
| DiagnosticControl::DiagnosticControl(DiagnosticSeverity sev, const Identifier* rule) |
| : severity(sev), rule_name(rule) { |
| TINT_ASSERT(AST, rule != nullptr); |
| if (rule) { |
| // It is invalid for a diagnostic rule name to be templated |
| TINT_ASSERT(AST, !rule->Is<TemplatedIdentifier>()); |
| } |
| } |
| |
| diag::Severity ToSeverity(DiagnosticSeverity sc) { |
| switch (sc) { |
| case DiagnosticSeverity::kError: |
| return diag::Severity::Error; |
| case DiagnosticSeverity::kWarning: |
| return diag::Severity::Warning; |
| case DiagnosticSeverity::kInfo: |
| return diag::Severity::Note; |
| default: |
| return diag::Severity::InternalCompilerError; |
| } |
| } |
| |
| {{ Eval "ParseEnum" (Sem.Enum "diagnostic_severity")}} |
| |
| {{ Eval "EnumOStream" (Sem.Enum "diagnostic_severity")}} |
| |
| {{ Eval "ParseEnum" (Sem.Enum "diagnostic_rule")}} |
| |
| {{ Eval "EnumOStream" (Sem.Enum "diagnostic_rule")}} |
| |
| } // namespace tint::ast |