clang 23.0.0git
HLSLBuiltinTypeDeclBuilder.h
Go to the documentation of this file.
1//===--- HLSLBuiltinTypeDeclBuilder.h - HLSL Builtin Type Decl Builder ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Helper classes for creating HLSL builtin class types. Used by external HLSL
10// sema source.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
15#define LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
16
17#include "clang/AST/Type.h"
18#include "clang/Sema/Sema.h"
19#include "llvm/ADT/StringMap.h"
20
21using llvm::hlsl::ResourceClass;
22using llvm::hlsl::ResourceDimension;
23
24namespace clang {
25
27class NamespaceDecl;
28class CXXRecordDecl;
29class FieldDecl;
30
31namespace hlsl {
32
33// Builder for builtin HLSL class types such as HLSL resource classes.
34// Allows creating declaration of builtin types using the builder pattern
35// like this:
36//
37// Decl = BuiltinTypeDeclBuilder(Sema, Namespace, "BuiltinClassName")
38// .addSimpleTemplateParams({"T"}, Concept)
39// .finalizeForwardDeclaration();
40//
41// And then completing the type like this:
42//
43// BuiltinTypeDeclBuilder(Sema, Decl)
44// .addDefaultHandleConstructor();
45// .addLoadMethods()
46// .completeDefinition();
47//
49private:
50 Sema &SemaRef;
51 CXXRecordDecl *Record = nullptr;
52 ClassTemplateDecl *Template = nullptr;
53 ClassTemplateDecl *PrevTemplate = nullptr;
54 NamespaceDecl *HLSLNamespace = nullptr;
55 llvm::StringMap<FieldDecl *> Fields;
56
57public:
60
62 BuiltinTypeDeclBuilder(Sema &SemaRef, NamespaceDecl *Namespace,
63 StringRef Name);
65
67 ConceptDecl *CD);
70
74
76 addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer,
77 bool HasCounter,
80 addTextureHandle(ResourceClass RC, bool IsROV, ResourceDimension RD,
84
85 // Builtin types constructors
89
90 // Static create methods
92
93 // Builtin types methods
99 bool IsConst, bool IsRef);
101 bool IsConst);
104
106
107private:
108 BuiltinTypeDeclBuilder &addCreateFromBinding();
109 BuiltinTypeDeclBuilder &addCreateFromImplicitBinding();
110 BuiltinTypeDeclBuilder &addCreateFromBindingWithImplicitCounter();
111 BuiltinTypeDeclBuilder &addCreateFromImplicitBindingWithImplicitCounter();
112 BuiltinTypeDeclBuilder &addResourceMember(StringRef MemberName,
113 ResourceClass RC,
114 ResourceDimension RD, bool IsROV,
115 bool RawBuffer, bool IsCounter,
116 AccessSpecifier Access);
118 addHandleMember(ResourceClass RC, ResourceDimension RD, bool IsROV,
119 bool RawBuffer,
122 addCounterHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer,
124 FieldDecl *getResourceHandleField() const;
125 FieldDecl *getResourceCounterHandleField() const;
126 QualType getFirstTemplateTypeParam();
127 QualType getHandleElementType();
128 Expr *getConstantIntExpr(int value);
129 HLSLAttributedResourceType::Attributes getResourceAttrs() const;
130};
131
132} // namespace hlsl
133
134} // namespace clang
135
136#endif // LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
llvm::dxil::ResourceClass ResourceClass
C Language Family Type Representation.
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R)
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Declaration of a class template.
Declaration of a C++20 concept.
The name of a declaration.
This represents one expression.
Definition Expr.h:112
Represents a member of a struct/union/class.
Definition Decl.h:3160
Represent a C++ namespace.
Definition Decl.h:592
A (possibly-)qualified type.
Definition TypeBase.h:937
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:856
The base class of the type hierarchy.
Definition TypeBase.h:1833
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R)
BuiltinTypeDeclBuilder & addSimpleTemplateParams(ArrayRef< StringRef > Names, ConceptDecl *CD)
BuiltinTypeDeclBuilder & addMemberVariable(StringRef Name, QualType Type, llvm::ArrayRef< Attr * > Attrs, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addLoadWithStatusFunction(DeclarationName &Name, bool IsConst)
BuiltinTypeDeclBuilder & addHandleAccessFunction(DeclarationName &Name, bool IsConst, bool IsRef)
BuiltinTypeDeclBuilder & addGetDimensionsMethodForBuffer()
BuiltinTypeDeclBuilder & addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addTextureHandle(ResourceClass RC, bool IsROV, ResourceDimension RD, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addSampleMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addStaticInitializationFunctions(bool HasCounter)
The JSON file list parser is used to communicate input to InstallAPI.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition Specifiers.h:123
@ AS_private
Definition Specifiers.h:126