24#include "llvm/ADT/SmallVector.h"
27using namespace llvm::hlsl;
46 HLSLNamespace->setImplicit(
true);
47 HLSLNamespace->setHasExternalLexicalStorage();
51 (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
52 defineTrivialHLSLTypes();
53 defineHLSLTypesWithForwardDeclarations();
69void HLSLExternalSemaSource::defineHLSLVectorAlias() {
76 &AST.
Idents.
get(
"element", tok::TokenKind::identifier),
false,
false);
77 TypeParam->setDefaultArgument(
81 TemplateParams.emplace_back(TypeParam);
85 &AST.
Idents.
get(
"element_count", tok::TokenKind::identifier), AST.
IntTy,
90 SizeParam->setDefaultArgument(
93 TemplateParams.emplace_back(SizeParam);
112 Record->setImplicit(
true);
124void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
125 defineHLSLVectorAlias();
155 QualType TType = Context.getTypeDeclType(
T);
159 Context.getTrivialTypeSourceInfo(TType, NameLoc);
162 Context, BoolTy, NameLoc, UTT_IsTypedResourceElementCompatible,
163 {TTypeSourceInfo}, NameLoc,
true);
181 QualType TType = Context.getTypeDeclType(
T);
185 Context.getTrivialTypeSourceInfo(TType, NameLoc);
189 {TTypeSourceInfo}, NameLoc,
true);
198 UETT_SizeOf, TTypeSourceInfo, BoolTy, NameLoc, NameLoc);
203 Context, llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1,
true),
204 Context.getSizeType(), NameLoc);
212 Context, NotIntangibleExpr, SizeGEQOneExpr, BO_LAnd, BoolTy,
VK_LValue,
219 bool isTypedBuffer) {
224 IdentifierInfo &ElementTypeII = Context.Idents.get(
"element_type");
233 T->setDeclContext(DC);
238 Context, DeclLoc, DeclLoc, {
T}, DeclLoc,
nullptr);
241 Expr *ConstraintExpr =
nullptr;
245 &Context.Idents.get(
"__is_typed_resource_element_compatible"));
249 &Context.Idents.get(
"__is_structured_resource_element_compatible"));
256 ConceptParams, ConstraintExpr);
267void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
270 *SemaPtr, HLSLNamespace,
true);
272 *SemaPtr, HLSLNamespace,
false);
274 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"Buffer")
275 .addSimpleTemplateParams({
"element_type"}, TypedBufferConcept)
276 .finalizeForwardDeclaration();
278 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
286 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"RWBuffer")
287 .addSimpleTemplateParams({
"element_type"}, TypedBufferConcept)
288 .finalizeForwardDeclaration();
290 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
299 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"RasterizerOrderedBuffer")
300 .addSimpleTemplateParams({
"element_type"}, StructuredBufferConcept)
301 .finalizeForwardDeclaration();
302 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
310 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"StructuredBuffer")
311 .addSimpleTemplateParams({
"element_type"}, StructuredBufferConcept)
312 .finalizeForwardDeclaration();
313 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
321 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"RWStructuredBuffer")
322 .addSimpleTemplateParams({
"element_type"}, StructuredBufferConcept)
323 .finalizeForwardDeclaration();
324 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
335 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"AppendStructuredBuffer")
336 .addSimpleTemplateParams({
"element_type"}, StructuredBufferConcept)
337 .finalizeForwardDeclaration();
338 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
346 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"ConsumeStructuredBuffer")
347 .addSimpleTemplateParams({
"element_type"}, StructuredBufferConcept)
348 .finalizeForwardDeclaration();
349 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
356 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
357 "RasterizerOrderedStructuredBuffer")
358 .addSimpleTemplateParams({
"element_type"}, StructuredBufferConcept)
359 .finalizeForwardDeclaration();
360 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
370 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"ByteAddressBuffer")
371 .finalizeForwardDeclaration();
372 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
377 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
"RWByteAddressBuffer")
378 .finalizeForwardDeclaration();
379 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
384 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
385 "RasterizerOrderedByteAddressBuffer")
386 .finalizeForwardDeclaration();
387 onCompletion(Decl, [
this](CXXRecordDecl *Decl) {
395 CompletionFunction Fn) {
396 if (!
Record->isCompleteDefinition())
397 Completions.insert(std::make_pair(
Record->getCanonicalDecl(), Fn));
407 if (
auto TDecl = dyn_cast<ClassTemplateSpecializationDecl>(
Record))
408 Record = TDecl->getSpecializedTemplate()->getTemplatedDecl();
410 auto It = Completions.find(
Record);
411 if (It == Completions.end())
Defines the clang::ASTContext interface.
llvm::dxil::ResourceClass ResourceClass
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static ConceptDecl * constructBufferConceptDecl(Sema &S, NamespaceDecl *NSD, bool isTypedBuffer)
static Expr * constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, bool IsROV, bool RawBuffer)
Set up common members and attributes for buffer types.
static Expr * constructStructuredBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
llvm::MachO::Record Record
This file declares semantic analysis for HLSL constructs.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
unsigned getIntWidth(QualType T) const
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
A builtin binary operation expression such as "x + y" or "x <= y".
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a C++ struct/union/class.
Declaration of a C++20 concept.
static ConceptDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, Expr *ConstraintExpr=nullptr)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void addDecl(Decl *D)
Add the declaration D into this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
decl_iterator decls_begin() const
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Decl - This represents one declaration (or definition), e.g.
DeclContext * getDeclContext()
The name of a declaration.
This represents one expression.
Represents difference between two FPOptions values.
void CompleteType(TagDecl *Tag) override
Complete an incomplete HLSL builtin type.
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Represents the results of name lookup.
Represent a C++ namespace.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
A C++ nested-name-specifier augmented with source location information.
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
A (possibly-)qualified type.
Sema - This implements semantic analysis and AST building for C.
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc, NamedDecl *TemplateParam=nullptr)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
ASTContext & getASTContext() const
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Encodes a location in the source.
Represents the declaration of a struct/union/class/enum.
Represents a template argument.
void setTemplateParameters(TemplateParameterList *TParams)
Stores a list of template parameters for a TemplateDecl and its derived classes.
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Declaration of a template type parameter.
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, UnsignedOrNone NumExpanded=std::nullopt)
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
static TypeAliasTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
A container of type source information.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Represents a C++ using-declaration.
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
BuiltinTypeDeclBuilder & addHandleConstructorFromImplicitBinding()
BuiltinTypeDeclBuilder & addCreateFromBinding()
BuiltinTypeDeclBuilder & addConsumeMethod()
BuiltinTypeDeclBuilder & addHandleConstructorFromBinding()
BuiltinTypeDeclBuilder & addArraySubscriptOperators()
BuiltinTypeDeclBuilder & completeDefinition()
BuiltinTypeDeclBuilder & addAppendMethod()
BuiltinTypeDeclBuilder & addIncrementCounterMethod()
BuiltinTypeDeclBuilder & addCopyAssignmentOperator()
BuiltinTypeDeclBuilder & addHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addCopyConstructor()
BuiltinTypeDeclBuilder & addCreateFromImplicitBinding()
BuiltinTypeDeclBuilder & addDefaultHandleConstructor()
BuiltinTypeDeclBuilder & addDecrementCounterMethod()
BuiltinTypeDeclBuilder & addLoadMethods()
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ OK_Ordinary
An ordinary object is located at an address in memory.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
U cast(CodeGen::Address addr)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...