clang 19.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
22namespace {
23void CreatUnsatisfiedConstraintRecord(
24 const ASTContext &C, const UnsatisfiedConstraintRecord &Detail,
25 UnsatisfiedConstraintRecord *TrailingObject) {
26 if (Detail.second.is<Expr *>())
27 new (TrailingObject) UnsatisfiedConstraintRecord{
28 Detail.first,
29 UnsatisfiedConstraintRecord::second_type(Detail.second.get<Expr *>())};
30 else {
31 auto &SubstitutionDiagnostic =
32 *Detail.second.get<std::pair<SourceLocation, StringRef> *>();
33 unsigned MessageSize = SubstitutionDiagnostic.second.size();
34 char *Mem = new (C) char[MessageSize];
35 memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
36 auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
37 SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
38 new (TrailingObject) UnsatisfiedConstraintRecord{
39 Detail.first, UnsatisfiedConstraintRecord::second_type(NewSubstDiag)};
40 }
41}
42} // namespace
43
45 const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
46 : NumRecords{Satisfaction.Details.size()},
47 IsSatisfied{Satisfaction.IsSatisfied}, ContainsErrors{
48 Satisfaction.ContainsErrors} {
49 for (unsigned I = 0; I < NumRecords; ++I)
50 CreatUnsatisfiedConstraintRecord(
51 C, Satisfaction.Details[I],
52 getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
53}
54
56 const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
57 : NumRecords{Satisfaction.NumRecords},
58 IsSatisfied{Satisfaction.IsSatisfied},
59 ContainsErrors{Satisfaction.ContainsErrors} {
60 for (unsigned I = 0; I < NumRecords; ++I)
61 CreatUnsatisfiedConstraintRecord(
62 C, *(Satisfaction.begin() + I),
63 getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
64}
65
68 const ConstraintSatisfaction &Satisfaction) {
69 std::size_t size =
70 totalSizeToAlloc<UnsatisfiedConstraintRecord>(
71 Satisfaction.Details.size());
72 void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
73 return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
74}
75
77 const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction) {
78 std::size_t size =
79 totalSizeToAlloc<UnsatisfiedConstraintRecord>(Satisfaction.NumRecords);
80 void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
81 return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
82}
83
85 llvm::FoldingSetNodeID &ID, const ASTContext &C,
86 const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
87 ID.AddPointer(ConstraintOwner);
88 ID.AddInteger(TemplateArgs.size());
89 for (auto &Arg : TemplateArgs)
90 Arg.Profile(ID, C);
91}
92
95 SourceLocation TemplateKWLoc,
96 DeclarationNameInfo ConceptNameInfo,
97 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
98 const ASTTemplateArgumentListInfo *ArgsAsWritten) {
99 return new (C) ConceptReference(NNS, TemplateKWLoc, ConceptNameInfo,
100 FoundDecl, NamedConcept, ArgsAsWritten);
101}
102
103void ConceptReference::print(llvm::raw_ostream &OS,
104 const PrintingPolicy &Policy) const {
105 if (NestedNameSpec)
106 NestedNameSpec.getNestedNameSpecifier()->print(OS, Policy);
107 ConceptName.printName(OS, Policy);
109 OS << "<";
110 llvm::ListSeparator Sep(", ");
111 // FIXME: Find corresponding parameter for argument
112 for (auto &ArgLoc : ArgsAsWritten->arguments()) {
113 OS << Sep;
114 ArgLoc.getArgument().print(Policy, OS, /*IncludeType*/ false);
115 }
116 OS << ">";
117 }
118}
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
Declaration of a C++20 concept.
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:128
bool hasExplicitTemplateArgs() const
Whether or not template arguments were explicitly specified in the concept reference (they might not ...
Definition: ASTConcept.h:213
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:94
void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition: ASTConcept.cpp:103
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:35
llvm::SmallVector< std::pair< const Expr *, Detail >, 4 > Details
Pairs of unsatisfied atomic constraint expressions along with the substituted constraint expr,...
Definition: ASTConcept.h:60
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C)
Definition: ASTConcept.h:62
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.
std::pair< const Expr *, llvm::PointerUnion< Expr *, std::pair< SourceLocation, StringRef > * > > UnsatisfiedConstraintRecord
Pairs of unsatisfied atomic constraint expressions along with the substituted constraint expr,...
Definition: ASTConcept.h:85
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:93
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:76
ASTConstraintSatisfaction(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:44
const UnsatisfiedConstraintRecord * begin() const
Definition: ASTConcept.h:98
static ASTConstraintSatisfaction * Create(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:67
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