5#ifndef V8_TORQUE_AST_H_
6#define V8_TORQUE_AST_H_
24#define AST_EXPRESSION_NODE_KIND_LIST(V) \
26 V(CallMethodExpression) \
27 V(IntrinsicCallExpression) \
29 V(LogicalOrExpression) \
30 V(LogicalAndExpression) \
32 V(ConditionalExpression) \
33 V(IdentifierExpression) \
34 V(StringLiteralExpression) \
35 V(IntegerLiteralExpression) \
36 V(FloatingPointLiteralExpression) \
37 V(FieldAccessExpression) \
38 V(ElementAccessExpression) \
39 V(DereferenceExpression) \
40 V(AssignmentExpression) \
41 V(IncrementDecrementExpression) \
43 V(AssumeTypeImpossibleExpression) \
44 V(StatementExpression) \
47#define AST_TYPE_EXPRESSION_NODE_KIND_LIST(V) \
48 V(BasicTypeExpression) \
49 V(FunctionTypeExpression) \
50 V(PrecomputedTypeExpression) \
51 V(UnionTypeExpression)
53#define AST_STATEMENT_NODE_KIND_LIST(V) \
55 V(ExpressionStatement) \
60 V(ContinueStatement) \
64 V(TailCallStatement) \
65 V(VarDeclarationStatement) \
68#define AST_TYPE_DECLARATION_NODE_KIND_LIST(V) \
69 V(AbstractTypeDeclaration) \
70 V(TypeAliasDeclaration) \
71 V(BitFieldStructDeclaration) \
75#define AST_DECLARATION_NODE_KIND_LIST(V) \
76 AST_TYPE_DECLARATION_NODE_KIND_LIST(V) \
77 V(GenericCallableDeclaration) \
78 V(GenericTypeDeclaration) \
79 V(SpecializationDeclaration) \
80 V(ExternConstDeclaration) \
81 V(NamespaceDeclaration) \
83 V(CppIncludeDeclaration) \
84 V(TorqueMacroDeclaration) \
85 V(TorqueBuiltinDeclaration) \
86 V(ExternalMacroDeclaration) \
87 V(ExternalBuiltinDeclaration) \
88 V(ExternalRuntimeDeclaration) \
89 V(IntrinsicDeclaration)
91#define AST_NODE_KIND_LIST(V) \
92 AST_EXPRESSION_NODE_KIND_LIST(V) \
93 AST_TYPE_EXPRESSION_NODE_KIND_LIST(V) \
94 AST_STATEMENT_NODE_KIND_LIST(V) \
95 AST_DECLARATION_NODE_KIND_LIST(V) \
103#define ENUM_ITEM(name) k##name,
121#define DEFINE_AST_NODE_LEAF_BOILERPLATE(T) \
122 static const Kind kKind = Kind::k##T; \
123 static T* cast(AstNode* node) { \
124 DCHECK_EQ(node->kind, kKind); \
125 return static_cast<T*>(node); \
127 static T* DynamicCast(AstNode* node) { \
128 if (!node) return nullptr; \
129 if (node->kind != kKind) return nullptr; \
130 return static_cast<T*>(node); \
134#define DEFINE_AST_NODE_INNER_BOILERPLATE(T) \
135 static T* cast(AstNode* node) { \
136 DCHECK(AstNodeClassCheck::IsInstanceOf<T>(node)); \
137 return static_cast<T*>(node); \
139 static T* DynamicCast(AstNode* node) { \
140 if (!node) return nullptr; \
141 if (!AstNodeClassCheck::IsInstanceOf<T>(node)) return nullptr; \
142 return static_cast<T*>(node); \
204 std::vector<Entry>
entries = {})
206 name(
std::move(name)),
223 nodes_.push_back(std::move(node));
232 std::string name = description.
name;
234 auto f = [&](
const auto& d) {
return d.name ==
name; };
248 std::vector<std::unique_ptr<AstNode>>
nodes_;
264 return os <<
id->value;
269 return a->value < b->
value;
283 std::vector<TypeExpression*>
args = {})
304 arguments(
std::move(arguments)) {}
307 for (
auto argument : arguments) {
308 argument->VisitAllSubExpressions(
callback);
327 arguments(
std::move(arguments)),
331 target->VisitAllSubExpressions(
callback);
333 for (
auto argument : arguments) {
334 argument->VisitAllSubExpressions(
callback);
352 arguments(
std::move(arguments)),
357 for (
auto argument : arguments) {
358 argument->VisitAllSubExpressions(
callback);
383 initializer.expression->VisitAllSubExpressions(
callback);
399 right->VisitAllSubExpressions(
callback);
414 right->VisitAllSubExpressions(
callback);
499 array->VisitAllSubExpressions(
callback);
500 index->VisitAllSubExpressions(
callback);
515 object->VisitAllSubExpressions(
callback);
550 value->VisitAllSubExpressions(
callback);
555 std::optional<std::string>
op;
588 expression(expression) {}
591 expression->VisitAllSubExpressions(
callback);
612 initializer.expression->VisitAllSubExpressions(
callback);
636 return std::vector<TypeExpression*>(
types.begin(),
747 expression(expression),
748 source(
std::move(source)) {}
773 std::optional<TypeExpression*>
type;
803 test(
std::move(test)),
810 std::optional<Expression*>
test;
941 std::optional<AnnotationParameter>
param;
955 std::optional<ClassFieldIndexInfo>
index;
975 transitioning(transitioning),
999 Error(
"Cannot use \"js-implicit\" with macros, use \"implicit\" instead.")
1000 .Position(parameters.implicit_kind_pos);
1003 std::optional<std::string>
op;
1009 std::
string external_assembler_name,
1015 std::move(parameters), return_type,
std::move(labels)),
1016 external_assembler_name(
std::move(external_assembler_name)) {}
1026 if (parameters.implicit_kind != ImplicitKind::kNoImplicit) {
1027 Error(
"Intinsics cannot have implicit parameters.");
1040 std::move(parameters), return_type,
std::move(labels)),
1041 export_to_csa(export_to_csa),
1050 bool javascript_linkage,
bool transitioning,
1054 std::move(parameters), return_type, {}),
1055 javascript_linkage(javascript_linkage) {
1056 if (parameters.implicit_kind == ImplicitKind::kJSImplicit &&
1057 !javascript_linkage) {
1059 "\"js-implicit\" is for implicit parameters passed according to the "
1060 "JavaScript calling convention. Use \"implicit\" instead.");
1062 if (parameters.implicit_kind == ImplicitKind::kImplicit &&
1063 javascript_linkage) {
1065 "The JavaScript calling convention implicitly passes a fixed set of "
1066 "values. Use \"js-implicit\" to refer to those.")
1067 .Position(parameters.implicit_kind_pos);
1080 std::move(parameters), return_type) {}
1089 bool has_custom_interface_descriptor,
1090 std::optional<
std::
string> use_counter_name,
1093 std::move(parameters), return_type),
1094 has_custom_interface_descriptor(has_custom_interface_descriptor),
1095 use_counter_name(use_counter_name),
1118 expression(expression) {}
1143 generic_parameters(
std::move(generic_parameters)),
1156 generic_parameters(
std::move(generic_parameters)),
1172 std::move(parameters), return_type,
1174 generic_parameters(
std::move(generic_parameters)),
1200 methods(
std::move(methods)),
1201 fields(
std::move(fields)) {}
1214 fields(
std::move(fields)) {}
1224 methods(
std::move(methods)),
1225 fields(
std::move(fields)) {}
1240 generates(
std::move(generates)),
1241 methods(
std::move(methods)),
1242 fields(
std::move(fields)),
1243 instance_type_constraints(
std::move(instance_type_constraints)) {}
1259#define ENUM_ITEM(name) \
1260 case AstNode::Kind::k##name: \
1261 return std::is_base_of<T, name>::value; \
1266 switch (node->kind) {
1277 if (
auto* block = BlockStatement::DynamicCast(stmt)) {
1278 return block->deferred;
1285template <
class T,
class... Args>
1287 return CurrentAst::Get().AddNode(
1288 std::make_unique<T>(CurrentSourcePosition::Get(), std::move(
args)...));
1292 std::string field) {
1298 std::vector<std::string> namespace_qualification, std::string name,
1299 std::vector<TypeExpression*>
args = {}) {
1311 std::vector<Identifier*>
labels = {}) {
1317 std::string callee, std::vector<Expression*> arguments,
1318 std::vector<Identifier*>
labels = {}) {
1320 std::move(arguments), std::move(
labels));
1327 std::optional<TypeExpression*>{}, initializer);
1331 std::vector<std::string> namespace_qualification,
Identifier* name,
1332 std::vector<TypeExpression*> generic_arguments = {}) {
1334 std::move(generic_arguments));
1338 TypeExpression* type, std::vector<NameAndExpression> initializers) {
const std::vector< Declaration * > & declarations() const
T * AddNode(std::unique_ptr< T > node)
std::map< SourceId, std::set< SourceId > > declared_imports_
std::vector< EnumDescription > & EnumDescriptions()
void AddEnumDescription(EnumDescription description)
std::vector< Declaration * > declarations_
void DeclareImportForCurrentFile(SourceId import_id)
std::vector< EnumDescription > enum_descriptions_
std::vector< std::unique_ptr< AstNode > > nodes_
std::vector< Declaration * > & declarations()
#define DECLARE_CONTEXTUAL_VARIABLE(VarName,...)
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
FunctionLiteral * literal
VarDeclarationStatement * MakeConstDeclarationStatement(std::string name, Expression *initializer)
static const char *const kThisParameterName
std::ostream & operator<<(std::ostream &os, Identifier *id)
BasicTypeExpression * MakeBasicTypeExpression(std::vector< std::string > namespace_qualification, Identifier *name, std::vector< TypeExpression * > generic_arguments={})
StructExpression * MakeStructExpression(TypeExpression *type, std::vector< NameAndExpression > initializers)
T * MakeNode(Args... args)
std::vector< GenericParameter > GenericParameters
FieldAccessExpression * MakeFieldAccessExpression(Expression *object, std::string field)
ConditionalAnnotationType
bool IsDeferred(Statement *stmt)
bool IsConstexprName(const std::string &name)
IdentifierExpression * MakeIdentifierExpression(std::vector< std::string > namespace_qualification, std::string name, std::vector< TypeExpression * > args={})
std::vector< LabelAndTypes > LabelAndTypesVector
CallExpression * MakeCallExpression(IdentifierExpression *callee, std::vector< Expression * > arguments, std::vector< Identifier * > labels={})
IncrementDecrementOperator
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
std::optional< TypeExpression * > extends
std::optional< std::string > generates
std::optional< AnnotationParameter > param
AssertStatement(SourcePosition pos, AssertKind kind, Expression *expression, std::string source)
std::optional< std::string > op
AssignmentExpression(SourcePosition pos, Expression *location, std::optional< std::string > op, Expression *value)
void VisitAllSubExpressions(VisitCallback callback) override
TypeExpression * excluded_type
void VisitAllSubExpressions(VisitCallback callback) override
static bool IsInstanceOf(AstNode *node)
AstNode(Kind kind, SourcePosition pos)
virtual ~AstNode()=default
std::vector< TypeExpression * > generic_arguments
std::vector< std::string > namespace_qualification
BasicTypeExpression(SourcePosition pos, Identifier *name)
NameAndTypeExpression name_and_type
std::vector< BitFieldDeclaration > fields
std::vector< Statement * > statements
std::vector< Identifier * > labels
IdentifierExpression * callee
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< Expression * > arguments
IdentifierExpression * method
std::vector< Identifier * > labels
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< Expression * > arguments
TypeExpression * return_type
CallableDeclaration(AstNode::Kind kind, SourcePosition pos, bool transitioning, Identifier *name, ParameterList parameters, TypeExpression *return_type, LabelAndTypesVector labels)
LabelAndTypesVector labels
std::vector< ClassFieldExpression > fields
std::vector< Declaration * > methods
std::vector< ClassFieldExpression > fields
InstanceTypeConstraints instance_type_constraints
std::optional< std::string > generates
std::vector< Declaration * > methods
NameAndTypeExpression name_and_type
std::vector< ConditionalAnnotation > conditions
FieldSynchronization synchronization
std::optional< ClassFieldIndexInfo > index
ConditionalAnnotationType type
void VisitAllSubExpressions(VisitCallback callback) override
DebugStatement(SourcePosition pos, Kind kind)
Declaration(Kind kind, SourcePosition pos)
void VisitAllSubExpressions(VisitCallback callback) override
void VisitAllSubExpressions(VisitCallback callback) override
Entry(std::string name, std::string alias_entry)
std::vector< Entry > entries
std::string constexpr_generates
EnumDescription(SourcePosition pos, std::string name, std::string constexpr_generates, bool is_open, std::vector< Entry > entries={})
Expression(Kind kind, SourcePosition pos)
std::function< void(Expression *)> VisitCallback
virtual void VisitAllSubExpressions(VisitCallback callback)
std::string external_assembler_name
void VisitAllSubExpressions(VisitCallback callback) override
void VisitAllSubExpressions(VisitCallback callback) override
std::optional< Statement * > action
std::optional< Expression * > test
std::optional< VarDeclarationStatement * > var_declaration
std::vector< TypeExpression * > parameters
TypeExpression * return_type
CallableDeclaration * declaration
GenericParameters generic_parameters
std::optional< TypeExpression * > constraint
TypeDeclaration * declaration
GenericParameters generic_parameters
std::vector< Expression * > arguments
void VisitAllSubExpressions(VisitCallback callback) override
IdentifierExpression(SourcePosition pos, Identifier *name, std::vector< TypeExpression * > args={})
std::vector< TypeExpression * > generic_arguments
std::vector< std::string > namespace_qualification
bool operator()(const Identifier *a, const Identifier *b)
std::optional< Statement * > if_false
std::vector< NameAndTypeExpression > parameters
void VisitAllSubExpressions(VisitCallback callback) override
IncrementDecrementOperator op
InstanceTypeConstraints()
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< TypeExpression * > generic_arguments
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< Expression * > arguments
std::vector< TypeExpression * > types
LocationExpression(Kind kind, SourcePosition pos)
void VisitAllSubExpressions(VisitCallback callback) override
void VisitAllSubExpressions(VisitCallback callback) override
std::optional< std::string > op
std::vector< Declaration * > declarations
std::vector< NameAndExpression > initializers
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< TypeExpression * > GetExplicitTypes()
std::vector< TypeExpression * > types
SourcePosition implicit_kind_pos
std::string arguments_variable
static ParameterList Empty()
ImplicitKind implicit_kind
std::vector< Identifier * > names
std::vector< TypeExpression * > GetImplicitTypes()
std::optional< Expression * > value
static SourcePosition Invalid()
std::vector< TypeExpression * > generic_parameters
void VisitAllSubExpressions(VisitCallback callback) override
Statement(Kind kind, SourcePosition pos)
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< StructFieldExpression > fields
std::vector< Declaration * > methods
void VisitAllSubExpressions(VisitCallback callback) override
std::vector< NameAndExpression > initializers
NameAndTypeExpression name_and_type
std::optional< std::string > use_counter_name
bool has_custom_interface_descriptor
std::optional< Statement * > body
std::optional< Statement * > body
TryHandler(SourcePosition pos, HandlerKind handler_kind, Identifier *label, const ParameterList ¶meters, Statement *body)
Expression * try_expression
TypeExpression(Kind kind, SourcePosition pos)
std::optional< Expression * > initializer
std::optional< TypeExpression * > type
#define AST_NODE_KIND_LIST(V)
#define DEFINE_AST_NODE_INNER_BOILERPLATE(T)
#define DEFINE_AST_NODE_LEAF_BOILERPLATE(T)