blob: bbfbb686ef412792155c6186ba2e78a76cd4af8c (
plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TORQUE_GLOBAL_CONTEXT_H_
#define V8_TORQUE_GLOBAL_CONTEXT_H_
#include <map>
#include <memory>
#include "src/common/globals.h"
#include "src/torque/ast.h"
#include "src/torque/contextual.h"
#include "src/torque/declarable.h"
namespace v8 {
namespace internal {
namespace torque {
class GlobalContext : public ContextualClass<GlobalContext> {
public:
GlobalContext(GlobalContext&&) V8_NOEXCEPT = default;
GlobalContext& operator=(GlobalContext&&) V8_NOEXCEPT = default;
explicit GlobalContext(Ast ast);
static Namespace* GetDefaultNamespace() { return Get().default_namespace_; }
template <class T>
T* RegisterDeclarable(std::unique_ptr<T> d) {
T* ptr = d.get();
declarables_.push_back(std::move(d));
return ptr;
}
static const std::vector<std::unique_ptr<Declarable>>& AllDeclarables() {
return Get().declarables_;
}
static void AddCppInclude(std::string include_path) {
Get().cpp_includes_.insert(std::move(include_path));
}
static const std::set<std::string>& CppIncludes() {
return Get().cpp_includes_;
}
static void SetCollectLanguageServerData() {
Get().collect_language_server_data_ = true;
}
static bool collect_language_server_data() {
return Get().collect_language_server_data_;
}
static void SetForceAssertStatements() {
Get().force_assert_statements_ = true;
}
static bool force_assert_statements() {
return Get().force_assert_statements_;
}
static Ast* ast() { return &Get().ast_; }
static std::string MakeUniqueName(const std::string& base) {
return base + "_" + std::to_string(Get().fresh_ids_[base]++);
}
struct PerFileStreams {
std::stringstream csa_headerfile;
std::stringstream csa_ccfile;
};
static PerFileStreams& GeneratedPerFile(SourceId file) {
return Get().generated_per_file_[file];
}
private:
bool collect_language_server_data_;
bool force_assert_statements_;
Namespace* default_namespace_;
Ast ast_;
std::vector<std::unique_ptr<Declarable>> declarables_;
std::set<std::string> cpp_includes_;
std::map<SourceId, PerFileStreams> generated_per_file_;
std::map<std::string, size_t> fresh_ids_;
friend class LanguageServerData;
};
template <class T>
T* RegisterDeclarable(std::unique_ptr<T> d) {
return GlobalContext::Get().RegisterDeclarable(std::move(d));
}
class TargetArchitecture : public ContextualClass<TargetArchitecture> {
public:
explicit TargetArchitecture(bool force_32bit);
static size_t TaggedSize() { return Get().tagged_size_; }
static size_t RawPtrSize() { return Get().raw_ptr_size_; }
static size_t MaxHeapAlignment() { return TaggedSize(); }
static bool ArePointersCompressed() { return TaggedSize() < RawPtrSize(); }
private:
const size_t tagged_size_;
const size_t raw_ptr_size_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_GLOBAL_CONTEXT_H_
|