v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
kythe-data.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_TORQUE_KYTHE_DATA_H_
6#define V8_TORQUE_KYTHE_DATA_H_
7
9#include "src/torque/ast.h"
12
13namespace v8 {
14namespace internal {
15namespace torque {
16
18 std::string file_path;
19 uint64_t start_offset;
20 uint64_t end_offset;
21};
22
23using kythe_entity_t = uint64_t;
24
26 public:
27 enum class Kind {
33 Type,
34 };
35
36 virtual ~KytheConsumer() = 0;
37
38 virtual kythe_entity_t AddDefinition(Kind kind, std::string name,
39 KythePosition pos) = 0;
40
41 virtual void AddUse(Kind kind, kythe_entity_t entity,
42 KythePosition use_pos) = 0;
43 virtual void AddCall(Kind kind, kythe_entity_t caller_entity,
44 KythePosition call_pos,
45 kythe_entity_t callee_entity) = 0;
46};
47inline KytheConsumer::~KytheConsumer() = default;
48
49class KytheData : public base::ContextualClass<KytheData> {
50 public:
51 KytheData() = default;
52
53 static void SetConsumer(KytheConsumer* consumer) {
54 Get().consumer_ = consumer;
55 }
56
57 // Constants
59 const Value* constant);
60 V8_EXPORT_PRIVATE static void AddConstantUse(SourcePosition use_position,
61 const Value* constant);
62 // Callables
64 Callable* callable);
65 V8_EXPORT_PRIVATE static void AddCall(Callable* caller,
66 SourcePosition call_position,
67 Callable* callee);
68 // Class fields
70 const Field* field);
71 V8_EXPORT_PRIVATE static void AddClassFieldUse(SourcePosition use_position,
72 const Field* field);
73 // Bindings
75 Binding<LocalValue>* binding);
77 Binding<LocalLabel>* binding);
78 V8_EXPORT_PRIVATE static void AddBindingUse(SourcePosition use_position,
79 Binding<LocalValue>* binding);
80 V8_EXPORT_PRIVATE static void AddBindingUse(SourcePosition use_position,
81 Binding<LocalLabel>* binding);
82
83 // Types
85 const Declarable* type_decl);
86 V8_EXPORT_PRIVATE static void AddTypeUse(SourcePosition use_position,
87 const Declarable* type_decl);
88
89 private:
91 uint64_t binding_index, const std::string& name,
92 const SourcePosition& ident_pos);
93
95 std::unordered_map<const Value*, kythe_entity_t> constants_;
96 std::unordered_map<Callable*, kythe_entity_t> callables_;
97
98 std::unordered_map<const Field*, std::set<SourcePosition>> field_uses_;
99 std::unordered_map<uint64_t, kythe_entity_t> local_bindings_;
100 std::unordered_map<const Declarable*, kythe_entity_t> types_;
101 std::unordered_map<const Field*, kythe_entity_t> class_fields_;
102};
103
104} // namespace torque
105} // namespace internal
106} // namespace v8
107
108#endif // V8_TORQUE_KYTHE_DATA_H_
Builtins::Kind kind
Definition builtins.cc:40
SourcePosition pos
static VarType & Get()
Definition contextual.h:64
virtual void AddUse(Kind kind, kythe_entity_t entity, KythePosition use_pos)=0
virtual kythe_entity_t AddDefinition(Kind kind, std::string name, KythePosition pos)=0
virtual void AddCall(Kind kind, kythe_entity_t caller_entity, KythePosition call_pos, kythe_entity_t callee_entity)=0
static V8_EXPORT_PRIVATE kythe_entity_t AddConstantDefinition(const Value *constant)
Definition kythe-data.cc:28
static kythe_entity_t AddBindingDefinitionImpl(uint64_t binding_index, const std::string &name, const SourcePosition &ident_pos)
std::unordered_map< uint64_t, kythe_entity_t > local_bindings_
Definition kythe-data.h:99
static void SetConsumer(KytheConsumer *consumer)
Definition kythe-data.h:53
std::unordered_map< const Field *, kythe_entity_t > class_fields_
Definition kythe-data.h:101
std::unordered_map< const Value *, kythe_entity_t > constants_
Definition kythe-data.h:95
static V8_EXPORT_PRIVATE void AddBindingUse(SourcePosition use_position, Binding< LocalValue > *binding)
static V8_EXPORT_PRIVATE kythe_entity_t AddBindingDefinition(Binding< LocalValue > *binding)
static V8_EXPORT_PRIVATE kythe_entity_t AddFunctionDefinition(Callable *callable)
Definition kythe-data.cc:53
std::unordered_map< const Declarable *, kythe_entity_t > types_
Definition kythe-data.h:100
static V8_EXPORT_PRIVATE kythe_entity_t AddTypeDefinition(const Declarable *type_decl)
std::unordered_map< const Field *, std::set< SourcePosition > > field_uses_
Definition kythe-data.h:98
static V8_EXPORT_PRIVATE void AddClassFieldUse(SourcePosition use_position, const Field *field)
Definition kythe-data.cc:99
std::unordered_map< Callable *, kythe_entity_t > callables_
Definition kythe-data.h:96
static V8_EXPORT_PRIVATE kythe_entity_t AddClassFieldDefinition(const Field *field)
Definition kythe-data.cc:85
static V8_EXPORT_PRIVATE void AddTypeUse(SourcePosition use_position, const Declarable *type_decl)
static V8_EXPORT_PRIVATE void AddConstantUse(SourcePosition use_position, const Value *constant)
Definition kythe-data.cc:43
static V8_EXPORT_PRIVATE void AddCall(Callable *caller, SourcePosition call_position, Callable *callee)
Definition kythe-data.cc:68
uint64_t kythe_entity_t
Definition kythe-data.h:23
#define V8_EXPORT_PRIVATE
Definition macros.h:460