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.
17class Severity<string N> {
18  string Name = N;
19}
20def SEV_Ignored : Severity<"Ignored">;
21def SEV_Remark  : Severity<"Remark">;
22def SEV_Warning : Severity<"Warning">;
23def SEV_Error   : Severity<"Error">;
24def SEV_Fatal   : Severity<"Fatal">;
25
26// Define the diagnostic classes.
27class DiagClass;
28def CLASS_NOTE      : DiagClass;
29def CLASS_REMARK    : DiagClass;
30def CLASS_WARNING   : DiagClass;
31def CLASS_EXTENSION : DiagClass;
32def CLASS_ERROR     : DiagClass;
33
34// Responses to a diagnostic in a SFINAE context.
35class SFINAEResponse;
36def SFINAE_SubstitutionFailure : SFINAEResponse;
37def SFINAE_Suppress            : SFINAEResponse;
38def SFINAE_Report              : SFINAEResponse;
39def SFINAE_AccessControl       : SFINAEResponse;
40
41// Textual substitutions which may be performed on the text of diagnostics
42class 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  bit Deferrable = 0;
49}
50
51// Diagnostic Categories.  These can be applied to groups or individual
52// diagnostics to specify a category.
53class DiagCategory<string Name> {
54  string CategoryName = Name;
55}
56
57// Diagnostic Groups.
58class DiagGroup<string Name, list<DiagGroup> subgroups = []> {
59  string GroupName = Name;
60  list<DiagGroup> SubGroups = subgroups;
61  string CategoryName = "";
62  code Documentation = [{}];
63}
64class InGroup<DiagGroup G> { DiagGroup Group = G; }
65//class IsGroup<string Name> { DiagGroup Group = DiagGroup<Name>; }
66
67// This defines documentation for diagnostic groups.
68include "DiagnosticDocs.td"
69
70// This defines all of the named diagnostic categories.
71include "DiagnosticCategories.td"
72
73// This defines all of the named diagnostic groups.
74include "DiagnosticGroups.td"
75
76
77// All diagnostics emitted by the compiler are an indirect subclass of this.
78class Diagnostic<string text, DiagClass DC, Severity defaultmapping> {
79  /// Component is specified by the file with a big let directive.
80  string         Component = ?;
81  string         Text = text;
82  DiagClass      Class = DC;
83  SFINAEResponse SFINAE = SFINAE_Suppress;
84  bit            AccessControl = 0;
85  bit            WarningNoWerror = 0;
86  bit            ShowInSystemHeader = 0;
87  bit            ShowInSystemMacro = 1;
88  bit            Deferrable = 0;
89  Severity       DefaultSeverity = defaultmapping;
90  DiagGroup      Group;
91  string         CategoryName = "";
92}
93
94class SFINAEFailure {
95  SFINAEResponse SFINAE = SFINAE_SubstitutionFailure;
96}
97class NoSFINAE {
98  SFINAEResponse SFINAE = SFINAE_Report;
99}
100class AccessControl {
101  SFINAEResponse SFINAE = SFINAE_AccessControl;
102}
103
104class ShowInSystemHeader {
105  bit ShowInSystemHeader = 1;
106}
107
108class SuppressInSystemHeader {
109  bit ShowInSystemHeader = 0;
110}
111
112class ShowInSystemMacro {
113  bit ShowInSystemMacro = 1;
114}
115
116class SuppressInSystemMacro {
117  bit ShowInSystemMacro = 0;
118}
119
120class Deferrable {
121  bit Deferrable = 1;
122}
123
124class NonDeferrable {
125  bit Deferrable = 0;
126}
127
128// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
129class Error<string str>     : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure {
130  bit ShowInSystemHeader = 1;
131}
132// Warnings default to on (but can be default-off'd with DefaultIgnore).
133// This is used for warnings about questionable code; warnings about
134// accepted language extensions should use Extension or ExtWarn below instead.
135class Warning<string str>   : Diagnostic<str, CLASS_WARNING, SEV_Warning>;
136// Remarks can be turned on with -R flags and provide commentary, e.g. on
137// optimizer decisions.
138class Remark<string str>    : Diagnostic<str, CLASS_REMARK, SEV_Ignored>;
139// Extensions are warnings about accepted language extensions.
140// Extension warnings are default-off but enabled by -pedantic.
141class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, SEV_Ignored>;
142// ExtWarns are warnings about accepted language extensions.
143// ExtWarn warnings are default-on.
144class ExtWarn<string str>   : Diagnostic<str, CLASS_EXTENSION, SEV_Warning>;
145// Notes can provide supplementary information on errors, warnings, and remarks.
146class Note<string str>      : Diagnostic<str, CLASS_NOTE, SEV_Fatal/*ignored*/>;
147
148
149class DefaultIgnore { Severity DefaultSeverity = SEV_Ignored; }
150class DefaultWarn   { Severity DefaultSeverity = SEV_Warning; }
151class DefaultError  { Severity DefaultSeverity = SEV_Error; }
152class DefaultFatal  { Severity DefaultSeverity = SEV_Fatal; }
153class DefaultWarnNoWerror {
154  bit WarningNoWerror = 1;
155}
156class DefaultRemark { Severity DefaultSeverity = SEV_Remark; }
157
158// Definitions for Diagnostics.
159include "DiagnosticASTKinds.td"
160include "DiagnosticAnalysisKinds.td"
161include "DiagnosticCommentKinds.td"
162include "DiagnosticCommonKinds.td"
163include "DiagnosticCrossTUKinds.td"
164include "DiagnosticDriverKinds.td"
165include "DiagnosticFrontendKinds.td"
166include "DiagnosticLexKinds.td"
167include "DiagnosticParseKinds.td"
168include "DiagnosticRefactoringKinds.td"
169include "DiagnosticSemaKinds.td"
170include "DiagnosticSerializationKinds.td"
171