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/StringExtras.h"
18
19using namespace clang;
20
21static void
23 const UnsatisfiedConstraintRecord &Detail,
24 UnsatisfiedConstraintRecord *TrailingObject) {
25 if (auto *E = dyn_cast<Expr *>(Detail))
26 new (TrailingObject) UnsatisfiedConstraintRecord(E);
27 else {
28 auto &SubstitutionDiagnostic =
29 *cast<std::pair<SourceLocation, StringRef> *>(Detail);
30 StringRef Message = C.backupStr(SubstitutionDiagnostic.second);
31 auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
32 SubstitutionDiagnostic.first, Message);
33 new (TrailingObject) UnsatisfiedConstraintRecord(NewSubstDiag);
34 }
35}
36
38 const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
39 : NumRecords{Satisfaction.Details.size()},
40 IsSatisfied{Satisfaction.IsSatisfied}, ContainsErrors{
41 Satisfaction.ContainsErrors} {
42 for (unsigned I = 0; I < NumRecords; ++I)
44 C, Satisfaction.Details[I],
45 getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
46}
47
49 const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
50 : NumRecords{Satisfaction.NumRecords},
51 IsSatisfied{Satisfaction.IsSatisfied},
52 ContainsErrors{Satisfaction.ContainsErrors} {
53 for (unsigned I = 0; I < NumRecords; ++I)
55 C, *(Satisfaction.begin() + I),
56 getTrailingObjects<UnsatisfiedConstraintRecord>() + I);
57}
58
61 const ConstraintSatisfaction &Satisfaction) {
62 std::size_t size =
63 totalSizeToAlloc<UnsatisfiedConstraintRecord>(
64 Satisfaction.Details.size());
65 void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
66 return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
67}
68
70 const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction) {
71 std::size_t size =
72 totalSizeToAlloc<UnsatisfiedConstraintRecord>(Satisfaction.NumRecords);
73 void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
74 return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
75}
76
78 llvm::FoldingSetNodeID &ID, const ASTContext &C,
79 const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
80 ID.AddPointer(ConstraintOwner);
81 ID.AddInteger(TemplateArgs.size());
82 for (auto &Arg : TemplateArgs)
83 Arg.Profile(ID, C);
84}
85
88 SourceLocation TemplateKWLoc,
89 DeclarationNameInfo ConceptNameInfo,
90 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
91 const ASTTemplateArgumentListInfo *ArgsAsWritten) {
92 return new (C) ConceptReference(NNS, TemplateKWLoc, ConceptNameInfo,
93 FoundDecl, NamedConcept, ArgsAsWritten);
94}
95
96void ConceptReference::print(llvm::raw_ostream &OS,
97 const PrintingPolicy &Policy) const {
98 if (NestedNameSpec)
99 NestedNameSpec.getNestedNameSpecifier()->print(OS, Policy);
100 ConceptName.printName(OS, Policy);
102 OS << "<";
103 llvm::ListSeparator Sep(", ");
104 // FIXME: Find corresponding parameter for argument
105 for (auto &ArgLoc : ArgsAsWritten->arguments()) {
106 OS << Sep;
107 ArgLoc.getArgument().print(Policy, OS, /*IncludeType*/ false);
108 }
109 OS << ">";
110 }
111}
static void CreateUnsatisfiedConstraintRecord(const ASTContext &C, const UnsatisfiedConstraintRecord &Detail, UnsatisfiedConstraintRecord *TrailingObject)
Definition: ASTConcept.cpp:22
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
Expr * E
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
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:87
void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition: ASTConcept.cpp:96
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 a decl that may have a name.
Definition: Decl.h:253
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:69
ASTConstraintSatisfaction(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:37
const UnsatisfiedConstraintRecord * begin() const
Definition: ASTConcept.h:94
static ASTConstraintSatisfaction * Create(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:60
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