Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
Line
Count
Source
1
//===-- ClangExternalASTSourceCallbacks.cpp -------------------------------===//
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
#include "Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h"
10
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
11
12
#include "clang/AST/Decl.h"
13
#include "clang/AST/DeclObjC.h"
14
15
using namespace lldb_private;
16
17
char ClangExternalASTSourceCallbacks::ID;
18
19
46.1k
void ClangExternalASTSourceCallbacks::CompleteType(clang::TagDecl *tag_decl) {
20
46.1k
  m_ast.CompleteTagDecl(tag_decl);
21
46.1k
}
22
23
void ClangExternalASTSourceCallbacks::CompleteType(
24
136
    clang::ObjCInterfaceDecl *objc_decl) {
25
136
  m_ast.CompleteObjCInterfaceDecl(objc_decl);
26
136
}
27
28
bool ClangExternalASTSourceCallbacks::layoutRecordType(
29
    const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
30
    llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
31
    llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
32
    llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
33
5.18k
        &VirtualBaseOffsets) {
34
5.18k
  return m_ast.LayoutRecordType(Record, Size, Alignment, FieldOffsets,
35
5.18k
                                BaseOffsets, VirtualBaseOffsets);
36
5.18k
}
37
38
void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
39
    const clang::DeclContext *decl_ctx,
40
    llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
41
2.90k
    llvm::SmallVectorImpl<clang::Decl *> &decls) {
42
2.90k
  if (decl_ctx) {
43
2.90k
    clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
44
2.90k
        const_cast<clang::DeclContext *>(decl_ctx));
45
2.90k
    if (tag_decl)
46
2.07k
      CompleteType(tag_decl);
47
2.90k
  }
48
2.90k
}
49
50
bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
51
23.5k
    const clang::DeclContext *DC, clang::DeclarationName Name) {
52
23.5k
  llvm::SmallVector<clang::NamedDecl *, 4> decls;
53
  // Objective-C methods are not added into the LookupPtr when they originate
54
  // from an external source. SetExternalVisibleDeclsForName() adds them.
55
23.5k
  if (auto *oid = llvm::dyn_cast<clang::ObjCInterfaceDecl>(DC)) {
56
1.24k
    clang::ObjCContainerDecl::method_range noload_methods(oid->noload_decls());
57
1.24k
    for (auto *omd : noload_methods)
58
3.24k
      if (omd->getDeclName() == Name)
59
58
        decls.push_back(omd);
60
1.24k
  }
61
23.5k
  return !SetExternalVisibleDeclsForName(DC, Name, decls).empty();
62
23.5k
}
63
64
OptionalClangModuleID
65
3.80k
ClangExternalASTSourceCallbacks::RegisterModule(clang::Module *module) {
66
3.80k
  m_modules.push_back(module);
67
3.80k
  unsigned id = m_modules.size();
68
3.80k
  m_ids.insert({module, id});
69
3.80k
  return OptionalClangModuleID(id);
70
3.80k
}
71
72
llvm::Optional<clang::ASTSourceDescriptor>
73
21.8k
ClangExternalASTSourceCallbacks::getSourceDescriptor(unsigned id) {
74
21.8k
  if (clang::Module *module = getModule(id))
75
13.9k
    return {*module};
76
7.88k
  return {};
77
21.8k
}
78
79
73.7k
clang::Module *ClangExternalASTSourceCallbacks::getModule(unsigned id) {
80
73.7k
  if (id && 
id <= m_modules.size()65.8k
)
81
65.8k
    return m_modules[id - 1];
82
7.88k
  return nullptr;
83
73.7k
}
84
85
OptionalClangModuleID
86
36.3k
ClangExternalASTSourceCallbacks::GetIDForModule(clang::Module *module) {
87
36.3k
  return OptionalClangModuleID(m_ids[module]);
88
36.3k
}