1 //===- ASTImporterLookupTable.h - ASTImporter specific lookup--*- C++ -*---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ASTImporterLookupTable class which implements a
11 // lookup procedure for the import mechanism.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H
16 #define LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H
18 #include "clang/AST/DeclBase.h" // lookup_result
19 #include "clang/AST/DeclarationName.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SetVector.h"
29 // There are certain cases when normal C/C++ lookup (localUncachedLookup)
30 // does not find AST nodes. E.g.:
34 // friend void foo(); // this is never found in the DC of the TU.
37 // // The fwd decl to Foo is not found in the lookupPtr of the DC of the
38 // // translation unit decl.
39 // // Here we could find the node by doing a traverse throught the list of
40 // // the Decls in the DC, but that would not scale.
41 // struct A { struct Foo *p; };
42 // This is a severe problem because the importer decides if it has to create a
43 // new Decl or not based on the lookup results.
44 // To overcome these cases we need an importer specific lookup table which
45 // holds every node and we are not interested in any C/C++ specific visibility
46 // considerations. Simply, we must know if there is an existing Decl in a
47 // given DC. Once we found it then we can handle any visibility related tasks.
48 class ASTImporterLookupTable {
50 // We store a list of declarations for each name.
51 // And we collect these lists for each DeclContext.
52 // We could have a flat map with (DeclContext, Name) tuple as key, but a two
53 // level map seems easier to handle.
54 using DeclList = llvm::SmallSetVector<NamedDecl *, 2>;
55 using NameMap = llvm::SmallDenseMap<DeclarationName, DeclList, 4>;
56 using DCMap = llvm::DenseMap<DeclContext *, NameMap>;
58 void add(DeclContext *DC, NamedDecl *ND);
59 void remove(DeclContext *DC, NamedDecl *ND);
64 ASTImporterLookupTable(TranslationUnitDecl &TU);
65 void add(NamedDecl *ND);
66 void remove(NamedDecl *ND);
67 using LookupResult = DeclList;
68 LookupResult lookup(DeclContext *DC, DeclarationName Name) const;
69 void dump(DeclContext *DC) const;
75 #endif // LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H