clang  14.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 
14 #include "clang/AST/ASTConcept.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/TemplateBase.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/FoldingSet.h"
20 using namespace clang;
21 
23  const ConstraintSatisfaction &Satisfaction):
24  NumRecords{Satisfaction.Details.size()},
25  IsSatisfied{Satisfaction.IsSatisfied} {
26  for (unsigned I = 0; I < NumRecords; ++I) {
27  auto &Detail = Satisfaction.Details[I];
28  if (Detail.second.is<Expr *>())
29  new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
30  UnsatisfiedConstraintRecord{Detail.first,
31  UnsatisfiedConstraintRecord::second_type(
32  Detail.second.get<Expr *>())};
33  else {
34  auto &SubstitutionDiagnostic =
35  *Detail.second.get<std::pair<SourceLocation, StringRef> *>();
36  unsigned MessageSize = SubstitutionDiagnostic.second.size();
37  char *Mem = new (C) char[MessageSize];
38  memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
39  auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
40  SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
41  new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
42  UnsatisfiedConstraintRecord{Detail.first,
43  UnsatisfiedConstraintRecord::second_type(
44  NewSubstDiag)};
45  }
46  }
47 }
48 
49 
52  const ConstraintSatisfaction &Satisfaction) {
53  std::size_t size =
54  totalSizeToAlloc<UnsatisfiedConstraintRecord>(
55  Satisfaction.Details.size());
56  void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
57  return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
58 }
59 
61  llvm::FoldingSetNodeID &ID, const ASTContext &C,
62  const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
63  ID.AddPointer(ConstraintOwner);
64  ID.AddInteger(TemplateArgs.size());
65  for (auto &Arg : TemplateArgs)
66  Arg.Profile(ID, C);
67 }
clang::ASTConstraintSatisfaction
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:77
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:54
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1549
Decl.h
clang::ConstraintSatisfaction::Details
llvm::SmallVector< std::pair< const Expr *, Detail >, 4 > Details
Pairs of unsatisfied atomic constraint expressions along with the substituted constraint expr,...
Definition: ASTConcept.h:53
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:102
clang::UnsatisfiedConstraintRecord
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:71
TemplateBase.h
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
ASTContext.h
ASTConcept.h
This file provides AST data structures related to concepts.
clang::ConstraintSatisfaction::Profile
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C)
Definition: ASTConcept.h:55
llvm::ArrayRef
Definition: LLVM.h:34
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang
Definition: CalledOnceCheck.h:17
clang::ASTConstraintSatisfaction::ASTConstraintSatisfaction
ASTConstraintSatisfaction(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:22
clang::ConstraintSatisfaction
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:29
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::ASTConstraintSatisfaction::Create
static ASTConstraintSatisfaction * Create(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:51