13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci#ifndef ES2PANDA_CHECKER_TSANALYZER_H 163af6ab5fSopenharmony_ci#define ES2PANDA_CHECKER_TSANALYZER_H 173af6ab5fSopenharmony_ci 183af6ab5fSopenharmony_ci#include "checker/SemanticAnalyzer.h" 193af6ab5fSopenharmony_ci#include "checker/TSchecker.h" 203af6ab5fSopenharmony_ci#include "util/helpers.h" 213af6ab5fSopenharmony_ci 223af6ab5fSopenharmony_cinamespace ark::es2panda::checker { 233af6ab5fSopenharmony_ci 243af6ab5fSopenharmony_ciclass TSAnalyzer final : public SemanticAnalyzer { 253af6ab5fSopenharmony_cipublic: 263af6ab5fSopenharmony_ci explicit TSAnalyzer(Checker *checker) : SemanticAnalyzer(checker) {}; 273af6ab5fSopenharmony_ci 283af6ab5fSopenharmony_ci // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 293af6ab5fSopenharmony_ci#define DECLARE_TSANALYZER_CHECK_METHOD(_, nodeType) checker::Type *Check(ir::nodeType *node) const override; 303af6ab5fSopenharmony_ci AST_NODE_MAPPING(DECLARE_TSANALYZER_CHECK_METHOD) 313af6ab5fSopenharmony_ci#undef DECLARE_TSANALYZER_CHECK_METHOD 323af6ab5fSopenharmony_ci 333af6ab5fSopenharmony_ci// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 343af6ab5fSopenharmony_ci#define DECLARE_TSANALYZER_CHECK_METHOD(_, __, nodeType, ___) \ 353af6ab5fSopenharmony_ci virtual checker::Type *Check(ir::nodeType *node) const override; 363af6ab5fSopenharmony_ci AST_NODE_REINTERPRET_MAPPING(DECLARE_TSANALYZER_CHECK_METHOD) 373af6ab5fSopenharmony_ci#undef DECLARE_TSANALYZER_CHECK_METHOD 383af6ab5fSopenharmony_ci 393af6ab5fSopenharmony_ci checker::Type *CheckDeleteKeyword([[maybe_unused]] checker::TSChecker *checker, ir::UnaryExpression *expr) const; 403af6ab5fSopenharmony_ci checker::Type *CheckLiteral([[maybe_unused]] checker::TSChecker *checker, ir::UnaryExpression *expr) const; 413af6ab5fSopenharmony_ci checker::Type *CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr, checker::Type *leftType, 423af6ab5fSopenharmony_ci checker::Type *rightType) const; 433af6ab5fSopenharmony_ci checker::Type *CheckBinaryExprArithmLogical(ir::BinaryExpression *expr, ExpressionTypeInfo *leftRightType, 443af6ab5fSopenharmony_ci TSChecker *checker) const; 453af6ab5fSopenharmony_ci void CheckComputed(ir::MemberExpression *expr, checker::Type *indexType) const; 463af6ab5fSopenharmony_ci void CheckSpread(std::unordered_map<util::StringView, lexer::SourcePosition> &allPropertiesMap, 473af6ab5fSopenharmony_ci checker::ObjectDescriptor *desc, ir::Expression *it) const; 483af6ab5fSopenharmony_ci checker::IndexInfo *CreateUnionTypeHelper(ArenaVector<checker::Type *> &computedPropTypes, 493af6ab5fSopenharmony_ci bool inConstContext) const; 503af6ab5fSopenharmony_ci void CheckNonComputed(checker::ObjectDescriptor *desc, ir::Expression *it, 513af6ab5fSopenharmony_ci std::unordered_map<util::StringView, lexer::SourcePosition> &allPropertiesMap, 523af6ab5fSopenharmony_ci bool inConstContext) const; 533af6ab5fSopenharmony_ci 543af6ab5fSopenharmony_ciprivate: 553af6ab5fSopenharmony_ci TSChecker *GetTSChecker() const; 563af6ab5fSopenharmony_ci 573af6ab5fSopenharmony_ci varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enumVar, 583af6ab5fSopenharmony_ci const ir::BinaryExpression *expr) const; 593af6ab5fSopenharmony_ci varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, varbinder::EnumVariable *enumVar, 603af6ab5fSopenharmony_ci const ir::AstNode *expr) const; 613af6ab5fSopenharmony_ci varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enumVar, 623af6ab5fSopenharmony_ci const ir::UnaryExpression *expr) const; 633af6ab5fSopenharmony_ci void InferEnumVariableType(varbinder::EnumVariable *variable, double *value, bool *initNext, bool *isLiteralEnum, 643af6ab5fSopenharmony_ci bool isConstEnum) const; 653af6ab5fSopenharmony_ci checker::Type *InferType(checker::TSChecker *checker, bool isConst, ir::TSEnumDeclaration *st) const; 663af6ab5fSopenharmony_ci}; 673af6ab5fSopenharmony_ci 683af6ab5fSopenharmony_ci} // namespace ark::es2panda::checker 693af6ab5fSopenharmony_ci 703af6ab5fSopenharmony_ci#endif // ES2PANDA_CHECKER_TSSANALYZER_H 71