Skip to content

Commit 46ab684

Browse files
authored
[utils][TableGen] Unify name qualifications in DirectiveEmitter (llvm#140606)
Remove extraneous qualifications from names when - the name is explicitly enclosed by corresponding namespaces, and - the name is in a body of a function defined in corresponding namespaces. Otherwise add missing qualifications. This applies to individual sections of TableGen output, and makes name lookup independent of the context in which these sections are included.
1 parent 9053947 commit 46ab684

File tree

3 files changed

+106
-116
lines changed

3 files changed

+106
-116
lines changed

llvm/test/TableGen/directive1.td

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def TDL_DirA : Directive<"dira"> {
9898
// CHECK-EMPTY:
9999
// CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
100100
// CHECK-EMPTY:
101-
// CHECK-NEXT: constexpr auto TDLD_dira = llvm::tdl::Directive::TDLD_dira;
101+
// CHECK-NEXT: constexpr auto TDLD_dira = Directive::TDLD_dira;
102102
// CHECK-EMPTY:
103103
// CHECK-NEXT: enum class Clause {
104104
// CHECK-NEXT: TDLC_clausea,
@@ -108,28 +108,28 @@ def TDL_DirA : Directive<"dira"> {
108108
// CHECK-EMPTY:
109109
// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 3;
110110
// CHECK-EMPTY:
111-
// CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
112-
// CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
113-
// CHECK-NEXT: constexpr auto TDLC_clausec = llvm::tdl::Clause::TDLC_clausec;
111+
// CHECK-NEXT: constexpr auto TDLC_clausea = Clause::TDLC_clausea;
112+
// CHECK-NEXT: constexpr auto TDLC_clauseb = Clause::TDLC_clauseb;
113+
// CHECK-NEXT: constexpr auto TDLC_clausec = Clause::TDLC_clausec;
114114
// CHECK-EMPTY:
115115
// CHECK-NEXT: enum class AKind {
116116
// CHECK-NEXT: TDLCV_vala=1,
117117
// CHECK-NEXT: TDLCV_valb=2,
118118
// CHECK-NEXT: TDLCV_valc=3,
119119
// CHECK-NEXT: };
120120
// CHECK-EMPTY:
121-
// CHECK-NEXT: constexpr auto TDLCV_vala = llvm::tdl::AKind::TDLCV_vala;
122-
// CHECK-NEXT: constexpr auto TDLCV_valb = llvm::tdl::AKind::TDLCV_valb;
123-
// CHECK-NEXT: constexpr auto TDLCV_valc = llvm::tdl::AKind::TDLCV_valc;
121+
// CHECK-NEXT: constexpr auto TDLCV_vala = AKind::TDLCV_vala;
122+
// CHECK-NEXT: constexpr auto TDLCV_valb = AKind::TDLCV_valb;
123+
// CHECK-NEXT: constexpr auto TDLCV_valc = AKind::TDLCV_valc;
124124
// CHECK-EMPTY:
125125
// CHECK-NEXT: // Enumeration helper functions
126-
// CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(llvm::StringRef Str);
126+
// CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(StringRef Str);
127127
// CHECK-EMPTY:
128-
// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlDirectiveName(Directive D);
128+
// CHECK-NEXT: LLVM_ABI StringRef getTdlDirectiveName(Directive D);
129129
// CHECK-EMPTY:
130-
// CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(llvm::StringRef Str);
130+
// CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(StringRef Str);
131131
// CHECK-EMPTY:
132-
// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlClauseName(Clause C);
132+
// CHECK-NEXT: LLVM_ABI StringRef getTdlClauseName(Clause C);
133133
// CHECK-EMPTY:
134134
// CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
135135
// CHECK-NEXT: LLVM_ABI bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
@@ -138,8 +138,8 @@ def TDL_DirA : Directive<"dira"> {
138138
// CHECK-NEXT: LLVM_ABI Association getDirectiveAssociation(Directive D);
139139
// CHECK-NEXT: LLVM_ABI Category getDirectiveCategory(Directive D);
140140
// CHECK-NEXT: LLVM_ABI SourceLanguage getDirectiveLanguages(Directive D);
141-
// CHECK-NEXT: LLVM_ABI AKind getAKind(StringRef);
142-
// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlAKindName(AKind);
141+
// CHECK-NEXT: LLVM_ABI AKind getAKind(StringRef Str);
142+
// CHECK-NEXT: LLVM_ABI StringRef getTdlAKindName(AKind x);
143143
// CHECK-EMPTY:
144144
// CHECK-NEXT: } // namespace tdl
145145
// CHECK-NEXT: } // namespace llvm
@@ -155,8 +155,8 @@ def TDL_DirA : Directive<"dira"> {
155155
// IMPL-NEXT: // Sets for dira
156156
// IMPL-EMPTY:
157157
// IMPL-NEXT: static allowedClauses_TDLD_dira {
158-
// IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
159-
// IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
158+
// IMPL-NEXT: Clause::TDLC_clausea,
159+
// IMPL-NEXT: Clause::TDLC_clauseb,
160160
// IMPL-NEXT: };
161161
// IMPL-EMPTY:
162162
// IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
@@ -311,29 +311,29 @@ def TDL_DirA : Directive<"dira"> {
311311
// IMPL-EMPTY:
312312
// IMPL-NEXT: #include "llvm/Support/ErrorHandling.h"
313313
// IMPL-EMPTY:
314-
// IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
315-
// IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
314+
// IMPL-NEXT: llvm::tdl::Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
315+
// IMPL-NEXT: return StringSwitch<Directive>(Str)
316316
// IMPL-NEXT: .Case("dira",TDLD_dira)
317317
// IMPL-NEXT: .Default(TDLD_dira);
318318
// IMPL-NEXT: }
319319
// IMPL-EMPTY:
320-
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
320+
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(llvm::tdl::Directive Kind) {
321321
// IMPL-NEXT: switch (Kind) {
322322
// IMPL-NEXT: case TDLD_dira:
323323
// IMPL-NEXT: return "dira";
324324
// IMPL-NEXT: }
325325
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
326326
// IMPL-NEXT: }
327327
// IMPL-EMPTY:
328-
// IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
329-
// IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
328+
// IMPL-NEXT: llvm::tdl::Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
329+
// IMPL-NEXT: return StringSwitch<Clause>(Str)
330330
// IMPL-NEXT: .Case("clausea",TDLC_clausea)
331331
// IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
332332
// IMPL-NEXT: .Case("clausec",TDLC_clausec)
333333
// IMPL-NEXT: .Default(TDLC_clauseb);
334334
// IMPL-NEXT: }
335335
// IMPL-EMPTY:
336-
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
336+
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(llvm::tdl::Clause Kind) {
337337
// IMPL-NEXT: switch (Kind) {
338338
// IMPL-NEXT: case TDLC_clausea:
339339
// IMPL-NEXT: return "clausea";
@@ -345,8 +345,8 @@ def TDL_DirA : Directive<"dira"> {
345345
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
346346
// IMPL-NEXT: }
347347
// IMPL-EMPTY:
348-
// IMPL-NEXT: AKind llvm::tdl::getAKind(llvm::StringRef Str) {
349-
// IMPL-NEXT: return llvm::StringSwitch<AKind>(Str)
348+
// IMPL-NEXT: llvm::tdl::AKind llvm::tdl::getAKind(llvm::StringRef Str) {
349+
// IMPL-NEXT: return StringSwitch<AKind>(Str)
350350
// IMPL-NEXT: .Case("vala",TDLCV_vala)
351351
// IMPL-NEXT: .Case("valb",TDLCV_valb)
352352
// IMPL-NEXT: .Case("valc",TDLCV_valc)
@@ -365,9 +365,9 @@ def TDL_DirA : Directive<"dira"> {
365365
// IMPL-NEXT: llvm_unreachable("Invalid Tdl AKind kind");
366366
// IMPL-NEXT: }
367367
// IMPL-EMPTY:
368-
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
369-
// IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
370-
// IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
368+
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(llvm::tdl::Directive D, llvm::tdl::Clause C, unsigned Version) {
369+
// IMPL-NEXT: assert(unsigned(D) <= Directive_enumSize);
370+
// IMPL-NEXT: assert(unsigned(C) <= Clause_enumSize);
371371
// IMPL-NEXT: switch (D) {
372372
// IMPL-NEXT: case TDLD_dira:
373373
// IMPL-NEXT: switch (C) {
@@ -385,24 +385,24 @@ def TDL_DirA : Directive<"dira"> {
385385
// IMPL-EMPTY:
386386
// IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
387387
// IMPL-NEXT: switch (Dir) {
388-
// IMPL-NEXT: case llvm::tdl::Directive::TDLD_dira:
389-
// IMPL-NEXT: return llvm::tdl::Association::None;
388+
// IMPL-NEXT: case TDLD_dira:
389+
// IMPL-NEXT: return Association::None;
390390
// IMPL-NEXT: } // switch (Dir)
391391
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
392392
// IMPL-NEXT: }
393393
// IMPL-EMPTY:
394394
// IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
395395
// IMPL-NEXT: switch (Dir) {
396-
// IMPL-NEXT: case llvm::tdl::TDLD_dira:
397-
// IMPL-NEXT: return llvm::tdl::Category::Executable;
396+
// IMPL-NEXT: case TDLD_dira:
397+
// IMPL-NEXT: return Category::Executable;
398398
// IMPL-NEXT: } // switch (Dir)
399399
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
400400
// IMPL-NEXT: }
401401
// IMPL-EMPTY:
402402
// IMPL-NEXT: llvm::tdl::SourceLanguage llvm::tdl::getDirectiveLanguages(llvm::tdl::Directive D) {
403403
// IMPL-NEXT: switch (D) {
404-
// IMPL-NEXT: case llvm::tdl::TDLD_dira:
405-
// IMPL-NEXT: return llvm::tdl::SourceLanguage::C | llvm::tdl::SourceLanguage::Fortran;
404+
// IMPL-NEXT: case TDLD_dira:
405+
// IMPL-NEXT: return SourceLanguage::C | SourceLanguage::Fortran;
406406
// IMPL-NEXT: } // switch(D)
407407
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
408408
// IMPL-NEXT: }

llvm/test/TableGen/directive2.td

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ def TDL_DirA : Directive<"dira"> {
9999
// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 4;
100100
// CHECK-EMPTY:
101101
// CHECK-NEXT: // Enumeration helper functions
102-
// CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(llvm::StringRef Str);
102+
// CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(StringRef Str);
103103
// CHECK-EMPTY:
104-
// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlDirectiveName(Directive D);
104+
// CHECK-NEXT: LLVM_ABI StringRef getTdlDirectiveName(Directive D);
105105
// CHECK-EMPTY:
106-
// CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(llvm::StringRef Str);
106+
// CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(StringRef Str);
107107
// CHECK-EMPTY:
108-
// CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlClauseName(Clause C);
108+
// CHECK-NEXT: LLVM_ABI StringRef getTdlClauseName(Clause C);
109109
// CHECK-EMPTY:
110110
// CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
111111
// CHECK-NEXT: LLVM_ABI bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
@@ -127,8 +127,8 @@ def TDL_DirA : Directive<"dira"> {
127127
// IMPL-NEXT: // Sets for dira
128128
// IMPL-EMPTY:
129129
// IMPL-NEXT: static allowedClauses_TDLD_dira {
130-
// IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
131-
// IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
130+
// IMPL-NEXT: Clause::TDLC_clausea,
131+
// IMPL-NEXT: Clause::TDLC_clauseb,
132132
// IMPL-NEXT: };
133133
// IMPL-EMPTY:
134134
// IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
@@ -259,30 +259,30 @@ def TDL_DirA : Directive<"dira"> {
259259
// IMPL-EMPTY:
260260
// IMPL-NEXT: #include "llvm/Support/ErrorHandling.h"
261261
// IMPL-EMPTY:
262-
// IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
263-
// IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
262+
// IMPL-NEXT: llvm::tdl::Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
263+
// IMPL-NEXT: return StringSwitch<Directive>(Str)
264264
// IMPL-NEXT: .Case("dira",TDLD_dira)
265265
// IMPL-NEXT: .Default(TDLD_dira);
266266
// IMPL-NEXT: }
267267
// IMPL-EMPTY:
268-
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
268+
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(llvm::tdl::Directive Kind) {
269269
// IMPL-NEXT: switch (Kind) {
270270
// IMPL-NEXT: case TDLD_dira:
271271
// IMPL-NEXT: return "dira";
272272
// IMPL-NEXT: }
273273
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
274274
// IMPL-NEXT: }
275275
// IMPL-EMPTY:
276-
// IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
277-
// IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
276+
// IMPL-NEXT: llvm::tdl::Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
277+
// IMPL-NEXT: return StringSwitch<Clause>(Str)
278278
// IMPL-NEXT: .Case("clausea",TDLC_clauseb)
279279
// IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
280280
// IMPL-NEXT: .Case("clausec",TDLC_clausec)
281281
// IMPL-NEXT: .Case("claused",TDLC_clauseb)
282282
// IMPL-NEXT: .Default(TDLC_clauseb);
283283
// IMPL-NEXT: }
284284
// IMPL-EMPTY:
285-
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
285+
// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(llvm::tdl::Clause Kind) {
286286
// IMPL-NEXT: switch (Kind) {
287287
// IMPL-NEXT: case TDLC_clausea:
288288
// IMPL-NEXT: return "clausea";
@@ -296,9 +296,9 @@ def TDL_DirA : Directive<"dira"> {
296296
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
297297
// IMPL-NEXT: }
298298
// IMPL-EMPTY:
299-
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
300-
// IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
301-
// IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
299+
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(llvm::tdl::Directive D, llvm::tdl::Clause C, unsigned Version) {
300+
// IMPL-NEXT: assert(unsigned(D) <= Directive_enumSize);
301+
// IMPL-NEXT: assert(unsigned(C) <= Clause_enumSize);
302302
// IMPL-NEXT: switch (D) {
303303
// IMPL-NEXT: case TDLD_dira:
304304
// IMPL-NEXT: switch (C) {
@@ -316,24 +316,24 @@ def TDL_DirA : Directive<"dira"> {
316316
// IMPL-EMPTY:
317317
// IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
318318
// IMPL-NEXT: switch (Dir) {
319-
// IMPL-NEXT: case llvm::tdl::Directive::TDLD_dira:
320-
// IMPL-NEXT: return llvm::tdl::Association::Block;
319+
// IMPL-NEXT: case TDLD_dira:
320+
// IMPL-NEXT: return Association::Block;
321321
// IMPL-NEXT: } // switch (Dir)
322322
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
323323
// IMPL-NEXT: }
324324
// IMPL-EMPTY:
325325
// IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
326326
// IMPL-NEXT: switch (Dir) {
327-
// IMPL-NEXT: case llvm::tdl::TDLD_dira:
328-
// IMPL-NEXT: return llvm::tdl::Category::Declarative;
327+
// IMPL-NEXT: case TDLD_dira:
328+
// IMPL-NEXT: return Category::Declarative;
329329
// IMPL-NEXT: } // switch (Dir)
330330
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
331331
// IMPL-NEXT: }
332332
// IMPL-EMPTY:
333333
// IMPL-NEXT: llvm::tdl::SourceLanguage llvm::tdl::getDirectiveLanguages(llvm::tdl::Directive D) {
334334
// IMPL-NEXT: switch (D) {
335-
// IMPL-NEXT: case llvm::tdl::TDLD_dira:
336-
// IMPL-NEXT: return llvm::tdl::SourceLanguage::C | llvm::tdl::SourceLanguage::Fortran;
335+
// IMPL-NEXT: case TDLD_dira:
336+
// IMPL-NEXT: return SourceLanguage::C | SourceLanguage::Fortran;
337337
// IMPL-NEXT: } // switch(D)
338338
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
339339
// IMPL-NEXT: }

0 commit comments

Comments
 (0)