ASTConcept.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include "clang/AST/ASTConcept.h"
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/Decl.h"
  16. #include "clang/AST/TemplateBase.h"
  17. #include "llvm/ADT/ArrayRef.h"
  18. #include "llvm/ADT/FoldingSet.h"
  19. using namespace clang;
  20. ASTConstraintSatisfaction::ASTConstraintSatisfaction(const ASTContext &C,
  21. const ConstraintSatisfaction &Satisfaction):
  22. NumRecords{Satisfaction.Details.size()},
  23. IsSatisfied{Satisfaction.IsSatisfied} {
  24. for (unsigned I = 0; I < NumRecords; ++I) {
  25. auto &Detail = Satisfaction.Details[I];
  26. if (Detail.second.is<Expr *>())
  27. new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
  28. UnsatisfiedConstraintRecord{Detail.first,
  29. UnsatisfiedConstraintRecord::second_type(
  30. Detail.second.get<Expr *>())};
  31. else {
  32. auto &SubstitutionDiagnostic =
  33. *Detail.second.get<std::pair<SourceLocation, StringRef> *>();
  34. unsigned MessageSize = SubstitutionDiagnostic.second.size();
  35. char *Mem = new (C) char[MessageSize];
  36. memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
  37. auto *NewSubstDiag = new (C) std::pair<SourceLocation, StringRef>(
  38. SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
  39. new (getTrailingObjects<UnsatisfiedConstraintRecord>() + I)
  40. UnsatisfiedConstraintRecord{Detail.first,
  41. UnsatisfiedConstraintRecord::second_type(
  42. NewSubstDiag)};
  43. }
  44. }
  45. }
  46. ASTConstraintSatisfaction *
  47. ASTConstraintSatisfaction::Create(const ASTContext &C,
  48. const ConstraintSatisfaction &Satisfaction) {
  49. std::size_t size =
  50. totalSizeToAlloc<UnsatisfiedConstraintRecord>(
  51. Satisfaction.Details.size());
  52. void *Mem = C.Allocate(size, alignof(ASTConstraintSatisfaction));
  53. return new (Mem) ASTConstraintSatisfaction(C, Satisfaction);
  54. }
  55. void ConstraintSatisfaction::Profile(
  56. llvm::FoldingSetNodeID &ID, const ASTContext &C,
  57. const NamedDecl *ConstraintOwner, ArrayRef<TemplateArgument> TemplateArgs) {
  58. ID.AddPointer(ConstraintOwner);
  59. ID.AddInteger(TemplateArgs.size());
  60. for (auto &Arg : TemplateArgs)
  61. Arg.Profile(ID, C);
  62. }