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