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 163af6ab5fSopenharmony_ci#ifndef ES2PANDA_CHECKER_SEMANTICANALYZER_H 173af6ab5fSopenharmony_ci#define ES2PANDA_CHECKER_SEMANTICANALYZER_H 183af6ab5fSopenharmony_ci 193af6ab5fSopenharmony_ci#include "compiler/core/dynamicContext.h" 203af6ab5fSopenharmony_ci#include "ir/opaqueTypeNode.h" 213af6ab5fSopenharmony_ci#include "ir/as/namedType.h" 223af6ab5fSopenharmony_ci#include "ir/as/prefixAssertionExpression.h" 233af6ab5fSopenharmony_ci#include "ir/base/catchClause.h" 243af6ab5fSopenharmony_ci#include "ir/base/classDefinition.h" 253af6ab5fSopenharmony_ci#include "ir/base/classProperty.h" 263af6ab5fSopenharmony_ci#include "ir/base/classStaticBlock.h" 273af6ab5fSopenharmony_ci#include "ir/base/decorator.h" 283af6ab5fSopenharmony_ci#include "ir/base/metaProperty.h" 293af6ab5fSopenharmony_ci#include "ir/base/methodDefinition.h" 303af6ab5fSopenharmony_ci#include "ir/base/property.h" 313af6ab5fSopenharmony_ci#include "ir/base/scriptFunction.h" 323af6ab5fSopenharmony_ci#include "ir/base/spreadElement.h" 333af6ab5fSopenharmony_ci#include "ir/base/templateElement.h" 343af6ab5fSopenharmony_ci#include "ir/base/tsIndexSignature.h" 353af6ab5fSopenharmony_ci#include "ir/base/tsMethodSignature.h" 363af6ab5fSopenharmony_ci#include "ir/base/tsPropertySignature.h" 373af6ab5fSopenharmony_ci#include "ir/base/tsSignatureDeclaration.h" 383af6ab5fSopenharmony_ci#include "ir/ets/etsClassLiteral.h" 393af6ab5fSopenharmony_ci#include "ir/ets/etsFunctionType.h" 403af6ab5fSopenharmony_ci#include "ir/ets/etsImportDeclaration.h" 413af6ab5fSopenharmony_ci#include "ir/ets/etsLaunchExpression.h" 423af6ab5fSopenharmony_ci#include "ir/ets/etsNewArrayInstanceExpression.h" 433af6ab5fSopenharmony_ci#include "ir/ets/etsNewClassInstanceExpression.h" 443af6ab5fSopenharmony_ci#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" 453af6ab5fSopenharmony_ci#include "ir/ets/etsPackageDeclaration.h" 463af6ab5fSopenharmony_ci#include "ir/ets/etsParameterExpression.h" 473af6ab5fSopenharmony_ci#include "ir/ets/etsPrimitiveType.h" 483af6ab5fSopenharmony_ci#include "ir/ets/etsScript.h" 493af6ab5fSopenharmony_ci#include "ir/ets/etsStringLiteralType.h" 503af6ab5fSopenharmony_ci#include "ir/ets/etsStructDeclaration.h" 513af6ab5fSopenharmony_ci#include "ir/ets/etsTypeReference.h" 523af6ab5fSopenharmony_ci#include "ir/ets/etsTypeReferencePart.h" 533af6ab5fSopenharmony_ci#include "ir/ets/etsWildcardType.h" 543af6ab5fSopenharmony_ci#include "ir/expressions/arrayExpression.h" 553af6ab5fSopenharmony_ci#include "ir/expressions/arrowFunctionExpression.h" 563af6ab5fSopenharmony_ci#include "ir/expressions/assignmentExpression.h" 573af6ab5fSopenharmony_ci#include "ir/expressions/awaitExpression.h" 583af6ab5fSopenharmony_ci#include "ir/expressions/binaryExpression.h" 593af6ab5fSopenharmony_ci#include "ir/expressions/blockExpression.h" 603af6ab5fSopenharmony_ci#include "ir/expressions/callExpression.h" 613af6ab5fSopenharmony_ci#include "ir/expressions/chainExpression.h" 623af6ab5fSopenharmony_ci#include "ir/expressions/classExpression.h" 633af6ab5fSopenharmony_ci#include "ir/expressions/conditionalExpression.h" 643af6ab5fSopenharmony_ci#include "ir/expressions/directEvalExpression.h" 653af6ab5fSopenharmony_ci#include "ir/expressions/functionExpression.h" 663af6ab5fSopenharmony_ci#include "ir/expressions/identifier.h" 673af6ab5fSopenharmony_ci#include "ir/expressions/importExpression.h" 683af6ab5fSopenharmony_ci#include "ir/expressions/memberExpression.h" 693af6ab5fSopenharmony_ci#include "ir/expressions/newExpression.h" 703af6ab5fSopenharmony_ci#include "ir/expressions/objectExpression.h" 713af6ab5fSopenharmony_ci#include "ir/expressions/omittedExpression.h" 723af6ab5fSopenharmony_ci#include "ir/expressions/sequenceExpression.h" 733af6ab5fSopenharmony_ci#include "ir/expressions/superExpression.h" 743af6ab5fSopenharmony_ci#include "ir/expressions/taggedTemplateExpression.h" 753af6ab5fSopenharmony_ci#include "ir/expressions/templateLiteral.h" 763af6ab5fSopenharmony_ci#include "ir/expressions/thisExpression.h" 773af6ab5fSopenharmony_ci#include "ir/expressions/typeofExpression.h" 783af6ab5fSopenharmony_ci#include "ir/expressions/unaryExpression.h" 793af6ab5fSopenharmony_ci#include "ir/expressions/updateExpression.h" 803af6ab5fSopenharmony_ci#include "ir/expressions/yieldExpression.h" 813af6ab5fSopenharmony_ci#include "ir/expressions/literals/bigIntLiteral.h" 823af6ab5fSopenharmony_ci#include "ir/expressions/literals/booleanLiteral.h" 833af6ab5fSopenharmony_ci#include "ir/expressions/literals/charLiteral.h" 843af6ab5fSopenharmony_ci#include "ir/expressions/literals/nullLiteral.h" 853af6ab5fSopenharmony_ci#include "ir/expressions/literals/numberLiteral.h" 863af6ab5fSopenharmony_ci#include "ir/expressions/literals/regExpLiteral.h" 873af6ab5fSopenharmony_ci#include "ir/expressions/literals/stringLiteral.h" 883af6ab5fSopenharmony_ci#include "ir/module/exportAllDeclaration.h" 893af6ab5fSopenharmony_ci#include "ir/module/exportDefaultDeclaration.h" 903af6ab5fSopenharmony_ci#include "ir/module/exportNamedDeclaration.h" 913af6ab5fSopenharmony_ci#include "ir/module/exportSpecifier.h" 923af6ab5fSopenharmony_ci#include "ir/module/importDeclaration.h" 933af6ab5fSopenharmony_ci#include "ir/module/importDefaultSpecifier.h" 943af6ab5fSopenharmony_ci#include "ir/module/importNamespaceSpecifier.h" 953af6ab5fSopenharmony_ci#include "ir/module/importSpecifier.h" 963af6ab5fSopenharmony_ci#include "ir/statements/assertStatement.h" 973af6ab5fSopenharmony_ci#include "ir/statements/blockStatement.h" 983af6ab5fSopenharmony_ci#include "ir/statements/breakStatement.h" 993af6ab5fSopenharmony_ci#include "ir/statements/classDeclaration.h" 1003af6ab5fSopenharmony_ci#include "ir/statements/continueStatement.h" 1013af6ab5fSopenharmony_ci#include "ir/statements/debuggerStatement.h" 1023af6ab5fSopenharmony_ci#include "ir/statements/doWhileStatement.h" 1033af6ab5fSopenharmony_ci#include "ir/statements/emptyStatement.h" 1043af6ab5fSopenharmony_ci#include "ir/statements/expressionStatement.h" 1053af6ab5fSopenharmony_ci#include "ir/statements/forInStatement.h" 1063af6ab5fSopenharmony_ci#include "ir/statements/forOfStatement.h" 1073af6ab5fSopenharmony_ci#include "ir/statements/forUpdateStatement.h" 1083af6ab5fSopenharmony_ci#include "ir/statements/functionDeclaration.h" 1093af6ab5fSopenharmony_ci#include "ir/statements/ifStatement.h" 1103af6ab5fSopenharmony_ci#include "ir/statements/labelledStatement.h" 1113af6ab5fSopenharmony_ci#include "ir/statements/returnStatement.h" 1123af6ab5fSopenharmony_ci#include "ir/statements/switchCaseStatement.h" 1133af6ab5fSopenharmony_ci#include "ir/statements/switchStatement.h" 1143af6ab5fSopenharmony_ci#include "ir/statements/throwStatement.h" 1153af6ab5fSopenharmony_ci#include "ir/statements/tryStatement.h" 1163af6ab5fSopenharmony_ci#include "ir/statements/variableDeclaration.h" 1173af6ab5fSopenharmony_ci#include "ir/statements/variableDeclarator.h" 1183af6ab5fSopenharmony_ci#include "ir/statements/whileStatement.h" 1193af6ab5fSopenharmony_ci#include "ir/ts/tsAnyKeyword.h" 1203af6ab5fSopenharmony_ci#include "ir/ts/tsArrayType.h" 1213af6ab5fSopenharmony_ci#include "ir/ts/tsAsExpression.h" 1223af6ab5fSopenharmony_ci#include "ir/ts/tsBigintKeyword.h" 1233af6ab5fSopenharmony_ci#include "ir/ts/tsBooleanKeyword.h" 1243af6ab5fSopenharmony_ci#include "ir/ts/tsClassImplements.h" 1253af6ab5fSopenharmony_ci#include "ir/ts/tsConditionalType.h" 1263af6ab5fSopenharmony_ci#include "ir/ts/tsConstructorType.h" 1273af6ab5fSopenharmony_ci#include "ir/ts/tsEnumDeclaration.h" 1283af6ab5fSopenharmony_ci#include "ir/ts/tsEnumMember.h" 1293af6ab5fSopenharmony_ci#include "ir/ts/tsExternalModuleReference.h" 1303af6ab5fSopenharmony_ci#include "ir/ts/tsFunctionType.h" 1313af6ab5fSopenharmony_ci#include "ir/ts/tsImportEqualsDeclaration.h" 1323af6ab5fSopenharmony_ci#include "ir/ts/tsImportType.h" 1333af6ab5fSopenharmony_ci#include "ir/ts/tsIndexedAccessType.h" 1343af6ab5fSopenharmony_ci#include "ir/ts/tsInferType.h" 1353af6ab5fSopenharmony_ci#include "ir/ts/tsInterfaceBody.h" 1363af6ab5fSopenharmony_ci#include "ir/ts/tsInterfaceDeclaration.h" 1373af6ab5fSopenharmony_ci#include "ir/ts/tsInterfaceHeritage.h" 1383af6ab5fSopenharmony_ci#include "ir/ts/tsIntersectionType.h" 1393af6ab5fSopenharmony_ci#include "ir/ts/tsLiteralType.h" 1403af6ab5fSopenharmony_ci#include "ir/ts/tsMappedType.h" 1413af6ab5fSopenharmony_ci#include "ir/ts/tsModuleBlock.h" 1423af6ab5fSopenharmony_ci#include "ir/ts/tsModuleDeclaration.h" 1433af6ab5fSopenharmony_ci#include "ir/ts/tsNamedTupleMember.h" 1443af6ab5fSopenharmony_ci#include "ir/ts/tsNeverKeyword.h" 1453af6ab5fSopenharmony_ci#include "ir/ts/tsNonNullExpression.h" 1463af6ab5fSopenharmony_ci#include "ir/ts/tsNullKeyword.h" 1473af6ab5fSopenharmony_ci#include "ir/ts/tsNumberKeyword.h" 1483af6ab5fSopenharmony_ci#include "ir/ts/tsObjectKeyword.h" 1493af6ab5fSopenharmony_ci#include "ir/ts/tsParameterProperty.h" 1503af6ab5fSopenharmony_ci#include "ir/ts/tsParenthesizedType.h" 1513af6ab5fSopenharmony_ci#include "ir/ts/tsQualifiedName.h" 1523af6ab5fSopenharmony_ci#include "ir/ts/tsStringKeyword.h" 1533af6ab5fSopenharmony_ci#include "ir/ts/tsThisType.h" 1543af6ab5fSopenharmony_ci#include "ir/ts/tsTupleType.h" 1553af6ab5fSopenharmony_ci#include "ir/ts/tsTypeAliasDeclaration.h" 1563af6ab5fSopenharmony_ci#include "ir/ts/tsTypeAssertion.h" 1573af6ab5fSopenharmony_ci#include "ir/ts/tsTypeLiteral.h" 1583af6ab5fSopenharmony_ci#include "ir/ts/tsTypeOperator.h" 1593af6ab5fSopenharmony_ci#include "ir/ts/tsTypeParameterDeclaration.h" 1603af6ab5fSopenharmony_ci#include "ir/ts/tsTypeParameter.h" 1613af6ab5fSopenharmony_ci#include "ir/ts/tsTypeParameterInstantiation.h" 1623af6ab5fSopenharmony_ci#include "ir/ts/tsTypePredicate.h" 1633af6ab5fSopenharmony_ci#include "ir/ts/tsTypeQuery.h" 1643af6ab5fSopenharmony_ci#include "ir/ts/tsTypeReference.h" 1653af6ab5fSopenharmony_ci#include "ir/ts/tsUndefinedKeyword.h" 1663af6ab5fSopenharmony_ci#include "ir/ts/tsUnionType.h" 1673af6ab5fSopenharmony_ci#include "ir/ts/tsUnknownKeyword.h" 1683af6ab5fSopenharmony_ci#include "ir/ts/tsVoidKeyword.h" 1693af6ab5fSopenharmony_ci 1703af6ab5fSopenharmony_cinamespace ark::es2panda::checker { 1713af6ab5fSopenharmony_ciclass Checker; 1723af6ab5fSopenharmony_ci 1733af6ab5fSopenharmony_ciclass SemanticAnalyzer { 1743af6ab5fSopenharmony_cipublic: 1753af6ab5fSopenharmony_ci explicit SemanticAnalyzer(Checker *checker) 1763af6ab5fSopenharmony_ci { 1773af6ab5fSopenharmony_ci checker_ = checker; 1783af6ab5fSopenharmony_ci } 1793af6ab5fSopenharmony_ci virtual ~SemanticAnalyzer() = default; 1803af6ab5fSopenharmony_ci NO_COPY_SEMANTIC(SemanticAnalyzer); 1813af6ab5fSopenharmony_ci NO_MOVE_SEMANTIC(SemanticAnalyzer); 1823af6ab5fSopenharmony_ci 1833af6ab5fSopenharmony_ci// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 1843af6ab5fSopenharmony_ci#define DECLARE_AST_NODE_CHECK_METHOD(_, nodeType) virtual checker::Type *Check(ir::nodeType *node) const = 0; 1853af6ab5fSopenharmony_ci AST_NODE_MAPPING(DECLARE_AST_NODE_CHECK_METHOD) 1863af6ab5fSopenharmony_ci#undef DECLARE_AST_NODE_CHECK_METHOD 1873af6ab5fSopenharmony_ci 1883af6ab5fSopenharmony_ci// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 1893af6ab5fSopenharmony_ci#define DECLARE_AST_NODE_CHECK_METHOD(_, __, nodeType, ___) virtual checker::Type *Check(ir::nodeType *node) const = 0; 1903af6ab5fSopenharmony_ci AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD) 1913af6ab5fSopenharmony_ci#undef DECLARE_AST_NODE_CHECK_METHOD 1923af6ab5fSopenharmony_ci 1933af6ab5fSopenharmony_ciprotected: 1943af6ab5fSopenharmony_ci Checker *GetChecker() const 1953af6ab5fSopenharmony_ci { 1963af6ab5fSopenharmony_ci return checker_; 1973af6ab5fSopenharmony_ci } 1983af6ab5fSopenharmony_ci 1993af6ab5fSopenharmony_ciprivate: 2003af6ab5fSopenharmony_ci Checker *checker_; 2013af6ab5fSopenharmony_ci}; 2023af6ab5fSopenharmony_ci} // namespace ark::es2panda::checker 2033af6ab5fSopenharmony_ci 2043af6ab5fSopenharmony_ci#endif // ES2PANDA_CHECKER_SEMANTICANALYZER_H 205