Bug 1874684 - Part 31: Correctly reject invalid durations in some RoundDuration calls...
[gecko.git] / js / src / frontend / LabelEmitter.h
blobf3d9ec67c015b24af0b2a631d731dff7023c475c
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
15 namespace js {
16 namespace frontend {
18 struct BytecodeEmitter;
19 class TaggedParserAtomIndex;
21 // Class for emitting labeled statement.
23 // Usage: (check for the return value is omitted for simplicity)
25 // `label: expr;`
26 // LabelEmitter le(this);
27 // le.emitLabel(name_of_label);
28 // emit(expr);
29 // le.emitEnd();
31 class MOZ_STACK_CLASS LabelEmitter {
32 BytecodeEmitter* bce_;
34 mozilla::Maybe<LabelControl> controlInfo_;
36 #ifdef DEBUG
37 // The state of this emitter.
39 // +-------+ emitLabel +-------+ emitEnd +-----+
40 // | Start |---------->| Label |-------->| End |
41 // +-------+ +-------+ +-----+
42 enum class State {
43 // The initial state.
44 Start,
46 // After calling emitLabel.
47 Label,
49 // After calling emitEnd.
50 End
52 State state_ = State::Start;
53 #endif
55 public:
56 explicit LabelEmitter(BytecodeEmitter* bce) : bce_(bce) {}
58 void emitLabel(TaggedParserAtomIndex name);
59 [[nodiscard]] bool emitEnd();
62 } /* namespace frontend */
63 } /* namespace js */
65 #endif /* frontend_LabelEmitter_h */