@@ -5045,15 +5045,26 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
50455045 // LayoutStruct - Layout struct for the buffer
50465046 CXXRecordDecl *LayoutStruct;
50475047
5048+ // For default (implicit) constant buffer, an array of references of global
5049+ // decls that belong to the buffer. The decls are already parented by the
5050+ // translation unit context. The array is allocated by the ASTContext
5051+ // allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5052+ ArrayRef<Decl *> DefaultBufferDecls;
5053+
50485054 HLSLBufferDecl (DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
50495055 IdentifierInfo *ID, SourceLocation IDLoc,
50505056 SourceLocation LBrace);
50515057
5058+ void setDefaultBufferDecls (ArrayRef<Decl *> Decls);
5059+
50525060public:
50535061 static HLSLBufferDecl *Create (ASTContext &C, DeclContext *LexicalParent,
50545062 bool CBuffer, SourceLocation KwLoc,
50555063 IdentifierInfo *ID, SourceLocation IDLoc,
50565064 SourceLocation LBrace);
5065+ static HLSLBufferDecl *
5066+ CreateDefaultCBuffer (ASTContext &C, DeclContext *LexicalParent,
5067+ ArrayRef<Decl *> DefaultCBufferDecls);
50575068 static HLSLBufferDecl *CreateDeserialized (ASTContext &C, GlobalDeclID ID);
50585069
50595070 SourceRange getSourceRange () const override LLVM_READONLY {
@@ -5079,6 +5090,28 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
50795090 return static_cast <HLSLBufferDecl *>(const_cast <DeclContext *>(DC));
50805091 }
50815092
5093+ // Iterator for the buffer decls. For constant buffers explicitly declared
5094+ // with `cbuffer` keyword this will the list of decls parented by this
5095+ // HLSLBufferDecl (equal to `decls()`).
5096+ // For implicit $Globals buffer this will be the list of default buffer
5097+ // declarations stored in DefaultBufferDecls plus the implicit layout
5098+ // struct (the only child of HLSLBufferDecl in this case).
5099+ //
5100+ // The iterator uses llvm::concat_iterator to concatenate the lists
5101+ // `decls()` and `DefaultBufferDecls`. For non-default buffers
5102+ // `DefaultBufferDecls` is always empty.
5103+ using buffer_decl_iterator =
5104+ llvm::concat_iterator<Decl *const , SmallVector<Decl *>::const_iterator,
5105+ decl_iterator>;
5106+ using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5107+
5108+ buffer_decl_range buffer_decls () const {
5109+ return buffer_decl_range (buffer_decls_begin (), buffer_decls_end ());
5110+ }
5111+ buffer_decl_iterator buffer_decls_begin () const ;
5112+ buffer_decl_iterator buffer_decls_end () const ;
5113+ bool buffer_decls_empty ();
5114+
50825115 friend class ASTDeclReader ;
50835116 friend class ASTDeclWriter ;
50845117};
0 commit comments