Skip to content

Commit c1bd1ee

Browse files
committed
Rework "llvm-tblgen: Anonymize some functions.", llvmorg-17-init-2668-gc45e90cf152d
Anonymous namespace should be applied only to class definitions.
1 parent 708eb1b commit c1bd1ee

File tree

2 files changed

+62
-64
lines changed

2 files changed

+62
-64
lines changed

llvm/utils/TableGen/DirectiveEmitter.cpp

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ class IfDefScope {
3737
StringRef Name;
3838
raw_ostream &OS;
3939
};
40+
} // namespace
4041

4142
// Generate enum class
42-
void GenerateEnumClass(const std::vector<Record *> &Records, raw_ostream &OS,
43-
StringRef Enum, StringRef Prefix,
44-
const DirectiveLanguage &DirLang) {
43+
static void GenerateEnumClass(const std::vector<Record *> &Records,
44+
raw_ostream &OS, StringRef Enum, StringRef Prefix,
45+
const DirectiveLanguage &DirLang) {
4546
OS << "\n";
4647
OS << "enum class " << Enum << " {\n";
4748
for (const auto &R : Records) {
@@ -71,9 +72,10 @@ void GenerateEnumClass(const std::vector<Record *> &Records, raw_ostream &OS,
7172

7273
// Generate enums for values that clauses can take.
7374
// Also generate function declarations for get<Enum>Name(StringRef Str).
74-
void GenerateEnumClauseVal(const std::vector<Record *> &Records,
75-
raw_ostream &OS, const DirectiveLanguage &DirLang,
76-
std::string &EnumHelperFuncs) {
75+
static void GenerateEnumClauseVal(const std::vector<Record *> &Records,
76+
raw_ostream &OS,
77+
const DirectiveLanguage &DirLang,
78+
std::string &EnumHelperFuncs) {
7779
for (const auto &R : Records) {
7880
Clause C{R};
7981
const auto &ClauseVals = C.getClauseVals();
@@ -115,9 +117,9 @@ void GenerateEnumClauseVal(const std::vector<Record *> &Records,
115117
}
116118
}
117119

118-
bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
119-
const Directive &Directive,
120-
llvm::StringSet<> &CrtClauses) {
120+
static bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
121+
const Directive &Directive,
122+
llvm::StringSet<> &CrtClauses) {
121123
bool HasError = false;
122124
for (const auto &C : Clauses) {
123125
VersionedClause VerClause{C};
@@ -134,7 +136,8 @@ bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
134136
// Check for duplicate clauses in lists. Clauses cannot appear twice in the
135137
// three allowed list. Also, since required implies allowed, clauses cannot
136138
// appear in both the allowedClauses and requiredClauses lists.
137-
bool HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
139+
static bool
140+
HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
138141
bool HasDuplicate = false;
139142
for (const auto &D : Directives) {
140143
Directive Dir{D};
@@ -160,8 +163,6 @@ bool HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
160163
return HasDuplicate;
161164
}
162165

163-
} // namespace
164-
165166
// Check consitency of records. Return true if an error has been detected.
166167
// Return false if the records are valid.
167168
bool DirectiveLanguage::HasValidityErrors() const {
@@ -248,12 +249,11 @@ void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
248249

249250
} // namespace llvm
250251

251-
namespace {
252-
253252
// Generate function implementation for get<Enum>Name(StringRef Str)
254-
void GenerateGetName(const std::vector<Record *> &Records, raw_ostream &OS,
255-
StringRef Enum, const DirectiveLanguage &DirLang,
256-
StringRef Prefix) {
253+
static void GenerateGetName(const std::vector<Record *> &Records,
254+
raw_ostream &OS, StringRef Enum,
255+
const DirectiveLanguage &DirLang,
256+
StringRef Prefix) {
257257
OS << "\n";
258258
OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
259259
<< DirLang.getName() << Enum << "Name(" << Enum << " Kind) {\n";
@@ -275,9 +275,10 @@ void GenerateGetName(const std::vector<Record *> &Records, raw_ostream &OS,
275275
}
276276

277277
// Generate function implementation for get<Enum>Kind(StringRef Str)
278-
void GenerateGetKind(const std::vector<Record *> &Records, raw_ostream &OS,
279-
StringRef Enum, const DirectiveLanguage &DirLang,
280-
StringRef Prefix, bool ImplicitAsUnknown) {
278+
static void GenerateGetKind(const std::vector<Record *> &Records,
279+
raw_ostream &OS, StringRef Enum,
280+
const DirectiveLanguage &DirLang, StringRef Prefix,
281+
bool ImplicitAsUnknown) {
281282

282283
auto DefaultIt = llvm::find_if(
283284
Records, [](Record *R) { return R->getValueAsBit("isDefault") == true; });
@@ -309,8 +310,8 @@ void GenerateGetKind(const std::vector<Record *> &Records, raw_ostream &OS,
309310
}
310311

311312
// Generate function implementation for get<ClauseVal>Kind(StringRef Str)
312-
void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
313-
raw_ostream &OS) {
313+
static void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
314+
raw_ostream &OS) {
314315
for (const auto &R : DirLang.getClauses()) {
315316
Clause C{R};
316317
const auto &ClauseVals = C.getClauseVals();
@@ -365,10 +366,11 @@ void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
365366
}
366367
}
367368

368-
void GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
369-
raw_ostream &OS, StringRef DirectiveName,
370-
const DirectiveLanguage &DirLang,
371-
llvm::StringSet<> &Cases) {
369+
static void
370+
GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
371+
raw_ostream &OS, StringRef DirectiveName,
372+
const DirectiveLanguage &DirLang,
373+
llvm::StringSet<> &Cases) {
372374
for (const auto &C : Clauses) {
373375
VersionedClause VerClause{C};
374376

@@ -384,8 +386,8 @@ void GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
384386
}
385387

386388
// Generate the isAllowedClauseForDirective function implementation.
387-
void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
388-
raw_ostream &OS) {
389+
static void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
390+
raw_ostream &OS) {
389391
OS << "\n";
390392
OS << "bool llvm::" << DirLang.getCppNamespace()
391393
<< "::isAllowedClauseForDirective("
@@ -438,9 +440,10 @@ void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
438440
}
439441

440442
// Generate a simple enum set with the give clauses.
441-
void GenerateClauseSet(const std::vector<Record *> &Clauses, raw_ostream &OS,
442-
StringRef ClauseSetPrefix, Directive &Dir,
443-
const DirectiveLanguage &DirLang) {
443+
static void GenerateClauseSet(const std::vector<Record *> &Clauses,
444+
raw_ostream &OS, StringRef ClauseSetPrefix,
445+
Directive &Dir,
446+
const DirectiveLanguage &DirLang) {
444447

445448
OS << "\n";
446449
OS << " static " << DirLang.getClauseEnumSetClass() << " " << ClauseSetPrefix
@@ -456,8 +459,8 @@ void GenerateClauseSet(const std::vector<Record *> &Clauses, raw_ostream &OS,
456459
}
457460

458461
// Generate an enum set for the 4 kinds of clauses linked to a directive.
459-
void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
460-
raw_ostream &OS) {
462+
static void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
463+
raw_ostream &OS) {
461464

462465
IfDefScope Scope("GEN_FLANG_DIRECTIVE_CLAUSE_SETS", OS);
463466

@@ -496,8 +499,8 @@ void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
496499
// Generate a map of directive (key) with DirectiveClauses struct as values.
497500
// The struct holds the 4 sets of enumeration for the 4 kinds of clauses
498501
// allowances (allowed, allowed once, allowed exclusive and required).
499-
void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
500-
raw_ostream &OS) {
502+
static void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
503+
raw_ostream &OS) {
501504

502505
IfDefScope Scope("GEN_FLANG_DIRECTIVE_CLAUSE_MAP", OS);
503506

@@ -531,8 +534,8 @@ void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
531534
// If the clause does not hold a value, an EMPTY_CLASS is used.
532535
// If the clause class is generic then a WRAPPER_CLASS is used. When the value
533536
// is optional, the value class is wrapped into a std::optional.
534-
void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
535-
raw_ostream &OS) {
537+
static void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
538+
raw_ostream &OS) {
536539

537540
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES", OS);
538541

@@ -559,8 +562,8 @@ void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
559562
}
560563

561564
// Generate a list of the different clause classes for Flang.
562-
void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
563-
raw_ostream &OS) {
565+
static void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
566+
raw_ostream &OS) {
564567

565568
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST", OS);
566569

@@ -572,8 +575,8 @@ void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
572575
}
573576

574577
// Generate dump node list for the clauses holding a generic class name.
575-
void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
576-
raw_ostream &OS) {
578+
static void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
579+
raw_ostream &OS) {
577580

578581
IfDefScope Scope("GEN_FLANG_DUMP_PARSE_TREE_CLAUSES", OS);
579582

@@ -587,8 +590,8 @@ void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
587590

588591
// Generate Unparse functions for clauses classes in the Flang parse-tree
589592
// If the clause is a non-generic class, no entry is generated.
590-
void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
591-
raw_ostream &OS) {
593+
static void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
594+
raw_ostream &OS) {
592595

593596
IfDefScope Scope("GEN_FLANG_CLAUSE_UNPARSE", OS);
594597

@@ -639,8 +642,8 @@ void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
639642
}
640643

641644
// Generate check in the Enter functions for clauses classes.
642-
void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
643-
raw_ostream &OS) {
645+
static void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
646+
raw_ostream &OS) {
644647

645648
IfDefScope Scope("GEN_FLANG_CLAUSE_CHECK_ENTER", OS);
646649

@@ -654,8 +657,8 @@ void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
654657

655658
// Generate the mapping for clauses between the parser class and the
656659
// corresponding clause Kind
657-
void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
658-
raw_ostream &OS) {
660+
static void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
661+
raw_ostream &OS) {
659662

660663
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_KIND_MAP", OS);
661664

@@ -675,15 +678,15 @@ void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
675678
<< " Parser clause\");\n";
676679
}
677680

678-
bool compareClauseName(Record *R1, Record *R2) {
681+
static bool compareClauseName(Record *R1, Record *R2) {
679682
Clause C1{R1};
680683
Clause C2{R2};
681684
return (C1.getName() > C2.getName());
682685
}
683686

684687
// Generate the parser for the clauses.
685-
void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
686-
raw_ostream &OS) {
688+
static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
689+
raw_ostream &OS) {
687690
std::vector<Record *> Clauses = DirLang.getClauses();
688691
// Sort clauses in reverse alphabetical order so with clauses with same
689692
// beginning, the longer option is tried before.
@@ -756,8 +759,8 @@ void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
756759

757760
// Generate the implementation section for the enumeration in the directive
758761
// language
759-
void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
760-
raw_ostream &OS) {
762+
static void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
763+
raw_ostream &OS) {
761764

762765
GenerateDirectiveClauseSets(DirLang, OS);
763766

@@ -778,8 +781,8 @@ void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
778781
GenerateFlangClausesParser(DirLang, OS);
779782
}
780783

781-
void GenerateClauseClassMacro(const DirectiveLanguage &DirLang,
782-
raw_ostream &OS) {
784+
static void GenerateClauseClassMacro(const DirectiveLanguage &DirLang,
785+
raw_ostream &OS) {
783786
// Generate macros style information for legacy code in clang
784787
IfDefScope Scope("GEN_CLANG_CLAUSE_CLASS", OS);
785788

@@ -874,8 +877,6 @@ void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
874877
GenerateIsAllowedClause(DirLang, OS);
875878
}
876879

877-
} // namespace
878-
879880
namespace llvm {
880881

881882
// Generate the implemenation section for the enumeration in the directive

llvm/utils/TableGen/InstrDocsEmitter.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@
2828

2929
using namespace llvm;
3030

31-
namespace {
32-
33-
void writeTitle(StringRef Str, raw_ostream &OS, char Kind = '-') {
34-
OS << std::string(Str.size(), Kind) << "\n" << Str << "\n"
31+
static void writeTitle(StringRef Str, raw_ostream &OS, char Kind = '-') {
32+
OS << std::string(Str.size(), Kind) << "\n"
33+
<< Str << "\n"
3534
<< std::string(Str.size(), Kind) << "\n";
3635
}
3736

38-
void writeHeader(StringRef Str, raw_ostream &OS, char Kind = '-') {
37+
static void writeHeader(StringRef Str, raw_ostream &OS, char Kind = '-') {
3938
OS << Str << "\n" << std::string(Str.size(), Kind) << "\n";
4039
}
4140

42-
std::string escapeForRST(StringRef Str) {
41+
static std::string escapeForRST(StringRef Str) {
4342
std::string Result;
4443
Result.reserve(Str.size() + 4);
4544
for (char C : Str) {
@@ -55,8 +54,6 @@ std::string escapeForRST(StringRef Str) {
5554
return Result;
5655
}
5756

58-
} // namespace
59-
6057
namespace llvm {
6158

6259
void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {

0 commit comments

Comments
 (0)