clang 17.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(),
75 FinalAttr::Keyword_final));
76 }
77
78 ~BuiltinTypeDeclBuilder() {
79 if (HLSLNamespace && !Template && Record->getDeclContext() == HLSLNamespace)
80 HLSLNamespace->addDecl(Record);
81 }
82
83 BuiltinTypeDeclBuilder &
84 addMemberVariable(StringRef Name, QualType Type,
85 AccessSpecifier Access = AccessSpecifier::AS_private) {
86 if (Record->isCompleteDefinition())
87 return *this;
88 assert(Record->isBeingDefined() &&
89 "Definition must be started before adding members!");
90 ASTContext &AST = Record->getASTContext();
91
92 IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
93 TypeSourceInfo *MemTySource =
96 AST, Record, SourceLocation(), SourceLocation(), &II, Type, MemTySource,
97 nullptr, false, InClassInitStyle::ICIS_NoInit);
98 Field->setAccess(Access);
99 Field->setImplicit(true);
100 Record->addDecl(Field);
101 Fields[Name] = Field;
102 return *this;
103 }
104
105 BuiltinTypeDeclBuilder &
106 addHandleMember(AccessSpecifier Access = AccessSpecifier::AS_private) {
107 if (Record->isCompleteDefinition())
108 return *this;
109 QualType Ty = Record->getASTContext().VoidPtrTy;
110 if (Template) {
111 if (const auto *TTD = dyn_cast<TemplateTypeParmDecl>(
112 Template->getTemplateParameters()->getParam(0)))
113 Ty = Record->getASTContext().getPointerType(
114 QualType(TTD->getTypeForDecl(), 0));
115 }
116 return addMemberVariable("h", Ty, Access);
117 }
118
119 BuiltinTypeDeclBuilder &
120 annotateResourceClass(HLSLResourceAttr::ResourceClass RC,
121 HLSLResourceAttr::ResourceKind RK) {
122 if (Record->isCompleteDefinition())
123 return *this;
124 Record->addAttr(
125 HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RC, RK));
126 return *this;
127 }
128
129 static DeclRefExpr *lookupBuiltinFunction(ASTContext &AST, Sema &S,
130 StringRef Name) {
131 CXXScopeSpec SS;
132 IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
133 DeclarationNameInfo NameInfo =
136 S.LookupParsedName(R, S.getCurScope(), &SS, false);
137 assert(R.isSingleResult() &&
138 "Since this is a builtin it should always resolve!");
139 auto *VD = cast<ValueDecl>(R.getFoundDecl());
140 QualType Ty = VD->getType();
142 VD, false, NameInfo, Ty, VK_PRValue);
143 }
144
145 static Expr *emitResourceClassExpr(ASTContext &AST, ResourceClass RC) {
147 AST,
148 llvm::APInt(AST.getIntWidth(AST.UnsignedCharTy),
149 static_cast<uint8_t>(RC)),
151 }
152
153 BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S,
154 ResourceClass RC) {
155 if (Record->isCompleteDefinition())
156 return *this;
157 ASTContext &AST = Record->getASTContext();
158
159 QualType ConstructorType =
161
162 CanQualType CanTy = Record->getTypeForDecl()->getCanonicalTypeUnqualified();
165 AST, Record, SourceLocation(),
166 DeclarationNameInfo(Name, SourceLocation()), ConstructorType,
167 AST.getTrivialTypeSourceInfo(ConstructorType, SourceLocation()),
168 ExplicitSpecifier(), false, true, false,
169 ConstexprSpecKind::Unspecified);
170
171 DeclRefExpr *Fn =
172 lookupBuiltinFunction(AST, S, "__builtin_hlsl_create_handle");
173
174 Expr *RCExpr = emitResourceClassExpr(AST, RC);
175 Expr *Call = CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue,
177
178 CXXThisExpr *This = new (AST) CXXThisExpr(
180 Constructor->getThisType().getTypePtr()->getPointeeType(), true);
181 This->setValueKind(ExprValueKind::VK_LValue);
182 Expr *Handle = MemberExpr::CreateImplicit(AST, This, false, Fields["h"],
183 Fields["h"]->getType(), VK_LValue,
185
186 // If the handle isn't a void pointer, cast the builtin result to the
187 // correct type.
188 if (Handle->getType().getCanonicalType() != AST.VoidPtrTy) {
190 AST, Handle->getType(), VK_PRValue, CK_Dependent, Call, nullptr,
193 SourceRange());
194 }
195
197 AST, Handle, Call, BO_Assign, Handle->getType(), VK_LValue, OK_Ordinary,
199
200 Constructor->setBody(
203 Constructor->setAccess(AccessSpecifier::AS_public);
204 Record->addDecl(Constructor);
205 return *this;
206 }
207
208 BuiltinTypeDeclBuilder &addArraySubscriptOperators() {
209 if (Record->isCompleteDefinition())
210 return *this;
211 addArraySubscriptOperator(true);
212 addArraySubscriptOperator(false);
213 return *this;
214 }
215
216 BuiltinTypeDeclBuilder &addArraySubscriptOperator(bool IsConst) {
217 if (Record->isCompleteDefinition())
218 return *this;
219 assert(Fields.count("h") > 0 &&
220 "Subscript operator must be added after the handle.");
221
222 FieldDecl *Handle = Fields["h"];
223 ASTContext &AST = Record->getASTContext();
224
225 assert(Handle->getType().getCanonicalType() != AST.VoidPtrTy &&
226 "Not yet supported for void pointer handles.");
227
228 QualType ElemTy =
230 QualType ReturnTy = ElemTy;
231
233
234 // Subscript operators return references to elements, const makes the
235 // reference and method const so that the underlying data is not mutable.
236 ReturnTy = AST.getLValueReferenceType(ReturnTy);
237 if (IsConst) {
238 ExtInfo.TypeQuals.addConst();
239 ReturnTy.addConst();
240 }
241
242 QualType MethodTy =
243 AST.getFunctionType(ReturnTy, {AST.UnsignedIntTy}, ExtInfo);
244 auto *TSInfo = AST.getTrivialTypeSourceInfo(MethodTy, SourceLocation());
245 auto *MethodDecl = CXXMethodDecl::Create(
246 AST, Record, SourceLocation(),
248 AST.DeclarationNames.getCXXOperatorName(OO_Subscript),
250 MethodTy, TSInfo, SC_None, false, false, ConstexprSpecKind::Unspecified,
252
253 IdentifierInfo &II = AST.Idents.get("Idx", tok::TokenKind::identifier);
254 auto *IdxParam = ParmVarDecl::Create(
255 AST, MethodDecl->getDeclContext(), SourceLocation(), SourceLocation(),
256 &II, AST.UnsignedIntTy,
258 SC_None, nullptr);
259 MethodDecl->setParams({IdxParam});
260
261 // Also add the parameter to the function prototype.
262 auto FnProtoLoc = TSInfo->getTypeLoc().getAs<FunctionProtoTypeLoc>();
263 FnProtoLoc.setParam(0, IdxParam);
264
265 auto *This = new (AST) CXXThisExpr(
267 MethodDecl->getThisType().getTypePtr()->getPointeeType(), true);
268 This->setValueKind(ExprValueKind::VK_LValue);
269 auto *HandleAccess = MemberExpr::CreateImplicit(
270 AST, This, false, Handle, Handle->getType(), VK_LValue, OK_Ordinary);
271
272 auto *IndexExpr = DeclRefExpr::Create(
273 AST, NestedNameSpecifierLoc(), SourceLocation(), IdxParam, false,
274 DeclarationNameInfo(IdxParam->getDeclName(), SourceLocation()),
276
277 auto *Array =
278 new (AST) ArraySubscriptExpr(HandleAccess, IndexExpr, ElemTy, VK_LValue,
280
281 auto *Return = ReturnStmt::Create(AST, SourceLocation(), Array, nullptr);
282
283 MethodDecl->setBody(CompoundStmt::Create(AST, {Return}, FPOptionsOverride(),
285 SourceLocation()));
286 MethodDecl->setLexicalDeclContext(Record);
287 MethodDecl->setAccess(AccessSpecifier::AS_public);
288 MethodDecl->addAttr(AlwaysInlineAttr::CreateImplicit(
290 AlwaysInlineAttr::CXX11_clang_always_inline));
291 Record->addDecl(MethodDecl);
292
293 return *this;
294 }
295
296 BuiltinTypeDeclBuilder &startDefinition() {
297 if (Record->isCompleteDefinition())
298 return *this;
299 Record->startDefinition();
300 return *this;
301 }
302
303 BuiltinTypeDeclBuilder &completeDefinition() {
304 if (Record->isCompleteDefinition())
305 return *this;
306 assert(Record->isBeingDefined() &&
307 "Definition must be started before completing it.");
308
309 Record->completeDefinition();
310 return *this;
311 }
312
313 TemplateParameterListBuilder addTemplateArgumentList();
314};
315
316struct TemplateParameterListBuilder {
317 BuiltinTypeDeclBuilder &Builder;
318 ASTContext &AST;
320
321 TemplateParameterListBuilder(BuiltinTypeDeclBuilder &RB)
322 : Builder(RB), AST(RB.Record->getASTContext()) {}
323
324 ~TemplateParameterListBuilder() { finalizeTemplateArgs(); }
325
326 TemplateParameterListBuilder &
327 addTypeParameter(StringRef Name, QualType DefaultValue = QualType()) {
328 if (Builder.Record->isCompleteDefinition())
329 return *this;
330 unsigned Position = static_cast<unsigned>(Params.size());
332 AST, Builder.Record->getDeclContext(), SourceLocation(),
333 SourceLocation(), /* TemplateDepth */ 0, Position,
334 &AST.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false,
335 /* ParameterPack */ false);
336 if (!DefaultValue.isNull())
337 Decl->setDefaultArgument(AST.getTrivialTypeSourceInfo(DefaultValue));
338
339 Params.emplace_back(Decl);
340 return *this;
341 }
342
343 BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
344 if (Params.empty())
345 return Builder;
346 auto *ParamList =
347 TemplateParameterList::Create(AST, SourceLocation(), SourceLocation(),
348 Params, SourceLocation(), nullptr);
349 Builder.Template = ClassTemplateDecl::Create(
350 AST, Builder.Record->getDeclContext(), SourceLocation(),
351 DeclarationName(Builder.Record->getIdentifier()), ParamList,
352 Builder.Record);
353 Builder.Record->setDescribedClassTemplate(Builder.Template);
354 Builder.Template->setImplicit(true);
355 Builder.Template->setLexicalDeclContext(Builder.Record->getDeclContext());
356 // NOTE: setPreviousDecl before addDecl so new decl replace old decl when
357 // make visible.
358 Builder.Template->setPreviousDecl(Builder.PrevTemplate);
359 Builder.Record->getDeclContext()->addDecl(Builder.Template);
360 Params.clear();
361
362 QualType T = Builder.Template->getInjectedClassNameSpecialization();
363 T = AST.getInjectedClassNameType(Builder.Record, T);
364
365 return Builder;
366 }
367};
368
369TemplateParameterListBuilder BuiltinTypeDeclBuilder::addTemplateArgumentList() {
370 return TemplateParameterListBuilder(*this);
371}
372} // namespace
373
375
377 SemaPtr = &S;
378 ASTContext &AST = SemaPtr->getASTContext();
379 // If the translation unit has external storage force external decls to load.
381 (void)AST.getTranslationUnitDecl()->decls_begin();
382
383 IdentifierInfo &HLSL = AST.Idents.get("hlsl", tok::TokenKind::identifier);
385 NamespaceDecl *PrevDecl = nullptr;
387 PrevDecl = Result.getAsSingle<NamespaceDecl>();
388 HLSLNamespace = NamespaceDecl::Create(
389 AST, AST.getTranslationUnitDecl(), /*Inline=*/false, SourceLocation(),
390 SourceLocation(), &HLSL, PrevDecl, /*Nested=*/false);
391 HLSLNamespace->setImplicit(true);
392 HLSLNamespace->setHasExternalLexicalStorage();
393 AST.getTranslationUnitDecl()->addDecl(HLSLNamespace);
394
395 // Force external decls in the HLSL namespace to load from the PCH.
396 (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
397 defineTrivialHLSLTypes();
398 forwardDeclareHLSLTypes();
399
400 // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
401 // built in types inside a namespace, but we are planning to change that in
402 // the near future. In order to be source compatible older versions of HLSL
403 // will need to implicitly use the hlsl namespace. For now in clang everything
404 // will get added to the namespace, and we can remove the using directive for
405 // future language versions to match HLSL's evolution.
408 NestedNameSpecifierLoc(), SourceLocation(), HLSLNamespace,
410
412}
413
414void HLSLExternalSemaSource::defineHLSLVectorAlias() {
415 ASTContext &AST = SemaPtr->getASTContext();
416
417 llvm::SmallVector<NamedDecl *> TemplateParams;
418
419 auto *TypeParam = TemplateTypeParmDecl::Create(
420 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
421 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
422 TypeParam->setDefaultArgument(AST.getTrivialTypeSourceInfo(AST.FloatTy));
423
424 TemplateParams.emplace_back(TypeParam);
425
426 auto *SizeParam = NonTypeTemplateParmDecl::Create(
427 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
428 &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
429 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
430 Expr *LiteralExpr =
431 IntegerLiteral::Create(AST, llvm::APInt(AST.getIntWidth(AST.IntTy), 4),
432 AST.IntTy, SourceLocation());
433 SizeParam->setDefaultArgument(LiteralExpr);
434 TemplateParams.emplace_back(SizeParam);
435
436 auto *ParamList =
438 TemplateParams, SourceLocation(), nullptr);
439
440 IdentifierInfo &II = AST.Idents.get("vector", tok::TokenKind::identifier);
441
443 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
445 AST, NestedNameSpecifierLoc(), SourceLocation(), SizeParam, false,
446 DeclarationNameInfo(SizeParam->getDeclName(), SourceLocation()),
447 AST.IntTy, VK_LValue),
449
450 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
451 SourceLocation(), &II,
452 AST.getTrivialTypeSourceInfo(AliasType));
453 Record->setImplicit(true);
454
455 auto *Template =
456 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
457 Record->getIdentifier(), ParamList, Record);
458
459 Record->setDescribedAliasTemplate(Template);
460 Template->setImplicit(true);
461 Template->setLexicalDeclContext(Record->getDeclContext());
462 HLSLNamespace->addDecl(Template);
463}
464
465void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
466 defineHLSLVectorAlias();
467
468 ResourceDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Resource")
470 .addHandleMember(AccessSpecifier::AS_public)
471 .completeDefinition()
472 .Record;
473}
474
475void HLSLExternalSemaSource::forwardDeclareHLSLTypes() {
477 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
478 .addTemplateArgumentList()
479 .addTypeParameter("element_type", SemaPtr->getASTContext().FloatTy)
480 .finalizeTemplateArgs()
481 .Record;
482 if (!Decl->isCompleteDefinition())
483 Completions.insert(
484 std::make_pair(Decl->getCanonicalDecl(),
485 std::bind(&HLSLExternalSemaSource::completeBufferType,
486 this, std::placeholders::_1)));
487}
488
490 if (!isa<CXXRecordDecl>(Tag))
491 return;
492 auto Record = cast<CXXRecordDecl>(Tag);
493
494 // If this is a specialization, we need to get the underlying templated
495 // declaration and complete that.
496 if (auto TDecl = dyn_cast<ClassTemplateSpecializationDecl>(Record))
497 Record = TDecl->getSpecializedTemplate()->getTemplatedDecl();
498 Record = Record->getCanonicalDecl();
499 auto It = Completions.find(Record);
500 if (It == Completions.end())
501 return;
502 It->second(Record);
503}
504
505void HLSLExternalSemaSource::completeBufferType(CXXRecordDecl *Record) {
506 BuiltinTypeDeclBuilder(Record)
507 .addHandleMember()
508 .addDefaultHandleConstructor(*SemaPtr, ResourceClass::UAV)
509 .addArraySubscriptOperators()
510 .annotateResourceClass(HLSLResourceAttr::UAV,
511 HLSLResourceAttr::TypedBuffer)
512 .completeDefinition();
513}
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:1060
unsigned getIntWidth(QualType T) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:635
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:1090
CanQualType VoidPtrTy
Definition: ASTContext.h:1105
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:631
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:1087
CanQualType VoidTy
Definition: ASTContext.h:1078
CanQualType UnsignedCharTy
Definition: ASTContext.h:1088
CanQualType UnsignedIntTy
Definition: ASTContext.h:1088
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:1537
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2656
@ AS_Keyword
__ptr16, alignas(...), etc.
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3814
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:4639
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2474
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:2654
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:2230
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:709
Represents the this expression in C++.
Definition: ExprCXX.h:1148
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:1478
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:1619
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2503
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
Definition: DeclBase.h:2509
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1475
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1238
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:536
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:340
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:943
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:1865
This represents one expression.
Definition: Expr.h:110
QualType getType() const
Definition: Expr.h:142
Represents difference between two FPOptions values.
Definition: LangOptions.h:806
Represents a member of a struct/union/class.
Definition: Decl.h:2941
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:4299
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1465
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:983
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:3232
This represents a decl that may have a name.
Definition: Decl.h:247
Represent a C++ namespace.
Definition: Decl.h:542
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
Definition: Decl.h:669
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition: DeclCXX.cpp:2913
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:2851
A (possibly-)qualified type.
Definition: Type.h:736
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:912
QualType getCanonicalType() const
Definition: Type.h:6701
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:13790
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:4293
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:4316
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:4296
ASTContext & getASTContext() const
Definition: Sema.h:1652
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:3440
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3543
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4452
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:426
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:138
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:5242
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:6620
The base class of the type hierarchy.
Definition: Type.h:1566
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:7381
Represents a C++ using-declaration.
Definition: DeclCXX.h:3449
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition: DeclCXX.cpp:2868
QualType getType() const
Definition: Decl.h:712
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1372
bool Call(InterpState &S, CodePtr &PC, const Function *Func)
Definition: Interp.h:1493
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:139
@ SC_None
Definition: Specifiers.h:238
@ 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:123
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:127
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:111
@ AS_public
Definition: Specifiers.h:112
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Extra information about a function prototype.
Definition: Type.h:4118