clang: lib/AST/ExprConcepts.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
26#include
27
28using namespace clang;
29
30ConceptSpecializationExpr::ConceptSpecializationExpr(
35 ConceptRef(Loc), SpecDecl(SpecDecl),
36 Satisfaction(Satisfaction
38 : nullptr) {
39 setDependence(computeDependence(this, !Satisfaction));
40
41
42 assert(->getNestedNameSpecifierLoc() ||
43 (->getNestedNameSpecifierLoc()
44 .getNestedNameSpecifier()
45 ->isInstantiationDependent() &&
46 ->getNestedNameSpecifierLoc()
47 .getNestedNameSpecifier()
48 ->containsUnexpandedParameterPack()));
49 assert((!isValueDependent() || isInstantiationDependent()) &&
50 "should not be value-dependent");
51}
52
53ConceptSpecializationExpr::ConceptSpecializationExpr(EmptyShell Empty)
54 : Expr(ConceptSpecializationExprClass, Empty) {}
55
61}
62
63ConceptSpecializationExpr::ConceptSpecializationExpr(
67 bool ContainsUnexpandedParameterPack)
69 ConceptRef(Loc), SpecDecl(SpecDecl),
70 Satisfaction(Satisfaction
72 : nullptr) {
74 if (!Satisfaction)
75 D |= ExprDependence::Value;
77 D |= ExprDependence::Instantiation;
78 if (ContainsUnexpandedParameterPack)
79 D |= ExprDependence::UnexpandedPack;
81}
82
88 bool ContainsUnexpandedParameterPack) {
89 return new (C)
91 ContainsUnexpandedParameterPack);
92}
93
97 auto TPL = cast<TemplateParameterList *>(TypeConstraintInfo.getPointer());
98 return cast(TPL->getParam(0))
99 ->getTypeConstraint();
100}
101
102
103
105 if (auto *ExprReq = dyn_castconcepts::ExprRequirement(R))
106 return ExprReq->getExpr() && ExprReq->getExpr()->containsErrors();
107
108 if (auto *NestedReq = dyn_castconcepts::NestedRequirement(R))
109 return !NestedReq->hasInvalidConstraint() &&
110 NestedReq->getConstraintExpr() &&
111 NestedReq->getConstraintExpr()->containsErrors();
112 return false;
113}
114
122 NumLocalParameters(LocalParameters.size()),
123 NumRequirements(Requirements.size()), Body(Body), LParenLoc(LParenLoc),
124 RParenLoc(RParenLoc), RBraceLoc(RBraceLoc) {
125 RequiresExprBits.IsSatisfied = false;
126 RequiresExprBits.RequiresKWLoc = RequiresKWLoc;
128 bool ContainsUnexpandedParameterPack = false;
130 Dependent |= P->getType()->isInstantiationDependentType();
131 ContainsUnexpandedParameterPack |=
132 P->getType()->containsUnexpandedParameterPack();
133 }
134 RequiresExprBits.IsSatisfied = true;
137 ContainsUnexpandedParameterPack |= R->containsUnexpandedParameterPack();
139 RequiresExprBits.IsSatisfied = R->isSatisfied();
140 if (!RequiresExprBits.IsSatisfied)
141 break;
142 }
143
145 setDependence(getDependence() | ExprDependence::Error);
146 }
147 std::copy(LocalParameters.begin(), LocalParameters.end(),
148 getTrailingObjects<ParmVarDecl *>());
149 std::copy(Requirements.begin(), Requirements.end(),
150 getTrailingObjects<concepts::Requirement *>());
151 RequiresExprBits.IsSatisfied |= Dependent;
152
153 if (ContainsUnexpandedParameterPack)
154 setDependence(getDependence() | ExprDependence::UnexpandedPack);
155
156
157
158
160 setDependence(getDependence() | ExprDependence::ValueInstantiation);
161}
162
164 unsigned NumLocalParameters,
165 unsigned NumRequirements)
166 : Expr(RequiresExprClass, Empty), NumLocalParameters(NumLocalParameters),
167 NumRequirements(NumRequirements) { }
168
174 void *Mem =
175 C.Allocate(totalSizeToAlloc<ParmVarDecl *, concepts::Requirement *>(
176 LocalParameters.size(), Requirements.size()),
178 return new (Mem)
179 RequiresExpr(C, RequiresKWLoc, Body, LParenLoc, LocalParameters,
180 RParenLoc, Requirements, RBraceLoc);
181}
182
185 unsigned NumLocalParameters, unsigned NumRequirements) {
186 void *Mem =
187 C.Allocate(totalSizeToAlloc<ParmVarDecl *, concepts::Requirement *>(
188 NumLocalParameters, NumRequirements),
190 return new (Mem) RequiresExpr(C, Empty, NumLocalParameters, NumRequirements);
191}
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
static bool RequirementContainsError(concepts::Requirement *R)
Defines Expressions and AST nodes for C++2a concepts.
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 ...
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.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
This represents one expression.
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
Represents a parameter to a function.
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
Encodes a location in the source.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
bool isTypeConstraint() const
const TypeConstraint * getTypeConstraint() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
The JSON file list parser is used to communicate input to InstallAPI.
@ OK_Ordinary
An ordinary object is located at an address in memory.
ExprDependence computeDependence(FullExpr *E)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....