13#ifndef LLVM_CLANG_SEMA_SEMACONCEPT_H
14#define LLVM_CLANG_SEMA_SEMACONCEPT_H
22#include "llvm/ADT/FoldingSet.h"
23#include "llvm/ADT/STLFunctionalExtras.h"
24#include "llvm/ADT/SmallBitVector.h"
25#include "llvm/ADT/SmallVector.h"
55 llvm::PointerUnion<const Expr *, const ConceptReference *>;
119 Atomic.Indexes.llvm::SmallBitVector::~SmallBitVector();
127 PackIndex.toInternalRepresentation(),
139 llvm::to_underlying(OpKind),
166 llvm::to_underlying(CCK), LHS, RHS} {}
181 return Atomic.IndexesForSubsumption;
197 assert(Indexes.count() == Args.size());
198 assert(IndexesForSubsumption.size() == Indexes.size());
199 assert((Indexes | IndexesForSubsumption) == Indexes);
201 Atomic.IndexesForSubsumption = std::move(IndexesForSubsumption);
202 Atomic.Indexes = std::move(Indexes);
203 Atomic.Args = Args.data();
204 Atomic.ParamList = ParamList;
219 Other.getParameterMapping();
223 Other.mappingOccurenceListForSubsumption();
225 if (ParameterMapping.size() != OtherParameterMapping.size())
227 for (
unsigned I = 0, S = ParameterMapping.size(); I < S; ++I) {
228 if (Indexes[I] != OtherIndexes[I])
232 llvm::FoldingSetNodeID IDA, IDB;
233 C.getCanonicalTemplateArgument(ParameterMapping[I].
getArgument())
235 C.getCanonicalTemplateArgument(OtherParameterMapping[I].
getArgument())
260 llvm_unreachable(
"Unknown ConstraintKind enum");
274 llvm_unreachable(
"Unknown ConstraintKind enum");
295 NormalizedConstraint *RHS) {
300 NormalizedConstraint *LHS,
301 NormalizedConstraint *RHS) {
335 Atomic.PackSubstitutionIndex);
341 NormalizedConstraintWithParamMapping;
358 NormalizedConstraintWithParamMapping;
391 NormalizedConstraintWithParamMapping;
399 SubConstraint, CSE, PackIndex);
448 enum Kind {
Atomic, FoldExpanded };
451 LLVM_PREFERRED_TYPE(Kind)
454 bool operator==(
const Literal &
Other)
const {
return Value ==
Other.Value; }
455 bool operator<(
const Literal &
Other)
const {
return Value <
Other.Value; }
457 using Clause = llvm::SmallVector<Literal>;
458 using Formula = llvm::SmallVector<Clause, 5>;
460 struct CNFFormula : Formula {
462 using Formula::Formula;
464 struct DNFFormula : Formula {
466 using Formula::Formula;
469 struct MappedAtomicConstraint {
470 const AtomicConstraint *Constraint;
474 struct FoldExpendedConstraintKey {
476 const AtomicConstraint *Constraint;
480 llvm::DenseMap<
const Expr *, llvm::SmallDenseMap<llvm::FoldingSetNodeID,
481 MappedAtomicConstraint>>
484 llvm::DenseMap<const Expr *, std::vector<FoldExpendedConstraintKey>> FoldMap;
488 llvm::DenseMap<uint16_t, const void *> ReverseMap;
493 std::pair<const FoldExpandedConstraint *, const FoldExpandedConstraint *>,
495 FoldSubsumptionCache;
502 bool Subsumes(
const DNFFormula &P,
const CNFFormula &Q);
503 bool Subsumes(Literal A, Literal B);
504 bool Subsumes(
const FoldExpandedConstraint *A,
505 const FoldExpandedConstraint *B);
506 bool DNFSubsumes(
const Clause &P,
const Clause &Q);
508 CNFFormula CNF(
const NormalizedConstraint &
C);
509 DNFFormula DNF(
const NormalizedConstraint &
C);
511 template <
typename FormulaType>
512 FormulaType Normalize(
const NormalizedConstraint &
C);
513 void AddUniqueClauseToFormula(Formula &F, Clause
C);
515 Literal find(
const AtomicConstraint *);
516 Literal find(
const FoldExpandedConstraint *);
518 uint16_t getNewLiteralId();
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
static Decl::Kind getKind(const Decl *D)
Defines the C++ template declaration subclasses.
Defines Expressions and AST nodes for C++2a concepts.
Defines the clang::SourceLocation class and associated facilities.
static const TemplateArgument & getArgument(const TemplateArgument &A)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const Expr * getConstraintExpr() const
static AtomicConstraint * Create(ASTContext &Ctx, const Expr *ConstraintExpr, const NamedDecl *ConstraintDecl, UnsignedOrNone PackIndex)
const NormalizedConstraint & getLHS() const
NormalizedConstraint & getLHS()
NormalizedConstraint & getRHS()
static CompoundConstraint * CreateConjunction(ASTContext &Ctx, NormalizedConstraint *LHS, NormalizedConstraint *RHS)
CompoundConstraintKind getCompoundKind() const
const NormalizedConstraint & getRHS() const
static CompoundConstraint * Create(ASTContext &Ctx, NormalizedConstraint *LHS, CompoundConstraintKind CCK, NormalizedConstraint *RHS)
const NormalizedConstraint & getNormalizedConstraint() const
const ConceptSpecializationExpr * getConceptSpecializationExpr() const
static ConceptIdConstraint * Create(ASTContext &Ctx, const ConceptReference *ConceptId, NormalizedConstraint *SubConstraint, const NamedDecl *ConstraintDecl, const ConceptSpecializationExpr *CSE, UnsignedOrNone PackIndex)
NormalizedConstraint & getNormalizedConstraint()
const ConceptReference * getConceptId() const
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.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
This represents one expression.
static bool AreCompatibleForSubsumption(const FoldExpandedConstraint &A, const FoldExpandedConstraint &B)
FoldOperatorKind getFoldOperator() const
NormalizedConstraint & getNormalizedPattern()
const Expr * getPattern() const
static FoldExpandedConstraint * Create(ASTContext &Ctx, const Expr *Pattern, const NamedDecl *ConstraintDecl, FoldOperatorKind OpKind, NormalizedConstraint *Constraint)
const NormalizedConstraint & getNormalizedPattern() const
Data structure that captures multiple levels of template argument lists for use in template instantia...
This represents a decl that may have a name.
UnsignedOrNone getPackSubstitutionIndex() const
const NamedDecl * getConstraintDecl() const
NormalizedConstraint(const Expr *ConstraintExpr, const NamedDecl *ConstraintDecl, UnsignedOrNone PackIndex)
Sema - This implements semantic analysis and AST building for C.
Encodes a location in the source.
A trivial tuple used to represent a source range.
std::optional< bool > Subsumes(const NamedDecl *DP, ArrayRef< AssociatedConstraint > P, const NamedDecl *DQ, ArrayRef< AssociatedConstraint > Q)
SubsumptionChecker(Sema &SemaRef, SubsumptionCallable Callable={})
llvm::function_ref< bool( const AtomicConstraint &, const AtomicConstraint &)> SubsumptionCallable
Location wrapper for a TemplateArgument.
Stores a list of template parameters for a TemplateDecl and its derived classes.
uint32_t Literal
Literals are represented as positive integers.
The JSON file list parser is used to communicate input to InstallAPI.
U cast(CodeGen::Address addr)
ActionResult< Expr * > ExprResult
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
ExprOrConcept ConstraintExpr
unsigned PackSubstitutionIndex
const NamedDecl * ConstraintDecl
TemplateArgumentLoc * Args
OccurenceList IndexesForSubsumption
TemplateParameterList * ParamList
NormalizedConstraint * LHS
NormalizedConstraint * RHS
const ConceptSpecializationExpr * CSE
NormalizedConstraint * Sub
const NamedDecl * ConstraintDecl
NormalizedConstraint * Constraint
OccurenceList IndexesForSubsumption
TemplateParameterList * ParamList
TemplateArgumentLoc * Args
A normalized constraint, as defined in C++ [temp.constr.normal], is either an atomic constraint,...
NormalizedConstraint(const ConceptReference *ConceptId, const NamedDecl *ConstraintDecl, NormalizedConstraint *SubConstraint, const ConceptSpecializationExpr *CSE, UnsignedOrNone PackIndex)
bool hasMatchingParameterMapping(ASTContext &C, const NormalizedConstraint &Other) const
NormalizedConstraint(const Expr *ConstraintExpr, const NamedDecl *ConstraintDecl, UnsignedOrNone PackIndex)
CompoundConstraintBits Compound
NormalizedConstraint(const Expr *Pattern, FoldOperatorKind OpKind, NormalizedConstraint *Constraint, const NamedDecl *ConstraintDecl)
SourceRange getSourceRange() const
NormalizedConstraint(NormalizedConstraint *LHS, CompoundConstraintKind CCK, NormalizedConstraint *RHS)
llvm::PointerUnion< const Expr *, const ConceptReference * > ExprOrConcept
ConstraintKind getKind() const
SourceLocation getEndLoc() const
const OccurenceList & mappingOccurenceList() const
AtomicConstraintBits Atomic
const OccurenceList & mappingOccurenceListForSubsumption() const
FoldExpandedConstraintBits FoldExpanded
TemplateParameterList * getUsedTemplateParamList() const
SourceLocation getBeginLoc() const
llvm::SmallBitVector OccurenceList
llvm::MutableArrayRef< TemplateArgumentLoc > getParameterMapping() const
bool hasParameterMapping() const
void updateParameterMapping(OccurenceList Indexes, OccurenceList IndexesForSubsumption, llvm::MutableArrayRef< TemplateArgumentLoc > Args, TemplateParameterList *ParamList)
constexpr unsigned toInternalRepresentation() const
static constexpr UnsignedOrNone fromInternalRepresentation(unsigned Rep)
ConstraintSatisfaction Satisfaction