Skip to content

Commit 116d20e

Browse files
committed
Fix Review comments:
-Update internals-manual -Update document generator comment, clarify we intend to document as if it is a 'select' -Add test coverage for other modifiers using '<' -Add additional suggested test coverage
1 parent 4fbfdc8 commit 116d20e

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

clang/docs/InternalsManual.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,21 @@ Description:
276276
diagnostic instead of having to do things textually. The selected string
277277
does undergo formatting.
278278

279+
**"enum_select format**
280+
281+
Example:
282+
``unknown frobbling of a %enum_select<FrobbleKind>{%VarDecl{variable declaration}|%FuncDecl{function declaration}}0 when blarging``
283+
Class:
284+
Integers
285+
Description:
286+
This format specifier is used exactly like a ``select`` specifier, except it
287+
additionally generates a namespace, enumeration, and enumerator list based on
288+
the format string given. In the above case, a namespace is generated named
289+
``FrobbleKind`` that has a anonymous enumeration with the enumerators
290+
``VarDecl`` and ``FuncDecl`` which correspond to the values 0 and 1. This
291+
permits a clearer use of the ``Diag`` in source code, as the above could be
292+
called as: ``Diag(Loc, diag::frobble) << diag::FrobbleKind::VarDecl``.
293+
279294
**"plural" format**
280295

281296
Example:
Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
1-
// RUN: clang-tblgen --gen-clang-diags-enums -I%S %s 2>&1 | FileCheck %s
1+
// RUN: not clang-tblgen --gen-clang-diags-enums -DERROR1 -I%S %s 2>&1 | FileCheck %s --check-prefixes=CHECK,C1
2+
// RUN: not clang-tblgen --gen-clang-diags-enums -DERROR2 -I%S %s 2>&1 | FileCheck %s --check-prefixes=CHECK,C2
3+
// RUN: not clang-tblgen --gen-clang-diags-enums -DERROR3 -I%S %s 2>&1 | FileCheck %s --check-prefixes=CHECK,C3
4+
// RUN: not clang-tblgen --gen-clang-diags-enums -DERROR4 -I%S %s 2>&1 | FileCheck %s --check-prefixes=CHECK,C4
25
include "DiagnosticBase.inc"
36

7+
// No real reason to diagnose these, the namespace generated as the
8+
// 'enumeration' name will never conflict with the enumerator.
9+
def EnumerationEnumeratorDupe : Error<"%enum_select<Matchy>{%Matchy{haha}}0">;
10+
11+
// Enumerator values aren't required, though this does seem kind of silly/not
12+
// particularly useful?
13+
def NoEnumerators : Error<"%enum_select<Name>{foo|bar|baz}0">;
14+
415
def DupeNames1 : Error<"%enum_select<DupeName>{}0">;
516
def DupeNames2 : Error<"%enum_select<DupeName>{}0">;
617
// CHECK: error: Duplicate enumeration name 'DupeName'
718
// CHECK-NEXT: def DupeNames2
819
// CHECK: note: Previous diagnostic is here
920
// CHECK-NEXT: def DupeNames1
1021

11-
def DupeValue : Error<"%enum_select<DupeValue>{%Name{V1}|%Name{V2}}0">;
12-
// CHECK: error: Duplicate enumerator name 'Name'
22+
def DupeValue : Error<"%enum_select<DupeValue>{%DName{V1}|%DName{V2}}0">;
23+
// CHECK: error: Duplicate enumerator name 'DName'
1324

25+
#ifdef ERROR1
1426
def EnumValNotExpected : Error<"%enum_select{V1|%Val2{V2}}0">;
15-
// CHECK: expected '<' after enum_select
27+
// C1: expected '<' after enum_select
28+
#endif
29+
30+
#ifdef ERROR2
31+
def SelectWithArrow : Error<"%select<Something>{V1|%Val2{V2}}0">;
32+
// C2: modifier '<' syntax not valid with %select
33+
#endif
34+
35+
#ifdef ERROR3
36+
// Missing closing > after the name of the enumeration
37+
def MissingClosing : Error<"%enum_select<MissingClosingName{}0">;
38+
// C3: expected '>' while parsing %enum_select
39+
#endif
1640

41+
#ifdef ERROR4
42+
// Missing { after the name of an enumerator
43+
def MissingTextAfterEnumerator: Error<"%enum_select<Name>{%OtherName|foo}0">;
44+
// C4: expected '{' while parsing %enum_select
45+
#endif

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,9 @@ struct DiagTextDocPrinter : DiagTextVisitor<DiagTextDocPrinter> {
910910
}
911911

912912
void VisitEnumSelect(EnumSelectPiece *P) {
913-
// For now, document this as if it were a 'select'.
913+
// Document this as if it were a 'select', which properly prints all of the
914+
// options correctly in a readable/reasonable manner. There isn't really
915+
// anything valuable we could add to readers here.
914916
VisitSelect(P);
915917
}
916918

@@ -1120,7 +1122,8 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
11201122
};
11211123

11221124
if (ModType != MT_EnumSelect && Text[0] == '<')
1123-
Builder.PrintFatalError("modifier '<' syntax not valid with " + Modifier);
1125+
Builder.PrintFatalError("modifier '<' syntax not valid with %" +
1126+
Modifier);
11241127

11251128
switch (ModType) {
11261129
case MT_Unknown:

0 commit comments

Comments
 (0)