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())
293 NormalizedConstraint *RHS) {
298 NormalizedConstraint *LHS,
299 NormalizedConstraint *RHS) {
333 Atomic.PackSubstitutionIndex);
339 NormalizedConstraintWithParamMapping;
356 NormalizedConstraintWithParamMapping;
389 NormalizedConstraintWithParamMapping;
397 SubConstraint, CSE, PackIndex);
446 enum Kind {
Atomic, FoldExpanded };
449 LLVM_PREFERRED_TYPE(Kind)
452 bool operator==(
const Literal &
Other)
const {
return Value ==
Other.Value; }
453 bool operator<(
const Literal &
Other)
const {
return Value <
Other.Value; }
455 using Clause = llvm::SmallVector<Literal>;
456 using Formula = llvm::SmallVector<Clause, 5>;
458 struct CNFFormula : Formula {
460 using Formula::Formula;
462 struct DNFFormula : Formula {
464 using Formula::Formula;
467 struct MappedAtomicConstraint {
468 const AtomicConstraint *Constraint;
472 struct FoldExpendedConstraintKey {
474 const AtomicConstraint *Constraint;
478 llvm::DenseMap<
const Expr *, llvm::SmallDenseMap<llvm::FoldingSetNodeID,
479 MappedAtomicConstraint>>
482 llvm::DenseMap<const Expr *, std::vector<FoldExpendedConstraintKey>> FoldMap;
486 llvm::DenseMap<uint16_t, const void *> ReverseMap;
491 std::pair<const FoldExpandedConstraint *, const FoldExpandedConstraint *>,
493 FoldSubsumptionCache;
500 bool Subsumes(
const DNFFormula &P,
const CNFFormula &Q);
501 bool Subsumes(Literal A, Literal B);
502 bool Subsumes(
const FoldExpandedConstraint *A,
503 const FoldExpandedConstraint *B);
504 bool DNFSubsumes(
const Clause &P,
const Clause &Q);
506 CNFFormula CNF(
const NormalizedConstraint &
C);
507 DNFFormula DNF(
const NormalizedConstraint &
C);
509 template <
typename FormulaType>
510 FormulaType Normalize(
const NormalizedConstraint &
C);
511 void AddUniqueClauseToFormula(Formula &F, Clause
C);
513 Literal find(
const AtomicConstraint *);
514 Literal find(
const FoldExpandedConstraint *);
516 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