| Saar Raz | fdf80e8 | 2019-12-06 01:30:21 +0200 | [diff] [blame] | 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" |
| Saar Raz | bb9b964 | 2020-01-22 04:06:51 +0200 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/TemplateBase.h" |
| 19 | #include "llvm/ADT/ArrayRef.h" |
| 20 | #include "llvm/ADT/FoldingSet.h" |
| Saar Raz | fdf80e8 | 2019-12-06 01:30:21 +0200 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | ASTConstraintSatisfaction::ASTConstraintSatisfaction(const ASTContext &C, |
| 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 = |
| Saar Raz | e7c2466 | 2019-12-06 01:53:18 +0200 | [diff] [blame] | 36 | *Detail.second.get<std::pair<SourceLocation, StringRef> *>(); |
| Saar Raz | fdf80e8 | 2019-12-06 01:30:21 +0200 | [diff] [blame] | 37 | unsigned MessageSize = SubstitutionDiagnostic.second.size(); |
| 38 | char *Mem = new (C) char[MessageSize]; |
| Saar Raz | e7c2466 | 2019-12-06 01:53:18 +0200 | [diff] [blame] | 39 | memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize); |
| Saar Raz | fdf80e8 | 2019-12-06 01:30:21 +0200 | [diff] [blame] | 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 | |
| 51 | ASTConstraintSatisfaction * |
| 52 | ASTConstraintSatisfaction::Create(const ASTContext &C, |
| 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 | } |
| Saar Raz | b933d37 | 2020-01-22 02:50:12 +0200 | [diff] [blame] | 60 | |
| 61 | void ConstraintSatisfaction::Profile( |
| Saar Raz | 713562f | 2020-01-25 22:54:27 +0200 | [diff] [blame] | 62 | llvm::FoldingSetNodeID &ID, const ASTContext &C, |
| 63 | const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) { |
| Saar Raz | b933d37 | 2020-01-22 02:50:12 +0200 | [diff] [blame] | 64 | ID.AddPointer(ConstraintOwner); |
| 65 | ID.AddInteger(TemplateArgs.size()); |
| 66 | for (auto &Arg : TemplateArgs) |
| 67 | Arg.Profile(ID, C); |
| 68 | } |