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" |
| 17 | using namespace clang; |
| 18 | |
| 19 | ASTConstraintSatisfaction::ASTConstraintSatisfaction(const ASTContext &C, |
| 20 | const ConstraintSatisfaction &Satisfaction): |
| 21 | NumRecords{Satisfaction.Details.size()}, |
| 22 | IsSatisfied{Satisfaction.IsSatisfied} { |
| 23 | for (unsigned I = 0; I < NumRecords; ++I) { |
| 24 | auto &Detail = Satisfaction.Details[I]; |
| 25 | if (Detail.second.is<Expr *>()) |
| 26 | new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I) |
| 27 | UnsatisfiedConstraintRecord{Detail.first, |
| 28 | UnsatisfiedConstraintRecord::second_type( |
| 29 | Detail.second.get<Expr *>())}; |
| 30 | else { |
| 31 | auto &SubstitutionDiagnostic = |
Saar Raz | e7c2466 | 2019-12-06 01:53:18 +0200 | [diff] [blame] | 32 | *Detail.second.get<std::pair<SourceLocation, StringRef> *>(); |
Saar Raz | fdf80e8 | 2019-12-06 01:30:21 +0200 | [diff] [blame] | 33 | unsigned MessageSize = SubstitutionDiagnostic.second.size(); |
| 34 | char *Mem = new (C) char[MessageSize]; |
Saar Raz | e7c2466 | 2019-12-06 01:53:18 +0200 | [diff] [blame] | 35 | memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize); |
Saar Raz | fdf80e8 | 2019-12-06 01:30:21 +0200 | [diff] [blame] | 36 | auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>( |
| 37 | SubstitutionDiagnostic.first, StringRef(Mem, MessageSize)); |
| 38 | new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I) |
| 39 | UnsatisfiedConstraintRecord{Detail.first, |
| 40 | UnsatisfiedConstraintRecord::second_type( |
| 41 | NewSubstDiag)}; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | |
| 47 | ASTConstraintSatisfaction * |
| 48 | ASTConstraintSatisfaction::Create(const ASTContext &C, |
| 49 | const ConstraintSatisfaction &Satisfaction) { |
| 50 | std::size_t size = |
| 51 | totalSizeToAlloc<UnsatisfiedConstraintRecord>( |
| 52 | Satisfaction.Details.size()); |
| 53 | void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction)); |
| 54 | return new (Mem) ASTConstraintSatisfaction(C, Satisfaction); |
| 55 | } |