| 1 | //===--- Diagnostic.td - C Language Family Diagnostic Handling ------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the TableGen core definitions for the diagnostics |
| 10 | // and diagnostic control. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | // See the Internals Manual, section The Diagnostics Subsystem for an overview. |
| 15 | |
| 16 | // Define the diagnostic severities. |
| 17 | class Severity<string N> { |
| 18 | string Name = N; |
| 19 | } |
| 20 | def SEV_Ignored : Severity<"Ignored">; |
| 21 | def SEV_Remark : Severity<"Remark">; |
| 22 | def SEV_Warning : Severity<"Warning">; |
| 23 | def SEV_Error : Severity<"Error">; |
| 24 | def SEV_Fatal : Severity<"Fatal">; |
| 25 | |
| 26 | // Define the diagnostic classes. |
| 27 | class DiagClass; |
| 28 | def CLASS_NOTE : DiagClass; |
| 29 | def CLASS_REMARK : DiagClass; |
| 30 | def CLASS_WARNING : DiagClass; |
| 31 | def CLASS_EXTENSION : DiagClass; |
| 32 | def CLASS_ERROR : DiagClass; |
| 33 | |
| 34 | // Responses to a diagnostic in a SFINAE context. |
| 35 | class SFINAEResponse; |
| 36 | def SFINAE_SubstitutionFailure : SFINAEResponse; |
| 37 | def SFINAE_Suppress : SFINAEResponse; |
| 38 | def SFINAE_Report : SFINAEResponse; |
| 39 | def SFINAE_AccessControl : SFINAEResponse; |
| 40 | |
| 41 | // Textual substitutions which may be performed on the text of diagnostics |
| 42 | class TextSubstitution<string Text> { |
| 43 | string Substitution = Text; |
| 44 | // TODO: These are only here to allow substitutions to be declared inline with |
| 45 | // diagnostics |
| 46 | string Component = ""; |
| 47 | string CategoryName = ""; |
| 48 | } |
| 49 | |
| 50 | // Diagnostic Categories. These can be applied to groups or individual |
| 51 | // diagnostics to specify a category. |
| 52 | class DiagCategory<string Name> { |
| 53 | string CategoryName = Name; |
| 54 | } |
| 55 | |
| 56 | // Diagnostic Groups. |
| 57 | class DiagGroup<string Name, list<DiagGroup> subgroups = []> { |
| 58 | string GroupName = Name; |
| 59 | list<DiagGroup> SubGroups = subgroups; |
| 60 | string CategoryName = ""; |
| 61 | code Documentation = [{}]; |
| 62 | } |
| 63 | class InGroup<DiagGroup G> { DiagGroup Group = G; } |
| 64 | //class IsGroup<string Name> { DiagGroup Group = DiagGroup<Name>; } |
| 65 | |
| 66 | // This defines documentation for diagnostic groups. |
| 67 | include "DiagnosticDocs.td" |
| 68 | |
| 69 | // This defines all of the named diagnostic categories. |
| 70 | include "DiagnosticCategories.td" |
| 71 | |
| 72 | // This defines all of the named diagnostic groups. |
| 73 | include "DiagnosticGroups.td" |
| 74 | |
| 75 | |
| 76 | // All diagnostics emitted by the compiler are an indirect subclass of this. |
| 77 | class Diagnostic<string text, DiagClass DC, Severity defaultmapping> { |
| 78 | /// Component is specified by the file with a big let directive. |
| 79 | string Component = ?; |
| 80 | string Text = text; |
| 81 | DiagClass Class = DC; |
| 82 | SFINAEResponse SFINAE = SFINAE_Suppress; |
| 83 | bit AccessControl = 0; |
| 84 | bit WarningNoWerror = 0; |
| 85 | bit ShowInSystemHeader = 0; |
| 86 | Severity DefaultSeverity = defaultmapping; |
| 87 | DiagGroup Group; |
| 88 | string CategoryName = ""; |
| 89 | } |
| 90 | |
| 91 | class SFINAEFailure { |
| 92 | SFINAEResponse SFINAE = SFINAE_SubstitutionFailure; |
| 93 | } |
| 94 | class NoSFINAE { |
| 95 | SFINAEResponse SFINAE = SFINAE_Report; |
| 96 | } |
| 97 | class AccessControl { |
| 98 | SFINAEResponse SFINAE = SFINAE_AccessControl; |
| 99 | } |
| 100 | |
| 101 | class ShowInSystemHeader { |
| 102 | bit ShowInSystemHeader = 1; |
| 103 | } |
| 104 | |
| 105 | class SuppressInSystemHeader { |
| 106 | bit ShowInSystemHeader = 0; |
| 107 | } |
| 108 | |
| 109 | // FIXME: ExtWarn and Extension should also be SFINAEFailure by default. |
| 110 | class Error<string str> : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure { |
| 111 | bit ShowInSystemHeader = 1; |
| 112 | } |
| 113 | // Warnings default to on (but can be default-off'd with DefaultIgnore). |
| 114 | // This is used for warnings about questionable code; warnings about |
| 115 | // accepted language extensions should use Extension or ExtWarn below instead. |
| 116 | class Warning<string str> : Diagnostic<str, CLASS_WARNING, SEV_Warning>; |
| 117 | // Remarks can be turned on with -R flags and provide commentary, e.g. on |
| 118 | // optimizer decisions. |
| 119 | class Remark<string str> : Diagnostic<str, CLASS_REMARK, SEV_Ignored>; |
| 120 | // Extensions are warnings about accepted language extensions. |
| 121 | // Extension warnings are default-off but enabled by -pedantic. |
| 122 | class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, SEV_Ignored>; |
| 123 | // ExtWarns are warnings about accepted language extensions. |
| 124 | // ExtWarn warnings are default-on. |
| 125 | class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, SEV_Warning>; |
| 126 | // Notes can provide supplementary information on errors, warnings, and remarks. |
| 127 | class Note<string str> : Diagnostic<str, CLASS_NOTE, SEV_Fatal/*ignored*/>; |
| 128 | |
| 129 | |
| 130 | class DefaultIgnore { Severity DefaultSeverity = SEV_Ignored; } |
| 131 | class DefaultWarn { Severity DefaultSeverity = SEV_Warning; } |
| 132 | class DefaultError { Severity DefaultSeverity = SEV_Error; } |
| 133 | class DefaultFatal { Severity DefaultSeverity = SEV_Fatal; } |
| 134 | class DefaultWarnNoWerror { |
| 135 | bit WarningNoWerror = 1; |
| 136 | } |
| 137 | class DefaultRemark { Severity DefaultSeverity = SEV_Remark; } |
| 138 | |
| 139 | // Definitions for Diagnostics. |
| 140 | include "DiagnosticASTKinds.td" |
| 141 | include "DiagnosticAnalysisKinds.td" |
| 142 | include "DiagnosticCommentKinds.td" |
| 143 | include "DiagnosticCommonKinds.td" |
| 144 | include "DiagnosticCrossTUKinds.td" |
| 145 | include "DiagnosticDriverKinds.td" |
| 146 | include "DiagnosticFrontendKinds.td" |
| 147 | include "DiagnosticLexKinds.td" |
| 148 | include "DiagnosticParseKinds.td" |
| 149 | include "DiagnosticRefactoringKinds.td" |
| 150 | include "DiagnosticSemaKinds.td" |
| 151 | include "DiagnosticSerializationKinds.td" |
| 152 | |
| 153 | |