clang 23.0.0git
HLSLExternalSemaSource.cpp
Go to the documentation of this file.
1//===--- HLSLExternalSemaSource.cpp - HLSL Sema Source --------------------===//
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//
10//===----------------------------------------------------------------------===//
11
15#include "clang/AST/Attr.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/Type.h"
21#include "clang/Sema/Lookup.h"
22#include "clang/Sema/Sema.h"
23#include "clang/Sema/SemaHLSL.h"
24#include "llvm/ADT/SmallVector.h"
25
26using namespace clang;
27using namespace llvm::hlsl;
28
30
32 SemaPtr = &S;
33 ASTContext &AST = SemaPtr->getASTContext();
34 // If the translation unit has external storage force external decls to load.
37
38 IdentifierInfo &HLSL = AST.Idents.get("hlsl", tok::TokenKind::identifier);
40 NamespaceDecl *PrevDecl = nullptr;
42 PrevDecl = Result.getAsSingle<NamespaceDecl>();
43 HLSLNamespace = NamespaceDecl::Create(
44 AST, AST.getTranslationUnitDecl(), /*Inline=*/false, SourceLocation(),
45 SourceLocation(), &HLSL, PrevDecl, /*Nested=*/false);
46 HLSLNamespace->setImplicit(true);
47 HLSLNamespace->setHasExternalLexicalStorage();
48 AST.getTranslationUnitDecl()->addDecl(HLSLNamespace);
49
50 // Force external decls in the HLSL namespace to load from the PCH.
51 (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
52 defineTrivialHLSLTypes();
53 defineHLSLTypesWithForwardDeclarations();
54
55 // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
56 // built in types inside a namespace, but we are planning to change that in
57 // the near future. In order to be source compatible older versions of HLSL
58 // will need to implicitly use the hlsl namespace. For now in clang everything
59 // will get added to the namespace, and we can remove the using directive for
60 // future language versions to match HLSL's evolution.
63 NestedNameSpecifierLoc(), SourceLocation(), HLSLNamespace,
65
67}
68
69void HLSLExternalSemaSource::defineHLSLVectorAlias() {
70 ASTContext &AST = SemaPtr->getASTContext();
71
72 llvm::SmallVector<NamedDecl *> TemplateParams;
73
74 auto *TypeParam = TemplateTypeParmDecl::Create(
75 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
76 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
77 TypeParam->setDefaultArgument(
80
81 TemplateParams.emplace_back(TypeParam);
82
83 auto *SizeParam = NonTypeTemplateParmDecl::Create(
84 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
85 &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
86 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
87 llvm::APInt Val(AST.getIntWidth(AST.IntTy), 4);
88 TemplateArgument Default(AST, llvm::APSInt(std::move(Val)), AST.IntTy,
89 /*IsDefaulted=*/true);
90 SizeParam->setDefaultArgument(
92 SourceLocation(), SizeParam));
93 TemplateParams.emplace_back(SizeParam);
94
95 auto *ParamList =
97 TemplateParams, SourceLocation(), nullptr);
98
99 IdentifierInfo &II = AST.Idents.get("vector", tok::TokenKind::identifier);
100
102 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
104 AST, NestedNameSpecifierLoc(), SourceLocation(), SizeParam, false,
105 DeclarationNameInfo(SizeParam->getDeclName(), SourceLocation()),
106 AST.IntTy, VK_LValue),
108
109 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
110 SourceLocation(), &II,
111 AST.getTrivialTypeSourceInfo(AliasType));
112 Record->setImplicit(true);
113
114 auto *Template =
115 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
116 Record->getIdentifier(), ParamList, Record);
117
118 Record->setDescribedAliasTemplate(Template);
119 Template->setImplicit(true);
120 Template->setLexicalDeclContext(Record->getDeclContext());
121 HLSLNamespace->addDecl(Template);
122}
123
124void HLSLExternalSemaSource::defineHLSLMatrixAlias() {
125 ASTContext &AST = SemaPtr->getASTContext();
126 llvm::SmallVector<NamedDecl *> TemplateParams;
127
128 auto *TypeParam = TemplateTypeParmDecl::Create(
129 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
130 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
131 TypeParam->setDefaultArgument(
132 AST, SemaPtr->getTrivialTemplateArgumentLoc(
134
135 TemplateParams.emplace_back(TypeParam);
136
137 // these should be 64 bit to be consistent with other clang matrices.
138 auto *RowsParam = NonTypeTemplateParmDecl::Create(
139 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
140 &AST.Idents.get("rows_count", tok::TokenKind::identifier), AST.IntTy,
141 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
142 llvm::APInt RVal(AST.getIntWidth(AST.IntTy), 4);
143 TemplateArgument RDefault(AST, llvm::APSInt(std::move(RVal)), AST.IntTy,
144 /*IsDefaulted=*/true);
145 RowsParam->setDefaultArgument(
146 AST, SemaPtr->getTrivialTemplateArgumentLoc(RDefault, AST.IntTy,
147 SourceLocation(), RowsParam));
148 TemplateParams.emplace_back(RowsParam);
149
150 auto *ColsParam = NonTypeTemplateParmDecl::Create(
151 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 2,
152 &AST.Idents.get("cols_count", tok::TokenKind::identifier), AST.IntTy,
153 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
154 llvm::APInt CVal(AST.getIntWidth(AST.IntTy), 4);
155 TemplateArgument CDefault(AST, llvm::APSInt(std::move(CVal)), AST.IntTy,
156 /*IsDefaulted=*/true);
157 ColsParam->setDefaultArgument(
158 AST, SemaPtr->getTrivialTemplateArgumentLoc(CDefault, AST.IntTy,
159 SourceLocation(), ColsParam));
160 TemplateParams.emplace_back(ColsParam);
161
162 const unsigned MaxMatDim = SemaPtr->getLangOpts().MaxMatrixDimension;
163
164 auto *MaxRow = IntegerLiteral::Create(
165 AST, llvm::APInt(AST.getIntWidth(AST.IntTy), MaxMatDim), AST.IntTy,
167 auto *MaxCol = IntegerLiteral::Create(
168 AST, llvm::APInt(AST.getIntWidth(AST.IntTy), MaxMatDim), AST.IntTy,
170
171 auto *RowsRef = DeclRefExpr::Create(
172 AST, NestedNameSpecifierLoc(), SourceLocation(), RowsParam,
173 /*RefersToEnclosingVariableOrCapture*/ false,
174 DeclarationNameInfo(RowsParam->getDeclName(), SourceLocation()),
175 AST.IntTy, VK_LValue);
176 auto *ColsRef = DeclRefExpr::Create(
177 AST, NestedNameSpecifierLoc(), SourceLocation(), ColsParam,
178 /*RefersToEnclosingVariableOrCapture*/ false,
179 DeclarationNameInfo(ColsParam->getDeclName(), SourceLocation()),
180 AST.IntTy, VK_LValue);
181
182 auto *RowsLE = BinaryOperator::Create(AST, RowsRef, MaxRow, BO_LE, AST.BoolTy,
185 auto *ColsLE = BinaryOperator::Create(AST, ColsRef, MaxCol, BO_LE, AST.BoolTy,
188
190 AST, RowsLE, ColsLE, BO_LAnd, AST.BoolTy, VK_PRValue, OK_Ordinary,
192
193 auto *ParamList = TemplateParameterList::Create(
194 AST, SourceLocation(), SourceLocation(), TemplateParams, SourceLocation(),
196
197 IdentifierInfo &II = AST.Idents.get("matrix", tok::TokenKind::identifier);
198
200 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
202 AST, NestedNameSpecifierLoc(), SourceLocation(), RowsParam, false,
203 DeclarationNameInfo(RowsParam->getDeclName(), SourceLocation()),
204 AST.IntTy, VK_LValue),
206 AST, NestedNameSpecifierLoc(), SourceLocation(), ColsParam, false,
207 DeclarationNameInfo(ColsParam->getDeclName(), SourceLocation()),
208 AST.IntTy, VK_LValue),
210
211 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
212 SourceLocation(), &II,
213 AST.getTrivialTypeSourceInfo(AliasType));
214 Record->setImplicit(true);
215
216 auto *Template =
217 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
218 Record->getIdentifier(), ParamList, Record);
219
220 Record->setDescribedAliasTemplate(Template);
221 Template->setImplicit(true);
222 Template->setLexicalDeclContext(Record->getDeclContext());
223 HLSLNamespace->addDecl(Template);
224}
225
226void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
227 defineHLSLVectorAlias();
228 defineHLSLMatrixAlias();
229}
230
231/// Set up common members and attributes for buffer types
233 ResourceClass RC, bool IsROV,
234 bool RawBuffer, bool HasCounter) {
236 .addBufferHandles(RC, IsROV, RawBuffer, HasCounter)
241}
242
243/// Set up common members and attributes for sampler types
252
253/// Set up common members and attributes for texture types
270
271// This function is responsible for constructing the constraint expression for
272// this concept:
273// template<typename T> concept is_typed_resource_element_compatible =
274// __is_typed_resource_element_compatible<T>;
277 ASTContext &Context = S.getASTContext();
278
279 // Obtain the QualType for 'bool'
280 QualType BoolTy = Context.BoolTy;
281
282 // Create a QualType that points to this TemplateTypeParmDecl
283 QualType TType = Context.getTypeDeclType(T);
284
285 // Create a TypeSourceInfo for the template type parameter 'T'
286 TypeSourceInfo *TTypeSourceInfo =
287 Context.getTrivialTypeSourceInfo(TType, NameLoc);
288
289 TypeTraitExpr *TypedResExpr = TypeTraitExpr::Create(
290 Context, BoolTy, NameLoc, UTT_IsTypedResourceElementCompatible,
291 {TTypeSourceInfo}, NameLoc, true);
292
293 return TypedResExpr;
294}
295
296// This function is responsible for constructing the constraint expression for
297// this concept:
298// template<typename T> concept is_structured_resource_element_compatible =
299// !__is_intangible<T> && sizeof(T) >= 1;
301 SourceLocation NameLoc,
303 ASTContext &Context = S.getASTContext();
304
305 // Obtain the QualType for 'bool'
306 QualType BoolTy = Context.BoolTy;
307
308 // Create a QualType that points to this TemplateTypeParmDecl
309 QualType TType = Context.getTypeDeclType(T);
310
311 // Create a TypeSourceInfo for the template type parameter 'T'
312 TypeSourceInfo *TTypeSourceInfo =
313 Context.getTrivialTypeSourceInfo(TType, NameLoc);
314
315 TypeTraitExpr *IsIntangibleExpr =
316 TypeTraitExpr::Create(Context, BoolTy, NameLoc, UTT_IsIntangibleType,
317 {TTypeSourceInfo}, NameLoc, true);
318
319 // negate IsIntangibleExpr
320 UnaryOperator *NotIntangibleExpr = UnaryOperator::Create(
321 Context, IsIntangibleExpr, UO_LNot, BoolTy, VK_LValue, OK_Ordinary,
322 NameLoc, false, FPOptionsOverride());
323
324 // element types also may not be of 0 size
325 UnaryExprOrTypeTraitExpr *SizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr(
326 UETT_SizeOf, TTypeSourceInfo, BoolTy, NameLoc, NameLoc);
327
328 // Create a BinaryOperator that checks if the size of the type is not equal to
329 // 1 Empty structs have a size of 1 in HLSL, so we need to check for that
331 Context, llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1, true),
332 Context.getSizeType(), NameLoc);
333
334 BinaryOperator *SizeGEQOneExpr =
335 BinaryOperator::Create(Context, SizeOfExpr, rhs, BO_GE, BoolTy, VK_LValue,
336 OK_Ordinary, NameLoc, FPOptionsOverride());
337
338 // Combine the two constraints
340 Context, NotIntangibleExpr, SizeGEQOneExpr, BO_LAnd, BoolTy, VK_LValue,
341 OK_Ordinary, NameLoc, FPOptionsOverride());
342
343 return CombinedExpr;
344}
345
347 bool isTypedBuffer) {
348 ASTContext &Context = S.getASTContext();
349 DeclContext *DC = NSD->getDeclContext();
350 SourceLocation DeclLoc = SourceLocation();
351
352 IdentifierInfo &ElementTypeII = Context.Idents.get("element_type");
354 Context, NSD->getDeclContext(), DeclLoc, DeclLoc,
355 /*D=*/0,
356 /*P=*/0,
357 /*Id=*/&ElementTypeII,
358 /*Typename=*/true,
359 /*ParameterPack=*/false);
360
361 T->setDeclContext(DC);
362 T->setReferenced();
363
364 // Create and Attach Template Parameter List to ConceptDecl
366 Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr);
367
368 DeclarationName DeclName;
369 Expr *ConstraintExpr = nullptr;
370
371 if (isTypedBuffer) {
372 DeclName = DeclarationName(
373 &Context.Idents.get("__is_typed_resource_element_compatible"));
374 ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T);
375 } else {
376 DeclName = DeclarationName(
377 &Context.Idents.get("__is_structured_resource_element_compatible"));
378 ConstraintExpr = constructStructuredBufferConstraintExpr(S, DeclLoc, T);
379 }
380
381 // Create a ConceptDecl
382 ConceptDecl *CD =
383 ConceptDecl::Create(Context, NSD->getDeclContext(), DeclLoc, DeclName,
384 ConceptParams, ConstraintExpr);
385
386 // Attach the template parameter list to the ConceptDecl
387 CD->setTemplateParameters(ConceptParams);
388
389 // Add the concept declaration to the Translation Unit Decl
390 NSD->getDeclContext()->addDecl(CD);
391
392 return CD;
393}
394
395void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
396 CXXRecordDecl *Decl;
397 ConceptDecl *TypedBufferConcept = constructBufferConceptDecl(
398 *SemaPtr, HLSLNamespace, /*isTypedBuffer*/ true);
399 ConceptDecl *StructuredBufferConcept = constructBufferConceptDecl(
400 *SemaPtr, HLSLNamespace, /*isTypedBuffer*/ false);
401
402 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Buffer")
403 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
404 .finalizeForwardDeclaration();
405
406 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
407 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
408 /*RawBuffer=*/false, /*HasCounter=*/false)
413 });
414
415 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
416 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
417 .finalizeForwardDeclaration();
418
419 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
420 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
421 /*RawBuffer=*/false, /*HasCounter=*/false)
426 });
427
428 Decl =
429 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RasterizerOrderedBuffer")
430 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
431 .finalizeForwardDeclaration();
432 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
433 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
434 /*RawBuffer=*/false, /*HasCounter=*/false)
439 });
440
441 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "StructuredBuffer")
442 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
443 .finalizeForwardDeclaration();
444 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
445 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
446 /*RawBuffer=*/true, /*HasCounter=*/false)
451 });
452
453 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWStructuredBuffer")
454 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
455 .finalizeForwardDeclaration();
456 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
457 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
458 /*RawBuffer=*/true, /*HasCounter=*/true)
465 });
466
467 Decl =
468 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "AppendStructuredBuffer")
469 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
470 .finalizeForwardDeclaration();
471 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
472 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
473 /*RawBuffer=*/true, /*HasCounter=*/true)
477 });
478
479 Decl =
480 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConsumeStructuredBuffer")
481 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
482 .finalizeForwardDeclaration();
483 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
484 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
485 /*RawBuffer=*/true, /*HasCounter=*/true)
489 });
490
491 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
492 "RasterizerOrderedStructuredBuffer")
493 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
494 .finalizeForwardDeclaration();
495 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
496 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
497 /*RawBuffer=*/true, /*HasCounter=*/true)
504 });
505
506 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
507 .finalizeForwardDeclaration();
508 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
509 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
510 /*RawBuffer=*/true, /*HasCounter=*/false)
514 });
515 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWByteAddressBuffer")
516 .finalizeForwardDeclaration();
517 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
518 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
519 /*RawBuffer=*/true, /*HasCounter=*/false)
524 });
525 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
526 "RasterizerOrderedByteAddressBuffer")
527 .finalizeForwardDeclaration();
528 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
529 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
530 /*RawBuffer=*/true, /*HasCounter=*/false)
533 });
534
535 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "SamplerState")
536 .finalizeForwardDeclaration();
537 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
538 setupSamplerType(Decl, *SemaPtr).completeDefinition();
539 });
540
541 Decl =
542 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "SamplerComparisonState")
543 .finalizeForwardDeclaration();
544 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
545 setupSamplerType(Decl, *SemaPtr).completeDefinition();
546 });
547
548 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Texture2D")
549 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
550 .finalizeForwardDeclaration();
551 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
552 setupTextureType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
553 ResourceDimension::Dim2D)
555 });
556}
557
558void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
559 CompletionFunction Fn) {
560 if (!Record->isCompleteDefinition())
561 Completions.insert(std::make_pair(Record->getCanonicalDecl(), Fn));
562}
563
565 if (!isa<CXXRecordDecl>(Tag))
566 return;
567 auto Record = cast<CXXRecordDecl>(Tag);
568
569 // If this is a specialization, we need to get the underlying templated
570 // declaration and complete that.
571 if (auto TDecl = dyn_cast<ClassTemplateSpecializationDecl>(Record))
572 Record = TDecl->getSpecializedTemplate()->getTemplatedDecl();
573 Record = Record->getCanonicalDecl();
574 auto It = Completions.find(Record);
575 if (It == Completions.end())
576 return;
577 It->second(Record);
578 Completions.erase(It);
579}
Defines the clang::ASTContext interface.
llvm::dxil::ResourceClass ResourceClass
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter)
Set up common members and attributes for buffer types.
static BuiltinTypeDeclBuilder setupSamplerType(CXXRecordDecl *Decl, Sema &S)
Set up common members and attributes for sampler types.
static ConceptDecl * constructBufferConceptDecl(Sema &S, NamespaceDecl *NSD, bool isTypedBuffer)
static Expr * constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
static BuiltinTypeDeclBuilder setupTextureType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, bool IsROV, ResourceDimension Dim)
Set up common members and attributes for texture types.
static Expr * constructStructuredBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
llvm::MachO::Record Record
Definition MachO.h:31
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 ...
Definition ASTContext.h:226
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttrLoc) const
Return the unique reference to the matrix type of the specified element type and size.
unsigned getIntWidth(QualType T) const
CanQualType FloatTy
IdentifierTable & Idents
Definition ASTContext.h:797
CanQualType BoolTy
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,...
CanQualType IntTy
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5076
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
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...
Definition DeclBase.h:1449
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...
Definition DeclBase.h:2688
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)
Definition Expr.cpp:488
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
DeclContext * getDeclContext()
Definition DeclBase.h:448
The name of a declaration.
This represents one expression.
Definition Expr.h:112
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'.
Definition Expr.cpp:975
Represents the results of name lookup.
Definition Lookup.h:147
Represent a C++ namespace.
Definition Decl.h:592
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition DeclCXX.cpp:3328
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.
Definition TypeBase.h:937
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:868
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,...
Definition Sema.h:9404
ASTContext & getASTContext() const
Definition Sema.h:939
const LangOptions & getLangOpts() const
Definition Sema.h:932
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.
Definition Decl.h:3717
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)
Definition Decl.cpp:5813
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.
Definition TypeBase.h:8320
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2897
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.
Definition ExprCXX.cpp:1914
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2628
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5133
Represents a C++ using-declaration.
Definition DeclCXX.h:3593
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition DeclCXX.cpp:3284
BuiltinTypeDeclBuilder & addSampleGradMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addGetDimensionsMethodForBuffer()
BuiltinTypeDeclBuilder & addSampleBiasMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addByteAddressBufferStoreMethods()
BuiltinTypeDeclBuilder & addTextureHandle(ResourceClass RC, bool IsROV, ResourceDimension RD, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addSampleLevelMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addByteAddressBufferLoadMethods()
BuiltinTypeDeclBuilder & addSampleMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addStaticInitializationFunctions(bool HasCounter)
BuiltinTypeDeclBuilder & addSampleCmpLevelZeroMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addSampleCmpMethods(ResourceDimension Dim)
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)
Definition Address.h:330
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition Specifiers.h:151
@ Result
The result type of a method or function.
Definition TypeBase.h:905
@ Template
We are parsing a template declaration.
Definition Parser.h:81
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:139
U cast(CodeGen::Address addr)
Definition Address.h:327
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...