V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
global-context.h
1 // Copyright 2017 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_GLOBAL_CONTEXT_H_
6 #define V8_TORQUE_GLOBAL_CONTEXT_H_
7 
8 #include "src/torque/declarable.h"
9 #include "src/torque/declarations.h"
10 #include "src/torque/type-oracle.h"
11 
12 namespace v8 {
13 namespace internal {
14 namespace torque {
15 
16 class GlobalContext : public ContextualClass<GlobalContext> {
17  public:
18  explicit GlobalContext(Ast ast) : verbose_(false), ast_(std::move(ast)) {
19  CurrentScope::Scope current_scope(nullptr);
20  CurrentSourcePosition::Scope current_source_position(
21  SourcePosition{CurrentSourceFile::Get(), -1, -1});
22  default_namespace_ =
23  RegisterDeclarable(base::make_unique<Namespace>("base"));
24  }
25  static Namespace* GetDefaultNamespace() { return Get().default_namespace_; }
26  template <class T>
27  T* RegisterDeclarable(std::unique_ptr<T> d) {
28  T* ptr = d.get();
29  declarables_.push_back(std::move(d));
30  return ptr;
31  }
32 
33  static const std::vector<std::unique_ptr<Declarable>>& AllDeclarables() {
34  return Get().declarables_;
35  }
36 
37  static const std::vector<Namespace*> GetNamespaces() {
38  std::vector<Namespace*> result;
39  for (auto& declarable : AllDeclarables()) {
40  if (Namespace* n = Namespace::DynamicCast(declarable.get())) {
41  result.push_back(n);
42  }
43  }
44  return result;
45  }
46 
47  static void SetVerbose() { Get().verbose_ = true; }
48  static bool verbose() { return Get().verbose_; }
49  static Ast* ast() { return &Get().ast_; }
50 
51  private:
52  bool verbose_;
53  Namespace* default_namespace_;
54  Ast ast_;
55  std::vector<std::unique_ptr<Declarable>> declarables_;
56 };
57 
58 template <class T>
59 T* RegisterDeclarable(std::unique_ptr<T> d) {
60  return GlobalContext::Get().RegisterDeclarable(std::move(d));
61 }
62 
63 } // namespace torque
64 } // namespace internal
65 } // namespace v8
66 
67 #endif // V8_TORQUE_GLOBAL_CONTEXT_H_
Definition: libplatform.h:13