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"
14 #include "frontend/ValueUsage.h"
19 struct BytecodeEmitter
;
21 // Class for emitting bytecode for expression statement.
23 // Usage: (check for the return value is omitted for simplicity)
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);
35 class MOZ_STACK_CLASS ExpressionStatementEmitter
{
36 BytecodeEmitter
* bce_
;
39 // The stack depth before emitting expression.
43 // The usage of the value of the expression.
44 ValueUsage valueUsage_
;
47 // The state of this emitter.
49 // +-------+ prepareForExpr +------+ emitEnd +-----+
50 // | Start |--------------->| Expr |-------->| End |
51 // +-------+ +------+ +-----+
56 // After calling prepareForExpr.
59 // After calling emitEnd.
62 State state_
= State::Start
;
66 ExpressionStatementEmitter(BytecodeEmitter
* bce
, ValueUsage valueUsage
);
68 // Parameters are the offset in the source code for each character below:
74 [[nodiscard
]] bool prepareForExpr(uint32_t beginPos
);
75 [[nodiscard
]] bool emitEnd();
78 } // namespace frontend
81 #endif /* frontend_ExpressionStatementEmitter_h */