blob: 6c517812dcbd1bef25a2f61df1a0478c2e80bcf1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the ASTImporter specific state, which may be shared
// amongst several ASTImporter objects.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
#define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
#include "clang/AST/ASTImporterLookupTable.h"
#include "clang/AST/Decl.h"
#include "llvm/ADT/DenseMap.h"
// FIXME We need this because of ImportError.
#include "clang/AST/ASTImporter.h"
namespace clang {
class TranslationUnitDecl;
/// Importer specific state, which may be shared amongst several ASTImporter
/// objects.
class ASTImporterSharedState {
/// Pointer to the import specific lookup table.
std::unique_ptr<ASTImporterLookupTable> LookupTable;
/// Mapping from the already-imported declarations in the "to"
/// context to the error status of the import of that declaration.
/// This map contains only the declarations that were not correctly
/// imported. The same declaration may or may not be included in
/// ImportedFromDecls. This map is updated continuously during imports and
/// never cleared (like ImportedFromDecls).
llvm::DenseMap<Decl *, ImportError> ImportErrors;
// FIXME put ImportedFromDecls here!
// And from that point we can better encapsulate the lookup table.
public:
ASTImporterSharedState() = default;
ASTImporterSharedState(TranslationUnitDecl &ToTU) {
LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
}
ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
void addDeclToLookup(Decl *D) {
if (LookupTable)
if (auto *ND = dyn_cast<NamedDecl>(D))
LookupTable->add(ND);
}
void removeDeclFromLookup(Decl *D) {
if (LookupTable)
if (auto *ND = dyn_cast<NamedDecl>(D))
LookupTable->remove(ND);
}
llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
auto Pos = ImportErrors.find(ToD);
if (Pos != ImportErrors.end())
return Pos->second;
else
return Optional<ImportError>();
}
void setImportDeclError(Decl *To, ImportError Error) {
ImportErrors[To] = Error;
}
};
} // namespace clang
#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|