Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/ASTImporterSharedState.h
Line
Count
Source
1
//===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//  This file defines the ASTImporter specific state, which may be shared
11
//  amongst several ASTImporter objects.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
16
#define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
17
18
#include "clang/AST/ASTImporterLookupTable.h"
19
#include "clang/AST/Decl.h"
20
#include "llvm/ADT/DenseMap.h"
21
// FIXME We need this because of ImportError.
22
#include "clang/AST/ASTImporter.h"
23
24
namespace clang {
25
26
class TranslationUnitDecl;
27
28
/// Importer specific state, which may be shared amongst several ASTImporter
29
/// objects.
30
class ASTImporterSharedState {
31
32
  /// Pointer to the import specific lookup table.
33
  std::unique_ptr<ASTImporterLookupTable> LookupTable;
34
35
  /// Mapping from the already-imported declarations in the "to"
36
  /// context to the error status of the import of that declaration.
37
  /// This map contains only the declarations that were not correctly
38
  /// imported. The same declaration may or may not be included in
39
  /// ImportedFromDecls. This map is updated continuously during imports and
40
  /// never cleared (like ImportedFromDecls).
41
  llvm::DenseMap<Decl *, ImportError> ImportErrors;
42
43
  // FIXME put ImportedFromDecls here!
44
  // And from that point we can better encapsulate the lookup table.
45
46
public:
47
472
  ASTImporterSharedState() = default;
48
49
1.13k
  ASTImporterSharedState(TranslationUnitDecl &ToTU) {
50
1.13k
    LookupTable = llvm::make_unique<ASTImporterLookupTable>(ToTU);
51
1.13k
  }
52
53
13.7k
  ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
54
55
9.81k
  void addDeclToLookup(Decl *D) {
56
9.81k
    if (LookupTable)
57
7.06k
      if (auto *ND = dyn_cast<NamedDecl>(D))
58
6.92k
        LookupTable->add(ND);
59
9.81k
  }
60
61
49
  void removeDeclFromLookup(Decl *D) {
62
49
    if (LookupTable)
63
49
      if (auto *ND = dyn_cast<NamedDecl>(D))
64
49
        LookupTable->remove(ND);
65
49
  }
66
67
25.3k
  llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
68
25.3k
    auto Pos = ImportErrors.find(ToD);
69
25.3k
    if (Pos != ImportErrors.end())
70
8
      return Pos->second;
71
25.3k
    else
72
25.3k
      return Optional<ImportError>();
73
25.3k
  }
74
75
173
  void setImportDeclError(Decl *To, ImportError Error) {
76
173
    ImportErrors[To] = Error;
77
173
  }
78
};
79
80
} // namespace clang
81
#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H