27#include "llvm/ADT/SmallVector.h"
29using namespace llvm::hlsl;
37static FunctionDecl *lookupBuiltinFunction(Sema &S, StringRef Name) {
39 S.getASTContext().Idents.get(Name, tok::TokenKind::identifier);
40 DeclarationNameInfo NameInfo =
41 DeclarationNameInfo(DeclarationName(&II), SourceLocation());
45 S.LookupName(R, S.getCurScope());
48 assert(R.isSingleResult() &&
49 "Since this is a builtin it should always resolve!");
53CXXConstructorDecl *lookupCopyConstructor(QualType ResTy) {
54 assert(ResTy->isRecordType() &&
"not a CXXRecord type");
55 for (
auto *CD : ResTy->getAsCXXRecordDecl()->ctors())
56 if (CD->isCopyConstructor())
62convertParamModifierToParamABI(HLSLParamModifierAttr::Spelling Modifier) {
63 assert(Modifier != HLSLParamModifierAttr::Spelling::Keyword_in &&
64 "HLSL 'in' parameters modifier cannot be converted to ParameterABI");
66 case HLSLParamModifierAttr::Spelling::Keyword_out:
68 case HLSLParamModifierAttr::Spelling::Keyword_inout:
71 llvm_unreachable(
"Invalid HLSL parameter modifier");
75QualType getInoutParameterType(ASTContext &AST, QualType Ty) {
76 assert(!Ty->isReferenceType() &&
77 "Pointer and reference types cannot be inout or out parameters");
132 HLSLParamModifierAttr::Spelling Modifier;
134 HLSLParamModifierAttr::Spelling Modifier)
135 : NameII(NameII), Ty(Ty), Modifier(Modifier) {}
142 LocalVar(StringRef Name,
QualType Ty) : Name(Name), Ty(Ty),
Decl(
nullptr) {}
164 enum class PlaceHolder {
176 Expr *convertPlaceholder(PlaceHolder PH);
177 Expr *convertPlaceholder(LocalVar &Var);
178 Expr *convertPlaceholder(
Expr *E) {
return E; }
184 QualType ReturnTy,
bool IsConst =
false,
186 : DeclBuilder(DB), Name(Name), ReturnTy(ReturnTy), Method(
nullptr),
187 IsConst(IsConst), IsCtor(IsCtor), SC(SC) {}
190 QualType ReturnTy,
bool IsConst =
false,
200 HLSLParamModifierAttr::Spelling Modifier =
201 HLSLParamModifierAttr::Keyword_in);
203 template <
typename... Ts>
205 QualType ReturnType, Ts... ArgSpecs);
206 template <
typename TLHS,
typename TRHS>
209 template <
typename T>
211 template <
typename ResourceT,
typename ValueT>
214 template <
typename T>
217 template <
typename ResourceT,
typename ValueT>
231 void ensureCompleteDecl() {
236 template <
typename ResourceT,
typename ValueT>
249 assert(!
Builder.Record->isCompleteDefinition() &&
250 "record is already complete");
252 unsigned Position =
static_cast<unsigned>(
Params.size());
256 &AST.
Idents.
get(Name, tok::TokenKind::identifier),
260 if (!DefaultValue.
isNull())
261 Decl->setDefaultArgument(AST,
262 Builder.SemaRef.getTrivialTemplateArgumentLoc(
304 "unexpected concept decl parameter count");
313 Builder.Record->getDeclContext(),
323 T->setDeclContext(DC);
325 QualType ConceptTType = Context.getTypeDeclType(ConceptTTPD);
331 QualType CSETType = Context.getTypeDeclType(
T);
339 Context,
Builder.Record->getDeclContext(), Loc, {CSETA});
379 Builder.Template->setImplicit(
true);
380 Builder.Template->setLexicalDeclContext(
Builder.Record->getDeclContext());
391Expr *BuiltinTypeMethodBuilder::convertPlaceholder(PlaceHolder PH) {
392 if (PH == PlaceHolder::Handle)
394 if (PH == PlaceHolder::CounterHandle)
397 if (PH == PlaceHolder::LastStmt) {
398 assert(!StmtsList.empty() &&
"no statements in the list");
399 Stmt *LastStmt = StmtsList.pop_back_val();
400 assert(
isa<ValueStmt>(LastStmt) &&
"last statement does not have a value");
412Expr *BuiltinTypeMethodBuilder::convertPlaceholder(LocalVar &Var) {
413 VarDecl *VD = Var.Decl;
414 assert(VD &&
"local variable is not declared");
416 VD->getASTContext(), NestedNameSpecifierLoc(), SourceLocation(), VD,
417 false, DeclarationNameInfo(VD->getDeclName(), SourceLocation()),
424 bool IsConst,
bool IsCtor,
426 : DeclBuilder(DB), ReturnTy(ReturnTy), Method(
nullptr), IsConst(IsConst),
427 IsCtor(IsCtor), SC(SC) {
429 assert((!NameStr.empty() || IsCtor) &&
"method needs a name");
430 assert(((IsCtor && !IsConst) || !IsCtor) &&
"constructor cannot be const");
438 AST.
Idents.
get(NameStr, tok::TokenKind::identifier);
445 HLSLParamModifierAttr::Spelling Modifier) {
446 assert(Method ==
nullptr &&
"Cannot add param, method already created");
447 const IdentifierInfo &II = DeclBuilder.SemaRef.getASTContext().Idents.get(
448 Name, tok::TokenKind::identifier);
449 Params.emplace_back(II, Ty, Modifier);
453void BuiltinTypeMethodBuilder::createDecl() {
454 assert(
Method ==
nullptr &&
"Method or constructor is already created");
460 uint32_t ArgIndex = 0;
463 bool UseParamExtInfo =
false;
464 for (Param &MP : Params) {
465 if (MP.Modifier != HLSLParamModifierAttr::Keyword_in) {
466 UseParamExtInfo =
true;
468 ParamExtInfos[ArgIndex] =
469 PI.
withABI(convertParamModifierToParamABI(MP.Modifier));
470 if (!MP.Ty->isDependentType())
471 MP.Ty = getInoutParameterType(AST, MP.Ty);
473 ParamTypes.emplace_back(MP.Ty);
477 FunctionProtoType::ExtProtoInfo ExtInfo;
479 ExtInfo.ExtParameterInfos = ParamExtInfos.data();
481 ExtInfo.TypeQuals.addConst();
487 DeclarationNameInfo NameInfo = DeclarationNameInfo(Name, SourceLocation());
490 AST, DeclBuilder.Record, SourceLocation(), NameInfo, FuncTy, TSInfo,
491 ExplicitSpecifier(),
false,
true,
false,
495 AST, DeclBuilder.Record, SourceLocation(), NameInfo, FuncTy, TSInfo, SC,
502 Method->getTypeSourceInfo()->getTypeLoc().getAs<FunctionProtoTypeLoc>();
503 for (
int I = 0, E = Params.size(); I != E; I++) {
504 Param &MP = Params[I];
506 AST, Method->getDeclContext(), SourceLocation(), SourceLocation(),
510 if (MP.Modifier != HLSLParamModifierAttr::Keyword_in) {
512 HLSLParamModifierAttr::Create(AST, SourceRange(), MP.Modifier);
515 Parm->setScopeInfo(CurScopeDepth, I);
516 ParmDecls.push_back(Parm);
517 FnProtoLoc.setParam(I, Parm);
519 Method->setParams({ParmDecls});
523 ensureCompleteDecl();
525 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
527 AST,
SourceLocation(), Method->getFunctionObjectParameterType(),
true);
528 FieldDecl *HandleField = DeclBuilder.getResourceHandleField();
535 ensureCompleteDecl();
537 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
539 AST,
SourceLocation(), Method->getFunctionObjectParameterType(),
true);
540 FieldDecl *HandleField = DeclBuilder.getResourceCounterHandleField();
548 ensureCompleteDecl();
550 assert(Var.Decl ==
nullptr &&
"local variable is already declared");
552 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
555 &AST.
Idents.
get(Var.Name, tok::TokenKind::identifier), Var.Ty,
559 StmtsList.push_back(DS);
564 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
568 StmtsList.push_back(ThisExpr);
572template <
typename... Ts>
575 QualType ReturnType, Ts... ArgSpecs) {
576 ensureCompleteDecl();
578 std::array<
Expr *,
sizeof...(ArgSpecs)> Args{
579 convertPlaceholder(std::forward<Ts>(ArgSpecs))...};
581 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
582 FunctionDecl *FD = lookupBuiltinFunction(DeclBuilder.SemaRef, BuiltinName);
596 StmtsList.push_back(
Call);
600template <
typename TLHS,
typename TRHS>
602 Expr *LHSExpr = convertPlaceholder(LHS);
603 Expr *RHSExpr = convertPlaceholder(RHS);
605 DeclBuilder.SemaRef.getASTContext(), LHSExpr, RHSExpr, BO_Assign,
608 StmtsList.push_back(AssignStmt);
614 Expr *PtrExpr = convertPlaceholder(Ptr);
620 StmtsList.push_back(Deref);
627 ensureCompleteDecl();
629 Expr *ResourceExpr = convertPlaceholder(ResourceRecord);
631 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
632 FieldDecl *HandleField = DeclBuilder.getResourceHandleField();
636 StmtsList.push_back(HandleExpr);
640template <
typename ResourceT,
typename ValueT>
643 ValueT HandleValue) {
644 return setFieldOnResource(ResourceRecord, HandleValue,
645 DeclBuilder.getResourceHandleField());
648template <
typename ResourceT,
typename ValueT>
651 ResourceT ResourceRecord, ValueT HandleValue) {
652 return setFieldOnResource(ResourceRecord, HandleValue,
653 DeclBuilder.getResourceCounterHandleField());
656template <
typename ResourceT,
typename ValueT>
658 ResourceT ResourceRecord, ValueT HandleValue,
FieldDecl *HandleField) {
659 ensureCompleteDecl();
661 Expr *ResourceExpr = convertPlaceholder(ResourceRecord);
662 Expr *HandleValueExpr = convertPlaceholder(HandleValue);
669 DeclBuilder.SemaRef.
getASTContext(), HandleMemberExpr, HandleValueExpr,
672 StmtsList.push_back(AssignStmt);
677BuiltinTypeMethodBuilder &
679 ensureCompleteDecl();
681 Expr *ResourceExpr = convertPlaceholder(ResourceRecord);
683 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
684 FieldDecl *HandleField = DeclBuilder.getResourceCounterHandleField();
688 StmtsList.push_back(HandleExpr);
694 ensureCompleteDecl();
696 Expr *ReturnValueExpr = convertPlaceholder(ReturnValue);
697 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
707 assert(CD &&
"no copy constructor found");
721 assert(!DeclBuilder.Record->isCompleteDefinition() &&
722 "record is already complete");
724 ensureCompleteDecl();
726 if (!Method->hasBody()) {
727 ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
728 assert((ReturnTy == AST.
VoidTy || !StmtsList.empty()) &&
729 "nothing to return from non-void method");
730 if (ReturnTy != AST.
VoidTy) {
731 if (
Expr *LastExpr = dyn_cast<Expr>(StmtsList.back())) {
733 ReturnTy.getNonReferenceType()) &&
734 "Return type of the last statement must match the return type "
737 StmtsList.pop_back();
746 Method->setLexicalDeclContext(DeclBuilder.Record);
748 Method->addAttr(AlwaysInlineAttr::CreateImplicit(
749 AST,
SourceRange(), AlwaysInlineAttr::CXX11_clang_always_inline));
750 DeclBuilder.Record->addDecl(Method);
756 : SemaRef(SemaRef), Record(R) {
757 Record->startDefinition();
758 Template = Record->getDescribedClassTemplate();
764 : SemaRef(SemaRef), HLSLNamespace(Namespace) {
770 if (SemaRef.LookupQualifiedName(
Result, HLSLNamespace)) {
773 if (
auto *TD = dyn_cast<ClassTemplateDecl>(
Found)) {
774 PrevDecl = TD->getTemplatedDecl();
777 PrevDecl = dyn_cast<CXXRecordDecl>(
Found);
778 assert(PrevDecl &&
"Unexpected lookup result type.");
783 Template = PrevTemplate;
790 Record->setImplicit(
true);
791 Record->setLexicalDeclContext(HLSLNamespace);
792 Record->setHasExternalLexicalStorage();
796 FinalAttr::CreateImplicit(AST,
SourceRange(), FinalAttr::Keyword_final));
800 if (HLSLNamespace && !Template && Record->getDeclContext() == HLSLNamespace)
801 HLSLNamespace->addDecl(Record);
808 assert(!Record->isCompleteDefinition() &&
"record is already complete");
809 assert(Record->isBeingDefined() &&
810 "Definition must be started before adding members!");
819 Field->setAccess(Access);
820 Field->setImplicit(
true);
821 for (
Attr *A : Attrs) {
826 Record->addDecl(Field);
827 Fields[Name] = Field;
833 bool RawBuffer,
bool HasCounter,
835 addHandleMember(RC, IsROV, RawBuffer, Access);
837 addCounterHandleMember(RC, IsROV, RawBuffer, Access);
842 ResourceClass RC,
bool IsROV,
bool RawBuffer,
AccessSpecifier Access) {
843 return addResourceMember(
"__handle", RC, IsROV, RawBuffer,
848 ResourceClass RC,
bool IsROV,
bool RawBuffer,
AccessSpecifier Access) {
849 return addResourceMember(
"__counter_handle", RC, IsROV, RawBuffer,
854 StringRef MemberName,
ResourceClass RC,
bool IsROV,
bool RawBuffer,
855 bool IsCounter, AccessSpecifier Access) {
856 assert(!
Record->isCompleteDefinition() &&
"record is already complete");
859 TypeSourceInfo *ElementTypeInfo =
863 QualType AttributedResTy = QualType();
865 HLSLResourceClassAttr::CreateImplicit(Ctx, RC),
866 IsROV ? HLSLROVAttr::CreateImplicit(Ctx) :
nullptr,
867 RawBuffer ? HLSLRawBufferAttr::CreateImplicit(Ctx) :
nullptr,
869 ? HLSLContainedTypeAttr::CreateImplicit(Ctx, ElementTypeInfo)
872 Attrs.push_back(HLSLIsCounterAttr::CreateImplicit(Ctx));
883 assert(!Record->isCompleteDefinition() &&
"record is already complete");
885 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
886 QualType HandleType = getResourceHandleField()->getType();
889 .callBuiltin(
"__builtin_hlsl_resource_uninitializedhandle", HandleType,
891 .assign(PH::Handle, PH::LastStmt)
898 addCreateFromBindingWithImplicitCounter();
899 addCreateFromImplicitBindingWithImplicitCounter();
901 addCreateFromBinding();
902 addCreateFromImplicitBinding();
919 assert(!
Record->isCompleteDefinition() &&
"record is already complete");
921 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
925 BuiltinTypeMethodBuilder::LocalVar TmpVar(
"tmp", RecordType);
931 .addParam(
"range", AST.
IntTy)
934 .declareLocalVar(TmpVar)
935 .accessHandleFieldOnResource(TmpVar)
936 .callBuiltin(
"__builtin_hlsl_resource_handlefrombinding", HandleType,
937 PH::LastStmt, PH::_0, PH::_1, PH::_2, PH::_3, PH::_4)
938 .setHandleFieldOnResource(TmpVar, PH::LastStmt)
956 assert(!
Record->isCompleteDefinition() &&
"record is already complete");
958 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
962 BuiltinTypeMethodBuilder::LocalVar TmpVar(
"tmp", RecordType);
968 .addParam(
"range", AST.
IntTy)
971 .declareLocalVar(TmpVar)
972 .accessHandleFieldOnResource(TmpVar)
973 .callBuiltin(
"__builtin_hlsl_resource_handlefromimplicitbinding",
974 HandleType, PH::LastStmt, PH::_0, PH::_1, PH::_2, PH::_3,
976 .setHandleFieldOnResource(TmpVar, PH::LastStmt)
997BuiltinTypeDeclBuilder::addCreateFromBindingWithImplicitCounter() {
998 assert(!
Record->isCompleteDefinition() &&
"record is already complete");
1000 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1002 QualType HandleType = getResourceHandleField()->
getType();
1004 BuiltinTypeMethodBuilder::LocalVar TmpVar(
"tmp", RecordType);
1007 "__createFromBindingWithImplicitCounter",
1011 .addParam(
"range", AST.
IntTy)
1015 .declareLocalVar(TmpVar)
1016 .accessHandleFieldOnResource(TmpVar)
1017 .callBuiltin(
"__builtin_hlsl_resource_handlefrombinding", HandleType,
1018 PH::LastStmt, PH::_0, PH::_1, PH::_2, PH::_3, PH::_4)
1019 .setHandleFieldOnResource(TmpVar, PH::LastStmt)
1020 .accessHandleFieldOnResource(TmpVar)
1021 .callBuiltin(
"__builtin_hlsl_resource_counterhandlefromimplicitbinding",
1022 HandleType, PH::LastStmt, PH::_5, PH::_1)
1023 .setCounterHandleFieldOnResource(TmpVar, PH::LastStmt)
1024 .returnValue(TmpVar)
1045BuiltinTypeDeclBuilder::addCreateFromImplicitBindingWithImplicitCounter() {
1046 assert(!Record->isCompleteDefinition() &&
"record is already complete");
1048 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1049 ASTContext &AST = SemaRef.getASTContext();
1050 QualType HandleType = getResourceHandleField()->getType();
1052 BuiltinTypeMethodBuilder::LocalVar TmpVar(
"tmp", RecordType);
1055 *
this,
"__createFromImplicitBindingWithImplicitCounter",
1059 .addParam(
"range", AST.
IntTy)
1063 .declareLocalVar(TmpVar)
1064 .accessHandleFieldOnResource(TmpVar)
1065 .callBuiltin(
"__builtin_hlsl_resource_handlefromimplicitbinding",
1066 HandleType, PH::LastStmt, PH::_0, PH::_1, PH::_2, PH::_3,
1068 .setHandleFieldOnResource(TmpVar, PH::LastStmt)
1069 .accessHandleFieldOnResource(TmpVar)
1070 .callBuiltin(
"__builtin_hlsl_resource_counterhandlefromimplicitbinding",
1071 HandleType, PH::LastStmt, PH::_5, PH::_1)
1072 .setCounterHandleFieldOnResource(TmpVar, PH::LastStmt)
1073 .returnValue(TmpVar)
1078 assert(!Record->isCompleteDefinition() &&
"record is already complete");
1085 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1089 MMB.
addParam(
"other", ConstRecordRefType)
1091 .
assign(PH::Handle, PH::LastStmt);
1093 if (getResourceCounterHandleField())
1101 assert(!Record->isCompleteDefinition() &&
"record is already complete");
1109 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1112 MMB.
addParam(
"other", ConstRecordRefType)
1114 .
assign(PH::Handle, PH::LastStmt);
1116 if (getResourceCounterHandleField())
1129 if (getResourceAttrs().ResourceClass == llvm::dxil::ResourceClass::UAV)
1136 assert(!Record->isCompleteDefinition() &&
"record is already complete");
1147FieldDecl *BuiltinTypeDeclBuilder::getResourceHandleField()
const {
1148 auto I = Fields.find(
"__handle");
1149 assert(I != Fields.end() &&
1150 I->second->getType()->isHLSLAttributedResourceType() &&
1151 "record does not have resource handle field");
1155FieldDecl *BuiltinTypeDeclBuilder::getResourceCounterHandleField()
const {
1156 auto I = Fields.find(
"__counter_handle");
1157 if (I == Fields.end() ||
1158 !I->second->getType()->isHLSLAttributedResourceType())
1163QualType BuiltinTypeDeclBuilder::getFirstTemplateTypeParam() {
1164 assert(
Template &&
"record it not a template");
1165 if (
const auto *TTD = dyn_cast<TemplateTypeParmDecl>(
1166 Template->getTemplateParameters()->getParam(0))) {
1167 return QualType(TTD->getTypeForDecl(), 0);
1172QualType BuiltinTypeDeclBuilder::getHandleElementType() {
1174 return getFirstTemplateTypeParam();
1176 return SemaRef.getASTContext().Char8Ty;
1179HLSLAttributedResourceType::Attributes
1180BuiltinTypeDeclBuilder::getResourceAttrs()
const {
1181 QualType HandleType = getResourceHandleField()->getType();
1186 assert(!Record->isCompleteDefinition() &&
"record is already complete");
1187 assert(Record->isBeingDefined() &&
1188 "Definition must be started before completing it.");
1190 Record->completeDefinition();
1194Expr *BuiltinTypeDeclBuilder::getConstantIntExpr(
int value) {
1204 if (Record->isCompleteDefinition()) {
1205 assert(Template &&
"existing record it not a template");
1206 assert(Template->getTemplateParameters()->size() == Names.size() &&
1207 "template param count mismatch");
1212 for (StringRef Name : Names)
1213 Builder.addTypeParameter(Name);
1214 return Builder.finalizeTemplateArgs(CD);
1218 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1220 SemaRef.getASTContext().UnsignedIntTy)
1221 .callBuiltin(
"__builtin_hlsl_buffer_update_counter",
QualType(),
1222 PH::CounterHandle, getConstantIntExpr(1))
1227 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1229 SemaRef.getASTContext().UnsignedIntTy)
1230 .callBuiltin(
"__builtin_hlsl_buffer_update_counter",
QualType(),
1231 PH::CounterHandle, getConstantIntExpr(-1))
1237 bool IsConst,
bool IsRef) {
1238 assert(!Record->isCompleteDefinition() &&
"record is already complete");
1240 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1242 QualType ElemTy = getHandleElementType();
1249 ReturnTy = AddrSpaceElemTy;
1261 .callBuiltin(
"__builtin_hlsl_resource_getpointer", ElemPtrTy, PH::Handle,
1263 .dereference(PH::LastStmt)
1268 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1270 QualType ElemTy = getHandleElementType();
1274 .addParam(
"value", ElemTy)
1275 .callBuiltin(
"__builtin_hlsl_buffer_update_counter", AST.
UnsignedIntTy,
1276 PH::CounterHandle, getConstantIntExpr(1))
1277 .callBuiltin(
"__builtin_hlsl_resource_getpointer",
1280 .dereference(PH::LastStmt)
1281 .assign(PH::LastStmt, PH::_0)
1286 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1288 QualType ElemTy = getHandleElementType();
1292 .callBuiltin(
"__builtin_hlsl_buffer_update_counter", AST.
UnsignedIntTy,
1293 PH::CounterHandle, getConstantIntExpr(-1))
1294 .callBuiltin(
"__builtin_hlsl_resource_getpointer",
1297 .dereference(PH::LastStmt)
1303 using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1307 QualType HandleTy = getResourceHandleField()->getType();
1312 if (AttrResTy->getAttrs().RawBuffer &&
1313 AttrResTy->getContainedType() != AST.
Char8Ty) {
1315 .addParam(
"numStructs", UIntTy, HLSLParamModifierAttr::Keyword_out)
1316 .addParam(
"stride", UIntTy, HLSLParamModifierAttr::Keyword_out)
1317 .callBuiltin(
"__builtin_hlsl_resource_getdimensions_x",
QualType(),
1319 .callBuiltin(
"__builtin_hlsl_resource_getstride",
QualType(),
1327 .addParam(
"dim", UIntTy, HLSLParamModifierAttr::Keyword_out)
1328 .callBuiltin(
"__builtin_hlsl_resource_getdimensions_x",
QualType(),
Defines the clang::ASTContext interface.
llvm::dxil::ResourceClass ResourceClass
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
llvm::MachO::Record Record
This file declares semantic analysis for HLSL constructs.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
CanQualType UnsignedIntTy
a trap message and trap category.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DeclarationNameTable DeclarationNames
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType UnsignedIntTy
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Attr - This represents one attribute.
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Represents a C++ constructor within a class.
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited=InheritedConstructor(), const AssociatedConstraint &TrailingRequiresClause={})
Represents a static or instance method of a struct/union/class.
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, const AssociatedConstraint &TrailingRequiresClause={})
Represents a C++ struct/union/class.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr)
Represents the this expression in C++.
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
QualType withConst() const
Retrieves a version of this type with const applied.
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a class template node.
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Declaration of a C++20 concept.
A reference to a concept and its template args, as it appears in the code.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
A reference to a declared variable, function, enum, etc.
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)
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
The name of a declaration.
This represents one expression.
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Represents a function declaration or definition.
QualType getReturnType() const
DeclarationNameInfo getNameInfo() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
ExtParameterInfo withABI(ParameterABI kind) const
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 ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
static ImplicitConceptSpecializationDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation SL, ArrayRef< TemplateArgument > ConvertedArgs)
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.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
static MemberExpr * CreateImplicit(const ASTContext &C, Expr *Base, bool IsArrow, ValueDecl *MemberDecl, QualType T, ExprValueKind VK, ExprObjectKind OK)
Create an implicit MemberExpr, with no location, qualifier, template arguments, and so on.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represent a C++ namespace.
A C++ nested-name-specifier augmented with source location information.
Represents a parameter to a function.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
A (possibly-)qualified type.
QualType withConst() const
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
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.
Scope * getCurScope() const
Retrieve the parser's current scope.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
ASTContext & getASTContext() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A convenient class for passing around template argument information.
void addArgument(const TemplateArgumentLoc &Loc)
Location wrapper for a TemplateArgument.
Represents a template argument.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
NamedDecl * getParam(unsigned Idx)
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)
A container of type source information.
The base class of the type hierarchy.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isRecordType() const
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
friend struct BuiltinTypeMethodBuilder
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R)
BuiltinTypeDeclBuilder & addSimpleTemplateParams(ArrayRef< StringRef > Names, ConceptDecl *CD)
BuiltinTypeDeclBuilder & addMemberVariable(StringRef Name, QualType Type, llvm::ArrayRef< Attr * > Attrs, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addConsumeMethod()
~BuiltinTypeDeclBuilder()
BuiltinTypeDeclBuilder & addHandleAccessFunction(DeclarationName &Name, bool IsConst, bool IsRef)
friend struct TemplateParameterListBuilder
BuiltinTypeDeclBuilder & addGetDimensionsMethodForBuffer()
BuiltinTypeDeclBuilder & addArraySubscriptOperators()
BuiltinTypeDeclBuilder & completeDefinition()
BuiltinTypeDeclBuilder & addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addAppendMethod()
BuiltinTypeDeclBuilder & addIncrementCounterMethod()
BuiltinTypeDeclBuilder & addCopyAssignmentOperator()
BuiltinTypeDeclBuilder & addCopyConstructor()
BuiltinTypeDeclBuilder & addStaticInitializationFunctions(bool HasCounter)
BuiltinTypeDeclBuilder & addDefaultHandleConstructor()
BuiltinTypeDeclBuilder & addDecrementCounterMethod()
BuiltinTypeDeclBuilder & addLoadMethods()
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ ICIS_NoInit
No in-class initializer.
@ OK_Ordinary
An ordinary object is located at an address in memory.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
StorageClass
Storage classes.
@ Result
The result type of a method or function.
ParameterABI
Kinds of parameter ABI.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
bool CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped, ArrayRef< const Attr * > AttrList, QualType &ResType, HLSLAttributedResourceLocInfo *LocInfo=nullptr)
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
U cast(CodeGen::Address addr)
@ Other
Other implicit parameter.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
BuiltinTypeMethodBuilder & addParam(StringRef Name, QualType Ty, HLSLParamModifierAttr::Spelling Modifier=HLSLParamModifierAttr::Keyword_in)
Expr * getResourceHandleExpr()
BuiltinTypeMethodBuilder & accessHandleFieldOnResource(T ResourceRecord)
BuiltinTypeDeclBuilder & finalize()
Expr * getResourceCounterHandleExpr()
BuiltinTypeMethodBuilder & operator=(const BuiltinTypeMethodBuilder &Other)=delete
BuiltinTypeMethodBuilder & returnThis()
BuiltinTypeMethodBuilder & callBuiltin(StringRef BuiltinName, QualType ReturnType, Ts... ArgSpecs)
BuiltinTypeMethodBuilder & dereference(T Ptr)
~BuiltinTypeMethodBuilder()
BuiltinTypeMethodBuilder & declareLocalVar(LocalVar &Var)
BuiltinTypeMethodBuilder & assign(TLHS LHS, TRHS RHS)
BuiltinTypeMethodBuilder(const BuiltinTypeMethodBuilder &Other)=delete
BuiltinTypeMethodBuilder & accessCounterHandleFieldOnResource(T ResourceRecord)
BuiltinTypeMethodBuilder & setCounterHandleFieldOnResource(ResourceT ResourceRecord, ValueT HandleValue)
BuiltinTypeMethodBuilder & setHandleFieldOnResource(ResourceT ResourceRecord, ValueT HandleValue)
friend BuiltinTypeDeclBuilder
BuiltinTypeMethodBuilder & returnValue(T ReturnValue)
BuiltinTypeMethodBuilder(BuiltinTypeDeclBuilder &DB, DeclarationName &Name, QualType ReturnTy, bool IsConst=false, bool IsCtor=false, StorageClass SC=SC_None)
TemplateParameterListBuilder & addTypeParameter(StringRef Name, QualType DefaultValue=QualType())
BuiltinTypeDeclBuilder & finalizeTemplateArgs(ConceptDecl *CD=nullptr)
llvm::SmallVector< NamedDecl * > Params
~TemplateParameterListBuilder()
TemplateParameterListBuilder(BuiltinTypeDeclBuilder &RB)
ConceptSpecializationExpr * constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD)
BuiltinTypeDeclBuilder & Builder