@@ -2115,13 +2115,19 @@ static const char *paramKind2Str(KernelParamKind K) {
2115
2115
#undef CASE
2116
2116
}
2117
2117
2118
- // Removes all "(anonymous namespace)::" substrings from given string
2119
- static std::string eraseAnonNamespace (std::string S) {
2118
+ // Removes all "(anonymous namespace)::" substrings from given string, and emits
2119
+ // it.
2120
+ static void emitWithoutAnonNamespaces (llvm::raw_ostream &OS, StringRef Source) {
2120
2121
const char S1[] = " (anonymous namespace)::" ;
2121
2122
2122
- for (auto Pos = S.find (S1); Pos != StringRef::npos; Pos = S.find (S1, Pos))
2123
- S.erase (Pos, sizeof (S1) - 1 );
2124
- return S;
2123
+ size_t Pos;
2124
+
2125
+ while ((Pos = Source.find (S1)) != StringRef::npos) {
2126
+ OS << Source.take_front (Pos);
2127
+ Source = Source.drop_front (Pos + sizeof (S1) - 1 );
2128
+ }
2129
+
2130
+ OS << Source;
2125
2131
}
2126
2132
2127
2133
static bool checkEnumTemplateParameter (const EnumDecl *ED,
@@ -2370,19 +2376,19 @@ void SYCLIntegrationHeader::emitForwardClassDecls(
2370
2376
}
2371
2377
}
2372
2378
2373
- static std::string getCPPTypeString ( QualType Ty) {
2379
+ static void emitCPPTypeString (raw_ostream &OS, QualType Ty) {
2374
2380
LangOptions LO;
2375
2381
PrintingPolicy P (LO);
2376
2382
P.SuppressTypedefs = true ;
2377
- return eraseAnonNamespace ( Ty.getAsString (P));
2383
+ emitWithoutAnonNamespaces (OS, Ty.getAsString (P));
2378
2384
}
2379
2385
2380
2386
static void printArguments (ASTContext &Ctx, raw_ostream &ArgOS,
2381
2387
ArrayRef<TemplateArgument> Args,
2382
2388
const PrintingPolicy &P);
2383
2389
2384
- static std::string getKernelNameTypeString (QualType T, ASTContext &Ctx,
2385
- const PrintingPolicy &TypePolicy);
2390
+ static void emitKernelNameType (QualType T, ASTContext &Ctx, raw_ostream &OS ,
2391
+ const PrintingPolicy &TypePolicy);
2386
2392
2387
2393
static void printArgument (ASTContext &Ctx, raw_ostream &ArgOS,
2388
2394
TemplateArgument Arg, const PrintingPolicy &P) {
@@ -2413,7 +2419,8 @@ static void printArgument(ASTContext &Ctx, raw_ostream &ArgOS,
2413
2419
TypePolicy.SuppressTypedefs = true ;
2414
2420
TypePolicy.SuppressTagKeyword = true ;
2415
2421
QualType T = Arg.getAsType ();
2416
- ArgOS << getKernelNameTypeString (T, Ctx, TypePolicy);
2422
+
2423
+ emitKernelNameType (T, Ctx, ArgOS, TypePolicy);
2417
2424
break ;
2418
2425
}
2419
2426
case TemplateArgument::ArgKind::Template: {
@@ -2451,42 +2458,46 @@ static void printTemplateArguments(ASTContext &Ctx, raw_ostream &ArgOS,
2451
2458
ArgOS << " >" ;
2452
2459
}
2453
2460
2454
- static std::string printRecordType ( QualType T, const CXXRecordDecl *RD,
2455
- const PrintingPolicy &TypePolicy) {
2461
+ static void emitRecordType (raw_ostream &OS, QualType T, const CXXRecordDecl *RD,
2462
+ const PrintingPolicy &TypePolicy) {
2456
2463
SmallString<64 > Buf;
2457
- llvm::raw_svector_ostream OS (Buf);
2458
- T.getCanonicalType ().getQualifiers ().print (OS , TypePolicy,
2464
+ llvm::raw_svector_ostream RecOS (Buf);
2465
+ T.getCanonicalType ().getQualifiers ().print (RecOS , TypePolicy,
2459
2466
/* appendSpaceIfNotEmpty*/ true );
2460
2467
if (const auto *TSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2461
2468
2462
2469
// Print template class name
2463
- TSD->printQualifiedName (OS , TypePolicy, /* WithGlobalNsPrefix*/ true );
2470
+ TSD->printQualifiedName (RecOS , TypePolicy, /* WithGlobalNsPrefix*/ true );
2464
2471
2465
2472
// Print template arguments substituting enumerators
2466
2473
ASTContext &Ctx = RD->getASTContext ();
2467
2474
const TemplateArgumentList &Args = TSD->getTemplateArgs ();
2468
- printTemplateArguments (Ctx, OS , Args.asArray (), TypePolicy);
2475
+ printTemplateArguments (Ctx, RecOS , Args.asArray (), TypePolicy);
2469
2476
2470
- return eraseAnonNamespace (OS.str ().str ());
2477
+ emitWithoutAnonNamespaces (OS, RecOS.str ());
2478
+ return ;
2471
2479
}
2472
- if (RD->getDeclContext ()->isFunctionOrMethod ())
2473
- return eraseAnonNamespace (T.getCanonicalType ().getAsString (TypePolicy));
2480
+ if (RD->getDeclContext ()->isFunctionOrMethod ()) {
2481
+ emitWithoutAnonNamespaces (OS, T.getCanonicalType ().getAsString (TypePolicy));
2482
+ return ;
2483
+ }
2484
+
2474
2485
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(RD->getDeclContext ());
2475
- RD->printQualifiedName (OS, TypePolicy, !(NS && NS->isAnonymousNamespace ()));
2476
- return eraseAnonNamespace (OS.str ().str ());
2486
+ RD->printQualifiedName (RecOS, TypePolicy,
2487
+ !(NS && NS->isAnonymousNamespace ()));
2488
+ emitWithoutAnonNamespaces (OS, RecOS.str ());
2477
2489
}
2478
2490
2479
- static std::string getKernelNameTypeString (QualType T, ASTContext &Ctx,
2480
- const PrintingPolicy &TypePolicy) {
2481
- if (T->isRecordType ())
2482
- return printRecordType (T, T->getAsCXXRecordDecl (), TypePolicy);
2483
- if (T->isEnumeralType ()) {
2484
- SmallString<64 > Buf;
2485
- llvm::raw_svector_ostream OS (Buf);
2486
- OS << " ::" << T.getCanonicalType ().getAsString (TypePolicy);
2487
- return eraseAnonNamespace (OS.str ().str ());
2488
- }
2489
- return eraseAnonNamespace (T.getCanonicalType ().getAsString (TypePolicy));
2491
+ static void emitKernelNameType (QualType T, ASTContext &Ctx, raw_ostream &OS,
2492
+ const PrintingPolicy &TypePolicy) {
2493
+ if (T->isRecordType ()) {
2494
+ emitRecordType (OS, T, T->getAsCXXRecordDecl (), TypePolicy);
2495
+ return ;
2496
+ }
2497
+
2498
+ if (T->isEnumeralType ())
2499
+ OS << " ::" ;
2500
+ emitWithoutAnonNamespaces (OS, T.getCanonicalType ().getAsString (TypePolicy));
2490
2501
}
2491
2502
2492
2503
void SYCLIntegrationHeader::emit (raw_ostream &O) {
@@ -2514,9 +2525,9 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
2514
2525
});
2515
2526
O << " // Specialization constants IDs:\n " ;
2516
2527
for (const auto &P : llvm::make_range (SpecConsts.begin (), End)) {
2517
- std::string CPPName = getCPPTypeString (P. first ) ;
2518
- O << " template <> struct sycl::detail::SpecConstantInfo< " << CPPName
2519
- << " > {\n " ;
2528
+ O << " template <> struct sycl::detail::SpecConstantInfo< " ;
2529
+ emitCPPTypeString (O, P. first );
2530
+ O << " > {\n " ;
2520
2531
O << " static constexpr const char* getName() {\n " ;
2521
2532
O << " return \" " << P.second << " \" ;\n " ;
2522
2533
O << " }\n " ;
@@ -2608,8 +2619,9 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
2608
2619
LangOptions LO;
2609
2620
PrintingPolicy P (LO);
2610
2621
P.SuppressTypedefs = true ;
2611
- O << " template <> struct KernelInfo<"
2612
- << getKernelNameTypeString (K.NameType , S.getASTContext (), P) << " > {\n " ;
2622
+ O << " template <> struct KernelInfo<" ;
2623
+ emitKernelNameType (K.NameType , S.getASTContext (), O, P);
2624
+ O << " > {\n " ;
2613
2625
}
2614
2626
O << " DLL_LOCAL\n " ;
2615
2627
O << " static constexpr const char* getName() { return \" " << K.Name
0 commit comments