Coverage Report

Created: 2022-05-17 06:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ASTImporterSharedState.h
Line
Count
Source
1
//===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
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 defines the ASTImporter specific state, which may be shared
10
//  amongst several ASTImporter objects.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
15
#define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
16
17
#include "clang/AST/ASTImportError.h"
18
#include "clang/AST/ASTImporterLookupTable.h"
19
#include "clang/AST/Decl.h"
20
#include "llvm/ADT/DenseMap.h"
21
22
namespace clang {
23
24
class TranslationUnitDecl;
25
26
/// Importer specific state, which may be shared amongst several ASTImporter
27
/// objects.
28
class ASTImporterSharedState {
29
30
  /// Pointer to the import specific lookup table.
31
  std::unique_ptr<ASTImporterLookupTable> LookupTable;
32
33
  /// Mapping from the already-imported declarations in the "to"
34
  /// context to the error status of the import of that declaration.
35
  /// This map contains only the declarations that were not correctly
36
  /// imported. The same declaration may or may not be included in
37
  /// ImportedFromDecls. This map is updated continuously during imports and
38
  /// never cleared (like ImportedFromDecls).
39
  llvm::DenseMap<Decl *, ImportError> ImportErrors;
40
41
  // FIXME put ImportedFromDecls here!
42
  // And from that point we can better encapsulate the lookup table.
43
44
public:
45
19.4k
  ASTImporterSharedState() = default;
46
47
2.32k
  ASTImporterSharedState(TranslationUnitDecl &ToTU) {
48
2.32k
    LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
49
2.32k
  }
50
51
3.80M
  ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
52
53
4.83M
  void addDeclToLookup(Decl *D) {
54
4.83M
    if (LookupTable)
55
16.0k
      if (auto *ND = dyn_cast<NamedDecl>(D))
56
15.8k
        LookupTable->add(ND);
57
4.83M
  }
58
59
120
  void removeDeclFromLookup(Decl *D) {
60
120
    if (LookupTable)
61
89
      if (auto *ND = dyn_cast<NamedDecl>(D))
62
89
        LookupTable->remove(ND);
63
120
  }
64
65
22.3M
  llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
66
22.3M
    auto Pos = ImportErrors.find(ToD);
67
22.3M
    if (Pos != ImportErrors.end())
68
8
      return Pos->second;
69
22.3M
    else
70
22.3M
      return Optional<ImportError>();
71
22.3M
  }
72
73
292
  void setImportDeclError(Decl *To, ImportError Error) {
74
292
    ImportErrors[To] = Error;
75
292
  }
76
};
77
78
} // namespace clang
79
#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H