Coverage Report

Created: 2022-01-18 06:27

/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
11.3k
FriendDecl *FriendDecl::getNextFriendSlowCase() {
30
11.3k
  return cast_or_null<FriendDecl>(
31
11.3k
                           NextFriend.get(getASTContext().getExternalSource()));
32
11.3k
}
33
34
FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
35
                               SourceLocation L,
36
                               FriendUnion Friend,
37
                               SourceLocation FriendL,
38
83.5k
                          ArrayRef<TemplateParameterList *> FriendTypeTPLists) {
39
83.5k
#ifndef NDEBUG
40
83.5k
  if (Friend.is<NamedDecl *>()) {
41
66.3k
    const auto *D = Friend.get<NamedDecl*>();
42
66.3k
    assert(isa<FunctionDecl>(D) ||
43
66.3k
           isa<CXXRecordDecl>(D) ||
44
66.3k
           isa<FunctionTemplateDecl>(D) ||
45
66.3k
           isa<ClassTemplateDecl>(D));
46
47
    // As a temporary hack, we permit template instantiation to point
48
    // to the original declaration when instantiating members.
49
0
    assert(D->getFriendObjectKind() ||
50
66.3k
           (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
51
    // These template parameters are for friend types only.
52
0
    assert(FriendTypeTPLists.empty());
53
66.3k
  }
54
0
#endif
55
56
0
  std::size_t Extra =
57
83.5k
      FriendDecl::additionalSizeToAlloc<TemplateParameterList *>(
58
83.5k
          FriendTypeTPLists.size());
59
83.5k
  auto *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
60
83.5k
                                           FriendTypeTPLists);
61
83.5k
  cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
62
83.5k
  return FD;
63
83.5k
}
64
65
FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
66
17.4k
                                           unsigned FriendTypeNumTPLists) {
67
17.4k
  std::size_t Extra =
68
17.4k
      additionalSizeToAlloc<TemplateParameterList *>(FriendTypeNumTPLists);
69
17.4k
  return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
70
17.4k
}
71
72
728k
FriendDecl *CXXRecordDecl::getFirstFriend() const {
73
728k
  ExternalASTSource *Source = getParentASTContext().getExternalSource();
74
728k
  Decl *First = data().FirstFriend.get(Source);
75
728k
  return First ? 
cast<FriendDecl>(First)60.1k
:
nullptr668k
;
76
728k
}