| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
#ifndef frontend_DecoratorEmitter_h |
| 6 |
#define frontend_DecoratorEmitter_h |
| 7 |
|
| 8 |
#include "mozilla/Attributes.h" |
| 9 |
#include "mozilla/Maybe.h" |
| 10 |
|
| 11 |
#include "frontend/ParseNode.h" |
| 12 |
|
| 13 |
#include "js/AllocPolicy.h" |
| 14 |
#include "js/Vector.h" |
| 15 |
|
| 16 |
namespace js::frontend { |
| 17 |
|
| 18 |
struct BytecodeEmitter; |
| 19 |
|
| 20 |
class MOZ_STACK_CLASS DecoratorEmitter { |
| 21 |
private: |
| 22 |
BytecodeEmitter* bce_; |
| 23 |
|
| 24 |
public: |
| 25 |
enum Kind { Method, Getter, Setter, Field, Accessor, Class }; |
| 26 |
|
| 27 |
explicit DecoratorEmitter(BytecodeEmitter* bce); |
| 28 |
|
| 29 |
[[nodiscard]] bool emitApplyDecoratorsToElementDefinition( |
| 30 |
Kind kind, ParseNode* key, ListNode* decorators, bool isStatic); |
| 31 |
|
| 32 |
[[nodiscard]] bool emitApplyDecoratorsToFieldDefinition(ParseNode* key, |
| 33 |
ListNode* decorators, |
| 34 |
bool isStatic); |
| 35 |
|
| 36 |
[[nodiscard]] bool emitApplyDecoratorsToAccessorDefinition( |
| 37 |
ParseNode* key, ListNode* decorators, bool isStatic); |
| 38 |
|
| 39 |
[[nodiscard]] bool emitApplyDecoratorsToClassDefinition(ParseNode* key, |
| 40 |
ListNode* decorators); |
| 41 |
|
| 42 |
[[nodiscard]] bool emitInitializeFieldOrAccessor(); |
| 43 |
|
| 44 |
[[nodiscard]] bool emitCreateAddInitializerFunction( |
| 45 |
FunctionNode* addInitializerFunction, TaggedParserAtomIndex initializers); |
| 46 |
|
| 47 |
[[nodiscard]] bool emitCallExtraInitializers( |
| 48 |
TaggedParserAtomIndex extraInitializers); |
| 49 |
|
| 50 |
private: |
| 51 |
[[nodiscard]] bool emitPropertyKey(ParseNode* key); |
| 52 |
|
| 53 |
[[nodiscard]] bool emitDecorationState(); |
| 54 |
|
| 55 |
[[nodiscard]] bool emitUpdateDecorationState(); |
| 56 |
|
| 57 |
[[nodiscard]] bool emitCallDecoratorForElement(Kind kind, ParseNode* key, |
| 58 |
bool isStatic, |
| 59 |
ParseNode* decorator); |
| 60 |
|
| 61 |
[[nodiscard]] bool emitCreateDecoratorAccessObject(); |
| 62 |
|
| 63 |
[[nodiscard]] bool emitCheckIsUndefined(); |
| 64 |
|
| 65 |
[[nodiscard]] bool emitCreateAddInitializerFunction(); |
| 66 |
|
| 67 |
[[nodiscard]] bool emitCreateDecoratorContextObject(Kind kind, ParseNode* key, |
| 68 |
bool isStatic, |
| 69 |
TokenPos pos); |
| 70 |
|
| 71 |
[[nodiscard]] bool emitHandleNewValueField(TaggedParserAtomIndex atom, |
| 72 |
int8_t offset); |
| 73 |
|
| 74 |
using DecoratorsVector = js::Vector<ParseNode*, 2, js::SystemAllocPolicy>; |
| 75 |
|
| 76 |
[[nodiscard]] bool reverseDecoratorsToApplicationOrder( |
| 77 |
const ListNode* decorators, DecoratorsVector& vec) const; |
| 78 |
}; |
| 79 |
|
| 80 |
} /* namespace js::frontend */ |
| 81 |
|
| 82 |
#endif /* frontend_DecoratorEmitter_h */ |