/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/ASTConcept.cpp
Line | Count | Source |
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 | | |
22 | | ASTConstraintSatisfaction::ASTConstraintSatisfaction(const ASTContext &C, |
23 | | const ConstraintSatisfaction &Satisfaction): |
24 | | NumRecords{Satisfaction.Details.size()}, |
25 | 666 | IsSatisfied{Satisfaction.IsSatisfied} { |
26 | 856 | for (unsigned I = 0; I < NumRecords; ++I190 ) { |
27 | 190 | auto &Detail = Satisfaction.Details[I]; |
28 | 190 | if (Detail.second.is<Expr *>()) |
29 | 179 | new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I) |
30 | 179 | UnsatisfiedConstraintRecord{Detail.first, |
31 | 179 | UnsatisfiedConstraintRecord::second_type( |
32 | 179 | Detail.second.get<Expr *>())}; |
33 | 11 | else { |
34 | 11 | auto &SubstitutionDiagnostic = |
35 | 11 | *Detail.second.get<std::pair<SourceLocation, StringRef> *>(); |
36 | 11 | unsigned MessageSize = SubstitutionDiagnostic.second.size(); |
37 | 11 | char *Mem = new (C) char[MessageSize]; |
38 | 11 | memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize); |
39 | 11 | auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>( |
40 | 11 | SubstitutionDiagnostic.first, StringRef(Mem, MessageSize)); |
41 | 11 | new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I) |
42 | 11 | UnsatisfiedConstraintRecord{Detail.first, |
43 | 11 | UnsatisfiedConstraintRecord::second_type( |
44 | 11 | NewSubstDiag)}; |
45 | 11 | } |
46 | 190 | } |
47 | 666 | } |
48 | | |
49 | | |
50 | | ASTConstraintSatisfaction * |
51 | | ASTConstraintSatisfaction::Create(const ASTContext &C, |
52 | 666 | const ConstraintSatisfaction &Satisfaction) { |
53 | 666 | std::size_t size = |
54 | 666 | totalSizeToAlloc<UnsatisfiedConstraintRecord>( |
55 | 666 | Satisfaction.Details.size()); |
56 | 666 | void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction)); |
57 | 666 | return new (Mem) ASTConstraintSatisfaction(C, Satisfaction); |
58 | 666 | } |
59 | | |
60 | | void ConstraintSatisfaction::Profile( |
61 | | llvm::FoldingSetNodeID &ID, const ASTContext &C, |
62 | 3.28k | const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) { |
63 | 3.28k | ID.AddPointer(ConstraintOwner); |
64 | 3.28k | ID.AddInteger(TemplateArgs.size()); |
65 | 3.28k | for (auto &Arg : TemplateArgs) |
66 | 3.62k | Arg.Profile(ID, C); |
67 | 3.28k | } |