@@ -359,7 +359,6 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
359359 OS << " static constexpr bool is_iterable = true;\n " ;
360360 OS << " };\n " ;
361361 }
362- LlvmNS.close ();
363362}
364363
365364// Given a list of spellings (for a given clause/directive), order them
@@ -931,27 +930,20 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
931930// Generate an enum set for the 4 kinds of clauses linked to a directive.
932931static void generateDirectiveClauseSets (const DirectiveLanguage &DirLang,
933932 Frontend FE, raw_ostream &OS) {
933+ IfDefEmitter Scope (OS, " GEN_" + getFESpelling (FE).upper () +
934+ " _DIRECTIVE_CLAUSE_SETS" );
934935
935- std::string IfDefName{" GEN_" };
936- IfDefName += getFESpelling (FE).upper ();
937- IfDefName += " _DIRECTIVE_CLAUSE_SETS" ;
938- IfDefEmitter Scope (OS, IfDefName);
939-
940- StringRef Namespace =
941- getFESpelling (FE == Frontend::Flang ? Frontend::LLVM : FE);
936+ std::string Namespace =
937+ getFESpelling (FE == Frontend::Flang ? Frontend::LLVM : FE).str ();
942938 // The namespace has to be different for clang vs flang, as 2 structs with the
943939 // same name but different layout is UB. So just put the 'clang' on in the
944940 // clang namespace.
945- OS << " namespace " << Namespace << " {\n " ;
946-
947- // Open namespaces defined in the directive language.
948- SmallVector<StringRef, 2 > Namespaces;
949- SplitString (DirLang.getCppNamespace (), Namespaces, " ::" );
950- for (auto Ns : Namespaces)
951- OS << " namespace " << Ns << " {\n " ;
941+ // Additionally, open namespaces defined in the directive language.
942+ if (!DirLang.getCppNamespace ().empty ())
943+ Namespace += " ::" + DirLang.getCppNamespace ().str ();
944+ NamespaceEmitter NS (OS, Namespace);
952945
953946 for (const Directive Dir : DirLang.getDirectives ()) {
954- OS << " \n " ;
955947 OS << " // Sets for " << Dir.getSpellingForIdentifier () << " \n " ;
956948
957949 generateClauseSet (Dir.getAllowedClauses (), OS, " allowedClauses_" , Dir,
@@ -963,23 +955,15 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
963955 generateClauseSet (Dir.getRequiredClauses (), OS, " requiredClauses_" , Dir,
964956 DirLang, FE);
965957 }
966-
967- // Closing namespaces
968- for (auto Ns : reverse (Namespaces))
969- OS << " } // namespace " << Ns << " \n " ;
970-
971- OS << " } // namespace " << Namespace << " \n " ;
972958}
973959
974960// Generate a map of directive (key) with DirectiveClauses struct as values.
975961// The struct holds the 4 sets of enumeration for the 4 kinds of clauses
976962// allowances (allowed, allowed once, allowed exclusive and required).
977963static void generateDirectiveClauseMap (const DirectiveLanguage &DirLang,
978964 Frontend FE, raw_ostream &OS) {
979- std::string IfDefName{" GEN_" };
980- IfDefName += getFESpelling (FE).upper ();
981- IfDefName += " _DIRECTIVE_CLAUSE_MAP" ;
982- IfDefEmitter Scope (OS, IfDefName);
965+ IfDefEmitter Scope (OS, " GEN_" + getFESpelling (FE).upper () +
966+ " _DIRECTIVE_CLAUSE_MAP" );
983967
984968 OS << " {\n " ;
985969
0 commit comments