blob: d3063924469b20bc9ebe94c1b814f85004d711f6 (
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
|
// 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_FILE_VISITOR_H_
#define V8_TORQUE_FILE_VISITOR_H_
#include <deque>
#include <string>
#include "src/torque/ast.h"
#include "src/torque/global-context.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
class FileVisitor {
public:
explicit FileVisitor(GlobalContext& global_context)
: global_context_(global_context),
declarations_(global_context.declarations()),
module_(global_context.GetDefaultModule()) {}
TypeVector GetTypeVector(const std::vector<TypeExpression*>& v) {
TypeVector result;
for (TypeExpression* t : v) {
result.push_back(declarations()->GetType(t));
}
return result;
}
Ast* ast() { return global_context_.ast(); }
Declarations* declarations() { return global_context_.declarations(); }
void DrainSpecializationQueue();
class ScopedModuleActivator {
public:
ScopedModuleActivator(FileVisitor* visitor, Module* module)
: visitor_(visitor), saved_module_(visitor->CurrentModule()) {
visitor->module_ = module;
}
~ScopedModuleActivator() { visitor_->module_ = saved_module_; }
private:
FileVisitor* visitor_;
Module* saved_module_;
};
protected:
static constexpr const char* kReturnValueVariable = "_return";
static constexpr const char* kDoneLabelName = "_done";
static constexpr const char* kForIndexValueVariable = "_for_index";
Module* CurrentModule() const { return module_; }
friend class ScopedModuleActivator;
std::string GetParameterVariableFromName(const std::string& name) {
return std::string("p_") + name;
}
Signature MakeSignature(const CallableNodeSignature* signature);
Signature MakeSignatureFromReturnType(TypeExpression* return_type);
struct PendingSpecialization {
SpecializationKey key;
CallableNode* callable;
const CallableNodeSignature* signature;
base::Optional<Statement*> body;
SourcePosition request_position;
};
void QueueGenericSpecialization(const SpecializationKey& key,
CallableNode* callable,
const CallableNodeSignature* signature,
base::Optional<Statement*> body);
void SpecializeGeneric(const PendingSpecialization& specialization);
virtual void Specialize(const SpecializationKey&, CallableNode* callable,
const CallableNodeSignature* signature,
Statement* body) = 0;
GlobalContext& global_context_;
Declarations* declarations_;
std::deque<PendingSpecialization> pending_specializations_;
std::set<SpecializationKey> completed_specializations_;
Callable* current_callable_;
Module* module_;
};
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_FILE_VISITOR_H_
|