forked from llvm-mirror/clang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang Tablegen][RFC] Allow Early Textual Substitutions in `Diagnosti…
…c` messages. Summary: There are cases where the same string or select is repeated verbatim in a lot of diagnostics. This can be a pain to maintain and update. Tablegen provides no way stash the common text somewhere and reuse it in the diagnostics, until now! This patch allows diagnostic texts to contain `%sub{<definition-name>}`, where `<definition-name>` names a Tablegen record of type `TextSubstitution`. These substitutions are done early, before the diagnostic string is otherwise processed. All `%sub` modifiers will be replaced before the diagnostic definitions are emitted. The substitution must specify all arguments used by the substitution, and modifier indexes in the substitution are re-numbered accordingly. For example: ``` def select_ovl_candidate : TextSubstitution<"%select{function|constructor}0%select{| template| %2}1">; ``` when used as ``` "candidate `%sub{select_ovl_candidate}3,2,1 not viable" ``` will act as if we wrote: ``` "candidate %select{function|constructor}3%select{| template| %1}2 not viable" ``` Reviewers: rsmith, rjmccall, aaron.ballman, a.sidorin Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46740 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332799 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
11 changed files
with
1,106 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,130 @@ | ||
// Define the diagnostic mappings. | ||
class DiagMapping; | ||
def MAP_IGNORE : DiagMapping; | ||
def MAP_WARNING : DiagMapping; | ||
def MAP_ERROR : DiagMapping; | ||
def MAP_FATAL : DiagMapping; | ||
//===--- DiagnosticBase.inc - A test file mimicking Diagnostic.td ---------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the TableGen core definitions for the diagnostics | ||
// and diagnostic control. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// See the Internals Manual, section The Diagnostics Subsystem for an overview. | ||
|
||
// Define the diagnostic severities. | ||
class Severity<string N> { | ||
string Name = N; | ||
} | ||
def SEV_Ignored : Severity<"Ignored">; | ||
def SEV_Remark : Severity<"Remark">; | ||
def SEV_Warning : Severity<"Warning">; | ||
def SEV_Error : Severity<"Error">; | ||
def SEV_Fatal : Severity<"Fatal">; | ||
|
||
// Define the diagnostic classes. | ||
class DiagClass; | ||
def CLASS_NOTE : DiagClass; | ||
def CLASS_REMARK : DiagClass; | ||
def CLASS_WARNING : DiagClass; | ||
def CLASS_EXTENSION : DiagClass; | ||
def CLASS_ERROR : DiagClass; | ||
|
||
// Responses to a diagnostic in a SFINAE context. | ||
class SFINAEResponse; | ||
def SFINAE_SubstitutionFailure : SFINAEResponse; | ||
def SFINAE_Suppress : SFINAEResponse; | ||
def SFINAE_Report : SFINAEResponse; | ||
def SFINAE_AccessControl : SFINAEResponse; | ||
|
||
// Textual substitutions which may be performed on the text of diagnostics | ||
class TextSubstitution<string Text> { | ||
string Substitution = Text; | ||
// TODO: These are only here to allow substitutions to be declared inline with | ||
// diagnostics | ||
string Component = ""; | ||
string CategoryName = ""; | ||
} | ||
|
||
// Diagnostic Categories. These can be applied to groups or individual | ||
// diagnostics to specify a category. | ||
class DiagCategory<string Name> { | ||
string CategoryName = Name; | ||
} | ||
|
||
// Diagnostic Groups. | ||
class DiagGroup<string Name, list<DiagGroup> subgroups = []> { | ||
string GroupName = Name; | ||
list<DiagGroup> SubGroups = subgroups; | ||
string CategoryName = ""; | ||
code Documentation = [{}]; | ||
} | ||
class InGroup<DiagGroup G> { DiagGroup Group = G; } | ||
//class IsGroup<string Name> { DiagGroup Group = DiagGroup<Name>; } | ||
|
||
include "DiagnosticDocs.inc" | ||
|
||
// All diagnostics emitted by the compiler are an indirect subclass of this. | ||
class Diagnostic<string text, DiagClass DC, DiagMapping defaultmapping> { | ||
string Text = text; | ||
DiagClass Class = DC; | ||
DiagMapping DefaultMapping = defaultmapping; | ||
DiagGroup Group; | ||
string CategoryName = ""; | ||
} | ||
|
||
class Error<string str> : Diagnostic<str, CLASS_ERROR, MAP_ERROR>; | ||
class Warning<string str> : Diagnostic<str, CLASS_WARNING, MAP_WARNING>; | ||
class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_IGNORE>; | ||
class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_WARNING>; | ||
class Note<string str> : Diagnostic<str, CLASS_NOTE, MAP_FATAL/*ignored*/>; | ||
class Diagnostic<string text, DiagClass DC, Severity defaultmapping> { | ||
/// Component is specified by the file with a big let directive. | ||
string Component = ?; | ||
string Text = text; | ||
DiagClass Class = DC; | ||
SFINAEResponse SFINAE = SFINAE_Suppress; | ||
bit AccessControl = 0; | ||
bit WarningNoWerror = 0; | ||
bit ShowInSystemHeader = 0; | ||
Severity DefaultSeverity = defaultmapping; | ||
DiagGroup Group; | ||
string CategoryName = ""; | ||
} | ||
|
||
class SFINAEFailure { | ||
SFINAEResponse SFINAE = SFINAE_SubstitutionFailure; | ||
} | ||
class NoSFINAE { | ||
SFINAEResponse SFINAE = SFINAE_Report; | ||
} | ||
class AccessControl { | ||
SFINAEResponse SFINAE = SFINAE_AccessControl; | ||
} | ||
|
||
class ShowInSystemHeader { | ||
bit ShowInSystemHeader = 1; | ||
} | ||
|
||
class SuppressInSystemHeader { | ||
bit ShowInSystemHeader = 0; | ||
} | ||
|
||
// FIXME: ExtWarn and Extension should also be SFINAEFailure by default. | ||
class Error<string str> : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure { | ||
bit ShowInSystemHeader = 1; | ||
} | ||
// Warnings default to on (but can be default-off'd with DefaultIgnore). | ||
// This is used for warnings about questionable code; warnings about | ||
// accepted language extensions should use Extension or ExtWarn below instead. | ||
class Warning<string str> : Diagnostic<str, CLASS_WARNING, SEV_Warning>; | ||
// Remarks can be turned on with -R flags and provide commentary, e.g. on | ||
// optimizer decisions. | ||
class Remark<string str> : Diagnostic<str, CLASS_REMARK, SEV_Ignored>; | ||
// Extensions are warnings about accepted language extensions. | ||
// Extension warnings are default-off but enabled by -pedantic. | ||
class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, SEV_Ignored>; | ||
// ExtWarns are warnings about accepted language extensions. | ||
// ExtWarn warnings are default-on. | ||
class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, SEV_Warning>; | ||
// Notes can provide supplementary information on errors, warnings, and remarks. | ||
class Note<string str> : Diagnostic<str, CLASS_NOTE, SEV_Fatal/*ignored*/>; | ||
|
||
|
||
class DefaultIgnore { Severity DefaultSeverity = SEV_Ignored; } | ||
class DefaultWarn { Severity DefaultSeverity = SEV_Warning; } | ||
class DefaultError { Severity DefaultSeverity = SEV_Error; } | ||
class DefaultFatal { Severity DefaultSeverity = SEV_Fatal; } | ||
class DefaultWarnNoWerror { | ||
bit WarningNoWerror = 1; | ||
} | ||
class DefaultRemark { Severity DefaultSeverity = SEV_Remark; } |
Oops, something went wrong.