Coverage Report

Created: 2023-09-30 09:22

/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
#include <optional>
15
16
using namespace lldb_private;
17
18
char ClangExternalASTSourceCallbacks::ID;
19
20
31.5k
void ClangExternalASTSourceCallbacks::CompleteType(clang::TagDecl *tag_decl) {
21
31.5k
  m_ast.CompleteTagDecl(tag_decl);
22
31.5k
}
23
24
void ClangExternalASTSourceCallbacks::CompleteType(
25
17
    clang::ObjCInterfaceDecl *objc_decl) {
26
17
  m_ast.CompleteObjCInterfaceDecl(objc_decl);
27
17
}
28
29
bool ClangExternalASTSourceCallbacks::layoutRecordType(
30
    const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
31
    llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
32
    llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
33
    llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
34
6.03k
        &VirtualBaseOffsets) {
35
6.03k
  return m_ast.LayoutRecordType(Record, Size, Alignment, FieldOffsets,
36
6.03k
                                BaseOffsets, VirtualBaseOffsets);
37
6.03k
}
38
39
void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
40
    const clang::DeclContext *decl_ctx,
41
    llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
42
502
    llvm::SmallVectorImpl<clang::Decl *> &decls) {
43
502
  if (decl_ctx) {
44
502
    clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
45
502
        const_cast<clang::DeclContext *>(decl_ctx));
46
502
    if (tag_decl)
47
60
      CompleteType(tag_decl);
48
502
  }
49
502
}
50
51
bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
52
2.04k
    const clang::DeclContext *DC, clang::DeclarationName Name) {
53
2.04k
  llvm::SmallVector<clang::NamedDecl *, 4> decls;
54
  // Objective-C methods are not added into the LookupPtr when they originate
55
  // from an external source. SetExternalVisibleDeclsForName() adds them.
56
2.04k
  if (auto *oid = llvm::dyn_cast<clang::ObjCInterfaceDecl>(DC)) {
57
123
    clang::ObjCContainerDecl::method_range noload_methods(oid->noload_decls());
58
123
    for (auto *omd : noload_methods)
59
187
      if (omd->getDeclName() == Name)
60
43
        decls.push_back(omd);
61
123
  }
62
2.04k
  return !SetExternalVisibleDeclsForName(DC, Name, decls).empty();
63
2.04k
}
64
65
OptionalClangModuleID
66
109
ClangExternalASTSourceCallbacks::RegisterModule(clang::Module *module) {
67
109
  m_modules.push_back(module);
68
109
  unsigned id = m_modules.size();
69
109
  m_ids.insert({module, id});
70
109
  return OptionalClangModuleID(id);
71
109
}
72
73
std::optional<clang::ASTSourceDescriptor>
74
377
ClangExternalASTSourceCallbacks::getSourceDescriptor(unsigned id) {
75
377
  if (clang::Module *module = getModule(id))
76
119
    return {*module};
77
258
  return {};
78
377
}
79
80
840
clang::Module *ClangExternalASTSourceCallbacks::getModule(unsigned id) {
81
840
  if (id && 
id <= m_modules.size()582
)
82
582
    return m_modules[id - 1];
83
258
  return nullptr;
84
840
}
85
86
OptionalClangModuleID
87
547
ClangExternalASTSourceCallbacks::GetIDForModule(clang::Module *module) {
88
547
  return OptionalClangModuleID(m_ids[module]);
89
547
}