Commit 4d70d33c authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[cleanup] Move GlobalContext constructor to new .cc file

This CL creates global-context.cc and moves the GlobalContext
constructor impl to this new file. Preparatory refactoring for import
syntax.

This CL also removes one unused static method from GlobalContext
and changes two use-sites where Get() was used together with a static
accessor.

Drive-by: "Include what you use" for global-context.h

Bug: v8:9183
Change-Id: Iafd877d03af9ad65b1c99ebd9743be64192f45c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1649790
Commit-Queue: Simon Zünd <szuend@chromium.org>
Auto-Submit: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62081}
parent b69a48e1
......@@ -3305,6 +3305,7 @@ v8_source_set("torque_base") {
"src/torque/declarations.h",
"src/torque/earley-parser.cc",
"src/torque/earley-parser.h",
"src/torque/global-context.cc",
"src/torque/global-context.h",
"src/torque/implementation-visitor.cc",
"src/torque/implementation-visitor.h",
......
// Copyright 2019 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.
#include "src/torque/global-context.h"
namespace v8 {
namespace internal {
namespace torque {
GlobalContext::GlobalContext(Ast ast)
: collect_language_server_data_(false),
force_assert_statements_(false),
ast_(std::move(ast)) {
CurrentScope::Scope current_scope(nullptr);
CurrentSourcePosition::Scope current_source_position(
SourcePosition{CurrentSourceFile::Get(), {-1, -1}, {-1, -1}});
default_namespace_ =
RegisterDeclarable(base::make_unique<Namespace>(kBaseNamespaceName));
}
} // namespace torque
} // namespace internal
} // namespace v8
......@@ -7,9 +7,9 @@
#include <map>
#include "src/torque/ast.h"
#include "src/torque/contextual.h"
#include "src/torque/declarable.h"
#include "src/torque/declarations.h"
#include "src/torque/type-oracle.h"
namespace v8 {
namespace internal {
......@@ -19,16 +19,8 @@ class GlobalContext : public ContextualClass<GlobalContext> {
public:
GlobalContext(GlobalContext&&) V8_NOEXCEPT = default;
GlobalContext& operator=(GlobalContext&&) V8_NOEXCEPT = default;
explicit GlobalContext(Ast ast)
: collect_language_server_data_(false),
force_assert_statements_(false),
ast_(std::move(ast)) {
CurrentScope::Scope current_scope(nullptr);
CurrentSourcePosition::Scope current_source_position(
SourcePosition{CurrentSourceFile::Get(), {-1, -1}, {-1, -1}});
default_namespace_ =
RegisterDeclarable(base::make_unique<Namespace>(kBaseNamespaceName));
}
explicit GlobalContext(Ast ast);
static Namespace* GetDefaultNamespace() { return Get().default_namespace_; }
template <class T>
T* RegisterDeclarable(std::unique_ptr<T> d) {
......@@ -41,16 +33,6 @@ class GlobalContext : public ContextualClass<GlobalContext> {
return Get().declarables_;
}
static const std::vector<Namespace*> GetNamespaces() {
std::vector<Namespace*> result;
for (auto& declarable : AllDeclarables()) {
if (Namespace* n = Namespace::DynamicCast(declarable.get())) {
result.push_back(n);
}
}
return result;
}
static void RegisterClass(const TypeAlias* alias) {
DCHECK(alias->ParentScope()->IsNamespace());
Get().classes_.push_back(alias);
......
......@@ -10,6 +10,7 @@
#include "src/base/macros.h"
#include "src/torque/ast.h"
#include "src/torque/cfg.h"
#include "src/torque/declarations.h"
#include "src/torque/global-context.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
......
......@@ -13,6 +13,7 @@
#include "src/torque/declarable.h"
#include "src/torque/global-context.h"
#include "src/torque/source-positions.h"
#include "src/torque/type-oracle.h"
namespace v8 {
namespace internal {
......
......@@ -57,11 +57,11 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
// Two-step process of predeclaration + resolution allows to resolve type
// declarations independent of the order they are given.
PredeclarationVisitor::Predeclare(GlobalContext::Get().ast());
PredeclarationVisitor::Predeclare(GlobalContext::ast());
PredeclarationVisitor::ResolvePredeclarations();
// Process other declarations.
DeclarationVisitor::Visit(GlobalContext::Get().ast());
DeclarationVisitor::Visit(GlobalContext::ast());
// A class types' fields are resolved here, which allows two class fields to
// mutually refer to each others.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment