clang
9.0.0
include
clang
AST
ASTImporterLookupTable.h
Go to the documentation of this file.
1
//===- ASTImporterLookupTable.h - ASTImporter specific lookup--*- 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 ASTImporterLookupTable class which implements a
10
// lookup procedure for the import mechanism.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H
15
#define LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H
16
17
#include "
clang/AST/DeclBase.h
"
// lookup_result
18
#include "
clang/AST/DeclarationName.h
"
19
#include "llvm/ADT/DenseMap.h"
20
#include "llvm/ADT/SetVector.h"
21
22
namespace
clang
{
23
24
class
ASTContext;
25
class
NamedDecl;
26
class
DeclContext;
27
28
// There are certain cases when normal C/C++ lookup (localUncachedLookup)
29
// does not find AST nodes. E.g.:
30
// Example 1:
31
// template <class T>
32
// struct X {
33
// friend void foo(); // this is never found in the DC of the TU.
34
// };
35
// Example 2:
36
// // The fwd decl to Foo is not found in the lookupPtr of the DC of the
37
// // translation unit decl.
38
// // Here we could find the node by doing a traverse throught the list of
39
// // the Decls in the DC, but that would not scale.
40
// struct A { struct Foo *p; };
41
// This is a severe problem because the importer decides if it has to create a
42
// new Decl or not based on the lookup results.
43
// To overcome these cases we need an importer specific lookup table which
44
// holds every node and we are not interested in any C/C++ specific visibility
45
// considerations. Simply, we must know if there is an existing Decl in a
46
// given DC. Once we found it then we can handle any visibility related tasks.
47
class
ASTImporterLookupTable
{
48
49
// We store a list of declarations for each name.
50
// And we collect these lists for each DeclContext.
51
// We could have a flat map with (DeclContext, Name) tuple as key, but a two
52
// level map seems easier to handle.
53
using
DeclList
=
llvm::SmallSetVector<NamedDecl *, 2>
;
54
using
NameMap = llvm::SmallDenseMap<DeclarationName, DeclList, 4>;
55
using
DCMap = llvm::DenseMap<DeclContext *, NameMap>;
56
57
void
add(
DeclContext
*DC,
NamedDecl
*ND);
58
void
remove
(
DeclContext
*DC,
NamedDecl
*ND);
59
60
DCMap LookupTable;
61
62
public
:
63
ASTImporterLookupTable
(
TranslationUnitDecl
&TU);
64
void
add(
NamedDecl
*ND);
65
void
remove
(
NamedDecl
*ND);
66
using
LookupResult
=
DeclList
;
67
LookupResult
lookup
(
DeclContext
*DC,
DeclarationName
Name)
const
;
68
void
dump
(
DeclContext
*DC)
const
;
69
void
dump
()
const
;
70
};
71
72
}
// namespace clang
73
74
#endif // LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H
DeclBase.h
clang::ASTImporterLookupTable::lookup
LookupResult lookup(DeclContext *DC, DeclarationName Name) const
Definition:
ASTImporterLookupTable.cpp:103
clang::ASTImporterLookupTable::ASTImporterLookupTable
ASTImporterLookupTable(TranslationUnitDecl &TU)
Definition:
ASTImporterLookupTable.cpp:66
llvm::SmallSetVector
Definition:
ExternalSemaSource.h:23
DeclarationName.h
clang
Dataflow Directional Tag Classes.
Definition:
CFGReachabilityAnalysis.h:21
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition:
DeclBase.h:1271
clang::ASTImporterLookupTable::dump
void dump() const
Definition:
ASTImporterLookupTable.cpp:132
clang::DeclarationName
The name of a declaration.
Definition:
DeclarationName.h:145
clang::ASTImporterLookupTable
Definition:
ASTImporterLookupTable.h:47
clang::TranslationUnitDecl
The top declaration context.
Definition:
Decl.h:107
clang::NamedDecl
This represents a decl that may have a name.
Definition:
Decl.h:248
Generated on Thu Sep 19 2019 15:18:00 for clang by
1.8.13