1/*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef ES2PANDA_COMPILER_CORE_ETSCOMPILER_H
16#define ES2PANDA_COMPILER_CORE_ETSCOMPILER_H
17
18#include "compiler/core/ASTCompiler.h"
19
20namespace ark::es2panda::compiler {
21
22class ETSCompiler final : public AstCompiler {
23public:
24    ETSCompiler() = default;
25
26// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
27#define DECLARE_ETSCOMPILER_COMPILE_METHOD(_, nodeType) void Compile(const ir::nodeType *node) const override;
28    AST_NODE_MAPPING(DECLARE_ETSCOMPILER_COMPILE_METHOD)
29#undef DECLARE_ETSCOMPILER_COMPILE_METHOD
30
31// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
32#define DECLARE_ETSCOMPILER_COMPILE_METHOD(_, __, nodeType, ___) void Compile(const ir::nodeType *node) const override;
33    AST_NODE_REINTERPRET_MAPPING(DECLARE_ETSCOMPILER_COMPILE_METHOD)
34#undef DECLARE_ETSCOMPILER_COMPILE_METHOD
35
36private:
37    bool IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const;
38    void GetDynamicNameParts(const ir::CallExpression *expr, ArenaVector<util::StringView> &parts) const;
39    void CompileDynamic(const ir::CallExpression *expr, compiler::VReg &calleeReg) const;
40    void CompileCastUnboxable(const ir::TSAsExpression *expr) const;
41    void CompileCastPrimitives(const ir::TSAsExpression *expr) const;
42    void CompileCast(const ir::TSAsExpression *expr) const;
43    void EmitCall(const ir::CallExpression *expr, compiler::VReg &calleeReg, checker::Signature *signature) const;
44    bool HandleArrayTypeLengthProperty(const ir::MemberExpression *expr, ETSGen *etsg) const;
45    bool HandleEnumTypes(const ir::MemberExpression *expr, ETSGen *etsg) const;
46    bool HandleStaticProperties(const ir::MemberExpression *expr, ETSGen *etsg) const;
47
48    static bool CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpression *expr);
49
50    ETSGen *GetETSGen() const;
51};
52
53}  // namespace ark::es2panda::compiler
54
55#endif  // ES2PANDA_COMPILER_CORE_ETSCOMPILER_H
56