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
34class ASTStmtReader;
35class ASTStmtWriter;
36
37
38
39
40
41
45
46private:
48
49
50
52
53
54
55
57
61
66 bool ContainsUnexpandedParameterPack);
68
69public:
74
79 bool ContainsUnexpandedParameterPack);
80
83 }
84
86
88
89
90
93 }
94
97 }
100 }
101
104 }
105
108 }
109
111
114 }
115
117 assert(SpecDecl && "Template Argument Decl not initialized");
118 return SpecDecl;
119 }
120
121
122
123
126 "isSatisfied called on a dependent ConceptSpecializationExpr");
128 }
129
130
131
132
135 "getSatisfaction called on dependent ConceptSpecializationExpr");
136 return *Satisfaction;
137 }
138
140 return T->getStmtClass() == ConceptSpecializationExprClass;
141 }
142
145 }
146
149 }
150
153 }
154
155
158 }
161 }
162};
163
164namespace concepts {
165
166
167
169public:
170
171
173private:
175
176 LLVM_PREFERRED_TYPE(bool)
177 bool Dependent : 1;
178 LLVM_PREFERRED_TYPE(bool)
179 bool ContainsUnexpandedParameterPack : 1;
180 LLVM_PREFERRED_TYPE(bool)
181 bool Satisfied : 1;
182public:
185
186
187
190 };
191
193 bool ContainsUnexpandedParameterPack, bool IsSatisfied = true) :
194 Kind(Kind), Dependent(IsDependent),
195 ContainsUnexpandedParameterPack(ContainsUnexpandedParameterPack),
196 Satisfied(IsSatisfied) {}
197
199
201 assert(!Dependent &&
202 "isSatisfied can only be called on non-dependent requirements.");
203 return Satisfied;
204 }
205
207 assert(!Dependent &&
208 "setSatisfied can only be called on non-dependent requirements.");
209 Satisfied = IsSatisfied;
210 }
211
212 void setDependent(bool IsDependent) { Dependent = IsDependent; }
214
216 ContainsUnexpandedParameterPack = Contains;
217 }
219 return ContainsUnexpandedParameterPack;
220 }
221};
222
223
224
226public:
232private:
233 llvm::PointerUnion<SubstitutionDiagnostic *, TypeSourceInfo *> Value;
235public:
238
239
240
241
242
244
245
246
250
253 this->Status = Status;
254 }
255
258 }
259
262 "Attempted to get substitution diagnostic when there has been no "
263 "substitution failure.");
264 return cast<SubstitutionDiagnostic *>(Value);
265 }
266
269 "Attempted to get type when there has been a substitution failure.");
270 return cast<TypeSourceInfo *>(Value);
271 }
272
275 }
276};
277
278
279
281public:
291 llvm::PointerIntPair<
292 llvm::PointerUnion<TemplateParameterList *, SubstitutionDiagnostic *>,
293 1, bool>
294 TypeConstraintInfo;
295 public:
298
299
301
302
303
305 TypeConstraintInfo(SubstDiag, false) {}
306
307
308
309
310
311
312
314
316 return TypeConstraintInfo.getInt();
317 }
318
321 return false;
324 }
325
327 return TypeConstraintInfo.getPointer().isNull();
328 }
329
332 isa<SubstitutionDiagnostic *>(TypeConstraintInfo.getPointer());
333 }
334
337 isa<TemplateParameterList *>(TypeConstraintInfo.getPointer());
338 }
339
342 return cast<SubstitutionDiagnostic *>(TypeConstraintInfo.getPointer());
343 }
344
346
349 return cast<TemplateParameterList *>(TypeConstraintInfo.getPointer());
350 }
351 };
352private:
353 llvm::PointerUnion<Expr *, SubstitutionDiagnostic *> Value;
354 SourceLocation NoexceptLoc;
355 ReturnTypeRequirement TypeReq;
358public:
361
362
363
364
365
366
367
368
373
374
375
376
377
378
379
380
381
382
385
388
391
393
396 }
397
399 return TypeReq;
400 }
401
405 return SubstitutedConstraintExpr;
406 }
407
410 "Attempted to get expression substitution diagnostic when there has "
411 "been no expression substitution failure");
412 return cast<SubstitutionDiagnostic *>(Value);
413 }
414
417 "ExprRequirement has no expression because there has been a "
418 "substitution failure.");
419 return cast<Expr *>(Value);
420 }
421
424 }
425};
426
427
428
430 Expr *Constraint = nullptr;
432 bool HasInvalidConstraint = false;
433 StringRef InvalidConstraintEntity;
434
435public:
438
442 Constraint(Constraint) {
444 "Nested requirement with non-dependent constraint must be "
445 "constructed with a ConstraintSatisfaction object");
446 }
447
452 Satisfaction.IsSatisfied),
453 Constraint(Constraint),
455
459 false,
460 false,
461 Satisfaction->IsSatisfied),
462 Satisfaction(Satisfaction), HasInvalidConstraint(true),
463 InvalidConstraintEntity(InvalidConstraintEntity) {}
464
469
471
474 return InvalidConstraintEntity;
475 }
476
479 "getConstraintExpr() may not be called "
480 "on nested requirements with invalid constraint.");
481 return Constraint;
482 }
483
485 return *Satisfaction;
486 }
487
490 }
491};
492}
493
494
495
496
497
498
499
501 llvm::TrailingObjects<RequiresExpr, ParmVarDecl *,
502 concepts::Requirement *> {
503 friend TrailingObjects;
505
506 unsigned NumLocalParameters;
507 unsigned NumRequirements;
512
513 unsigned numTrailingObjects(OverloadToken<ParmVarDecl *>) const {
514 return NumLocalParameters;
515 }
516
517 unsigned numTrailingObjects(OverloadToken<concepts::Requirement *>) const {
518 return NumRequirements;
519 }
520
521 RequiresExpr(ASTContext &C, SourceLocation RequiresKWLoc,
522 RequiresExprBodyDecl *Body, SourceLocation LParenLoc,
523 ArrayRef<ParmVarDecl *> LocalParameters,
524 SourceLocation RParenLoc,
525 ArrayRef<concepts::Requirement *> Requirements,
526 SourceLocation RBraceLoc);
527 RequiresExpr(ASTContext &C, EmptyShell Empty, unsigned NumLocalParameters,
528 unsigned NumRequirements);
529
530public:
531 static RequiresExpr *Create(ASTContext &C, SourceLocation RequiresKWLoc,
532 RequiresExprBodyDecl *Body,
533 SourceLocation LParenLoc,
534 ArrayRef<ParmVarDecl *> LocalParameters,
535 SourceLocation RParenLoc,
536 ArrayRef<concepts::Requirement *> Requirements,
537 SourceLocation RBraceLoc);
538 static RequiresExpr *
539 Create(ASTContext &C, EmptyShell Empty, unsigned NumLocalParameters,
540 unsigned NumRequirements);
541
543 return {getTrailingObjects<ParmVarDecl *>(), NumLocalParameters};
544 }
545
547
549 return {getTrailingObjects<concepts::Requirement *>(), NumRequirements};
550 }
551
552
553
556 && "isSatisfied called on a dependent RequiresExpr");
558 }
559
562 "setSatisfied called on a dependent RequiresExpr");
564 }
565
568 }
569
573
575 return T->getStmtClass() == RequiresExprClass;
576 }
577
580 }
582 return RBraceLoc;
583 }
584
585
588 }
591 }
592};
593
594}
595
596#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 ...
Reads an AST files chain containing the contents of a translation unit.
Declaration of a C++20 concept.
A reference to a concept and its template args, as it appears in the code.
bool hasExplicitTemplateArgs() const
Whether or not template arguments were explicitly specified in the concept reference (they might not ...
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
NamedDecl * getFoundDecl() const
const DeclarationNameInfo & getConceptNameInfo() const
SourceLocation getConceptNameLoc() const
ConceptDecl * getNamedConcept() const
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getTemplateKWLoc() const
Represents the specialization of a concept - evaluates to a prvalue of type bool.
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getExprLoc() const LLVM_READONLY
const_child_range children() const
bool isSatisfied() const
Whether or not the concept with the given arguments was satisfied when the expression was created.
ArrayRef< TemplateArgument > getTemplateArguments() const
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
NamedDecl * getFoundDecl() const
bool hasExplicitTemplateArgs() const
static bool classof(const Stmt *T)
ConceptReference * getConceptReference() const
SourceLocation getConceptNameLoc() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const DeclarationNameInfo & getConceptNameInfo() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
SourceLocation getTemplateKWLoc() const
ConceptDecl * getNamedConcept() const
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.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
ArrayRef< TemplateArgument > getTemplateArguments() const
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...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
SourceLocation getRBraceLoc() const
void setSatisfied(bool IsSatisfied)
SourceLocation getRequiresKWLoc() const
SourceLocation getEndLoc() const LLVM_READONLY
const_child_range children() const
RequiresExprBodyDecl * getBody() const
ArrayRef< concepts::Requirement * > getRequirements() const
bool isSatisfied() const
Whether or not the requires clause is satisfied.
SourceLocation getBeginLoc() const LLVM_READONLY
static bool classof(const Stmt *T)
ArrayRef< ParmVarDecl * > getLocalParameters() const
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
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.
ReturnTypeRequirement()
No return type requirement was specified.
bool containsUnexpandedParameterPack() const
bool isTypeConstraint() const
TemplateParameterList * getTypeConstraintTemplateParameterList() const
const TypeConstraint * getTypeConstraint() const
bool isSubstitutionFailure() const
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
ReturnTypeRequirement(SubstitutionDiagnostic *SubstDiag)
A return type requirement was specified but it was a substitution failure.
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
ConceptSpecializationExpr * getReturnTypeRequirementSubstitutedConstraintExpr() const
bool isExprSubstitutionFailure() const
@ SS_ConstraintsNotSatisfied
@ SS_TypeRequirementSubstitutionFailure
@ SS_ExprSubstitutionFailure
const ReturnTypeRequirement & getReturnTypeRequirement() const
SatisfactionStatus getSatisfactionStatus() const
SourceLocation getNoexceptLoc() const
static bool classof(const Requirement *R)
bool hasNoexceptRequirement() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
NestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction *Satisfaction)
static bool classof(const Requirement *R)
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
bool hasInvalidConstraint() const
Expr * getConstraintExpr() const
NestedRequirement(ASTContext &C, StringRef InvalidConstraintEntity, const ConstraintSatisfaction &Satisfaction)
StringRef getInvalidConstraintEntity()
NestedRequirement(ASTContext &C, Expr *Constraint, const ConstraintSatisfaction &Satisfaction)
NestedRequirement(Expr *Constraint)
A static requirement that can be used in a requires-expression to check properties of types and expre...
void setSatisfied(bool IsSatisfied)
void setContainsUnexpandedParameterPack(bool Contains)
void setDependent(bool IsDependent)
RequirementKind getKind() const
bool containsUnexpandedParameterPack() const
Requirement(RequirementKind Kind, bool IsDependent, bool ContainsUnexpandedParameterPack, bool IsSatisfied=true)
A requires-expression requirement which queries the existence of a type name or type template special...
TypeRequirement(SubstitutionDiagnostic *Diagnostic)
Construct a type requirement when the nested name specifier is invalid due to a bad substitution.
static bool classof(const Requirement *R)
bool isSubstitutionFailure() const
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
SatisfactionStatus getSatisfactionStatus() const
void setSatisfactionStatus(SatisfactionStatus Status)
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
const FunctionProtoType * T
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....
StringRef SubstitutedEntity