clang  10.0.0git
ASTConcept.cpp
Go to the documentation of this file.
1 //===--- ASTConcept.cpp - Concepts Related AST Data Structures --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file defines AST data structures related to concepts.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/AST/ASTConcept.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/TemplateBase.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/FoldingSet.h"
21 using namespace clang;
22 
24  const ConstraintSatisfaction &Satisfaction):
25  NumRecords{Satisfaction.Details.size()},
26  IsSatisfied{Satisfaction.IsSatisfied} {
27  for (unsigned I = 0; I < NumRecords; ++I) {
28  auto &Detail = Satisfaction.Details[I];
29  if (Detail.second.is<Expr *>())
30  new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
31  UnsatisfiedConstraintRecord{Detail.first,
32  UnsatisfiedConstraintRecord::second_type(
33  Detail.second.get<Expr *>())};
34  else {
35  auto &SubstitutionDiagnostic =
36  *Detail.second.get<std::pair<SourceLocation, StringRef> *>();
37  unsigned MessageSize = SubstitutionDiagnostic.second.size();
38  char *Mem = new (C) char[MessageSize];
39  memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
40  auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
41  SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
42  new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
43  UnsatisfiedConstraintRecord{Detail.first,
44  UnsatisfiedConstraintRecord::second_type(
45  NewSubstDiag)};
46  }
47  }
48 }
49 
50 
53  const ConstraintSatisfaction &Satisfaction) {
54  std::size_t size =
55  totalSizeToAlloc<UnsatisfiedConstraintRecord>(
56  Satisfaction.Details.size());
57  void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
58  return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
59 }
60 
62  llvm::FoldingSetNodeID &ID, const ASTContext &C,
63  const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
64  ID.AddPointer(ConstraintOwner);
65  ID.AddInteger(TemplateArgs.size());
66  for (auto &Arg : TemplateArgs)
67  Arg.Profile(ID, C);
68 }
Defines the clang::ASTContext interface.
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
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:168
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:40
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:29
This represents one expression.
Definition: Expr.h:108
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C)
Definition: ASTConcept.h:55
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:686
Dataflow Directional Tag Classes.
ASTConstraintSatisfaction(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:23
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
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:77
static ASTConstraintSatisfaction * Create(const ASTContext &C, const ConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:52
This represents a decl that may have a name.
Definition: Decl.h:223
This file provides AST data structures related to concepts.