Coverage Report

Created: 2020-02-15 09:57

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