@@ -353,10 +353,8 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
353353 OS << " LLVM_ABI Association getDirectiveAssociation(Directive D);\n " ;
354354 OS << " LLVM_ABI Category getDirectiveCategory(Directive D);\n " ;
355355 OS << " LLVM_ABI SourceLanguage getDirectiveLanguages(Directive D);\n " ;
356- if (EnumHelperFuncs.length () > 0 ) {
357- OS << EnumHelperFuncs;
358- OS << " \n " ;
359- }
356+ if (EnumHelperFuncs.length () > 0 )
357+ OS << EnumHelperFuncs << ' \n ' ;
360358
361359 DirLangNS.close ();
362360
@@ -368,7 +366,6 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
368366 OS << " static constexpr bool is_iterable = true;\n " ;
369367 OS << " };\n " ;
370368 }
371- LlvmNS.close ();
372369}
373370
374371// Given a list of spellings (for a given clause/directive), order them
@@ -940,24 +937,18 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
940937// Generate an enum set for the 4 kinds of clauses linked to a directive.
941938static void generateDirectiveClauseSets (const DirectiveLanguage &DirLang,
942939 Frontend FE, raw_ostream &OS) {
940+ IfDefEmitter Scope (OS, " GEN_" + getFESpelling (FE).upper () +
941+ " _DIRECTIVE_CLAUSE_SETS" );
943942
944- std::string IfDefName{" GEN_" };
945- IfDefName += getFESpelling (FE).upper ();
946- IfDefName += " _DIRECTIVE_CLAUSE_SETS" ;
947- IfDefEmitter Scope (OS, IfDefName);
948-
949- StringRef Namespace =
950- getFESpelling (FE == Frontend::Flang ? Frontend::LLVM : FE);
943+ std::string Namespace =
944+ getFESpelling (FE == Frontend::Flang ? Frontend::LLVM : FE).str ();
951945 // The namespace has to be different for clang vs flang, as 2 structs with the
952946 // same name but different layout is UB. So just put the 'clang' on in the
953947 // clang namespace.
954- OS << " namespace " << Namespace << " {\n " ;
955-
956- // Open namespaces defined in the directive language.
957- SmallVector<StringRef, 2 > Namespaces;
958- SplitString (DirLang.getCppNamespace (), Namespaces, " ::" );
959- for (auto Ns : Namespaces)
960- OS << " namespace " << Ns << " {\n " ;
948+ // Additionally, open namespaces defined in the directive language.
949+ if (!DirLang.getCppNamespace ().empty ())
950+ Namespace += " ::" + DirLang.getCppNamespace ().str ();
951+ NamespaceEmitter NS (OS, Namespace);
961952
962953 for (const Directive Dir : DirLang.getDirectives ()) {
963954 OS << " \n " ;
@@ -972,23 +963,15 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
972963 generateClauseSet (Dir.getRequiredClauses (), OS, " requiredClauses_" , Dir,
973964 DirLang, FE);
974965 }
975-
976- // Closing namespaces
977- for (auto Ns : reverse (Namespaces))
978- OS << " } // namespace " << Ns << " \n " ;
979-
980- OS << " } // namespace " << Namespace << " \n " ;
981966}
982967
983968// Generate a map of directive (key) with DirectiveClauses struct as values.
984969// The struct holds the 4 sets of enumeration for the 4 kinds of clauses
985970// allowances (allowed, allowed once, allowed exclusive and required).
986971static void generateDirectiveClauseMap (const DirectiveLanguage &DirLang,
987972 Frontend FE, raw_ostream &OS) {
988- std::string IfDefName{" GEN_" };
989- IfDefName += getFESpelling (FE).upper ();
990- IfDefName += " _DIRECTIVE_CLAUSE_MAP" ;
991- IfDefEmitter Scope (OS, IfDefName);
973+ IfDefEmitter Scope (OS, " GEN_" + getFESpelling (FE).upper () +
974+ " _DIRECTIVE_CLAUSE_MAP" );
992975
993976 OS << " {\n " ;
994977
0 commit comments