| 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(); |
| 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 | addHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, |
| 76 | AccessSpecifier Access = AccessSpecifier::AS_private); |
| 77 | BuiltinTypeDeclBuilder &addArraySubscriptOperators(); |
| 78 | |
| 79 | // Builtin types constructors |
| 80 | BuiltinTypeDeclBuilder &addDefaultHandleConstructor(); |
| 81 | BuiltinTypeDeclBuilder &addHandleConstructorFromBinding(); |
| 82 | BuiltinTypeDeclBuilder &addHandleConstructorFromImplicitBinding(); |
| 83 | |
| 84 | // Builtin types methods |
| 85 | BuiltinTypeDeclBuilder &addLoadMethods(); |
| 86 | BuiltinTypeDeclBuilder &addIncrementCounterMethod(); |
| 87 | BuiltinTypeDeclBuilder &addDecrementCounterMethod(); |
| 88 | BuiltinTypeDeclBuilder &addHandleAccessFunction(DeclarationName &Name, |
| 89 | bool IsConst, bool IsRef); |
| 90 | BuiltinTypeDeclBuilder &addAppendMethod(); |
| 91 | BuiltinTypeDeclBuilder &addConsumeMethod(); |
| 92 | |
| 93 | private: |
| 94 | FieldDecl *getResourceHandleField(); |
| 95 | QualType getFirstTemplateTypeParam(); |
| 96 | QualType getHandleElementType(); |
| 97 | Expr *getConstantIntExpr(int value); |
| 98 | }; |
| 99 | |
| 100 | } // namespace hlsl |
| 101 | |
| 102 | } // namespace clang |
| 103 | |
| 104 | #endif // LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H |
| 105 | |