Coverage Report

Created: 2021-09-21 08:58

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