19
19
20
20
#include " indexer/index/in_memory_index.h"
21
21
#include " indexer/index/types.h"
22
+ #include " absl/container/flat_hash_map.h"
22
23
#include " clang/AST/ASTConsumer.h"
23
24
#include " clang/AST/Decl.h"
24
25
#include " clang/AST/DeclTemplate.h"
28
29
#include " clang/AST/Type.h"
29
30
#include " clang/Basic/SourceLocation.h"
30
31
#include " clang/Frontend/CompilerInstance.h"
32
+ #include " clang/Sema/Sema.h"
31
33
32
34
namespace oss_fuzz {
33
35
namespace indexer {
@@ -36,9 +38,12 @@ namespace indexer {
36
38
// instead.
37
39
class AstVisitor : public clang ::RecursiveASTVisitor<AstVisitor> {
38
40
public:
39
- AstVisitor (InMemoryIndex &index, clang::ASTContext &context,
40
- clang::CompilerInstance &compiler)
41
- : index_(index), context_(context), compiler_(compiler) {}
41
+ AstVisitor (InMemoryIndex& index, clang::ASTContext& context,
42
+ clang::CompilerInstance& compiler)
43
+ : index_(index),
44
+ context_ (context),
45
+ compiler_(compiler),
46
+ sema_(compiler.getSema()) {}
42
47
43
48
bool shouldVisitImplicitCode () const { return true ; }
44
49
bool shouldVisitTemplateInstantiations () const { return true ; }
@@ -69,11 +74,18 @@ class AstVisitor : public clang::RecursiveASTVisitor<AstVisitor> {
69
74
LocationId GetLocationId (clang::SourceLocation start,
70
75
clang::SourceLocation end);
71
76
LocationId GetLocationId (const clang::Decl *decl);
77
+ std::optional<Entity> GetEntityForDecl (
78
+ const clang::Decl* decl, bool for_reference = false ,
79
+ LocationId location_id = kInvalidLocationId );
72
80
EntityId GetEntityIdForDecl (const clang::Decl *decl,
73
- LocationId location_id = kInvalidLocationId ,
74
81
bool for_reference = false );
75
- std::optional<EntityId> GetEntityIdForCanonicalDecl (
76
- const clang::Decl *canonical_decl, const clang::Decl *original_decl);
82
+ std::optional<SubstituteRelationship> GetTemplateSubstituteRelationship (
83
+ const clang::Decl* template_decl, const clang::Decl* original_decl);
84
+ void SynthesizeInheritedMemberEntities (
85
+ const clang::CXXRecordDecl* class_decl);
86
+ void AddSyntheticMemberReference (const clang::CXXRecordDecl* child_class,
87
+ const clang::ValueDecl* inherited_member,
88
+ const clang::SourceRange& range);
77
89
void AddTypeReferencesFromLocation (LocationId location_id,
78
90
const clang::Type *type,
79
91
bool outermost_type = true );
@@ -84,9 +96,23 @@ class AstVisitor : public clang::RecursiveASTVisitor<AstVisitor> {
84
96
void AddTypeReferencesForSourceRange (const clang::SourceRange &range,
85
97
const clang::Type *type);
86
98
99
+ void AddVirtualMethodLinks (const clang::CXXMethodDecl* method_decl,
100
+ EntityId child_id);
101
+ void AddSynthesizedVirtualMethodLinks (
102
+ const clang::CXXMethodDecl* prototype_method_decl,
103
+ const clang::CXXRecordDecl* child_class_decl, EntityId child_id);
104
+
87
105
InMemoryIndex &index_;
88
106
clang::ASTContext &context_;
89
107
clang::CompilerInstance &compiler_;
108
+ clang::Sema& sema_;
109
+
110
+ struct CachedEntityId {
111
+ EntityId entity_id;
112
+ bool for_reference_only;
113
+ };
114
+
115
+ absl::flat_hash_map<const clang::Decl*, CachedEntityId> decl_to_entity_id_;
90
116
};
91
117
} // namespace indexer
92
118
} // namespace oss_fuzz
0 commit comments