@@ -68,7 +68,18 @@ namespace {
68
68
// / Various utilities.
69
69
class Util {
70
70
public:
71
- using DeclContextDesc = std::pair<clang::Decl::Kind, StringRef>;
71
+ using DeclContextDesc = std::pair<Decl::Kind, StringRef>;
72
+
73
+ template <size_t N>
74
+ static constexpr DeclContextDesc MakeDeclContextDesc (Decl::Kind K,
75
+ const char (&Str)[N]) {
76
+ return DeclContextDesc{K, llvm::StringLiteral{Str}};
77
+ }
78
+
79
+ static constexpr DeclContextDesc MakeDeclContextDesc (Decl::Kind K,
80
+ llvm::StringRef SR) {
81
+ return DeclContextDesc{K, SR};
82
+ }
72
83
73
84
// / Checks whether given clang type is a full specialization of the SYCL
74
85
// / accessor class.
@@ -4314,57 +4325,53 @@ bool Util::isSyclSamplerType(QualType Ty) { return isSyclType(Ty, "sampler"); }
4314
4325
bool Util::isSyclStreamType (QualType Ty) { return isSyclType (Ty, " stream" ); }
4315
4326
4316
4327
bool Util::isSyclHalfType (QualType Ty) {
4317
- llvm::StringLiteral Name = " half" ;
4318
4328
std::array<DeclContextDesc, 5 > Scopes = {
4319
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " cl" } ,
4320
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " sycl" } ,
4321
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " detail" } ,
4322
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " half_impl" } ,
4323
- Util::DeclContextDesc{ Decl::Kind::CXXRecord, Name} };
4329
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " cl" ) ,
4330
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " sycl" ) ,
4331
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " detail" ) ,
4332
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " half_impl" ) ,
4333
+ Util::MakeDeclContextDesc ( Decl::Kind::CXXRecord, " half " ) };
4324
4334
return matchQualifiedTypeName (Ty, Scopes);
4325
4335
}
4326
4336
4327
4337
bool Util::isSyclSpecConstantType (QualType Ty) {
4328
- llvm::StringLiteral Name = " spec_constant" ;
4329
4338
std::array<DeclContextDesc, 5 > Scopes = {
4330
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " cl" },
4331
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " sycl" },
4332
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " ONEAPI" },
4333
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " experimental" },
4334
- Util::DeclContextDesc{Decl::Kind::ClassTemplateSpecialization, Name}};
4339
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " cl" ),
4340
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " sycl" ),
4341
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " ONEAPI" ),
4342
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " experimental" ),
4343
+ Util::MakeDeclContextDesc (Decl::Kind::ClassTemplateSpecialization,
4344
+ " spec_constant" )};
4335
4345
return matchQualifiedTypeName (Ty, Scopes);
4336
4346
}
4337
4347
4338
4348
bool Util::isSyclKernelHandlerType (QualType Ty) {
4339
- llvm::StringLiteral Name = " kernel_handler" ;
4340
4349
std::array<DeclContextDesc, 3 > Scopes = {
4341
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " cl" } ,
4342
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " sycl" } ,
4343
- Util::DeclContextDesc{ Decl::Kind::CXXRecord, Name} };
4350
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " cl" ) ,
4351
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " sycl" ) ,
4352
+ Util::MakeDeclContextDesc ( Decl::Kind::CXXRecord, " kernel_handler " ) };
4344
4353
return matchQualifiedTypeName (Ty, Scopes);
4345
4354
}
4346
4355
4347
4356
bool Util::isSyclBufferLocationType (QualType Ty) {
4348
- llvm::StringLiteral PropertyName = " buffer_location" ;
4349
- llvm::StringLiteral InstanceName = " instance" ;
4350
4357
std::array<DeclContextDesc, 6 > Scopes = {
4351
- Util::DeclContextDesc{ Decl::Kind::Namespace, " cl" } ,
4352
- Util::DeclContextDesc{ Decl::Kind::Namespace, " sycl" } ,
4353
- Util::DeclContextDesc{ Decl::Kind::Namespace, " INTEL" } ,
4354
- Util::DeclContextDesc{ Decl::Kind::Namespace, " property" } ,
4355
- Util::DeclContextDesc{ Decl::Kind::CXXRecord, PropertyName} ,
4356
- Util::DeclContextDesc{ Decl::Kind::ClassTemplateSpecialization,
4357
- InstanceName} };
4358
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " cl" ) ,
4359
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " sycl" ) ,
4360
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " INTEL" ) ,
4361
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " property" ) ,
4362
+ Util::MakeDeclContextDesc ( Decl::Kind::CXXRecord, " buffer_location " ) ,
4363
+ Util::MakeDeclContextDesc ( Decl::Kind::ClassTemplateSpecialization,
4364
+ " instance " ) };
4358
4365
return matchQualifiedTypeName (Ty, Scopes);
4359
4366
}
4360
4367
4361
4368
bool Util::isSyclType (QualType Ty, StringRef Name, bool Tmpl) {
4362
4369
Decl::Kind ClassDeclKind =
4363
4370
Tmpl ? Decl::Kind::ClassTemplateSpecialization : Decl::Kind::CXXRecord;
4364
4371
std::array<DeclContextDesc, 3 > Scopes = {
4365
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " cl" } ,
4366
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " sycl" } ,
4367
- Util::DeclContextDesc{ ClassDeclKind, Name} };
4372
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " cl" ) ,
4373
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " sycl" ) ,
4374
+ Util::MakeDeclContextDesc ( ClassDeclKind, Name) };
4368
4375
return matchQualifiedTypeName (Ty, Scopes);
4369
4376
}
4370
4377
@@ -4378,18 +4385,18 @@ bool Util::isSyclFunction(const FunctionDecl *FD, StringRef Name) {
4378
4385
return false ;
4379
4386
4380
4387
std::array<DeclContextDesc, 2 > Scopes = {
4381
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " cl" } ,
4382
- Util::DeclContextDesc{clang:: Decl::Kind::Namespace, " sycl" } };
4388
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " cl" ) ,
4389
+ Util::MakeDeclContextDesc ( Decl::Kind::Namespace, " sycl" ) };
4383
4390
return matchContext (DC, Scopes);
4384
4391
}
4385
4392
4386
4393
bool Util::isAccessorPropertyListType (QualType Ty) {
4387
- llvm::StringLiteral Name = " accessor_property_list" ;
4388
4394
std::array<DeclContextDesc, 4 > Scopes = {
4389
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " cl" },
4390
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " sycl" },
4391
- Util::DeclContextDesc{clang::Decl::Kind::Namespace, " ONEAPI" },
4392
- Util::DeclContextDesc{Decl::Kind::ClassTemplateSpecialization, Name}};
4395
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " cl" ),
4396
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " sycl" ),
4397
+ Util::MakeDeclContextDesc (Decl::Kind::Namespace, " ONEAPI" ),
4398
+ Util::MakeDeclContextDesc (Decl::Kind::ClassTemplateSpecialization,
4399
+ " accessor_property_list" )};
4393
4400
return matchQualifiedTypeName (Ty, Scopes);
4394
4401
}
4395
4402
@@ -4401,17 +4408,17 @@ bool Util::matchContext(const DeclContext *Ctx,
4401
4408
StringRef Name = " " ;
4402
4409
4403
4410
for (const auto &Scope : llvm::reverse (Scopes)) {
4404
- clang:: Decl::Kind DK = Ctx->getDeclKind ();
4411
+ Decl::Kind DK = Ctx->getDeclKind ();
4405
4412
if (DK != Scope.first )
4406
4413
return false ;
4407
4414
4408
4415
switch (DK) {
4409
- case clang:: Decl::Kind::ClassTemplateSpecialization:
4416
+ case Decl::Kind::ClassTemplateSpecialization:
4410
4417
// ClassTemplateSpecializationDecl inherits from CXXRecordDecl
4411
- case clang:: Decl::Kind::CXXRecord:
4418
+ case Decl::Kind::CXXRecord:
4412
4419
Name = cast<CXXRecordDecl>(Ctx)->getName ();
4413
4420
break ;
4414
- case clang:: Decl::Kind::Namespace:
4421
+ case Decl::Kind::Namespace:
4415
4422
Name = cast<NamespaceDecl>(Ctx)->getName ();
4416
4423
break ;
4417
4424
default :
0 commit comments