clang: include/clang/AST/ExprConcepts.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_AST_EXPRCONCEPTS_H
15#define LLVM_CLANG_AST_EXPRCONCEPTS_H
16
27#include "llvm/ADT/STLFunctionalExtras.h"
28#include "llvm/Support/ErrorHandling.h"
29#include "llvm/Support/TrailingObjects.h"
30#include
31#include
32
36
37
38
39
40
41
42class ConceptSpecializationExpr final : public Expr {
45
46private:
48
49
50
52
53
54
55
57
61
66 bool ContainsUnexpandedParameterPack);
68
69public:
70 static ConceptSpecializationExpr *
74
75 static ConceptSpecializationExpr *
79 bool ContainsUnexpandedParameterPack);
80
82 return SpecDecl->getTemplateArguments();
83 }
84
86
90
91
92
94 return ConceptRef->hasExplicitTemplateArgs();
95 }
96
98 return ConceptRef->getConceptNameLoc();
99 }
101 return ConceptRef->getTemplateArgsAsWritten();
102 }
103
105 return ConceptRef->getNestedNameSpecifierLoc();
106 }
107
109 return ConceptRef->getTemplateKWLoc();
110 }
111
113
115 return ConceptRef->getConceptNameInfo();
116 }
117
119 assert(SpecDecl && "Template Argument Decl not initialized");
120 return SpecDecl;
121 }
122
123
124
125
128 "isSatisfied called on a dependent ConceptSpecializationExpr");
129 return Satisfaction->IsSatisfied;
130 }
131
132
133
134
137 "getSatisfaction called on dependent ConceptSpecializationExpr");
138 return *Satisfaction;
139 }
140
142 return T->getStmtClass() == ConceptSpecializationExprClass;
143 }
144
146 return ConceptRef->getBeginLoc();
147 }
148
150 return ConceptRef->getEndLoc();
151 }
152
154 return ConceptRef->getLocation();
155 }
156
157
164};
165
167
168
169
171public:
172
173
175private:
177
178 LLVM_PREFERRED_TYPE(bool)
180 LLVM_PREFERRED_TYPE(bool)
181 bool ContainsUnexpandedParameterPack : 1;
182 LLVM_PREFERRED_TYPE(bool)
183 bool Satisfied : 1;
184public:
193
195 bool ContainsUnexpandedParameterPack, bool IsSatisfied = true) :
196 Kind(Kind), Dependent(IsDependent),
197 ContainsUnexpandedParameterPack(ContainsUnexpandedParameterPack),
198 Satisfied(IsSatisfied) {}
199
201
203 assert(!Dependent &&
204 "isSatisfied can only be called on non-dependent requirements.");
205 return Satisfied;
206 }
207
209 assert(!Dependent &&
210 "setSatisfied can only be called on non-dependent requirements.");
211 Satisfied = IsSatisfied;
212 }
213
214 void setDependent(bool IsDependent) { Dependent = IsDependent; }
216
218 ContainsUnexpandedParameterPack = Contains;
219 }
221 return ContainsUnexpandedParameterPack;
222 }
223};
224
225
226
228public:
234private:
235 llvm::PointerUnion<SubstitutionDiagnostic *, TypeSourceInfo *> Value;
236 SatisfactionStatus Status;
237public:
240
241
242
243
244
246
247
248
252
255 this->Status = Status;
256 }
257
261
264 "Attempted to get substitution diagnostic when there has been no "
265 "substitution failure.");
267 }
268
271 "Attempted to get type when there has been a substitution failure.");
273 }
274
278};
279
280
281
283public:
293 llvm::PointerIntPair<
294 llvm::PointerUnion<TemplateParameterList *, SubstitutionDiagnostic *>,
295 1, bool>
296 TypeConstraintInfo;
297 public:
300
301
303
304
305
307 TypeConstraintInfo(SubstDiag, false) {}
308
309
310
311
312
313
314
317
319 return TypeConstraintInfo.getInt();
320 }
321
328
330 return TypeConstraintInfo.getPointer().isNull();
331 }
332
337
342
347
349
354 };
355private:
356 llvm::PointerUnion<Expr *, SubstitutionDiagnostic *> Value;
357 SourceLocation NoexceptLoc;
358 ReturnTypeRequirement TypeReq;
360 SatisfactionStatus Status;
361public:
364
365
366
367
368
369
370
371
376
377
378
379
380
381
382
383
384
385
388
391
394
396
400
402 return TypeReq;
403 }
404
408 return SubstitutedConstraintExpr;
409 }
410
413 "Attempted to get expression substitution diagnostic when there has "
414 "been no expression substitution failure");
416 }
417
420 "ExprRequirement has no expression because there has been a "
421 "substitution failure.");
423 }
424
428};
429
430
431
433 Expr *Constraint = nullptr;
435 bool HasInvalidConstraint = false;
436 StringRef InvalidConstraintEntity;
437
438public:
441
445 Constraint(Constraint) {
446 assert(Constraint->isInstantiationDependent() &&
447 "Nested requirement with non-dependent constraint must be "
448 "constructed with a ConstraintSatisfaction object");
449 }
450
455 Satisfaction.IsSatisfied),
456 Constraint(Constraint),
458
462 false,
463 false,
464 Satisfaction->IsSatisfied),
465 Satisfaction(Satisfaction), HasInvalidConstraint(true),
466 InvalidConstraintEntity(InvalidConstraintEntity) {}
467
472
474
477 return InvalidConstraintEntity;
478 }
479
482 "getConstraintExpr() may not be called "
483 "on nested requirements with invalid constraint.");
484 return Constraint;
485 }
486
488 return *Satisfaction;
489 }
490
494};
495}
496
497
498
499
500
501
502
503class RequiresExpr final : public Expr,
504 llvm::TrailingObjects<RequiresExpr, ParmVarDecl *,
505 concepts::Requirement *> {
506 friend TrailingObjects;
508
509 unsigned NumLocalParameters;
510 unsigned NumRequirements;
515
516 unsigned numTrailingObjects(OverloadToken<ParmVarDecl *>) const {
517 return NumLocalParameters;
518 }
519
527 unsigned NumRequirements);
528
529public:
539 unsigned NumRequirements);
540
542 return getTrailingObjects<ParmVarDecl *>(NumLocalParameters);
543 }
544
546
548 return getTrailingObjects<concepts::Requirement *>(NumRequirements);
549 }
550
551
552
555 && "isSatisfied called on a dependent RequiresExpr");
557 }
558
561 "setSatisfied called on a dependent RequiresExpr");
563 }
564
568
572
574 return T->getStmtClass() == RequiresExprClass;
575 }
576
581 return RBraceLoc;
582 }
583
584
591};
592
593}
594
595#endif
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Declaration of a C++20 concept.
A reference to a concept and its template args, as it appears in the code.
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition ExprConcepts.h:42
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprConcepts.h:149
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprConcepts.h:145
SourceLocation getExprLoc() const LLVM_READONLY
Definition ExprConcepts.h:153
const_child_range children() const
Definition ExprConcepts.h:161
child_range children()
Definition ExprConcepts.h:158
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
Definition ExprConcepts.h:126
ArrayRef< TemplateArgument > getTemplateArguments() const
Definition ExprConcepts.h:81
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ExprConcepts.h:100
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ExprConcepts.h:104
friend class ASTReader
Definition ExprConcepts.h:43
NamedDecl * getFoundDecl() const
Definition ExprConcepts.h:112
bool hasExplicitTemplateArgs() const
Definition ExprConcepts.h:93
static bool classof(const Stmt *T)
Definition ExprConcepts.h:141
ConceptReference * getConceptReference() const
Definition ExprConcepts.h:85
SourceLocation getConceptNameLoc() const
Definition ExprConcepts.h:97
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
Definition ExprConcepts.h:118
friend class ASTStmtReader
Definition ExprConcepts.h:44
const DeclarationNameInfo & getConceptNameInfo() const
Definition ExprConcepts.h:114
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
Definition ExprConcepts.h:135
SourceLocation getTemplateKWLoc() const
Definition ExprConcepts.h:108
ConceptDecl * getNamedConcept() const
Definition ExprConcepts.h:87
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
This represents a decl that may have a name.
A C++ nested-name-specifier augmented with source location information.
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition ExprConcepts.h:505
SourceLocation getLParenLoc() const
Definition ExprConcepts.h:569
SourceLocation getRParenLoc() const
Definition ExprConcepts.h:570
SourceLocation getRBraceLoc() const
Definition ExprConcepts.h:571
void setSatisfied(bool IsSatisfied)
Definition ExprConcepts.h:559
SourceLocation getRequiresKWLoc() const
Definition ExprConcepts.h:565
child_range children()
Definition ExprConcepts.h:585
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprConcepts.h:580
const_child_range children() const
Definition ExprConcepts.h:588
RequiresExprBodyDecl * getBody() const
Definition ExprConcepts.h:545
ArrayRef< concepts::Requirement * > getRequirements() const
Definition ExprConcepts.h:547
bool isSatisfied() const
Whether or not the requires clause is satisfied.
Definition ExprConcepts.h:553
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprConcepts.h:577
static bool classof(const Stmt *T)
Definition ExprConcepts.h:573
ArrayRef< ParmVarDecl * > getLocalParameters() const
Definition ExprConcepts.h:541
friend class ASTStmtReader
Definition ExprConcepts.h:507
Encodes a location in the source.
Stmt - This represents one statement.
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
llvm::iterator_range< child_iterator > child_range
RequiresExprBitfields RequiresExprBits
ConstStmtIterator const_child_iterator
llvm::iterator_range< const_child_iterator > const_child_range
Stores a list of template parameters for a TemplateDecl and its derived classes.
bool containsUnexpandedParameterPack() const
Determine whether this template parameter list contains an unexpanded parameter pack.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
A container of type source information.
Definition ExprConcepts.h:292
ReturnTypeRequirement()
No return type requirement was specified.
Definition ExprConcepts.h:302
bool containsUnexpandedParameterPack() const
Definition ExprConcepts.h:322
bool isTypeConstraint() const
Definition ExprConcepts.h:338
TemplateParameterList * getTypeConstraintTemplateParameterList() const
Definition ExprConcepts.h:350
const TypeConstraint * getTypeConstraint() const
bool isSubstitutionFailure() const
Definition ExprConcepts.h:333
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition ExprConcepts.h:343
friend ASTStmtReader
Definition ExprConcepts.h:298
bool isEmpty() const
Definition ExprConcepts.h:329
friend ASTStmtWriter
Definition ExprConcepts.h:299
bool isDependent() const
Definition ExprConcepts.h:318
ReturnTypeRequirement(SubstitutionDiagnostic *SubstDiag)
A return type requirement was specified but it was a substitution failure.
Definition ExprConcepts.h:306
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition ExprConcepts.h:411
ConceptSpecializationExpr * getReturnTypeRequirementSubstitutedConstraintExpr() const
Definition ExprConcepts.h:406
bool isExprSubstitutionFailure() const
Definition ExprConcepts.h:397
friend ASTStmtWriter
Definition ExprConcepts.h:363
SatisfactionStatus
Definition ExprConcepts.h:284
@ SS_Dependent
Definition ExprConcepts.h:285
@ SS_Satisfied
Definition ExprConcepts.h:290
@ SS_ConstraintsNotSatisfied
Definition ExprConcepts.h:289
@ SS_NoexceptNotMet
Definition ExprConcepts.h:287
@ SS_TypeRequirementSubstitutionFailure
Definition ExprConcepts.h:288
@ SS_ExprSubstitutionFailure
Definition ExprConcepts.h:286
Expr * getExpr() const
Definition ExprConcepts.h:418
const ReturnTypeRequirement & getReturnTypeRequirement() const
Definition ExprConcepts.h:401
friend ASTStmtReader
Definition ExprConcepts.h:362
SatisfactionStatus getSatisfactionStatus() const
Definition ExprConcepts.h:395
SourceLocation getNoexceptLoc() const
Definition ExprConcepts.h:393
static bool classof(const Requirement *R)
Definition ExprConcepts.h:425
ExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, ReturnTypeRequirement Req, SatisfactionStatus Status, ConceptSpecializationExpr *SubstitutedConstraintExpr=nullptr)
Construct a compound requirement.
bool hasNoexceptRequirement() const
Definition ExprConcepts.h:392
bool isSimple() const
Definition ExprConcepts.h:389
bool isCompound() const
Definition ExprConcepts.h:390
NestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction *Satisfaction)
Definition ExprConcepts.h:459
static bool classof(const Requirement *R)
Definition ExprConcepts.h:491
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
Definition ExprConcepts.h:487
friend ASTStmtReader
Definition ExprConcepts.h:439
bool hasInvalidConstraint() const
Definition ExprConcepts.h:473
Expr * getConstraintExpr() const
Definition ExprConcepts.h:480
NestedRequirement(ASTContext &C, StringRef InvalidConstraintEntity, const ConstraintSatisfaction &Satisfaction)
Definition ExprConcepts.h:468
StringRef getInvalidConstraintEntity()
Definition ExprConcepts.h:475
NestedRequirement(ASTContext &C, Expr *Constraint, const ConstraintSatisfaction &Satisfaction)
Definition ExprConcepts.h:451
friend ASTStmtWriter
Definition ExprConcepts.h:440
NestedRequirement(Expr *Constraint)
Definition ExprConcepts.h:442
void setSatisfied(bool IsSatisfied)
Definition ExprConcepts.h:208
bool isDependent() const
Definition ExprConcepts.h:215
void setContainsUnexpandedParameterPack(bool Contains)
Definition ExprConcepts.h:217
void setDependent(bool IsDependent)
Definition ExprConcepts.h:214
bool isSatisfied() const
Definition ExprConcepts.h:202
RequirementKind
Definition ExprConcepts.h:174
@ RK_Compound
Definition ExprConcepts.h:174
@ RK_Nested
Definition ExprConcepts.h:174
@ RK_Type
Definition ExprConcepts.h:174
@ RK_Simple
Definition ExprConcepts.h:174
RequirementKind getKind() const
Definition ExprConcepts.h:200
bool containsUnexpandedParameterPack() const
Definition ExprConcepts.h:220
Requirement(RequirementKind Kind, bool IsDependent, bool ContainsUnexpandedParameterPack, bool IsSatisfied=true)
Definition ExprConcepts.h:194
TypeRequirement(SubstitutionDiagnostic *Diagnostic)
Construct a type requirement when the nested name specifier is invalid due to a bad substitution.
Definition ExprConcepts.h:249
static bool classof(const Requirement *R)
Definition ExprConcepts.h:275
bool isSubstitutionFailure() const
Definition ExprConcepts.h:258
friend ASTStmtWriter
Definition ExprConcepts.h:239
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition ExprConcepts.h:262
friend ASTStmtReader
Definition ExprConcepts.h:238
TypeSourceInfo * getType() const
Definition ExprConcepts.h:269
SatisfactionStatus getSatisfactionStatus() const
Definition ExprConcepts.h:253
SatisfactionStatus
Definition ExprConcepts.h:229
@ SS_Satisfied
Definition ExprConcepts.h:232
@ SS_SubstitutionFailure
Definition ExprConcepts.h:231
@ SS_Dependent
Definition ExprConcepts.h:230
TypeRequirement(TypeSourceInfo *T)
Construct a type requirement from a type.
void setSatisfactionStatus(SatisfactionStatus Status)
Definition ExprConcepts.h:254
Definition ExprConcepts.h:166
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
const FunctionProtoType * T
static OpenACCComputeConstruct * Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirectiveLoc, SourceLocation EndLoc, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
U cast(CodeGen::Address addr)
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Represents an explicit template argument list in C++, e.g., the "" in "sort".
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition ExprConcepts.h:185
SourceLocation DiagLoc
Definition ExprConcepts.h:190
StringRef SubstitutedEntity
Definition ExprConcepts.h:186
StringRef DiagMessage
Definition ExprConcepts.h:191