v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
declarations.h
Go to the documentation of this file.
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_DECLARATIONS_H_
6#define V8_TORQUE_DECLARATIONS_H_
7
8#include <memory>
9#include <optional>
10#include <string>
11
13#include "src/torque/utils.h"
14
15namespace v8::internal::torque {
16
17static constexpr const char* const kFromConstexprMacroName = "FromConstexpr";
18static constexpr const char* kMacroEndLabelName = "__macro_end";
19static constexpr const char* kBreakLabelName = "__break";
20static constexpr const char* kContinueLabelName = "__continue";
21static constexpr const char* kCatchLabelName = "__catch";
22static constexpr const char* kNextCaseLabelName = "__NextCase";
23
24template <class T>
25std::vector<T*> FilterDeclarables(const std::vector<Declarable*> list) {
26 std::vector<T*> result;
27 for (Declarable* declarable : list) {
28 if (T* t = T::DynamicCast(declarable)) {
29 result.push_back(t);
30 }
31 }
32 return result;
33}
34
35inline std::string UnwrapTNodeTypeName(const std::string& generates) {
36 if (generates.length() < 7 || generates.substr(0, 6) != "TNode<" ||
37 generates.substr(generates.length() - 1, 1) != ">") {
38 ReportError("generated type \"", generates,
39 "\" should be of the form \"TNode<...>\"");
40 }
41 return generates.substr(6, generates.length() - 7);
42}
43
45 public:
46 static std::vector<Declarable*> TryLookup(const QualifiedName& name) {
47 return CurrentScope::Get()->Lookup(name);
48 }
49
50 static std::vector<Declarable*> TryLookupShallow(const QualifiedName& name) {
51 return CurrentScope::Get()->LookupShallow(name);
52 }
53
54 template <class T>
55 static std::vector<T*> TryLookup(const QualifiedName& name) {
56 return FilterDeclarables<T>(TryLookup(name));
57 }
58
59 static std::vector<Declarable*> Lookup(const QualifiedName& name) {
60 std::vector<Declarable*> d = TryLookup(name);
61 if (d.empty()) {
62 ReportError("cannot find \"", name, "\"");
63 }
64 return d;
65 }
66
67 static std::vector<Declarable*> LookupGlobalScope(const QualifiedName& name);
68
69 static const TypeAlias* LookupTypeAlias(const QualifiedName& name);
70 static const Type* LookupType(const QualifiedName& name);
71 static const Type* LookupType(const Identifier* identifier);
72 static std::optional<const Type*> TryLookupType(const QualifiedName& name);
73 static const Type* LookupGlobalType(const QualifiedName& name);
74
76 const BuiltinPointerType* type);
77
78 static Value* LookupValue(const QualifiedName& name);
79
80 static Macro* TryLookupMacro(const std::string& name,
81 const TypeVector& types);
82 static std::optional<Builtin*> TryLookupBuiltin(const QualifiedName& name);
83
84 static std::vector<GenericCallable*> LookupGeneric(const std::string& name);
86
88 static GenericType* LookupGlobalUniqueGenericType(const std::string& name);
89 static std::optional<GenericType*> TryLookupGenericType(
90 const QualifiedName& name);
91
92 static Namespace* DeclareNamespace(const std::string& name);
93 static TypeAlias* DeclareType(const Identifier* name, const Type* type);
94
95 static TypeAlias* PredeclareTypeAlias(const Identifier* name,
96 TypeDeclaration* type,
97 bool redeclaration);
98 static TorqueMacro* CreateTorqueMacro(std::string external_name,
99 std::string readable_name,
100 bool exported_to_csa,
101 Signature signature,
102 std::optional<Statement*> body,
103 bool is_user_defined);
104 static ExternMacro* CreateExternMacro(std::string name,
105 std::string external_assembler_name,
106 Signature signature);
107 static Macro* DeclareMacro(const std::string& name, bool accessible_from_csa,
108 std::optional<std::string> external_assembler_name,
109 const Signature& signature,
110 std::optional<Statement*> body,
111 std::optional<std::string> op = {},
112 bool is_user_defined = true);
113
114 static Method* CreateMethod(AggregateType* class_type,
115 const std::string& name, Signature signature,
116 Statement* body);
117
118 static Intrinsic* CreateIntrinsic(const std::string& name,
119 const Signature& signature);
120
121 static Intrinsic* DeclareIntrinsic(const std::string& name,
122 const Signature& signature);
123
124 static Builtin* CreateBuiltin(std::string external_name,
125 std::string readable_name, Builtin::Kind kind,
126 Builtin::Flags flags, Signature signature,
127 std::optional<std::string> use_counter_name,
128 std::optional<Statement*> body);
129
130 static RuntimeFunction* DeclareRuntimeFunction(const std::string& name,
131 const Signature& signature);
132
133 static ExternConstant* DeclareExternConstant(Identifier* name,
134 const Type* type,
135 std::string value);
136 static NamespaceConstant* DeclareNamespaceConstant(Identifier* name,
137 const Type* type,
138 Expression* body);
139
140 static GenericCallable* DeclareGenericCallable(
141 const std::string& name, GenericCallableDeclaration* ast_node);
142 static GenericType* DeclareGenericType(const std::string& name,
143 GenericTypeDeclaration* ast_node);
144
145 template <class T>
146 static T* Declare(const std::string& name, T* d) {
147 CurrentScope::Get()->AddDeclarable(name, d);
148 return d;
149 }
150 template <class T>
151 static T* Declare(const std::string& name, std::unique_ptr<T> d) {
152 return CurrentScope::Get()->AddDeclarable(name,
153 RegisterDeclarable(std::move(d)));
154 }
155 static Macro* DeclareOperator(const std::string& name, Macro* m);
156
157 static std::string GetGeneratedCallableName(
158 const std::string& name, const TypeVector& specialized_types);
159};
160
161} // namespace v8::internal::torque
162
163#endif // V8_TORQUE_DECLARATIONS_H_
Builtins::Kind kind
Definition builtins.cc:40
base::Flags< Flag > Flags
Definition declarable.h:501
static Value * LookupValue(const QualifiedName &name)
static std::optional< Builtin * > TryLookupBuiltin(const QualifiedName &name)
static Intrinsic * CreateIntrinsic(const std::string &name, const Signature &signature)
static TypeAlias * DeclareType(const Identifier *name, const Type *type)
static TorqueMacro * CreateTorqueMacro(std::string external_name, std::string readable_name, bool exported_to_csa, Signature signature, std::optional< Statement * > body, bool is_user_defined)
static Macro * TryLookupMacro(const std::string &name, const TypeVector &types)
static std::vector< Declarable * > LookupGlobalScope(const QualifiedName &name)
static std::vector< T * > TryLookup(const QualifiedName &name)
static T * Declare(const std::string &name, T *d)
static Macro * DeclareMacro(const std::string &name, bool accessible_from_csa, std::optional< std::string > external_assembler_name, const Signature &signature, std::optional< Statement * > body, std::optional< std::string > op={}, bool is_user_defined=true)
static std::vector< Declarable * > TryLookupShallow(const QualifiedName &name)
static ExternConstant * DeclareExternConstant(Identifier *name, const Type *type, std::string value)
static Builtin * CreateBuiltin(std::string external_name, std::string readable_name, Builtin::Kind kind, Builtin::Flags flags, Signature signature, std::optional< std::string > use_counter_name, std::optional< Statement * > body)
static Namespace * DeclareNamespace(const std::string &name)
static Method * CreateMethod(AggregateType *class_type, const std::string &name, Signature signature, Statement *body)
static std::vector< GenericCallable * > LookupGeneric(const std::string &name)
static RuntimeFunction * DeclareRuntimeFunction(const std::string &name, const Signature &signature)
static ExternMacro * CreateExternMacro(std::string name, std::string external_assembler_name, Signature signature)
static std::vector< Declarable * > TryLookup(const QualifiedName &name)
static GenericCallable * LookupUniqueGeneric(const QualifiedName &name)
static Intrinsic * DeclareIntrinsic(const std::string &name, const Signature &signature)
static GenericCallable * DeclareGenericCallable(const std::string &name, GenericCallableDeclaration *ast_node)
static const Type * LookupGlobalType(const QualifiedName &name)
static std::string GetGeneratedCallableName(const std::string &name, const TypeVector &specialized_types)
static const TypeAlias * LookupTypeAlias(const QualifiedName &name)
static Macro * DeclareOperator(const std::string &name, Macro *m)
static GenericType * LookupGlobalUniqueGenericType(const std::string &name)
static T * Declare(const std::string &name, std::unique_ptr< T > d)
static const Type * LookupType(const QualifiedName &name)
static NamespaceConstant * DeclareNamespaceConstant(Identifier *name, const Type *type, Expression *body)
static Builtin * FindSomeInternalBuiltinWithType(const BuiltinPointerType *type)
static TypeAlias * PredeclareTypeAlias(const Identifier *name, TypeDeclaration *type, bool redeclaration)
static GenericType * LookupUniqueGenericType(const QualifiedName &name)
static std::vector< Declarable * > Lookup(const QualifiedName &name)
static std::optional< GenericType * > TryLookupGenericType(const QualifiedName &name)
static GenericType * DeclareGenericType(const std::string &name, GenericTypeDeclaration *ast_node)
static std::optional< const Type * > TryLookupType(const QualifiedName &name)
ZoneVector< RpoNumber > & result
int m
Definition mul-fft.cc:294
T * RegisterDeclarable(std::unique_ptr< T > d)
static constexpr const char * kContinueLabelName
std::string UnwrapTNodeTypeName(const std::string &generates)
static constexpr const char *const kFromConstexprMacroName
void ReportError(Args &&... args)
Definition utils.h:96
static constexpr const char * kBreakLabelName
std::vector< T * > FilterDeclarables(const std::vector< Declarable * > list)
static constexpr const char * kMacroEndLabelName
static constexpr const char * kNextCaseLabelName
std::vector< const Type * > TypeVector
Definition types.h:85
static constexpr const char * kCatchLabelName
Intrinsic
Definition v8-template.h:41
Symbol identifier