19#define VISIT_AND_RETURN_IF_STACK_OVERFLOW(param) \
21 if (CheckStackOverflow()) return;
38 InitializeAstVisitor(stack_limit);
69 :
processor_(processor), previous_(processor->breakable_) {
70 processor->breakable_ = processor->breakable_ || breakable;
85#define DEF_VISIT(type) void Visit##type(type* node);
133void Processor::VisitBlock(
Block* node) {
142 if (!node->ignore_completion_value()) {
143 BreakableScope scope(
this, node->is_breakable());
150void Processor::VisitExpressionStatement(ExpressionStatement* node) {
153 node->set_expression(
SetResult(node->expression()));
160void Processor::VisitIfStatement(IfStatement* node) {
164 Visit(node->then_statement());
169 Visit(node->else_statement());
198void Processor::VisitWhileStatement(WhileStatement* node) {
203void Processor::VisitForStatement(ForStatement* node) {
208void Processor::VisitForInStatement(ForInStatement* node) {
213void Processor::VisitForOfStatement(ForOfStatement* node) {
218void Processor::VisitTryCatchStatement(TryCatchStatement* node) {
228 node->set_catch_block(
static_cast<Block*
>(
replacement_));
235void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) {
250 factory()->ast_value_factory()->dot_result_string());
257 node->finally_block()->statements()->InsertAt(
260 node->finally_block()->statements()->Add(
272 Expression* assignment =
SetResult(undef);
273 node->finally_block()->statements()->InsertAt(
289void Processor::VisitSwitchStatement(SwitchStatement* node) {
295 BreakableScope scope(
this);
298 for (
int i = clauses->
length() - 1;
i >= 0; --
i) {
299 CaseClause* clause = clauses->at(
i);
308void Processor::VisitContinueStatement(ContinueStatement* node) {
314void Processor::VisitBreakStatement(BreakStatement* node) {
320void Processor::VisitWithStatement(WithStatement* node) {
321 Visit(node->statement());
329void Processor::VisitSloppyBlockFunctionStatement(
330 SloppyBlockFunctionStatement* node) {
331 Visit(node->statement());
337void Processor::VisitEmptyStatement(EmptyStatement* node) {
342void Processor::VisitReturnStatement(ReturnStatement* node) {
348void Processor::VisitDebuggerStatement(DebuggerStatement* node) {
352void Processor::VisitInitializeClassMembersStatement(
353 InitializeClassMembersStatement* node) {
357void Processor::VisitInitializeClassStaticElementsStatement(
358 InitializeClassStaticElementsStatement* node) {
362void Processor::VisitAutoAccessorGetterBody(AutoAccessorGetterBody* node) {
366void Processor::VisitAutoAccessorSetterBody(AutoAccessorSetterBody* node) {
371#define DEF_VISIT(type) \
372 void Processor::Visit##type(type* expr) { UNREACHABLE(); }
378#define DEF_VISIT(type) \
379 void Processor::Visit##type(type* expr) { UNREACHABLE(); }
388 RuntimeCallCounterId::kCompileRewriteReturnResult,
389 RuntimeCallStats::kThreadSpecific);
393 Scope* scope = function->scope();
403 return RewriteBody(info, scope, body, out_has_stack_overflow).has_value();
408 bool* out_has_stack_overflow) {
415 info->ast_value_factory()->dot_result_string());
417 result, info->ast_value_factory(), info->
zone());
418 processor.Process(body);
420 if (processor.result_assigned()) {
423 processor.factory()->NewVariableProxy(
result,
pos);
424 if (!info->flags().is_repl_mode()) {
427 processor.factory()->NewReturnStatement(result_value,
pos);
428 body->
Add(result_statement, info->zone());
433 if (processor.HasStackOverflow()) {
434 *out_has_stack_overflow =
true;
441#undef VISIT_AND_RETURN_IF_STACK_OVERFLOW
#define EXPRESSION_NODE_LIST(V)
#define DECLARATION_NODE_LIST(V)
Assignment * NewAssignment(Token::Value op, Expression *target, Expression *value, int pos)
Literal * NewUndefinedLiteral(int pos)
VariableProxy * NewVariableProxy(Variable *var, int start_position=kNoSourcePosition)
Block * NewBlock(int capacity, bool ignore_completion_value)
void Visit(AstNode *node)
ZonePtrList< Statement > * statements()
BreakableScope(Processor *processor, bool breakable=true)
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS()
Processor(uintptr_t stack_limit, DeclarationScope *closure_scope, Variable *result, AstValueFactory *ast_value_factory, Zone *zone)
Statement * AssignUndefinedBefore(Statement *s)
void Process(ZonePtrList< Statement > *statements)
DeclarationScope * closure_scope()
void VisitIterationStatement(IterationStatement *stmt)
DeclarationScope * closure_scope_
Expression * SetResult(Expression *value)
AstNodeFactory * factory()
bool result_assigned() const
static V8_EXPORT_PRIVATE bool Rewrite(ParseInfo *info, bool *out_has_stack_overflow)
static std::optional< VariableProxy * > RewriteBody(ParseInfo *info, Scope *scope, ZonePtrList< Statement > *body, bool *out_has_stack_overflow)
bool is_repl_mode_scope() const
DeclarationScope * AsDeclarationScope()
bool is_script_scope() const
bool is_eval_scope() const
DeclarationScope * GetClosureScope()
Variable * NewTemporary(const AstRawString *name)
void Set(int index, const T &element)
V8_INLINE int length() const
V8_INLINE bool is_empty() const
void Add(const T &element, Zone *zone)
ZoneVector< RpoNumber > & result
ProcessorImpl * processor_
SnapshotTable< OpIndex, VariableData >::Key Variable
constexpr int kNoSourcePosition
ZoneList< T * > ZonePtrList
#define VISIT_AND_RETURN_IF_STACK_OVERFLOW(param)
#define DCHECK_NOT_NULL(val)
#define CHECK_NOT_NULL(val)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)