| 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 |
|
| 21 |
using llvm::hlsl::ResourceClass; |
| 22 |
|
| 23 |
namespace clang { |
| 24 |
|
| 25 |
class ClassTemplateDecl; |
| 26 |
class NamespaceDecl; |
| 27 |
class CXXRecordDecl; |
| 28 |
class FieldDecl; |
| 29 |
|
| 30 |
namespace hlsl { |
| 31 |
|
| 32 |
// Builder for builtin HLSL class types such as HLSL resource classes. |
| 33 |
// Allows creating declaration of builtin types using the builder pattern |
| 34 |
// like this: |
| 35 |
// |
| 36 |
// Decl = BuiltinTypeDeclBuilder(Sema, Namespace, "BuiltinClassName") |
| 37 |
// .addSimpleTemplateParams({"T"}, Concept) |
| 38 |
// .finalizeForwardDeclaration(); |
| 39 |
// |
| 40 |
// And then completing the type like this: |
| 41 |
// |
| 42 |
// BuiltinTypeDeclBuilder(Sema, Decl) |
| 43 |
// .addDefaultHandleConstructor(); |
| 44 |
// .addLoadMethods() |
| 45 |
// .completeDefinition(); |
| 46 |
// |
| 47 |
class BuiltinTypeDeclBuilder { |
| 48 |
private: |
| 49 |
Sema &SemaRef; |
| 50 |
CXXRecordDecl *Record = nullptr; |
| 51 |
ClassTemplateDecl *Template = nullptr; |
| 52 |
ClassTemplateDecl *PrevTemplate = nullptr; |
| 53 |
NamespaceDecl *HLSLNamespace = nullptr; |
| 54 |
llvm::StringMap<FieldDecl *> Fields; |
| 55 |
|
| 56 |
public: |
| 57 |
friend struct TemplateParameterListBuilder; |
| 58 |
friend struct BuiltinTypeMethodBuilder; |
| 59 |
|
| 60 |
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R); |
| 61 |
BuiltinTypeDeclBuilder(Sema &SemaRef, NamespaceDecl *Namespace, |
| 62 |
StringRef Name); |
| 63 |
~BuiltinTypeDeclBuilder(); |
| 64 |
|
| 65 |
BuiltinTypeDeclBuilder &addSimpleTemplateParams(ArrayRef<StringRef> Names, |
| 66 |
ConceptDecl *CD); |
| 67 |
CXXRecordDecl *finalizeForwardDeclaration() { return Record; } |
| 68 |
BuiltinTypeDeclBuilder &completeDefinition(); |
| 69 |
|
| 70 |
BuiltinTypeDeclBuilder & |
| 71 |
addMemberVariable(StringRef Name, QualType Type, llvm::ArrayRef<Attr *> Attrs, |
| 72 |
AccessSpecifier Access = AccessSpecifier::AS_private); |
| 73 |
|
| 74 |
BuiltinTypeDeclBuilder & |
| 75 |
addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, |
| 76 |
bool HasCounter, |
| 77 |
AccessSpecifier Access = AccessSpecifier::AS_private); |
| 78 |
BuiltinTypeDeclBuilder &addArraySubscriptOperators(); |
| 79 |
|
| 80 |
// Builtin types constructors |
| 81 |
BuiltinTypeDeclBuilder &addDefaultHandleConstructor(); |
| 82 |
BuiltinTypeDeclBuilder &addCopyConstructor(); |
| 83 |
BuiltinTypeDeclBuilder &addCopyAssignmentOperator(); |
| 84 |
|
| 85 |
// Static create methods |
| 86 |
BuiltinTypeDeclBuilder &addStaticInitializationFunctions(bool HasCounter); |
| 87 |
|
| 88 |
// Builtin types methods |
| 89 |
BuiltinTypeDeclBuilder &addLoadMethods(); |
| 90 |
BuiltinTypeDeclBuilder &addIncrementCounterMethod(); |
| 91 |
BuiltinTypeDeclBuilder &addDecrementCounterMethod(); |
| 92 |
BuiltinTypeDeclBuilder &addHandleAccessFunction(DeclarationName &Name, |
| 93 |
bool IsConst, bool IsRef); |
| 94 |
BuiltinTypeDeclBuilder &addLoadWithStatusFunction(DeclarationName &Name, |
| 95 |
bool IsConst); |
| 96 |
BuiltinTypeDeclBuilder &addAppendMethod(); |
| 97 |
BuiltinTypeDeclBuilder &addConsumeMethod(); |
| 98 |
|
| 99 |
BuiltinTypeDeclBuilder &addGetDimensionsMethodForBuffer(); |
| 100 |
|
| 101 |
private: |
| 102 |
BuiltinTypeDeclBuilder &addCreateFromBinding(); |
| 103 |
BuiltinTypeDeclBuilder &addCreateFromImplicitBinding(); |
| 104 |
BuiltinTypeDeclBuilder &addCreateFromBindingWithImplicitCounter(); |
| 105 |
BuiltinTypeDeclBuilder &addCreateFromImplicitBindingWithImplicitCounter(); |
| 106 |
BuiltinTypeDeclBuilder &addResourceMember(StringRef MemberName, |
| 107 |
ResourceClass RC, bool IsROV, |
| 108 |
bool RawBuffer, bool IsCounter, |
| 109 |
AccessSpecifier Access); |
| 110 |
BuiltinTypeDeclBuilder & |
| 111 |
addHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, |
| 112 |
AccessSpecifier Access = AccessSpecifier::AS_private); |
| 113 |
BuiltinTypeDeclBuilder & |
| 114 |
addCounterHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, |
| 115 |
AccessSpecifier Access = AccessSpecifier::AS_private); |
| 116 |
FieldDecl *getResourceHandleField() const; |
| 117 |
FieldDecl *getResourceCounterHandleField() const; |
| 118 |
QualType getFirstTemplateTypeParam(); |
| 119 |
QualType getHandleElementType(); |
| 120 |
Expr *getConstantIntExpr(int value); |
| 121 |
HLSLAttributedResourceType::Attributes getResourceAttrs() const; |
| 122 |
}; |
| 123 |
|
| 124 |
} // namespace hlsl |
| 125 |
|
| 126 |
} // namespace clang |
| 127 |
|
| 128 |
#endif // LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H |