1 /* 2 * Copyright (c) 2021-2025 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 20 namespace ark::es2panda::compiler { 21 22 class ETSCompiler final : public AstCompiler { 23 public: 24 ETSCompiler() = default; 25 /* CC-OFFNXT(G.PRE.02,G.PRE.09) name part*/ 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 /* CC-OFFNXT(G.PRE.02,G.PRE.09) name part*/ 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 36 private: 37 void GetDynamicNameParts(const ir::CallExpression *expr, ArenaVector<util::StringView> &parts) const; 38 void CompileDynamic(const ir::CallExpression *expr, compiler::VReg &calleeReg) const; 39 void CompileCastUnboxable(const ir::TSAsExpression *expr) const; 40 void CompileCastPrimitives(const ir::TSAsExpression *expr) const; 41 void CompileCast(const ir::TSAsExpression *expr) const; 42 void EmitCall(const ir::CallExpression *expr, compiler::VReg &calleeReg, checker::Signature *signature) const; 43 bool HandleArrayTypeLengthProperty(const ir::MemberExpression *expr, ETSGen *etsg) const; 44 bool HandleStaticProperties(const ir::MemberExpression *expr, ETSGen *etsg) const; 45 void CompileArrayCreation(const ir::ArrayExpression *expr) const; 46 void CompileTupleCreation(const ir::ArrayExpression *tupleInitializer) 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