@@ -189,12 +189,29 @@ struct BuiltinTypeDeclBuilder {
189
189
BuiltinTypeDeclBuilder &addArraySubscriptOperators (Sema &S) {
190
190
if (Record->isCompleteDefinition ())
191
191
return *this ;
192
- addArraySubscriptOperator (S, true );
193
- addArraySubscriptOperator (S, false );
192
+ ASTContext &AST = Record->getASTContext ();
193
+ DeclarationName Subscript =
194
+ AST.DeclarationNames .getCXXOperatorName (OO_Subscript);
195
+ addHandleAccessFunction (S, Subscript, /* IsConst=*/ true , /* IsRef=*/ true );
196
+ addHandleAccessFunction (S, Subscript, /* IsConst=*/ false , /* IsRef=*/ true );
197
+ return *this ;
198
+ }
199
+
200
+ BuiltinTypeDeclBuilder &addLoadMethods (Sema &S) {
201
+ if (Record->isCompleteDefinition ())
202
+ return *this ;
203
+
204
+ ASTContext &AST = Record->getASTContext ();
205
+ IdentifierInfo &II =
206
+ AST.Idents .get (" Load" , tok::TokenKind::identifier);
207
+ DeclarationName Load (&II);
208
+ addHandleAccessFunction (S, Load, /* IsConst=*/ false , /* IsRef=*/ false );
209
+
194
210
return *this ;
195
211
}
196
212
197
- BuiltinTypeDeclBuilder &addArraySubscriptOperator (Sema &S, bool IsConst) {
213
+ BuiltinTypeDeclBuilder &addHandleAccessFunction (Sema &S, DeclarationName Name,
214
+ bool IsConst, bool IsRef) {
198
215
if (Record->isCompleteDefinition ())
199
216
return *this ;
200
217
@@ -216,18 +233,16 @@ struct BuiltinTypeDeclBuilder {
216
233
ExtInfo.TypeQuals .addConst ();
217
234
ReturnTy.addConst ();
218
235
}
219
- ReturnTy = AST.getLValueReferenceType (ReturnTy);
236
+ if (IsRef)
237
+ ReturnTy = AST.getLValueReferenceType (ReturnTy);
220
238
221
239
QualType MethodTy =
222
240
AST.getFunctionType (ReturnTy, {AST.UnsignedIntTy }, ExtInfo);
223
241
auto *TSInfo = AST.getTrivialTypeSourceInfo (MethodTy, SourceLocation ());
224
242
auto *MethodDecl = CXXMethodDecl::Create (
225
243
AST, Record, SourceLocation (),
226
- DeclarationNameInfo (
227
- AST.DeclarationNames .getCXXOperatorName (OO_Subscript),
228
- SourceLocation ()),
229
- MethodTy, TSInfo, SC_None, false , false , ConstexprSpecKind::Unspecified,
230
- SourceLocation ());
244
+ DeclarationNameInfo (Name, SourceLocation ()), MethodTy, TSInfo, SC_None,
245
+ false , false , ConstexprSpecKind::Unspecified, SourceLocation ());
231
246
232
247
IdentifierInfo &II = AST.Idents .get (" Idx" , tok::TokenKind::identifier);
233
248
auto *IdxParam = ParmVarDecl::Create (
@@ -489,6 +504,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
489
504
ResourceKind::TypedBuffer, /* IsROV=*/ false ,
490
505
/* RawBuffer=*/ false )
491
506
.addArraySubscriptOperators (*SemaPtr)
507
+ .addLoadMethods (*SemaPtr)
492
508
.completeDefinition ();
493
509
});
494
510
@@ -501,6 +517,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
501
517
ResourceKind::TypedBuffer, /* IsROV=*/ true ,
502
518
/* RawBuffer=*/ false )
503
519
.addArraySubscriptOperators (*SemaPtr)
520
+ .addLoadMethods (*SemaPtr)
504
521
.completeDefinition ();
505
522
});
506
523
0 commit comments