Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/DeclFriend.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation ----===//
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
// This file implements the AST classes related to C++ friend
10
// declarations.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/DeclFriend.h"
15
#include "clang/AST/Decl.h"
16
#include "clang/AST/DeclBase.h"
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/ASTContext.h"
19
#include "clang/AST/DeclTemplate.h"
20
#include "clang/Basic/LLVM.h"
21
#include "llvm/Support/Casting.h"
22
#include <cassert>
23
#include <cstddef>
24
25
using namespace clang;
26
27
0
void FriendDecl::anchor() {}
28
29
1.92k
FriendDecl *FriendDecl::getNextFriendSlowCase() {
30
1.92k
  return cast_or_null<FriendDecl>(
31
1.92k
                           NextFriend.get(getASTContext().getExternalSource()));
32
1.92k
}
33
34
FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
35
                               SourceLocation L,
36
                               FriendUnion Friend,
37
                               SourceLocation FriendL,
38
112k
                          ArrayRef<TemplateParameterList *> FriendTypeTPLists) {
39
112k
#ifndef NDEBUG
40
112k
  if (Friend.is<NamedDecl *>()) {
41
87.7k
    const auto *D = Friend.get<NamedDecl*>();
42
87.7k
    assert(isa<FunctionDecl>(D) ||
43
87.7k
           isa<CXXRecordDecl>(D) ||
44
87.7k
           isa<FunctionTemplateDecl>(D) ||
45
87.7k
           isa<ClassTemplateDecl>(D));
46
47
    // As a temporary hack, we permit template instantiation to point
48
    // to the original declaration when instantiating members.
49
87.7k
    assert(D->getFriendObjectKind() ||
50
87.7k
           (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
51
    // These template parameters are for friend types only.
52
87.7k
    assert(FriendTypeTPLists.empty());
53
87.7k
  }
54
112k
#endif
55
56
112k
  std::size_t Extra =
57
112k
      FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(
58
112k
          FriendTypeTPLists.size());
59
112k
  auto *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
60
112k
                                           FriendTypeTPLists);
61
112k
  cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
62
112k
  return FD;
63
112k
}
64
65
FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
66
2.96k
                                           unsigned FriendTypeNumTPLists) {
67
2.96k
  std::size_t Extra =
68
2.96k
      additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);
69
2.96k
  return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
70
2.96k
}
71
72
408k
FriendDecl *CXXRecordDecl::getFirstFriend() const {
73
408k
  ExternalASTSource *Source = getParentASTContext().getExternalSource();
74
408k
  Decl *First = data().FirstFriend.get(Source);
75
408k
  return First ? 
cast<FriendDecl>(First)28.9k
:
nullptr379k
;
76
408k
}