xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/AST/ASTConcept.cpp (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
1*e038c9c4Sjoerg //===--- ASTConcept.cpp - Concepts Related AST Data Structures --*- C++ -*-===//
2*e038c9c4Sjoerg //
3*e038c9c4Sjoerg //                     The LLVM Compiler Infrastructure
4*e038c9c4Sjoerg //
5*e038c9c4Sjoerg // This file is distributed under the University of Illinois Open Source
6*e038c9c4Sjoerg // License. See LICENSE.TXT for details.
7*e038c9c4Sjoerg //
8*e038c9c4Sjoerg //===----------------------------------------------------------------------===//
9*e038c9c4Sjoerg ///
10*e038c9c4Sjoerg /// \file
11*e038c9c4Sjoerg /// \brief This file defines AST data structures related to concepts.
12*e038c9c4Sjoerg ///
13*e038c9c4Sjoerg //===----------------------------------------------------------------------===//
14*e038c9c4Sjoerg 
15*e038c9c4Sjoerg #include "clang/AST/ASTConcept.h"
16*e038c9c4Sjoerg #include "clang/AST/ASTContext.h"
17*e038c9c4Sjoerg #include "clang/AST/Decl.h"
18*e038c9c4Sjoerg #include "clang/AST/TemplateBase.h"
19*e038c9c4Sjoerg #include "llvm/ADT/ArrayRef.h"
20*e038c9c4Sjoerg #include "llvm/ADT/FoldingSet.h"
21*e038c9c4Sjoerg using namespace clang;
22*e038c9c4Sjoerg 
ASTConstraintSatisfaction(const ASTContext & C,const ConstraintSatisfaction & Satisfaction)23*e038c9c4Sjoerg ASTConstraintSatisfaction::ASTConstraintSatisfaction(const ASTContext &C,
24*e038c9c4Sjoerg     const ConstraintSatisfaction &Satisfaction):
25*e038c9c4Sjoerg     NumRecords{Satisfaction.Details.size()},
26*e038c9c4Sjoerg     IsSatisfied{Satisfaction.IsSatisfied} {
27*e038c9c4Sjoerg   for (unsigned I = 0; I < NumRecords; ++I) {
28*e038c9c4Sjoerg     auto &Detail = Satisfaction.Details[I];
29*e038c9c4Sjoerg     if (Detail.second.is<Expr *>())
30*e038c9c4Sjoerg       new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
31*e038c9c4Sjoerg          UnsatisfiedConstraintRecord{Detail.first,
32*e038c9c4Sjoerg                                      UnsatisfiedConstraintRecord::second_type(
33*e038c9c4Sjoerg                                          Detail.second.get<Expr *>())};
34*e038c9c4Sjoerg     else {
35*e038c9c4Sjoerg       auto &SubstitutionDiagnostic =
36*e038c9c4Sjoerg           *Detail.second.get<std::pair<SourceLocation, StringRef> *>();
37*e038c9c4Sjoerg       unsigned MessageSize = SubstitutionDiagnostic.second.size();
38*e038c9c4Sjoerg       char *Mem = new (C) char[MessageSize];
39*e038c9c4Sjoerg       memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
40*e038c9c4Sjoerg       auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
41*e038c9c4Sjoerg           SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
42*e038c9c4Sjoerg       new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
43*e038c9c4Sjoerg          UnsatisfiedConstraintRecord{Detail.first,
44*e038c9c4Sjoerg                                      UnsatisfiedConstraintRecord::second_type(
45*e038c9c4Sjoerg                                          NewSubstDiag)};
46*e038c9c4Sjoerg     }
47*e038c9c4Sjoerg   }
48*e038c9c4Sjoerg }
49*e038c9c4Sjoerg 
50*e038c9c4Sjoerg 
51*e038c9c4Sjoerg ASTConstraintSatisfaction *
Create(const ASTContext & C,const ConstraintSatisfaction & Satisfaction)52*e038c9c4Sjoerg ASTConstraintSatisfaction::Create(const ASTContext &C,
53*e038c9c4Sjoerg                                   const ConstraintSatisfaction &Satisfaction) {
54*e038c9c4Sjoerg   std::size_t size =
55*e038c9c4Sjoerg       totalSizeToAlloc<UnsatisfiedConstraintRecord>(
56*e038c9c4Sjoerg           Satisfaction.Details.size());
57*e038c9c4Sjoerg   void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
58*e038c9c4Sjoerg   return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
59*e038c9c4Sjoerg }
60*e038c9c4Sjoerg 
Profile(llvm::FoldingSetNodeID & ID,const ASTContext & C,const NamedDecl * ConstraintOwner,ArrayRef<TemplateArgument> TemplateArgs)61*e038c9c4Sjoerg void ConstraintSatisfaction::Profile(
62*e038c9c4Sjoerg     llvm::FoldingSetNodeID &ID, const ASTContext &C,
63*e038c9c4Sjoerg     const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
64*e038c9c4Sjoerg   ID.AddPointer(ConstraintOwner);
65*e038c9c4Sjoerg   ID.AddInteger(TemplateArgs.size());
66*e038c9c4Sjoerg   for (auto &Arg : TemplateArgs)
67*e038c9c4Sjoerg     Arg.Profile(ID, C);
68*e038c9c4Sjoerg }
69