clang 20.0.0git
ASTConcept.cpp
Go to the documentation of this file.
1//===--- ASTConcept.cpp - Concepts Related AST Data Structures --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// \brief This file defines AST data structures related to concepts.
11///
12//===----------------------------------------------------------------------===//
13
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/StringExtras.h"
19
20using namespace clang;
21
22static void
24 const UnsatisfiedConstraintRecord &Detail,
25 UnsatisfiedConstraintRecord *TrailingObject) {
26 if (Detail.is<Expr *>())
27 new (TrailingObject) UnsatisfiedConstraintRecord(Detail.get<Expr *>());
28 else {
29 auto &SubstitutionDiagnostic =
30 *Detail.get<std::pair<SourceLocation, StringRef> *>();
31 StringRef Message = C.backupStr(SubstitutionDiagnostic.second);
32 auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
33 SubstitutionDiagnostic.first, Message);
34 new (TrailingObject) UnsatisfiedConstraintRecord(NewSubstDiag);
35 }
36}
37
39 const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
40 : NumRecords{Satisfaction.Details.size()},
41 IsSatisfied{Satisfaction.IsSatisfied}, ContainsErrors{
42 Satisfaction.ContainsErrors} {
43 for (unsigned I = 0; I < NumRecords; ++I)
45 C, Satisfaction.Details[I],
46 getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
47}
48
50 const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
51 : NumRecords{Satisfaction.NumRecords},
52 IsSatisfied{Satisfaction.IsSatisfied},
53 ContainsErrors{Satisfaction.ContainsErrors} {
54 for (unsigned I = 0; I < NumRecords; ++I)
56 C, *(Satisfaction.begin() + I),
57 getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
58}
59
62 const ConstraintSatisfaction &Satisfaction) {
63 std::size_t size =
64 totalSizeToAlloc<UnsatisfiedConstraintRecord>(
65 Satisfaction.Details.size());
66 void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
67 return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
68}
69
71 const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction) {
72 std::size_t size =
73 totalSizeToAlloc<UnsatisfiedConstraintRecord>(Satisfaction.NumRecords);
74 void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
75 return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
76}
77
79 llvm::FoldingSetNodeID &ID, const ASTContext &C,
80 const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
81 ID.AddPointer(ConstraintOwner);
82 ID.AddInteger(TemplateArgs.size());
83 for (auto &Arg : TemplateArgs)
84 Arg.Profile(ID, C);
85}
86
89 SourceLocation TemplateKWLoc,
90 DeclarationNameInfo ConceptNameInfo,
91 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
92 const ASTTemplateArgumentListInfo *ArgsAsWritten) {
93 return new (C) ConceptReference(NNS, TemplateKWLoc, ConceptNameInfo,
94 FoundDecl, NamedConcept, ArgsAsWritten);
95}
96
97void ConceptReference::print(llvm::raw_ostream &OS,
98 const PrintingPolicy &Policy) const {
99 if (NestedNameSpec)
100 NestedNameSpec.getNestedNameSpecifier()->print(OS, Policy);
101 ConceptName.printName(OS, Policy);
103 OS << "<";
104 llvm::ListSeparator Sep(", ");
105 // FIXME: Find corresponding parameter for argument
106 for (auto &ArgLoc : ArgsAsWritten->arguments()) {
107 OS << Sep;
108 ArgLoc.getArgument().print(Policy, OS, /*IncludeType*/ false);
109 }
110 OS << ">";
111 }
112}
static void CreateUnsatisfiedConstraintRecord(const ASTContext &C, const UnsatisfiedConstraintRecord &Detail, UnsatisfiedConstraintRecord *TrailingObject)
Definition: ASTConcept.cpp:23
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
Declaration of a C++20 concept.
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:124
bool hasExplicitTemplateArgs() const
Whether or not template arguments were explicitly specified in the concept reference (they might not ...
Definition: ASTConcept.h:209
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:88
void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition: ASTConcept.cpp:97
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:35
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C)
Definition: ASTConcept.h:60
llvm::SmallVector< Detail, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition: ASTConcept.h:58
This represents one expression.
Definition: Expr.h:110
This represents a decl that may have a name.
Definition: Decl.h:249
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
llvm::PointerUnion< Expr *, std::pair< SourceLocation, StringRef > * > UnsatisfiedConstraintRecord
Pairs of unsatisfied atomic constraint expressions along with the substituted constraint expr,...
Definition: ASTConcept.h:81
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:89
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:70
ASTConstraintSatisfaction(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:38
const UnsatisfiedConstraintRecord * begin() const
Definition: ASTConcept.h:94
static ASTConstraintSatisfaction * Create(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:61
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:705
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57