clang  19.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 
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/Attr.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/Basic/AttrKinds.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 
24 using namespace clang;
25 using namespace llvm::hlsl;
26 
27 namespace {
28 
29 struct TemplateParameterListBuilder;
30 
31 struct 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 
67  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,
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 =
94  auto *Field = FieldDecl::Create(
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 &annotateResourceClass(ResourceClass RC,
119  ResourceKind RK, bool IsROV) {
120  if (Record->isCompleteDefinition())
121  return *this;
122  Record->addAttr(HLSLResourceAttr::CreateImplicit(Record->getASTContext(),
123  RC, RK, IsROV));
124  return *this;
125  }
126 
127  static DeclRefExpr *lookupBuiltinFunction(ASTContext &AST, Sema &S,
128  StringRef Name) {
129  IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
130  DeclarationNameInfo NameInfo =
132  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
133  // AllowBuiltinCreation is false but LookupDirect will create
134  // the builtin when searching the global scope anyways...
135  S.LookupName(R, S.getCurScope());
136  // FIXME: If the builtin function was user-declared in global scope,
137  // this assert *will* fail. Should this call LookupBuiltin instead?
138  assert(R.isSingleResult() &&
139  "Since this is a builtin it should always resolve!");
140  auto *VD = cast<ValueDecl>(R.getFoundDecl());
141  QualType Ty = VD->getType();
143  VD, false, NameInfo, Ty, VK_PRValue);
144  }
145 
146  static Expr *emitResourceClassExpr(ASTContext &AST, ResourceClass RC) {
147  return IntegerLiteral::Create(
148  AST,
150  static_cast<uint8_t>(RC)),
152  }
153 
154  BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S,
155  ResourceClass RC) {
156  if (Record->isCompleteDefinition())
157  return *this;
158  ASTContext &AST = Record->getASTContext();
159 
160  QualType ConstructorType =
162 
163  CanQualType CanTy = Record->getTypeForDecl()->getCanonicalTypeUnqualified();
166  AST, Record, SourceLocation(),
167  DeclarationNameInfo(Name, SourceLocation()), ConstructorType,
168  AST.getTrivialTypeSourceInfo(ConstructorType, SourceLocation()),
169  ExplicitSpecifier(), false, true, false,
171 
172  DeclRefExpr *Fn =
173  lookupBuiltinFunction(AST, S, "__builtin_hlsl_create_handle");
174 
175  Expr *RCExpr = emitResourceClassExpr(AST, RC);
176  Expr *Call = CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue,
178 
180  AST, SourceLocation(), Constructor->getFunctionObjectParameterType(),
181  true);
182  Expr *Handle = MemberExpr::CreateImplicit(AST, This, false, Fields["h"],
183  Fields["h"]->getType(), VK_LValue,
184  OK_Ordinary);
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(
201  CompoundStmt::Create(AST, {Assign}, FPOptionsOverride(),
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),
249  SourceLocation()),
250  MethodTy, TSInfo, SC_None, false, false, ConstexprSpecKind::Unspecified,
251  SourceLocation());
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 =
267  MethodDecl->getFunctionObjectParameterType(), true);
268  auto *HandleAccess = MemberExpr::CreateImplicit(
269  AST, This, false, Handle, Handle->getType(), VK_LValue, OK_Ordinary);
270 
271  auto *IndexExpr = DeclRefExpr::Create(
272  AST, NestedNameSpecifierLoc(), SourceLocation(), IdxParam, false,
273  DeclarationNameInfo(IdxParam->getDeclName(), SourceLocation()),
275 
276  auto *Array =
277  new (AST) ArraySubscriptExpr(HandleAccess, IndexExpr, ElemTy, VK_LValue,
279 
280  auto *Return = ReturnStmt::Create(AST, SourceLocation(), Array, nullptr);
281 
282  MethodDecl->setBody(CompoundStmt::Create(AST, {Return}, FPOptionsOverride(),
283  SourceLocation(),
284  SourceLocation()));
285  MethodDecl->setLexicalDeclContext(Record);
286  MethodDecl->setAccess(AccessSpecifier::AS_public);
287  MethodDecl->addAttr(AlwaysInlineAttr::CreateImplicit(
288  AST, SourceRange(), AlwaysInlineAttr::CXX11_clang_always_inline));
289  Record->addDecl(MethodDecl);
290 
291  return *this;
292  }
293 
294  BuiltinTypeDeclBuilder &startDefinition() {
295  if (Record->isCompleteDefinition())
296  return *this;
297  Record->startDefinition();
298  return *this;
299  }
300 
301  BuiltinTypeDeclBuilder &completeDefinition() {
302  if (Record->isCompleteDefinition())
303  return *this;
304  assert(Record->isBeingDefined() &&
305  "Definition must be started before completing it.");
306 
307  Record->completeDefinition();
308  return *this;
309  }
310 
311  TemplateParameterListBuilder addTemplateArgumentList(Sema &S);
312  BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S,
313  ArrayRef<StringRef> Names);
314 };
315 
316 struct TemplateParameterListBuilder {
317  BuiltinTypeDeclBuilder &Builder;
318  Sema &S;
320 
321  TemplateParameterListBuilder(Sema &S, BuiltinTypeDeclBuilder &RB)
322  : Builder(RB), S(S) {}
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  S.Context, Builder.Record->getDeclContext(), SourceLocation(),
333  SourceLocation(), /* TemplateDepth */ 0, Position,
334  &S.Context.Idents.get(Name, tok::TokenKind::identifier),
335  /* Typename */ false,
336  /* ParameterPack */ false);
337  if (!DefaultValue.isNull())
338  Decl->setDefaultArgument(
339  S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(),
340  SourceLocation()));
341 
342  Params.emplace_back(Decl);
343  return *this;
344  }
345 
346  BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
347  if (Params.empty())
348  return Builder;
350  SourceLocation(), Params,
351  SourceLocation(), nullptr);
352  Builder.Template = ClassTemplateDecl::Create(
353  S.Context, Builder.Record->getDeclContext(), SourceLocation(),
354  DeclarationName(Builder.Record->getIdentifier()), ParamList,
355  Builder.Record);
356  Builder.Record->setDescribedClassTemplate(Builder.Template);
357  Builder.Template->setImplicit(true);
358  Builder.Template->setLexicalDeclContext(Builder.Record->getDeclContext());
359  // NOTE: setPreviousDecl before addDecl so new decl replace old decl when
360  // make visible.
361  Builder.Template->setPreviousDecl(Builder.PrevTemplate);
362  Builder.Record->getDeclContext()->addDecl(Builder.Template);
363  Params.clear();
364 
365  QualType T = Builder.Template->getInjectedClassNameSpecialization();
366  T = S.Context.getInjectedClassNameType(Builder.Record, T);
367 
368  return Builder;
369  }
370 };
371 } // namespace
372 
373 TemplateParameterListBuilder
374 BuiltinTypeDeclBuilder::addTemplateArgumentList(Sema &S) {
375  return TemplateParameterListBuilder(S, *this);
376 }
377 
378 BuiltinTypeDeclBuilder &
379 BuiltinTypeDeclBuilder::addSimpleTemplateParams(Sema &S,
380  ArrayRef<StringRef> Names) {
381  TemplateParameterListBuilder Builder = this->addTemplateArgumentList(S);
382  for (StringRef Name : Names)
383  Builder.addTypeParameter(Name);
384  return Builder.finalizeTemplateArgs();
385 }
386 
388 
390  SemaPtr = &S;
391  ASTContext &AST = SemaPtr->getASTContext();
392  // If the translation unit has external storage force external decls to load.
394  (void)AST.getTranslationUnitDecl()->decls_begin();
395 
396  IdentifierInfo &HLSL = AST.Idents.get("hlsl", tok::TokenKind::identifier);
398  NamespaceDecl *PrevDecl = nullptr;
399  if (S.LookupQualifiedName(Result, AST.getTranslationUnitDecl()))
400  PrevDecl = Result.getAsSingle<NamespaceDecl>();
401  HLSLNamespace = NamespaceDecl::Create(
402  AST, AST.getTranslationUnitDecl(), /*Inline=*/false, SourceLocation(),
403  SourceLocation(), &HLSL, PrevDecl, /*Nested=*/false);
404  HLSLNamespace->setImplicit(true);
405  HLSLNamespace->setHasExternalLexicalStorage();
406  AST.getTranslationUnitDecl()->addDecl(HLSLNamespace);
407 
408  // Force external decls in the HLSL namespace to load from the PCH.
409  (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
410  defineTrivialHLSLTypes();
411  defineHLSLTypesWithForwardDeclarations();
412 
413  // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
414  // built in types inside a namespace, but we are planning to change that in
415  // the near future. In order to be source compatible older versions of HLSL
416  // will need to implicitly use the hlsl namespace. For now in clang everything
417  // will get added to the namespace, and we can remove the using directive for
418  // future language versions to match HLSL's evolution.
421  NestedNameSpecifierLoc(), SourceLocation(), HLSLNamespace,
422  AST.getTranslationUnitDecl());
423 
425 }
426 
427 void HLSLExternalSemaSource::defineHLSLVectorAlias() {
428  ASTContext &AST = SemaPtr->getASTContext();
429 
430  llvm::SmallVector<NamedDecl *> TemplateParams;
431 
432  auto *TypeParam = TemplateTypeParmDecl::Create(
433  AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
434  &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
435  TypeParam->setDefaultArgument(
436  AST, SemaPtr->getTrivialTemplateArgumentLoc(
438 
439  TemplateParams.emplace_back(TypeParam);
440 
441  auto *SizeParam = NonTypeTemplateParmDecl::Create(
442  AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
443  &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
444  false, AST.getTrivialTypeSourceInfo(AST.IntTy));
445  llvm::APInt Val(AST.getIntWidth(AST.IntTy), 4);
446  TemplateArgument Default(AST, llvm::APSInt(std::move(Val)), AST.IntTy,
447  /*IsDefaulted=*/true);
448  SizeParam->setDefaultArgument(
449  AST, SemaPtr->getTrivialTemplateArgumentLoc(Default, AST.IntTy,
450  SourceLocation(), SizeParam));
451  TemplateParams.emplace_back(SizeParam);
452 
453  auto *ParamList =
455  TemplateParams, SourceLocation(), nullptr);
456 
457  IdentifierInfo &II = AST.Idents.get("vector", tok::TokenKind::identifier);
458 
460  AST.getTemplateTypeParmType(0, 0, false, TypeParam),
462  AST, NestedNameSpecifierLoc(), SourceLocation(), SizeParam, false,
463  DeclarationNameInfo(SizeParam->getDeclName(), SourceLocation()),
464  AST.IntTy, VK_LValue),
465  SourceLocation());
466 
467  auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
468  SourceLocation(), &II,
469  AST.getTrivialTypeSourceInfo(AliasType));
470  Record->setImplicit(true);
471 
472  auto *Template =
473  TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
474  Record->getIdentifier(), ParamList, Record);
475 
476  Record->setDescribedAliasTemplate(Template);
477  Template->setImplicit(true);
478  Template->setLexicalDeclContext(Record->getDeclContext());
479  HLSLNamespace->addDecl(Template);
480 }
481 
482 void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
483  defineHLSLVectorAlias();
484 
485  ResourceDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Resource")
486  .startDefinition()
487  .addHandleMember(AccessSpecifier::AS_public)
488  .completeDefinition()
489  .Record;
490 }
491 
492 /// Set up common members and attributes for buffer types
493 static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
494  ResourceClass RC, ResourceKind RK,
495  bool IsROV) {
496  return BuiltinTypeDeclBuilder(Decl)
497  .addHandleMember()
498  .addDefaultHandleConstructor(S, RC)
499  .annotateResourceClass(RC, RK, IsROV);
500 }
501 
502 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
504  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
505  .addSimpleTemplateParams(*SemaPtr, {"element_type"})
506  .Record;
507  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
508  setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
509  ResourceKind::TypedBuffer, /*IsROV=*/false)
510  .addArraySubscriptOperators()
511  .completeDefinition();
512  });
513 
514  Decl =
515  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RasterizerOrderedBuffer")
516  .addSimpleTemplateParams(*SemaPtr, {"element_type"})
517  .Record;
518  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
519  setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
520  ResourceKind::TypedBuffer, /*IsROV=*/true)
521  .addArraySubscriptOperators()
522  .completeDefinition();
523  });
524 }
525 
526 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
527  CompletionFunction Fn) {
528  Completions.insert(std::make_pair(Record->getCanonicalDecl(), Fn));
529 }
530 
532  if (!isa<CXXRecordDecl>(Tag))
533  return;
534  auto Record = cast<CXXRecordDecl>(Tag);
535 
536  // If this is a specialization, we need to get the underlying templated
537  // declaration and complete that.
538  if (auto TDecl = dyn_cast<ClassTemplateSpecializationDecl>(Record))
539  Record = TDecl->getSpecializedTemplate()->getTemplatedDecl();
540  Record = Record->getCanonicalDecl();
541  auto It = Completions.find(Record);
542  if (It == Completions.end())
543  return;
544  It->second(Record);
545 }
Defines the clang::ASTContext interface.
Defines the clang::attr::Kind enum.
llvm::APSInt APSInt
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, ResourceKind RK, bool IsROV)
Set up common members and attributes for buffer types.
Defines helper utilities for supporting the HLSL runtime environment.
llvm::MachO::Record Record
Definition: MachO.h:31
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
unsigned getIntWidth(QualType T) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:651
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:1106
CanQualType VoidPtrTy
Definition: ASTContext.h:1121
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:647
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:1103
CanQualType VoidTy
Definition: ASTContext.h:1094
CanQualType UnsignedCharTy
Definition: ASTContext.h:1104
CanQualType UnsignedIntTy
Definition: ASTContext.h:1104
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:1583
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1076
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2716
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3892
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:4843
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
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:2723
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:2274
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
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:132
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:712
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:1519
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:1549
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:383
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1716
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2637
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
Definition: DeclBase.h:2643
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1572
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition: Expr.cpp:488
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
void setImplicit(bool I=true)
Definition: DeclBase.h:600
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
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:1897
This represents one expression.
Definition: Expr.h:110
QualType getType() const
Definition: Expr.h:142
Represents difference between two FPOptions values.
Definition: LangOptions.h:956
Represents a member of a struct/union/class.
Definition: Decl.h:3060
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)
Definition: Decl.cpp:4549
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1507
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
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:1032
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:3285
This represents a decl that may have a name.
Definition: Decl.h:249
Represent a C++ namespace.
Definition: Decl.h:548
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
Definition: Decl.h:675
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition: DeclCXX.cpp:2982
A C++ nested-name-specifier augmented with source location information.
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2919
A (possibly-)qualified type.
Definition: Type.h:940
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:1151
QualType getCanonicalType() const
Definition: Type.h:7423
void addConst()
Definition: Type.h:446
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1204
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:462
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.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:7487
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:7510
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:7490
ASTContext & Context
Definition: Sema.h:857
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:697
ASTContext & getASTContext() const
Definition: Sema.h:526
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
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:3587
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3690
Represents a template argument.
Definition: TemplateBase.h:61
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:144
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, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:5558
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:7342
The base class of the type hierarchy.
Definition: Type.h:1813
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8117
Represents a C++ using-declaration.
Definition: DeclCXX.h:3512
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition: DeclCXX.cpp:2937
QualType getType() const
Definition: Decl.h:718
llvm::APInt APInt
Definition: Integral.h:29
bool Call(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
Definition: Interp.h:2179
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1903
The JSON file list parser is used to communicate input to InstallAPI.
@ ICIS_NoInit
No in-class initializer.
Definition: Specifiers.h:269
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:148
@ SC_None
Definition: Specifiers.h:247
@ Class
The "class" keyword.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:132
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:136
const FunctionProtoType * T
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:120
@ AS_public
Definition: Specifiers.h:121
@ AS_private
Definition: Specifiers.h:123
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Extra information about a function prototype.
Definition: Type.h:4747