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_LabelEmitter_h
8 #define frontend_LabelEmitter_h
10 #include "mozilla/Attributes.h" // MOZ_STACK_CLASS
11 #include "mozilla/Maybe.h" // Maybe
13 #include "frontend/BytecodeControlStructures.h" // LabelControl
18 struct BytecodeEmitter
;
19 class TaggedParserAtomIndex
;
21 // Class for emitting labeled statement.
23 // Usage: (check for the return value is omitted for simplicity)
26 // LabelEmitter le(this);
27 // le.emitLabel(name_of_label);
31 class MOZ_STACK_CLASS LabelEmitter
{
32 BytecodeEmitter
* bce_
;
34 mozilla::Maybe
<LabelControl
> controlInfo_
;
37 // The state of this emitter.
39 // +-------+ emitLabel +-------+ emitEnd +-----+
40 // | Start |---------->| Label |-------->| End |
41 // +-------+ +-------+ +-----+
46 // After calling emitLabel.
49 // After calling emitEnd.
52 State state_
= State::Start
;
56 explicit LabelEmitter(BytecodeEmitter
* bce
) : bce_(bce
) {}
58 void emitLabel(TaggedParserAtomIndex name
);
59 [[nodiscard
]] bool emitEnd();
62 } /* namespace frontend */
65 #endif /* frontend_LabelEmitter_h */