clang 18.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
14#include "clang/AST/Attr.h"
15#include "clang/AST/DeclCXX.h"
18#include "clang/Sema/Lookup.h"
19#include "clang/Sema/Sema.h"
20#include "llvm/Frontend/HLSL/HLSLResource.h"
21
22#include <functional>
23
24using namespace clang;
25using namespace llvm::hlsl;
26
27namespace {
28
29struct TemplateParameterListBuilder;
30
31struct BuiltinTypeDeclBuilder {
32 CXXRecordDecl *Record = nullptr;
33 ClassTemplateDecl *Template = nullptr;
34 ClassTemplateDecl *PrevTemplate = nullptr;
35 NamespaceDecl *HLSLNamespace = nullptr;
36 llvm::StringMap<FieldDecl *> Fields;
37
38 BuiltinTypeDeclBuilder(CXXRecordDecl *R) : Record(R) {
39 Record->startDefinition();
40 Template = Record->getDescribedClassTemplate();
41 }
42
43 BuiltinTypeDeclBuilder(Sema &S, NamespaceDecl *Namespace, StringRef Name)
44 : HLSLNamespace(Namespace) {
45 ASTContext &AST = S.getASTContext();
46 IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
47
49 CXXRecordDecl *PrevDecl = nullptr;
50 if (S.LookupQualifiedName(Result, HLSLNamespace)) {
51 NamedDecl *Found = Result.getFoundDecl();
52 if (auto *TD = dyn_cast<ClassTemplateDecl>(Found)) {
53 PrevDecl = TD->getTemplatedDecl();
54 PrevTemplate = TD;
55 } else
56 PrevDecl = dyn_cast<CXXRecordDecl>(Found);
57 assert(PrevDecl && "Unexpected lookup result type.");
58 }
59
60 if (PrevDecl && PrevDecl->isCompleteDefinition()) {
61 Record = PrevDecl;
62 return;
63 }
64
65 Record = CXXRecordDecl::Create(AST, TagDecl::TagKind::TTK_Class,
66 HLSLNamespace, SourceLocation(),
67 SourceLocation(), &II, PrevDecl, true);
68 Record->setImplicit(true);
69 Record->setLexicalDeclContext(HLSLNamespace);
70 Record->setHasExternalLexicalStorage();
71
72 // Don't let anyone derive from built-in types.
73 Record->addAttr(FinalAttr::CreateImplicit(AST, SourceRange(),
74 FinalAttr::Keyword_final));
75 }
76
77 ~BuiltinTypeDeclBuilder() {
78 if (HLSLNamespace && !Template && Record->getDeclContext() == HLSLNamespace)
79 HLSLNamespace->addDecl(Record);
80 }
81
82 BuiltinTypeDeclBuilder &
83 addMemberVariable(StringRef Name, QualType Type,
84 AccessSpecifier Access = AccessSpecifier::AS_private) {
85 if (Record->isCompleteDefinition())
86 return *this;
87 assert(Record->isBeingDefined() &&
88 "Definition must be started before adding members!");
89 ASTContext &AST = Record->getASTContext();
90
91 IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
92 TypeSourceInfo *MemTySource =
95 AST, Record, SourceLocation(), SourceLocation(), &II, Type, MemTySource,
96 nullptr, false, InClassInitStyle::ICIS_NoInit);
97 Field->setAccess(Access);
98 Field->setImplicit(true);
99 Record->addDecl(Field);
100 Fields[Name] = Field;
101 return *this;
102 }
103
104 BuiltinTypeDeclBuilder &
105 addHandleMember(AccessSpecifier Access = AccessSpecifier::AS_private) {
106 if (Record->isCompleteDefinition())
107 return *this;
108 QualType Ty = Record->getASTContext().VoidPtrTy;
109 if (Template) {
110 if (const auto *TTD = dyn_cast<TemplateTypeParmDecl>(
111 Template->getTemplateParameters()->getParam(0)))
112 Ty = Record->getASTContext().getPointerType(
113 QualType(TTD->getTypeForDecl(), 0));
114 }
115 return addMemberVariable("h", Ty, Access);
116 }
117
118 BuiltinTypeDeclBuilder &
119 annotateResourceClass(HLSLResourceAttr::ResourceClass RC,
120 HLSLResourceAttr::ResourceKind RK) {
121 if (Record->isCompleteDefinition())
122 return *this;
123 Record->addAttr(
124 HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RC, RK));
125 return *this;
126 }
127
128 static DeclRefExpr *lookupBuiltinFunction(ASTContext &AST, Sema &S,
129 StringRef Name) {
130 CXXScopeSpec SS;
131 IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
132 DeclarationNameInfo NameInfo =
135 S.LookupParsedName(R, S.getCurScope(), &SS, false);
136 assert(R.isSingleResult() &&
137 "Since this is a builtin it should always resolve!");
138 auto *VD = cast<ValueDecl>(R.getFoundDecl());
139 QualType Ty = VD->getType();
141 VD, false, NameInfo, Ty, VK_PRValue);
142 }
143
144 static Expr *emitResourceClassExpr(ASTContext &AST, ResourceClass RC) {
146 AST,
147 llvm::APInt(AST.getIntWidth(AST.UnsignedCharTy),
148 static_cast<uint8_t>(RC)),
150 }
151
152 BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S,
153 ResourceClass RC) {
154 if (Record->isCompleteDefinition())
155 return *this;
156 ASTContext &AST = Record->getASTContext();
157
158 QualType ConstructorType =
160
161 CanQualType CanTy = Record->getTypeForDecl()->getCanonicalTypeUnqualified();
164 AST, Record, SourceLocation(),
165 DeclarationNameInfo(Name, SourceLocation()), ConstructorType,
166 AST.getTrivialTypeSourceInfo(ConstructorType, SourceLocation()),
167 ExplicitSpecifier(), false, true, false,
168 ConstexprSpecKind::Unspecified);
169
170 DeclRefExpr *Fn =
171 lookupBuiltinFunction(AST, S, "__builtin_hlsl_create_handle");
172
173 Expr *RCExpr = emitResourceClassExpr(AST, RC);
174 Expr *Call = CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue,
176
178 AST, SourceLocation(),
179 Constructor->getThisObjectType(), true);
180 Expr *Handle = MemberExpr::CreateImplicit(AST, This, false, Fields["h"],
181 Fields["h"]->getType(), VK_LValue,
183
184 // If the handle isn't a void pointer, cast the builtin result to the
185 // correct type.
186 if (Handle->getType().getCanonicalType() != AST.VoidPtrTy) {
188 AST, Handle->getType(), VK_PRValue, CK_Dependent, Call, nullptr,
191 SourceRange());
192 }
193
195 AST, Handle, Call, BO_Assign, Handle->getType(), VK_LValue, OK_Ordinary,
197
198 Constructor->setBody(
201 Constructor->setAccess(AccessSpecifier::AS_public);
202 Record->addDecl(Constructor);
203 return *this;
204 }
205
206 BuiltinTypeDeclBuilder &addArraySubscriptOperators() {
207 if (Record->isCompleteDefinition())
208 return *this;
209 addArraySubscriptOperator(true);
210 addArraySubscriptOperator(false);
211 return *this;
212 }
213
214 BuiltinTypeDeclBuilder &addArraySubscriptOperator(bool IsConst) {
215 if (Record->isCompleteDefinition())
216 return *this;
217 assert(Fields.count("h") > 0 &&
218 "Subscript operator must be added after the handle.");
219
220 FieldDecl *Handle = Fields["h"];
221 ASTContext &AST = Record->getASTContext();
222
223 assert(Handle->getType().getCanonicalType() != AST.VoidPtrTy &&
224 "Not yet supported for void pointer handles.");
225
226 QualType ElemTy =
228 QualType ReturnTy = ElemTy;
229
231
232 // Subscript operators return references to elements, const makes the
233 // reference and method const so that the underlying data is not mutable.
234 ReturnTy = AST.getLValueReferenceType(ReturnTy);
235 if (IsConst) {
236 ExtInfo.TypeQuals.addConst();
237 ReturnTy.addConst();
238 }
239
240 QualType MethodTy =
241 AST.getFunctionType(ReturnTy, {AST.UnsignedIntTy}, ExtInfo);
242 auto *TSInfo = AST.getTrivialTypeSourceInfo(MethodTy, SourceLocation());
243 auto *MethodDecl = CXXMethodDecl::Create(
244 AST, Record, SourceLocation(),
246 AST.DeclarationNames.getCXXOperatorName(OO_Subscript),
248 MethodTy, TSInfo, SC_None, false, false, ConstexprSpecKind::Unspecified,
250
251 IdentifierInfo &II = AST.Idents.get("Idx", tok::TokenKind::identifier);
252 auto *IdxParam = ParmVarDecl::Create(
253 AST, MethodDecl->getDeclContext(), SourceLocation(), SourceLocation(),
254 &II, AST.UnsignedIntTy,
256 SC_None, nullptr);
257 MethodDecl->setParams({IdxParam});
258
259 // Also add the parameter to the function prototype.
260 auto FnProtoLoc = TSInfo->getTypeLoc().getAs<FunctionProtoTypeLoc>();
261 FnProtoLoc.setParam(0, IdxParam);
262
264 AST, SourceLocation(),
265 MethodDecl->getThisObjectType(), true);
266 auto *HandleAccess = MemberExpr::CreateImplicit(
267 AST, This, false, Handle, Handle->getType(), VK_LValue, OK_Ordinary);
268
269 auto *IndexExpr = DeclRefExpr::Create(
270 AST, NestedNameSpecifierLoc(), SourceLocation(), IdxParam, false,
271 DeclarationNameInfo(IdxParam->getDeclName(), SourceLocation()),
273
274 auto *Array =
275 new (AST) ArraySubscriptExpr(HandleAccess, IndexExpr, ElemTy, VK_LValue,
277
278 auto *Return = ReturnStmt::Create(AST, SourceLocation(), Array, nullptr);
279
280 MethodDecl->setBody(CompoundStmt::Create(AST, {Return}, FPOptionsOverride(),
282 SourceLocation()));
283 MethodDecl->setLexicalDeclContext(Record);
284 MethodDecl->setAccess(AccessSpecifier::AS_public);
285 MethodDecl->addAttr(AlwaysInlineAttr::CreateImplicit(
286 AST, SourceRange(), AlwaysInlineAttr::CXX11_clang_always_inline));
287 Record->addDecl(MethodDecl);
288
289 return *this;
290 }
291
292 BuiltinTypeDeclBuilder &startDefinition() {
293 if (Record->isCompleteDefinition())
294 return *this;
295 Record->startDefinition();
296 return *this;
297 }
298
299 BuiltinTypeDeclBuilder &completeDefinition() {
300 if (Record->isCompleteDefinition())
301 return *this;
302 assert(Record->isBeingDefined() &&
303 "Definition must be started before completing it.");
304
305 Record->completeDefinition();
306 return *this;
307 }
308
309 TemplateParameterListBuilder addTemplateArgumentList();
310};
311
312struct TemplateParameterListBuilder {
313 BuiltinTypeDeclBuilder &Builder;
314 ASTContext &AST;
316
317 TemplateParameterListBuilder(BuiltinTypeDeclBuilder &RB)
318 : Builder(RB), AST(RB.Record->getASTContext()) {}
319
320 ~TemplateParameterListBuilder() { finalizeTemplateArgs(); }
321
322 TemplateParameterListBuilder &
323 addTypeParameter(StringRef Name, QualType DefaultValue = QualType()) {
324 if (Builder.Record->isCompleteDefinition())
325 return *this;
326 unsigned Position = static_cast<unsigned>(Params.size());
328 AST, Builder.Record->getDeclContext(), SourceLocation(),
329 SourceLocation(), /* TemplateDepth */ 0, Position,
330 &AST.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false,
331 /* ParameterPack */ false);
332 if (!DefaultValue.isNull())
333 Decl->setDefaultArgument(AST.getTrivialTypeSourceInfo(DefaultValue));
334
335 Params.emplace_back(Decl);
336 return *this;
337 }
338
339 BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
340 if (Params.empty())
341 return Builder;
342 auto *ParamList =
343 TemplateParameterList::Create(AST, SourceLocation(), SourceLocation(),
344 Params, SourceLocation(), nullptr);
345 Builder.Template = ClassTemplateDecl::Create(
346 AST, Builder.Record->getDeclContext(), SourceLocation(),
347 DeclarationName(Builder.Record->getIdentifier()), ParamList,
348 Builder.Record);
349 Builder.Record->setDescribedClassTemplate(Builder.Template);
350 Builder.Template->setImplicit(true);
351 Builder.Template->setLexicalDeclContext(Builder.Record->getDeclContext());
352 // NOTE: setPreviousDecl before addDecl so new decl replace old decl when
353 // make visible.
354 Builder.Template->setPreviousDecl(Builder.PrevTemplate);
355 Builder.Record->getDeclContext()->addDecl(Builder.Template);
356 Params.clear();
357
358 QualType T = Builder.Template->getInjectedClassNameSpecialization();
359 T = AST.getInjectedClassNameType(Builder.Record, T);
360
361 return Builder;
362 }
363};
364
365TemplateParameterListBuilder BuiltinTypeDeclBuilder::addTemplateArgumentList() {
366 return TemplateParameterListBuilder(*this);
367}
368} // namespace
369
371
373 SemaPtr = &S;
374 ASTContext &AST = SemaPtr->getASTContext();
375 // If the translation unit has external storage force external decls to load.
377 (void)AST.getTranslationUnitDecl()->decls_begin();
378
379 IdentifierInfo &HLSL = AST.Idents.get("hlsl", tok::TokenKind::identifier);
381 NamespaceDecl *PrevDecl = nullptr;
383 PrevDecl = Result.getAsSingle<NamespaceDecl>();
384 HLSLNamespace = NamespaceDecl::Create(
385 AST, AST.getTranslationUnitDecl(), /*Inline=*/false, SourceLocation(),
386 SourceLocation(), &HLSL, PrevDecl, /*Nested=*/false);
387 HLSLNamespace->setImplicit(true);
388 HLSLNamespace->setHasExternalLexicalStorage();
389 AST.getTranslationUnitDecl()->addDecl(HLSLNamespace);
390
391 // Force external decls in the HLSL namespace to load from the PCH.
392 (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
393 defineTrivialHLSLTypes();
394 forwardDeclareHLSLTypes();
395
396 // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
397 // built in types inside a namespace, but we are planning to change that in
398 // the near future. In order to be source compatible older versions of HLSL
399 // will need to implicitly use the hlsl namespace. For now in clang everything
400 // will get added to the namespace, and we can remove the using directive for
401 // future language versions to match HLSL's evolution.
404 NestedNameSpecifierLoc(), SourceLocation(), HLSLNamespace,
406
408}
409
410void HLSLExternalSemaSource::defineHLSLVectorAlias() {
411 ASTContext &AST = SemaPtr->getASTContext();
412
413 llvm::SmallVector<NamedDecl *> TemplateParams;
414
415 auto *TypeParam = TemplateTypeParmDecl::Create(
416 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
417 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
418 TypeParam->setDefaultArgument(AST.getTrivialTypeSourceInfo(AST.FloatTy));
419
420 TemplateParams.emplace_back(TypeParam);
421
422 auto *SizeParam = NonTypeTemplateParmDecl::Create(
423 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
424 &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
425 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
426 Expr *LiteralExpr =
427 IntegerLiteral::Create(AST, llvm::APInt(AST.getIntWidth(AST.IntTy), 4),
428 AST.IntTy, SourceLocation());
429 SizeParam->setDefaultArgument(LiteralExpr);
430 TemplateParams.emplace_back(SizeParam);
431
432 auto *ParamList =
434 TemplateParams, SourceLocation(), nullptr);
435
436 IdentifierInfo &II = AST.Idents.get("vector", tok::TokenKind::identifier);
437
439 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
441 AST, NestedNameSpecifierLoc(), SourceLocation(), SizeParam, false,
442 DeclarationNameInfo(SizeParam->getDeclName(), SourceLocation()),
443 AST.IntTy, VK_LValue),
445
446 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
447 SourceLocation(), &II,
448 AST.getTrivialTypeSourceInfo(AliasType));
449 Record->setImplicit(true);
450
451 auto *Template =
452 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
453 Record->getIdentifier(), ParamList, Record);
454
455 Record->setDescribedAliasTemplate(Template);
456 Template->setImplicit(true);
457 Template->setLexicalDeclContext(Record->getDeclContext());
458 HLSLNamespace->addDecl(Template);
459}
460
461void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
462 defineHLSLVectorAlias();
463
464 ResourceDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Resource")
466 .addHandleMember(AccessSpecifier::AS_public)
467 .completeDefinition()
468 .Record;
469}
470
471void HLSLExternalSemaSource::forwardDeclareHLSLTypes() {
473 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
474 .addTemplateArgumentList()
475 .addTypeParameter("element_type", SemaPtr->getASTContext().FloatTy)
476 .finalizeTemplateArgs()
477 .Record;
478 if (!Decl->isCompleteDefinition())
479 Completions.insert(
480 std::make_pair(Decl->getCanonicalDecl(),
481 std::bind(&HLSLExternalSemaSource::completeBufferType,
482 this, std::placeholders::_1)));
483}
484
486 if (!isa<CXXRecordDecl>(Tag))
487 return;
488 auto Record = cast<CXXRecordDecl>(Tag);
489
490 // If this is a specialization, we need to get the underlying templated
491 // declaration and complete that.
492 if (auto TDecl = dyn_cast<ClassTemplateSpecializationDecl>(Record))
493 Record = TDecl->getSpecializedTemplate()->getTemplatedDecl();
494 Record = Record->getCanonicalDecl();
495 auto It = Completions.find(Record);
496 if (It == Completions.end())
497 return;
498 It->second(Record);
499}
500
501void HLSLExternalSemaSource::completeBufferType(CXXRecordDecl *Record) {
502 BuiltinTypeDeclBuilder(Record)
503 .addHandleMember()
504 .addDefaultHandleConstructor(*SemaPtr, ResourceClass::UAV)
505 .addArraySubscriptOperators()
506 .annotateResourceClass(HLSLResourceAttr::UAV,
507 HLSLResourceAttr::TypedBuffer)
508 .completeDefinition();
509}
Defines the clang::ASTContext interface.
Defines the clang::attr::Kind enum.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines helper utilities for supporting the HLSL runtime environment.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1059
unsigned getIntWidth(QualType T) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:634
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
CanQualType FloatTy
Definition: ASTContext.h:1089
CanQualType VoidPtrTy
Definition: ASTContext.h:1104
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
IdentifierTable & Idents
Definition: ASTContext.h:630
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
Definition: ASTContext.h:1086
CanQualType VoidTy
Definition: ASTContext.h:1077
CanQualType UnsignedCharTy
Definition: ASTContext.h:1087
CanQualType UnsignedIntTy
Definition: ASTContext.h:1087
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1542
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2676
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3847
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:4751
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2491
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(), Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2657
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, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2232
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
Definition: DeclCXX.cpp:131
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:73
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:711
Represents the this expression in C++.
Definition: ExprCXX.h:1148
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1518
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.
Definition: Expr.cpp:1509
Declaration of a class template.
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)
Definition: Stmt.cpp:382
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1642
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2521
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
Definition: DeclBase.h:2527
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1498
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1242
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:538
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
void setImplicit(bool I=true)
Definition: DeclBase.h:577
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:341
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:946
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
The name of a declaration.
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1882
This represents one expression.
Definition: Expr.h:110
QualType getType() const
Definition: Expr.h:142
Represents difference between two FPOptions values.
Definition: LangOptions.h:820
Represents a member of a struct/union/class.
Definition: Decl.h:2962
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition: Decl.cpp:4431
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1471
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:1000
Represents the results of name lookup.
Definition: Lookup.h:46
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.
Definition: Expr.h:3252
This represents a decl that may have a name.
Definition: Decl.h:247
Represent a C++ namespace.
Definition: Decl.h:544
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
Definition: Decl.h:671
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition: DeclCXX.cpp:2916
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, IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2888
A (possibly-)qualified type.
Definition: Type.h:736
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:944
QualType getCanonicalType() const
Definition: Type.h:6799
void addConst()
Definition: Type.h:266
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1202
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:14024
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:4360
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:4383
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:4363
ASTContext & getASTContext() const
Definition: Sema.h:1692
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Encodes a location in the source.
A trivial tuple used to represent a source range.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3477
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3580
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4623
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:429
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:140
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
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, std::optional< unsigned > NumExpanded=std::nullopt)
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:5418
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: Type.h:6718
The base class of the type hierarchy.
Definition: Type.h:1597
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:7480
Represents a C++ using-declaration.
Definition: DeclCXX.h:3466
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition: DeclCXX.cpp:2871
QualType getType() const
Definition: Decl.h:714
bool Call(InterpState &S, CodePtr OpPC, const Function *Func)
Definition: Interp.h:1752
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1631
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:142
@ SC_None
Definition: Specifiers.h:241
@ Result
The result type of a method or function.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:126
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:130
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:114
@ AS_public
Definition: Specifiers.h:115
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Extra information about a function prototype.
Definition: Type.h:4194