clang 24.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 = nullptr);
70 ArrayRef<QualType> DefaultTypes, ConceptDecl *CD);
73
77
79 addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer,
80 bool HasCounter,
83 addTextureHandle(ResourceClass RC, bool IsROV, bool IsArray,
84 ResourceDimension RD,
89 addArraySubscriptOperators(ResourceDimension Dim = ResourceDimension::Unknown,
90 bool IsArray = false);
91
92 // Builtin types constructors
99
100 // Static create methods
102
103 // Builtin types methods
106 bool IsArray = false);
111 bool IsArray = false);
113 bool IsArray = false);
115 bool IsArray = false);
117 bool IsArray = false);
119 bool IsArray = false);
121 bool IsArray = false);
124 bool IsArray = false);
126 bool IsArray = false);
130 bool IsConstReturn,
131 bool IsRef, QualType IndexTy,
132 QualType ElemTy = QualType());
135 QualType ReturnTy = QualType());
137 QualType ValueType);
139 addByteAddressBufferInterlockedMethod(StringRef MethodName, QualType ValueTy,
140 StringRef BuiltinName);
143
146 BuiltinTypeDeclBuilder &addMipsMember(ResourceDimension Dim);
147
148private:
149 BuiltinTypeDeclBuilder &addCreateFromBinding();
150 BuiltinTypeDeclBuilder &addCreateFromImplicitBinding();
151 BuiltinTypeDeclBuilder &addCreateFromBindingWithImplicitCounter();
152 BuiltinTypeDeclBuilder &addCreateFromImplicitBindingWithImplicitCounter();
154 addResourceMember(StringRef MemberName, ResourceClass RC,
155 ResourceDimension RD, bool IsROV, bool RawBuffer,
156 bool IsCounter, bool IsArray, QualType ElementTy,
159 CXXRecordDecl *addPrivateNestedRecord(StringRef Name);
160 CXXRecordDecl *addMipsSliceType(ResourceDimension Dim, QualType ReturnType);
161 CXXRecordDecl *addMipsType(ResourceDimension Dim, QualType ReturnType);
163 addHandleMember(ResourceClass RC, ResourceDimension RD, bool IsROV,
164 bool RawBuffer, bool IsArray, QualType ElementTy,
167 addCounterHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer,
168 QualType ElementTy,
170 QualType getGatherReturnType();
171 BuiltinTypeDeclBuilder &addDerivativeAvailability(StringRef MethodName);
172 FieldDecl *getResourceHandleField() const;
173 FieldDecl *getResourceCounterHandleField() const;
174 QualType getFirstTemplateTypeParam();
175 QualType getHandleElementType();
176 Expr *getConstantIntExpr(int value);
177 Expr *getConstantUnsignedIntExpr(unsigned value);
178 HLSLAttributedResourceType::Attributes getResourceAttrs() const;
179};
180
181} // namespace hlsl
182
183} // namespace clang
184
185#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:3204
Represent a C++ namespace.
Definition Decl.h:592
A (possibly-)qualified type.
Definition TypeBase.h:938
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
The base class of the type hierarchy.
Definition TypeBase.h:1876
BuiltinTypeDeclBuilder & addStoreFunction(DeclarationName &Name, bool IsConst, QualType ValueType)
BuiltinTypeDeclBuilder & addDefaultHandleConstructor(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R)
BuiltinTypeDeclBuilder & addMemberVariable(StringRef Name, QualType Type, llvm::ArrayRef< Attr * > Attrs, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addHandleAccessFunction(DeclarationName &Name, bool IsConstReturn, bool IsRef, QualType IndexTy, QualType ElemTy=QualType())
BuiltinTypeDeclBuilder & addSampleGradMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCopyAssignmentOperator(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder & addGatherCmpMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addGetDimensionsMethodForBuffer()
BuiltinTypeDeclBuilder & addConstantBufferConversionToType()
BuiltinTypeDeclBuilder & addTextureLoadMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addByteAddressBufferInterlockedMethod(StringRef MethodName, QualType ValueTy, StringRef BuiltinName)
BuiltinTypeDeclBuilder & addSampleBiasMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addByteAddressBufferStoreMethods()
BuiltinTypeDeclBuilder & addSampleMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addArraySubscriptOperators(ResourceDimension Dim=ResourceDimension::Unknown, bool IsArray=false)
BuiltinTypeDeclBuilder & addSampleLevelMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCopyConstructor(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder & addTextureHandle(ResourceClass RC, bool IsROV, bool IsArray, ResourceDimension RD, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addLoadWithStatusFunction(DeclarationName &Name, QualType ReturnTy=QualType())
BuiltinTypeDeclBuilder & addSampleCmpMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addMipsMember(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addByteAddressBufferLoadMethods()
BuiltinTypeDeclBuilder & addStaticInitializationFunctions(bool HasCounter)
BuiltinTypeDeclBuilder & addGatherMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCalculateLodMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addGetDimensionsMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addByteAddressBufferInterlockedMethods()
BuiltinTypeDeclBuilder & addSimpleTemplateParams(ArrayRef< StringRef > Names, ConceptDecl *CD=nullptr)
BuiltinTypeDeclBuilder & addSampleCmpLevelZeroMethods(ResourceDimension Dim, bool IsArray=false)
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:124
@ AS_public
Definition Specifiers.h:125
@ AS_private
Definition Specifiers.h:127