Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / frontend / ExpressionStatementEmitter.h
blobd1435304202e035a913b72dd12862c90610ca51f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef frontend_ExpressionStatementEmitter_h
8 #define frontend_ExpressionStatementEmitter_h
10 #include "mozilla/Attributes.h"
12 #include <stdint.h>
14 #include "frontend/ValueUsage.h"
16 namespace js {
17 namespace frontend {
19 struct BytecodeEmitter;
21 // Class for emitting bytecode for expression statement.
23 // Usage: (check for the return value is omitted for simplicity)
25 // `expr;`
26 // // IgnoreValue if this is in normal script.
27 // // WantValue if this is in eval script.
28 // ValueUsage valueUsage = ...;
30 // ExpressionStatementEmitter ese(this, valueUsage);
31 // ese.prepareForExpr(offset_of_expr);
32 // emit(expr);
33 // ese.emitEnd();
35 class MOZ_STACK_CLASS ExpressionStatementEmitter {
36 BytecodeEmitter* bce_;
38 #ifdef DEBUG
39 // The stack depth before emitting expression.
40 int32_t depth_;
41 #endif
43 // The usage of the value of the expression.
44 ValueUsage valueUsage_;
46 #ifdef DEBUG
47 // The state of this emitter.
49 // +-------+ prepareForExpr +------+ emitEnd +-----+
50 // | Start |--------------->| Expr |-------->| End |
51 // +-------+ +------+ +-----+
52 enum class State {
53 // The initial state.
54 Start,
56 // After calling prepareForExpr.
57 Expr,
59 // After calling emitEnd.
60 End
62 State state_ = State::Start;
63 #endif
65 public:
66 ExpressionStatementEmitter(BytecodeEmitter* bce, ValueUsage valueUsage);
68 // Parameters are the offset in the source code for each character below:
70 // expr;
71 // ^
72 // |
73 // beginPos
74 [[nodiscard]] bool prepareForExpr(uint32_t beginPos);
75 [[nodiscard]] bool emitEnd();
78 } // namespace frontend
79 } // namespace js
81 #endif /* frontend_ExpressionStatementEmitter_h */