diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 729d0c351967de948d2138e891232149cc3869f4..54e8f0238e01c82c41a285ae436236bee47ff667 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -100,23 +100,6 @@ if(PANDA_WITH_ETS) file(COPY "${GENERATED_DIR}/arktsconfig.json" DESTINATION "${CMAKE_BINARY_DIR}/bin-gtests") endif() -# add check for PANDA_PRODUCT_BUILD after normal version tracking will be implemented -execute_process( - COMMAND date "+%Y-%m-%d_%H:%M:%S" - OUTPUT_VARIABLE CURRENT_DATE - OUTPUT_STRIP_TRAILING_WHITESPACE -) -execute_process( - COMMAND git rev-parse HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE LAST_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -add_definitions(-DES2PANDA_DATE="${CURRENT_DATE}") -add_definitions(-DES2PANDA_HASH="${LAST_COMMIT_HASH}") - - add_custom_command( OUTPUT ${GENERATED_STAMP} COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR} diff --git a/ets2panda/ast_verifier/ASTVerifier.cpp b/ets2panda/ast_verifier/ASTVerifier.cpp index e55eaac5bb4bfcf16edb00c06b1de418aba183b4..b924a2e2661e780865767b956b4deb0c8cc9ca94 100644 --- a/ets2panda/ast_verifier/ASTVerifier.cpp +++ b/ets2panda/ast_verifier/ASTVerifier.cpp @@ -15,6 +15,8 @@ #include "ASTVerifier.h" +#include "public/public.h" + namespace ark::es2panda::compiler::ast_verifier { using AstToCheck = ArenaMap; @@ -217,6 +219,11 @@ void ASTVerifier::DumpMessages() const } } +const util::Options &ASTVerifier::Options() const +{ + return *context_.config->options; +} + void InvariantMessages::AddCheckMessage(const std::string &cause, const ir::AstNode &node) { messages_.emplace_back(cause.data(), &node); diff --git a/ets2panda/ast_verifier/ASTVerifier.h b/ets2panda/ast_verifier/ASTVerifier.h index edd854d180e676902b83c79a880c711717515d54..8c6d05a78dbdeeebde976f14a737367dbf199864 100644 --- a/ets2panda/ast_verifier/ASTVerifier.h +++ b/ets2panda/ast_verifier/ASTVerifier.h @@ -52,7 +52,6 @@ #include "util/options.h" #include "utils/arena_containers.h" #include "varbinder/variable.h" -#include "public/public.h" #ifdef ASTV_ENABLE_LOGGING // CC-OFFNXT(G.PRE.02) macro to enable conditionally @@ -179,10 +178,7 @@ private: return enabled_[T::ID] && allowed_[T::ID]; } - const util::Options &Options() const - { - return *context_.config->options; - } + const util::Options &Options() const; public: using SourcePath = std::string_view; diff --git a/ets2panda/ast_verifier/invariants/checkConstProperties.cpp b/ets2panda/ast_verifier/invariants/checkConstProperties.cpp index b35435ee17db49685287dbe29b7d5e09835f4422..c91280cf34e88a56c3b5fecbd70d1988de077356 100644 --- a/ets2panda/ast_verifier/invariants/checkConstProperties.cpp +++ b/ets2panda/ast_verifier/invariants/checkConstProperties.cpp @@ -14,6 +14,7 @@ */ #include "checkConstProperties.h" +#include "ir/base/classDefinition.h" #include "ir/expressions/callExpression.h" #include "ir/expressions/memberExpression.h" #include "checker/types/signature.h" diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 0ce40af3ff5f16d7b945d41e7498d36fc5d29973..d470dea42741bf3a9b5d35789a5405d813ff2da1 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -16,17 +16,29 @@ #include "ETSAnalyzer.h" #include "checker/ETSchecker.h" -#include "compiler/lowering/util.h" #include "generated/diagnostic.h" #include "checker/types/globalTypesHolder.h" +#include "checker/types/ets/etsFunctionType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsTypeAliasType.h" +#include "checker/types/ets/etsStringType.h" +#include "checker/types/ets/etsBigIntType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsResizableArrayType.h" +#include "checker/types/ets/etsAsyncFuncReturnType.h" #include "checker/types/gradualType.h" -#include "evaluate/scopedDebugInfoPlugin.h" +#include "checker/types/typeError.h" #include "types/signature.h" -#include "compiler/lowering/ets/setJumpTarget.h" -#include "checker/types/ets/etsAsyncFuncReturnType.h" #include "types/type.h" -#include "checker/types/typeError.h" +#include "evaluate/scopedDebugInfoPlugin.h" +#include "compiler/lowering/ets/setJumpTarget.h" +#include "compiler/lowering/util.h" + +#include "ir/brokenTypeNode.h" +#include "ir/ets/etsUnionType.h" +#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/expressions/dummyNode.h" #include @@ -577,6 +589,11 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewArrayInstanceExpression *expr) const return expr->TsType(); } +static bool TypeIsAllowedForInstantiation(checker::Type *type) +{ + return !(type->IsETSNullType() || type->IsETSUndefinedType() || type->IsETSNeverType() || type->IsETSVoidType()); +} + static checker::Type *CheckInstantiatedNewType(ETSChecker *checker, ir::ETSNewClassInstanceExpression *expr) { checker::Type *res = expr->GetTypeRef()->Check(checker); @@ -586,7 +603,7 @@ static checker::Type *CheckInstantiatedNewType(ETSChecker *checker, ir::ETSNewCl if (calleeType->IsETSUnionType()) { return checker->TypeError(expr->GetTypeRef(), diagnostic::UNION_NONCONSTRUCTIBLE, expr->Start()); } - if (!ir::ETSNewClassInstanceExpression::TypeIsAllowedForInstantiation(calleeType)) { + if (!TypeIsAllowedForInstantiation(calleeType)) { return checker->TypeError(expr->GetTypeRef(), diagnostic::CALLEE_NONCONSTRUCTIBLE, {calleeType}, expr->Start()); } if (!calleeType->IsETSObjectType()) { @@ -4225,3 +4242,1006 @@ checker::Type *ETSAnalyzer::ReturnTypeForStatement([[maybe_unused]] const ir::St } } // namespace ark::es2panda::checker + +namespace ark::es2panda::ir { + +checker::VerifiedType PrefixAssertionExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType NamedType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ClassStaticBlock::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType Decorator::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSFunctionType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSUnionType::Check(checker::ETSChecker *checker) +{ + for (auto *it : Types()) { + it->Check(checker); + } + + return {this, GetType(checker)}; +} + +checker::VerifiedType ETSPackageDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSNewClassInstanceExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSClassLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSTypeReferencePart::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSPrimitiveType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSTypeReference::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSNewMultiDimArrayInstanceExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSWildcardType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSNewArrayInstanceExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSUndefinedKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSBooleanKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSExternalModuleReference::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSEnumMember::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSStringKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSNonNullExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSQualifiedName::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSInterfaceDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSAnyKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSVoidKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSNumberKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSUnknownKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSArrayType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ImportDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ExportSpecifier::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ImportDefaultSpecifier::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ExportAllDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ExportDefaultDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ExportNamedDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ImportSpecifier::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ImportNamespaceSpecifier::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ThisExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ObjectExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BlockExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType OmittedExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ChainExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ArrayExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType MemberExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType UpdateExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType DirectEvalExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType DummyNode::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ClassExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType AwaitExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BinaryExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ImportExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType UnaryExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType Identifier::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType SequenceExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType UndefinedLiteral::Check(checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSUndefinedType()); + return {this, TsType()}; +} + +checker::VerifiedType NumberLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType StringLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType NullLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType RegExpLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TypeofExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType NewExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType CallExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ArrowFunctionExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ConditionalExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType CatchClause::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ClassDefinition::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSSignatureDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSMethodSignature::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType MetaProperty::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ClassProperty::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType Property::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType SwitchStatement::Check(checker::ETSChecker *const checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSAsExpression::Check(checker::ETSChecker *const checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSEnumDeclaration::Check(checker::ETSChecker *const checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSPropertySignature::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSIndexSignature::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TemplateElement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType MethodDefinition::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ScriptFunction::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ReturnStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType FunctionDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType AnnotationUsage::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType AnnotationDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ForUpdateStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType LabelledStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ExpressionStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType EmptyStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType DebuggerStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ForOfStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ForInStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ContinueStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType SwitchCaseStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType VariableDeclarator::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType DoWhileStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ClassDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BreakStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSStructDeclaration::Check(checker::ETSChecker *checker) +{ + ES2PANDA_ASSERT(checker->IsAnyError()); + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSNeverType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSUndefinedType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSNullType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSNonNullishTypeNode::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSStringLiteralType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSKeyofType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSConditionalType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSMappedType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypePredicate::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeAssertion::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSParenthesizedType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeParameter::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeParameterDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeAliasDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSInterfaceBody::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSThisType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSConstructorType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSIndexedAccessType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeOperator::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSParameterProperty::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSInferType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeReference::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSBigintKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSModuleBlock::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSNullKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeParameterInstantiation::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTupleType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSLiteralType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSNamedTupleMember::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSNeverKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSObjectKeyword::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSImportEqualsDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSInterfaceHeritage::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSTypeQuery::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSFunctionType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSIntersectionType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSModuleDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSClassImplements::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSUnionType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TSImportType::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BrokenTypeNode::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType AssignmentExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType FunctionExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType YieldExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TemplateLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType SuperExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TaggedTemplateExpression::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BooleanLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BigIntLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType CharLiteral::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType SpreadElement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType OverloadDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType VariableDeclaration::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType AssertStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType TryStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType WhileStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType BlockStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ThrowStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType LoopStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::VerifiedType IfStatement::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType OpaqueTypeNode::Check(checker::ETSChecker *checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +checker::VerifiedType ETSParameterExpression::Check(checker::ETSChecker *const checker) +{ + return {this, checker->GetAnalyzer()->Check(this)}; +} + +// NOTE(dkofanov): 'GetType' methods should be removed: + +checker::Type *ETSNonNullishTypeNode::GetType(checker::ETSChecker *checker) +{ + return TsType() != nullptr ? TsType() : Check(checker); +} + +checker::Type *ETSWildcardType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + return checker->GlobalWildcardType(); +} + +checker::Type *BrokenTypeNode::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + return checker->GlobalTypeError(); +} + +checker::Type *OpaqueTypeNode::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + return TsType(); +} + +checker::Type *ETSFunctionType::GetType(checker::ETSChecker *checker) +{ + return Check(checker); +} + +checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + switch (GetPrimitiveType()) { + case PrimitiveType::BYTE: { + SetTsType(checker->GlobalByteBuiltinType()); + return TsType(); + } + case PrimitiveType::SHORT: { + SetTsType(checker->GlobalShortBuiltinType()); + return TsType(); + } + case PrimitiveType::INT: { + SetTsType(checker->GlobalIntBuiltinType()); + return TsType(); + } + case PrimitiveType::LONG: { + SetTsType(checker->GlobalLongBuiltinType()); + return TsType(); + } + case PrimitiveType::FLOAT: { + SetTsType(checker->GlobalFloatBuiltinType()); + return TsType(); + } + case PrimitiveType::DOUBLE: { + SetTsType(checker->GlobalDoubleBuiltinType()); + return TsType(); + } + case PrimitiveType::BOOLEAN: { + SetTsType(checker->GlobalETSBooleanBuiltinType()); + return TsType(); + } + case PrimitiveType::CHAR: { + SetTsType(checker->GlobalCharBuiltinType()); + return TsType(); + } + case PrimitiveType::VOID: { + if (LIKELY(checker->CheckVoidAnnotation(this))) { + SetTsType(checker->GlobalVoidType()); + return TsType(); + } + + return checker->InvalidateType(this); + } + default: { + ES2PANDA_UNREACHABLE(); + } + } +} + +checker::Type *TSArrayType::GetType(checker::ETSChecker *checker) +{ + checker::Type *type = checker->CreateETSArrayType(elementType_->GetType(checker), IsReadonlyType()); + if (IsReadonlyType()) { + type = checker->GetReadonlyType(type); + } + SetTsType(type); + return type; +} + +checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + // NOTE: validate + return checker->GlobalETSObjectType(); +} + +checker::Type *TSThisType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + auto *containingClass = checker->Context().ContainingClass(); + if (containingClass == nullptr) { + return checker->GlobalTypeError(); + } + return containingClass; +} + +checker::Type *ETSKeyofType::GetType(checker::ETSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + auto *typeReference = type_->GetType(checker); + ES2PANDA_ASSERT(typeReference); + + if (typeReference->IsETSPrimitiveType()) { + typeReference = checker->MaybeBoxType(typeReference); + } + + if (!typeReference->IsETSObjectType()) { + checker->LogError(diagnostic::KEYOF_REFERENCE_TYPE, {}, Start()); + SetTsType(checker->GlobalTypeError()); + return checker->GlobalTypeError(); + } + + checker::TypeStackElement tse(checker, GetHistoryNode(), {{diagnostic::CYCLIC_TYPE_OF, {}}}, Start()); + if (tse.HasTypeError()) { + return checker->GlobalTypeError(); + } + + SetTsType(checker->CreateUnionFromKeyofType(typeReference->AsETSObjectType())); + return TsType(); +} + +checker::Type *ETSUndefinedType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSUndefinedType()); + return TsType(); +} + +checker::Type *ETSNullType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSNullType()); + return TsType(); +} + +checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + auto *type = Part()->GetType(checker); + if (IsReadonlyType()) { + type = checker->GetReadonlyType(type); + } + return SetTsType(type); +} + +static bool CheckConstituentTypesValid(ArenaVector const &constituentTypes) +{ + for (auto &it : constituentTypes) { + if (it->IsTypeError()) { + return false; + } + } + return true; +} + +checker::Type *ETSUnionType::GetType(checker::ETSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + checker->CheckAnnotations(this); + + ArenaVector types(checker->Allocator()->Adapter()); + + for (auto *it : Types()) { + types.push_back(it->GetType(checker)); + } + + checker->Relation()->SetNode(this); + if (!CheckConstituentTypesValid(types)) { + SetTsType(checker->GlobalTypeError()); + } else { + SetTsType(checker->CreateETSUnionType(std::move(types))); + } + checker->Relation()->SetNode(nullptr); + return TsType(); +} + +checker::Type *ETSStringLiteralType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->CreateETSStringLiteralType(value_)); + return TsType(); +} + +checker::Type *ETSNeverType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSNeverType()); + return TsType(); +} + +} // namespace ark::es2panda::ir diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index d3127e33aa2eb640069872c868a0be4ba0186073..30a27792aa3f53b938e0fa931bbe02e6c83637f1 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -15,6 +15,10 @@ #include "ETSAnalyzerHelpers.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsExtensionFuncHelperType.h" #include "checker/types/typeError.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index fcee9f460c42a61cb2f1b45cac30585e8f09cb62..14d2e0045f401a061d018c4edd738a75e9c6785f 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -33,10 +33,11 @@ #include "checker/ets/assignAnalyzer.h" #include "checker/ets/etsWarningAnalyzer.h" #include "checker/types/globalTypesHolder.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsTupleType.h" #include "ir/base/scriptFunction.h" #include "util/helpers.h" #include "evaluate/scopedDebugInfoPlugin.h" -#include "checker/types/ets/etsTupleType.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 5aaf2180560f96f9ba72ed83b5af9b65b07164b6..12fd4c04b4bb3f735bc55d2eb1addbb3a19ae521 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -16,13 +16,13 @@ #ifndef ES2PANDA_CHECKER_ETS_CHECKER_H #define ES2PANDA_CHECKER_ETS_CHECKER_H -#include #include +#include #include "checker/checker.h" #include "checker/types/globalTypesHolder.h" -#include "checker/types/ets/etsResizableArrayType.h" +#include "checker/types/ets/etsObjectTypeConstants.h" #include "checker/types/ets/types.h" #include "checker/resolveResult.h" #include "ir/visitor/AstVisitor.h" diff --git a/ets2panda/checker/SemanticAnalyzer.h b/ets2panda/checker/SemanticAnalyzer.h index 1126ba93c03b19140c9f8c2a5b66671fcfd2a0d1..a373385b117a5d437e196152383e94c0fec4e4bd 100644 --- a/ets2panda/checker/SemanticAnalyzer.h +++ b/ets2panda/checker/SemanticAnalyzer.h @@ -17,160 +17,8 @@ #define ES2PANDA_CHECKER_SEMANTICANALYZER_H #include "compiler/core/dynamicContext.h" -#include "ir/opaqueTypeNode.h" -#include "ir/as/namedType.h" -#include "ir/as/prefixAssertionExpression.h" -#include "ir/base/catchClause.h" -#include "ir/base/classDefinition.h" -#include "ir/base/classProperty.h" -#include "ir/base/classStaticBlock.h" -#include "ir/base/decorator.h" -#include "ir/base/metaProperty.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/overloadDeclaration.h" -#include "ir/base/property.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/spreadElement.h" -#include "ir/base/templateElement.h" -#include "ir/base/tsIndexSignature.h" -#include "ir/base/tsMethodSignature.h" -#include "ir/base/tsPropertySignature.h" -#include "ir/base/tsSignatureDeclaration.h" -#include "ir/ets/etsClassLiteral.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/ets/etsIntrinsicNode.h" -#include "ir/ets/etsImportDeclaration.h" -#include "ir/ets/etsKeyofType.h" -#include "ir/ets/etsNewArrayInstanceExpression.h" -#include "ir/ets/etsNewClassInstanceExpression.h" -#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" -#include "ir/ets/etsPackageDeclaration.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/ets/etsPrimitiveType.h" -#include "ir/ets/etsModule.h" -#include "ir/ets/etsStringLiteralType.h" -#include "ir/ets/etsNeverType.h" -#include "ir/ets/etsNonNullishTypeNode.h" -#include "ir/ets/etsNullishTypes.h" -#include "ir/ets/etsStructDeclaration.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/ets/etsWildcardType.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/awaitExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/blockExpression.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/chainExpression.h" -#include "ir/expressions/classExpression.h" -#include "ir/expressions/conditionalExpression.h" -#include "ir/expressions/directEvalExpression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/importExpression.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/newExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/omittedExpression.h" -#include "ir/expressions/sequenceExpression.h" -#include "ir/expressions/superExpression.h" -#include "ir/expressions/taggedTemplateExpression.h" -#include "ir/expressions/templateLiteral.h" -#include "ir/expressions/thisExpression.h" -#include "ir/expressions/typeofExpression.h" -#include "ir/expressions/unaryExpression.h" -#include "ir/expressions/updateExpression.h" -#include "ir/expressions/yieldExpression.h" -#include "ir/expressions/literals/bigIntLiteral.h" -#include "ir/expressions/literals/booleanLiteral.h" -#include "ir/expressions/literals/charLiteral.h" -#include "ir/expressions/literals/nullLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/regExpLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/exportAllDeclaration.h" -#include "ir/module/exportDefaultDeclaration.h" -#include "ir/module/exportNamedDeclaration.h" -#include "ir/module/exportSpecifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/module/importDefaultSpecifier.h" -#include "ir/module/importNamespaceSpecifier.h" -#include "ir/module/importSpecifier.h" -#include "ir/statements/assertStatement.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/breakStatement.h" -#include "ir/statements/classDeclaration.h" -#include "ir/statements/continueStatement.h" -#include "ir/statements/debuggerStatement.h" -#include "ir/statements/doWhileStatement.h" -#include "ir/statements/emptyStatement.h" -#include "ir/statements/expressionStatement.h" -#include "ir/statements/forInStatement.h" -#include "ir/statements/forOfStatement.h" -#include "ir/statements/forUpdateStatement.h" -#include "ir/statements/functionDeclaration.h" -#include "ir/statements/ifStatement.h" -#include "ir/statements/labelledStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/statements/switchCaseStatement.h" -#include "ir/statements/switchStatement.h" -#include "ir/statements/throwStatement.h" -#include "ir/statements/tryStatement.h" -#include "ir/statements/variableDeclaration.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/statements/whileStatement.h" -#include "ir/ts/tsAnyKeyword.h" -#include "ir/ts/tsArrayType.h" -#include "ir/ts/tsAsExpression.h" -#include "ir/ts/tsBigintKeyword.h" -#include "ir/ts/tsBooleanKeyword.h" -#include "ir/ts/tsClassImplements.h" -#include "ir/ts/tsConditionalType.h" -#include "ir/ts/tsConstructorType.h" -#include "ir/ts/tsEnumDeclaration.h" -#include "ir/ts/tsEnumMember.h" -#include "ir/ts/tsExternalModuleReference.h" -#include "ir/ts/tsFunctionType.h" -#include "ir/ts/tsImportEqualsDeclaration.h" -#include "ir/ts/tsImportType.h" -#include "ir/ts/tsIndexedAccessType.h" -#include "ir/ts/tsInferType.h" -#include "ir/ts/tsInterfaceBody.h" -#include "ir/ts/tsInterfaceDeclaration.h" -#include "ir/ts/tsInterfaceHeritage.h" -#include "ir/ts/tsIntersectionType.h" -#include "ir/ts/tsLiteralType.h" -#include "ir/ts/tsMappedType.h" -#include "ir/ts/tsModuleBlock.h" -#include "ir/ts/tsModuleDeclaration.h" -#include "ir/ts/tsNamedTupleMember.h" -#include "ir/ts/tsNeverKeyword.h" -#include "ir/ts/tsNonNullExpression.h" -#include "ir/ts/tsNullKeyword.h" -#include "ir/ts/tsNumberKeyword.h" -#include "ir/ts/tsObjectKeyword.h" -#include "ir/ts/tsParameterProperty.h" -#include "ir/ts/tsParenthesizedType.h" -#include "ir/ts/tsQualifiedName.h" -#include "ir/ts/tsStringKeyword.h" -#include "ir/ts/tsThisType.h" -#include "ir/ts/tsTupleType.h" -#include "ir/ts/tsTypeAliasDeclaration.h" -#include "ir/ts/tsTypeAssertion.h" -#include "ir/ts/tsTypeLiteral.h" -#include "ir/ts/tsTypeOperator.h" -#include "ir/ts/tsTypeParameterDeclaration.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/ts/tsTypePredicate.h" -#include "ir/ts/tsTypeQuery.h" -#include "ir/ts/tsTypeReference.h" -#include "ir/ts/tsUndefinedKeyword.h" -#include "ir/ts/tsUnionType.h" -#include "ir/ts/tsUnknownKeyword.h" -#include "ir/ts/tsVoidKeyword.h" +#include "ir/astNodeMapping.h" +#include "checker/types/ets/types.h" namespace ark::es2panda::checker { class Checker; diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 655c154d5f62250d0c9fb34c1864a88a80a7bb09..8df9b6a9ee0db2b36628fed1d651b75133757600 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -18,6 +18,12 @@ #include "checker/TSchecker.h" #include "checker/ts/destructuringContext.h" +#include "ir/ets/etsUnionType.h" +#include "ir/expressions/dummyNode.h" +#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/statements/annotationDeclaration.h" +#include "ir/brokenTypeNode.h" + namespace ark::es2panda::checker { TSChecker *TSAnalyzer::GetTSChecker() const @@ -2123,4 +2129,973 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const { return nullptr; } + } // namespace ark::es2panda::checker + +namespace ark::es2panda::ir { + +checker::Type *PrefixAssertionExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *NamedType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSIntrinsicNode::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return nullptr; +} + +checker::Type *ETSFunctionType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSUnionType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return nullptr; +} + +checker::Type *ETSPackageDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSNewClassInstanceExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSClassLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSStructDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *ETSNeverType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *ETSUndefinedType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *ETSNullType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *ETSTypeReferencePart::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSPrimitiveType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSTypeReference::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSNewMultiDimArrayInstanceExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSWildcardType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSNonNullishTypeNode::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *ETSStringLiteralType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *ETSNewArrayInstanceExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSKeyofType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return nullptr; +} + +checker::Type *TSUndefinedKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSBooleanKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSConditionalType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSExternalModuleReference::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSMappedType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypePredicate::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeAssertion::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSParenthesizedType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeParameter::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSEnumMember::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeParameterDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSStringKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeAliasDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSNonNullExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSInterfaceBody::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSThisType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSConstructorType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSIndexedAccessType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSEnumDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeOperator::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSParameterProperty::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSQualifiedName::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSInterfaceDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSInferType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeReference::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSAnyKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSBigintKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSModuleBlock::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSNullKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeParameterInstantiation::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTupleType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSVoidKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSLiteralType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSNamedTupleMember::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSAsExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSNeverKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSObjectKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSImportEqualsDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSInterfaceHeritage::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeQuery::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSFunctionType::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSIntersectionType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSNumberKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSClassImplements::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSUnionType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSUnknownKeyword::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSArrayType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSImportType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ImportDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExportSpecifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ImportDefaultSpecifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExportAllDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExportDefaultDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExportNamedDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ImportSpecifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ImportNamespaceSpecifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BrokenTypeNode::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ThisExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *AssignmentExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ObjectExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *FunctionExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BlockExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + ES2PANDA_UNREACHABLE(); +} + +checker::Type *OmittedExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ChainExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ArrayExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *MemberExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *UpdateExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *DirectEvalExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *DummyNode::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *YieldExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ClassExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TemplateLiteral::Check([[maybe_unused]] checker::TSChecker *checker) +{ + // NOTE: aszilagyi. + return checker->GlobalAnyType(); +} + +checker::Type *AwaitExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BinaryExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *SuperExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ImportExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TaggedTemplateExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *UnaryExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *Identifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *SequenceExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BooleanLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *UndefinedLiteral::Check(checker::TSChecker *checker) +{ + return checker->GlobalUndefinedType(); +} + +checker::Type *NumberLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *StringLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BigIntLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *CharLiteral::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *NullLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *RegExpLiteral::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TypeofExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *NewExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *CallExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ArrowFunctionExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ConditionalExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *CatchClause::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ClassDefinition::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSSignatureDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSMethodSignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *SpreadElement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *Decorator::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *MetaProperty::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ClassStaticBlock::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *OverloadDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return nullptr; +} + +checker::Type *ClassProperty::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *Property::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSPropertySignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSIndexSignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TemplateElement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *MethodDefinition::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ScriptFunction::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ReturnStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *FunctionDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *VariableDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *SwitchStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *AssertStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TryStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *AnnotationUsage::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *AnnotationDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ForUpdateStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *LabelledStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExpressionStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *WhileStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BlockStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ThrowStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *EmptyStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *DebuggerStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *IfStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ForOfStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ForInStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ContinueStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *SwitchCaseStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *VariableDeclarator::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *DoWhileStatement::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ClassDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *BreakStatement::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *OpaqueTypeNode::Check([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSParameterExpression::Check(checker::TSChecker *const checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +// NOTE(dkofanov): 'GetType' methods should be removed: + +checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalAnyType(); +} + +checker::Type *TSAnyKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalAnyType(); +} + +checker::Type *TSArrayType::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->Allocator()->New(elementType_->GetType(checker)); +} + +checker::Type *TSBigintKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalBigintType(); +} + +checker::Type *TSBooleanKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalBooleanType(); +} + +checker::Type *TSIndexedAccessType::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + checker::Type *baseType = objectType_->GetType(checker); + checker::Type *indexType = indexType_->GetType(checker); + checker::Type *resolved = checker->GetPropertyTypeForIndexType(baseType, indexType); + + SetTsType(resolved); + return TsType(); +} + +checker::Type *TSLiteralType::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + SetTsType(literal_->Check(checker)); + return TsType(); +} + +checker::Type *TSNeverKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalNeverType(); +} + +checker::Type *TSNullKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalNullType(); +} + +checker::Type *TSNumberKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalNumberType(); +} + +checker::Type *TSObjectKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalNonPrimitiveType(); +} + +checker::Type *TSParenthesizedType::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + SetTsType(type_->GetType(checker)); + return TsType(); +} + +checker::Type *TSStringKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalStringType(); +} + +checker::Type *TSVoidKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalVoidType(); +} + +checker::Type *TSTypeReference::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + if (typeName_->IsTSQualifiedName()) { + return checker->GlobalAnyType(); + } + + ES2PANDA_ASSERT(typeName_->IsIdentifier()); + varbinder::Variable *var = typeName_->AsIdentifier()->Variable(); + + if (var == nullptr) { + checker->ThrowTypeError({"Cannot find name ", typeName_->AsIdentifier()->Name()}, Start()); + } + + SetTsType(checker->GetTypeReferenceType(this, var)); + return TsType(); +} + +checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalUndefinedType(); +} + +checker::Type *TSUnknownKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GlobalUnknownType(); +} + +checker::Type *TSTypeQuery::GetType([[maybe_unused]] checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *TSTypeLiteral::GetType(checker::TSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + checker::ObjectDescriptor *desc = checker->Allocator()->New(checker->Allocator()); + checker::Type *type = checker->Allocator()->New(desc); + ES2PANDA_ASSERT(type != nullptr); + type->SetVariable(Variable()); + + SetTsType(type); + return TsType(); +} + +checker::Type *TSConstructorType::GetType(checker::TSChecker *checker) +{ + return checker->CheckTypeCached(this); +} + +checker::Type *TSUnionType::GetType(checker::TSChecker *checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + ArenaVector types(checker->Allocator()->Adapter()); + + for (auto *it : types_) { + types.push_back(it->GetType(checker)); + } + + SetTsType(checker->CreateUnionType(std::move(types))); + return TsType(); +} + +checker::Type *TSFunctionType::GetType(checker::TSChecker *checker) +{ + return checker->CheckTypeCached(this); +} + +} // namespace ark::es2panda::ir diff --git a/ets2panda/checker/checkerContext.cpp b/ets2panda/checker/checkerContext.cpp index fa10d82fac4f1bb494e247289620832e0fec818f..36b7097e747f10f6c65ea74fb153bebfbb1cc3d1 100644 --- a/ets2panda/checker/checkerContext.cpp +++ b/ets2panda/checker/checkerContext.cpp @@ -14,6 +14,7 @@ */ #include "ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ets/aliveAnalyzer.cpp b/ets2panda/checker/ets/aliveAnalyzer.cpp index e4edb04a7a1eadcccc752a94d25838480119604d..2748b5fd549f42fb9d6220dfd0989bcefe7cdc0e 100644 --- a/ets2panda/checker/ets/aliveAnalyzer.cpp +++ b/ets2panda/checker/ets/aliveAnalyzer.cpp @@ -49,6 +49,7 @@ #include "varbinder/variable.h" #include "varbinder/declaration.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" #include "ir/base/catchClause.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 46ea410c02ed3c94a3d3e0194380d5c1deebfb6c..c7d4b031202285bfd10d2bd4f69e3b589e05c492 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -17,6 +17,7 @@ #include "checker/types/globalTypesHolder.h" #include "checker/types/typeError.h" +#include "checker/types/ets/etsUnionType.h" #include "lexer/token/token.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ets/assignAnalyzer.cpp b/ets2panda/checker/ets/assignAnalyzer.cpp index a411f9d429bf07f01adc90396a3a08a1261112b7..81f9f7c30bcdc91dc9c2d39a58d8be7a44ec5d58 100644 --- a/ets2panda/checker/ets/assignAnalyzer.cpp +++ b/ets2panda/checker/ets/assignAnalyzer.cpp @@ -15,6 +15,7 @@ #include "assignAnalyzer.h" +#include "ir/base/catchClause.h" #include "ir/base/classDefinition.h" #include "ir/base/classProperty.h" #include "ir/base/classStaticBlock.h" @@ -58,9 +59,9 @@ #include "varbinder/declaration.h" #include "checker/ETSchecker.h" #include "checker/types/gradualType.h" -#include "ir/base/catchClause.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsBooleanType.h" #include "parser/program/program.h" -#include "checker/types/ts/objectType.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ets/etsWarningAnalyzer.cpp b/ets2panda/checker/ets/etsWarningAnalyzer.cpp index f207387c3f3d1c864cf618001ad783eeda5b3e71..3310efd922f4eff80ae39ec5394c6263fb5d9ed8 100644 --- a/ets2panda/checker/ets/etsWarningAnalyzer.cpp +++ b/ets2panda/checker/ets/etsWarningAnalyzer.cpp @@ -34,6 +34,7 @@ #include "ir/base/classDefinition.h" #include "ir/statements/forOfStatement.h" #include "ir/statements/variableDeclarator.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 1fd04a4a9e88ed3d4b7489ecfbe585db545fbe43..182549949ce66dc4dfb3f790dd27857bf3023dc9 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -15,8 +15,12 @@ #include +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsReadonlyType.h" #include "checker/types/ets/etsResizableArrayType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsNonNullishType.h" #include "generated/signatures.h" #include "checker/ets/wideningConverter.h" #include "ir/astNodeFlags.h" diff --git a/ets2panda/checker/ets/function_helpers.h b/ets2panda/checker/ets/function_helpers.h index 7730c65f761e4decde9ef61df925a6af35a41b56..1ee7b3e71d52110a6f07a0abc8bbb82b47de6fc0 100644 --- a/ets2panda/checker/ets/function_helpers.h +++ b/ets2panda/checker/ets/function_helpers.h @@ -18,6 +18,7 @@ #include "checker/ETSchecker.h" #include "checker/ets/typeRelationContext.h" +#include "checker/types/ets/etsTypeParameter.h" #include "checker/types/ets/etsObjectType.h" #include "checker/types/type.h" #include "ir/base/catchClause.h" diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 3ed10f6daa0e06b99d331a8c189cb036b546d1fa..20306de5d21038203cdd137fbaeba5b3629f1433 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -21,8 +21,15 @@ #include "checker/types/gradualType.h" #include "checker/checkerContext.h" #include "checker/ETSAnalyzerHelpers.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsResizableArrayType.h" #include "checker/types/ets/etsEnumType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsStringType.h" +#include "checker/types/ets/etsBooleanType.h" #include "checker/ets/typeRelationContext.h" #include "checker/ets/typeConverter.h" #include "evaluate/scopedDebugInfoPlugin.h" diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 3a2c876796b279d11c1623da93556dec47c02a82..b0eb65b59d1af08a69b791bb0429b67384fe8df2 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -17,11 +17,20 @@ #include "checker/ETSchecker.h" #include "checker/checkerContext.h" #include "checker/ets/typeRelationContext.h" +#include "checker/types/ets/etsFunctionType.h" #include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsTypeAliasType.h" +#include "checker/types/ets/etsReadonlyType.h" #include "checker/types/ets/etsPartialTypeParameter.h" #include "checker/types/ets/etsAwaitedType.h" #include "checker/types/gradualType.h" +#include "checker/types/ets/etsNonNullishType.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/intType.h" +#include "checker/types/ets/longType.h" +#include "checker/types/ets/shortType.h" #include "compiler/lowering/phase.h" #include "ir/base/classDefinition.h" #include "ir/base/classElement.h" diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 9fac309638e45f2e2b96e96d35d4a548657e5abe..1e7d48037d7abb70dda3e6ab089a73d7529439ce 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -18,8 +18,14 @@ #include "checker/ets/wideningConverter.h" #include "checker/types/globalTypesHolder.h" #include "checker/types/gradualType.h" +#include "checker/types/ets/etsAnyType.h" +#include "checker/types/ets/etsFunctionType.h" #include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsTypeAliasType.h" #include "checker/types/ets/etsPartialTypeParameter.h" +#include "checker/types/ets/etsNonNullishType.h" +#include "checker/types/ets/etsEnumType.h" #include "ir/base/catchClause.h" #include "ir/base/scriptFunction.h" #include "ir/base/classProperty.h" diff --git a/ets2panda/checker/ets/typeConverter.h b/ets2panda/checker/ets/typeConverter.h index 46635fdc5d66f58cfaa086f6b093a378a749bac2..7537d20b41c7de75eb1e705fd364f6e25ceb3218 100644 --- a/ets2panda/checker/ets/typeConverter.h +++ b/ets2panda/checker/ets/typeConverter.h @@ -18,9 +18,17 @@ #include "checker/types/typeFlag.h" #include "checker/types/ets/types.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/charType.h" +#include "checker/types/ets/doubleType.h" +#include "checker/types/ets/floatType.h" +#include "checker/types/ets/intType.h" +#include "checker/types/ets/longType.h" +#include "checker/types/ets/shortType.h" namespace ark::es2panda::checker { class ETSChecker; +class Type; class TypeConverter { public: diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 15b1e21069f490568c61f57d34f97f45801b2411..e01c4eaf97c67c27d2569bf8ae2f84ef1293cc2c 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -15,9 +15,25 @@ #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" #include "checker/types/ets/etsEnumType.h" #include "checker/types/ets/etsResizableArrayType.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsUnionType.h" + +#include "checker/types/ets/etsTypeAliasType.h" +#include "checker/types/ets/etsExtensionFuncHelperType.h" +#include "checker/types/ets/etsStringType.h" +#include "checker/types/ets/etsBooleanType.h" +#include "checker/types/ets/etsBigIntType.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/charType.h" +#include "checker/types/ets/doubleType.h" +#include "checker/types/ets/floatType.h" +#include "checker/types/ets/intType.h" +#include "checker/types/ets/longType.h" +#include "checker/types/ets/shortType.h" #include "checker/types/globalTypesHolder.h" #include "checker/types/gradualType.h" #include "checker/types/type.h" diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index d2835dec80367d14eb1aa29ef1050222f0848e85..1eb14731404714c40b8bfee9e141e091f5dee80a 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -14,6 +14,7 @@ */ #include "typeRelationContext.h" +#include "checker/types/ets/etsTypeParameter.h" namespace ark::es2panda::checker { bool AssignmentContext::ValidateArrayTypeInitializerByElement(TypeRelation *relation, ir::ArrayExpression *node, diff --git a/ets2panda/checker/ets/typeRelationContext.h b/ets2panda/checker/ets/typeRelationContext.h index 7ba41f94c85585a2607a67f9da63bea20b07c3ff..2d3d745376399aabec6b084fc69456cda0abc5d2 100644 --- a/ets2panda/checker/ets/typeRelationContext.h +++ b/ets2panda/checker/ets/typeRelationContext.h @@ -17,6 +17,7 @@ #define ES2PANDA_COMPILER_CHECKER_ETS_TYPE_RELATION_CONTEXT_H #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { class ETSChecker; diff --git a/ets2panda/checker/ets/utilityTypeHandlers.cpp b/ets2panda/checker/ets/utilityTypeHandlers.cpp index 215712fff1d03a2c2eba0d3b61de02e150ba4629..8fe5ebcd0c8256a21998ede157f6072eebb52fc4 100644 --- a/ets2panda/checker/ets/utilityTypeHandlers.cpp +++ b/ets2panda/checker/ets/utilityTypeHandlers.cpp @@ -21,9 +21,13 @@ #include "ir/ets/etsUnionType.h" #include "ir/expressions/literals/undefinedLiteral.h" #include "varbinder/ETSBinder.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsPartialTypeParameter.h" #include "checker/types/ets/etsAwaitedType.h" -#include "compiler/lowering/util.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsReadonlyType.h" + #include "util/nameMangler.h" #include diff --git a/ets2panda/checker/ets/validateHelpers.cpp b/ets2panda/checker/ets/validateHelpers.cpp index ead157339ea626fbba740c0fda764617e5ce8ff7..126df304b322ce43a8ca82881d44b06b2368f90c 100644 --- a/ets2panda/checker/ets/validateHelpers.cpp +++ b/ets2panda/checker/ets/validateHelpers.cpp @@ -14,6 +14,7 @@ */ #include "varbinder/variableFlags.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsTupleType.h" #include "checker/ETSchecker.h" diff --git a/ets2panda/checker/typeChecker/TypeChecker.h b/ets2panda/checker/typeChecker/TypeChecker.h index 864753b273ad8713ffc5957a7b5456f8c59b6881..bb49a3c2d448ff70a68a406df385e5379dbbbf20 100644 --- a/ets2panda/checker/typeChecker/TypeChecker.h +++ b/ets2panda/checker/typeChecker/TypeChecker.h @@ -17,6 +17,7 @@ #define PANDA_TYPECHECKER_H #include "ir/visitor/IterateAstVisitor.h" +#include "checker/checker.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/charType.cpp b/ets2panda/checker/types/ets/charType.cpp index 43bbec66cd258fa3b35bd307b86ec6a804ea5725..edc87d23c17f4673047e50fab6691df3107f89c1 100644 --- a/ets2panda/checker/types/ets/charType.cpp +++ b/ets2panda/checker/types/ets/charType.cpp @@ -17,6 +17,7 @@ #include "checker/ets/conversion.h" #include "checker/ets/wideningConverter.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void CharType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/doubleType.cpp b/ets2panda/checker/types/ets/doubleType.cpp index ad58d7bc8c9a5470fb94e12a8b57660b0dd10813..8d46e5d696720f1ab2877193070380434c8565c6 100644 --- a/ets2panda/checker/types/ets/doubleType.cpp +++ b/ets2panda/checker/types/ets/doubleType.cpp @@ -17,6 +17,7 @@ #include "checker/ets/conversion.h" #include "checker/ets/wideningConverter.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void DoubleType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/etsAnyType.cpp b/ets2panda/checker/types/ets/etsAnyType.cpp index c1e5307545c902a90b0062e2aa9fa97ff2b5abda..cec2ca4933b050944bcc762b7744339d4873706b 100644 --- a/ets2panda/checker/types/ets/etsAnyType.cpp +++ b/ets2panda/checker/types/ets/etsAnyType.cpp @@ -18,6 +18,7 @@ #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" +#include "checker/types/ets/etsObjectType.h" #include "etsTypeParameter.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index 79d9cc398389767328cfa2ccc2d9a51868e91f81..cccb0ff6cb52e1762ed1cf278d51e29164124f4f 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -21,6 +21,7 @@ #include "checker/ets/conversion.h" #include "checker/types/typeRelation.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsResizableArrayType.h" namespace ark::es2panda::checker { void ETSArrayType::ToString(std::stringstream &ss, bool precise) const diff --git a/ets2panda/checker/types/ets/etsBooleanType.cpp b/ets2panda/checker/types/ets/etsBooleanType.cpp index f19823daa2f3ab0f1dc703ee184a7708609884c5..9ffb7557bd07f434c26b51f23babd519faffe611 100644 --- a/ets2panda/checker/types/ets/etsBooleanType.cpp +++ b/ets2panda/checker/types/ets/etsBooleanType.cpp @@ -17,6 +17,7 @@ #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void ETSBooleanType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index 669ab5d1ed0a67aaf076429635f2f8b91605e10d..1030a44fad4ece135066bf564e8d73fb7e34eb06 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -14,6 +14,8 @@ */ #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/types/globalTypesHolder.h" #include "checker/types/typeError.h" #include "compiler/lowering/phase.h" diff --git a/ets2panda/checker/types/ets/etsNeverType.cpp b/ets2panda/checker/types/ets/etsNeverType.cpp index 0b5401c3ba54c9e81c5e0428d85d081a23493238..8d96d40cd58e0c064811a89329518adabeb13d5c 100644 --- a/ets2panda/checker/types/ets/etsNeverType.cpp +++ b/ets2panda/checker/types/ets/etsNeverType.cpp @@ -16,6 +16,7 @@ #include "etsNeverType.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/ets/conversion.h" #include "etsTypeParameter.h" diff --git a/ets2panda/checker/types/ets/etsNonNullishType.cpp b/ets2panda/checker/types/ets/etsNonNullishType.cpp index 7eee9243faa5f557ecf58a3de9251d1ccf8b59a6..548d856293a07282a5fcba762918168380a53301 100644 --- a/ets2panda/checker/types/ets/etsNonNullishType.cpp +++ b/ets2panda/checker/types/ets/etsNonNullishType.cpp @@ -18,6 +18,7 @@ #include "ir/expressions/identifier.h" #include "ir/ts/tsTypeParameter.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsNonNullishType.h" #include "checker/ets/conversion.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsNullishTypes.cpp b/ets2panda/checker/types/ets/etsNullishTypes.cpp index e9abc5839f4d6d494453c5aa8d7ad9fab029c3b0..c17cf677f309f4d48b42cb9b3c21322ad2e07437 100644 --- a/ets2panda/checker/types/ets/etsNullishTypes.cpp +++ b/ets2panda/checker/types/ets/etsNullishTypes.cpp @@ -18,6 +18,7 @@ #include "ir/expressions/identifier.h" #include "ir/ts/tsTypeParameter.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/ets/conversion.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 49679056d425bbf4f018bfe93351f7b7a7c7c021..42edc8465d43d48968b17553e6b59f6757eafc71 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -18,7 +18,10 @@ #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" #include "checker/types/globalTypesHolder.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsTypeParameter.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" +#include "checker/types/ets/etsResizableArrayType.h" #include "checker/types/ets/etsEnumType.h" #include "compiler/lowering/phase.h" #include "util/nameMangler.h" diff --git a/ets2panda/checker/types/ets/etsPartialTypeParameter.cpp b/ets2panda/checker/types/ets/etsPartialTypeParameter.cpp index 9333d54633a9c357e64dde7d9bbdc270b617ec4d..db8681428d4737c3022562b8ec26be7e57e57bbc 100644 --- a/ets2panda/checker/types/ets/etsPartialTypeParameter.cpp +++ b/ets2panda/checker/types/ets/etsPartialTypeParameter.cpp @@ -15,6 +15,7 @@ #include "etsPartialTypeParameter.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index 38930b20a3a519e024ff6bba7b36b785e0619191..32feb1eab3bb24a2f0e7ac9c9117fd5217a7850e 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -17,6 +17,7 @@ #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" +#include "checker/types/ets/etsObjectType.h" #include "ir/ets/etsTuple.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsTupleType.h b/ets2panda/checker/types/ets/etsTupleType.h index f6a76125a9f8d2032f1526238b5be2e100543fef..5c0c8a4f140680ba19fe896445238ea80978ec6a 100644 --- a/ets2panda/checker/types/ets/etsTupleType.h +++ b/ets2panda/checker/types/ets/etsTupleType.h @@ -30,7 +30,7 @@ public: typeList_(typeList), // NOLINTNEXTLINE(readability-implicit-bool-conversion) wrapperType_(checker->GlobalBuiltinTupleType(typeList_.size()) != nullptr - ? checker->GlobalBuiltinTupleType(typeList_.size())->AsETSObjectType() + ? checker->GlobalBuiltinTupleType(typeList_.size()) : nullptr) { typeFlags_ |= TypeFlag::ETS_TUPLE; diff --git a/ets2panda/checker/types/ets/etsTypeParameter.cpp b/ets2panda/checker/types/ets/etsTypeParameter.cpp index 53c70fcfcc2cc884654aae6c0b78e1453262d4a5..757a32ebddc39f18400a4a11fe4ebf08c8f3a574 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.cpp +++ b/ets2panda/checker/types/ets/etsTypeParameter.cpp @@ -17,6 +17,7 @@ #include "ir/expressions/identifier.h" #include "ir/ts/tsTypeParameter.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp index b68c4d4b00b61b534234a1eedeb387423c717fab..9b26f966fc3249e0faa628ebe77f288f2e5ef711 100644 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ b/ets2panda/checker/types/ets/etsUnionType.cpp @@ -19,6 +19,7 @@ #include "checker/ets/conversion.h" #include "checker/types/ets/etsTupleType.h" #include "checker/types/globalTypesHolder.h" +#include "checker/types/ets/etsTypeParameter.h" #include "checker/ETSchecker.h" namespace ark::es2panda::checker { diff --git a/ets2panda/checker/types/ets/etsUnionType.h b/ets2panda/checker/types/ets/etsUnionType.h index 0ae2e8a38bdf30728e7547aefc0292a7dea020fe..06d2b9c5f8a01d415d262243b6b8a5c91633eab4 100644 --- a/ets2panda/checker/types/ets/etsUnionType.h +++ b/ets2panda/checker/types/ets/etsUnionType.h @@ -17,10 +17,10 @@ #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_UNION_TYPE_H #include "checker/types/type.h" -#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { class GlobalTypesHolder; +class ETSObjectType; class ETSUnionType : public Type { public: diff --git a/ets2panda/checker/types/ets/floatType.cpp b/ets2panda/checker/types/ets/floatType.cpp index 958f338480b0afa1b7787edfc1f443222202edb5..1ac8fcbc2682fd03569e7494204943263b9cf1d6 100644 --- a/ets2panda/checker/types/ets/floatType.cpp +++ b/ets2panda/checker/types/ets/floatType.cpp @@ -17,6 +17,7 @@ #include "checker/ets/conversion.h" #include "checker/ets/wideningConverter.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void FloatType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/intType.cpp b/ets2panda/checker/types/ets/intType.cpp index 3587ee1bc0b071c21700acadf8ecc3315412f5a6..bc9b42c878849cfb77a3a312c3cb5a1d78bfe4bd 100644 --- a/ets2panda/checker/types/ets/intType.cpp +++ b/ets2panda/checker/types/ets/intType.cpp @@ -17,6 +17,7 @@ #include "checker/ets/conversion.h" #include "checker/ets/wideningConverter.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void IntType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/longType.cpp b/ets2panda/checker/types/ets/longType.cpp index 7b8c5b34fae0af6e8144ecc4412a82528e8c93ba..bdd3fcd360e4fdbd69d8063bc346a2bb749f32a6 100644 --- a/ets2panda/checker/types/ets/longType.cpp +++ b/ets2panda/checker/types/ets/longType.cpp @@ -17,6 +17,7 @@ #include "checker/ets/conversion.h" #include "checker/ets/wideningConverter.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void LongType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/shortType.cpp b/ets2panda/checker/types/ets/shortType.cpp index c7f79a229ea6be5b256578cf30154725121f5e93..c1eddf97e39e7710f2ce08fd3ab1ef326b318e9a 100644 --- a/ets2panda/checker/types/ets/shortType.cpp +++ b/ets2panda/checker/types/ets/shortType.cpp @@ -17,6 +17,7 @@ #include "checker/ets/conversion.h" #include "checker/ets/wideningConverter.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::checker { void ShortType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/types.h b/ets2panda/checker/types/ets/types.h index e82a8fa0a503b690ae1cd7a15531ebfa873e4fd8..b1b9b18ffa73b0530aa2108526382080ceda7b48 100644 --- a/ets2panda/checker/types/ets/types.h +++ b/ets2panda/checker/types/ets/types.h @@ -16,31 +16,36 @@ #ifndef ES2PANDA_COMPILER_CHECKER_TYPES_ETS_H #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_H -#include "byteType.h" -#include "charType.h" -#include "doubleType.h" -#include "floatType.h" -#include "intType.h" -#include "longType.h" -#include "shortType.h" -#include "etsBooleanType.h" -#include "etsExtensionFuncHelperType.h" -#include "etsFunctionType.h" -#include "etsUnionType.h" -#include "etsVoidType.h" -#include "etsStringType.h" -#include "etsBigIntType.h" -#include "etsObjectType.h" -#include "etsTypeAliasType.h" -#include "etsArrayType.h" -#include "wildcardType.h" -#include "etsTypeParameter.h" -#include "etsNonNullishType.h" -#include "etsNullishTypes.h" -#include "checker/types/signature.h" -#include "etsReadonlyType.h" -#include "etsAnyType.h" -#include "etsNeverType.h" -#include "etsEnumType.h" +namespace ark::es2panda::checker { +class ByteType; +class CharType; +class DoubleType; +class FloatType; +class IntType; +class LongType; +class ShortType; +class WildcardType; +class ETSBooleanType; +class ETSExtensionFuncHelperType; +class ETSFunctionType; +class ETSUnionType; +class ETSVoidType; +class ETSStringType; +class ETSBigIntType; +class ETSObjectType; +class ETSTypeAliasType; +class ETSArrayType; +class ETSResizableArrayType; +class ETSTypeParameter; +class ETSNonNullishType; +class ETSNullishTypes; +class ETSReadonlyType; +class ETSAnyType; +class ETSNeverType; +class ETSEnumType; +class Signature; +class SignatureInfo; -#endif /* TYPES_H */ +} // namespace ark::es2panda::checker + +#endif /* ES2PANDA_COMPILER_CHECKER_TYPES_ETS_H */ diff --git a/ets2panda/checker/types/typeRelation.cpp b/ets2panda/checker/types/typeRelation.cpp index 8f690add63e9681dab6a7af9941341fdd3c669de..cf4ed4348f5cc7fc56ff978305cf0a6489a3914e 100644 --- a/ets2panda/checker/types/typeRelation.cpp +++ b/ets2panda/checker/types/typeRelation.cpp @@ -19,6 +19,8 @@ #include "checker/ETSchecker.h" #include "checker/types/ts/indexInfo.h" #include "checker/types/signature.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsUnionType.h" namespace ark::es2panda::checker { ArenaAllocator *TypeRelation::Allocator() diff --git a/ets2panda/compiler/base/lreference.cpp b/ets2panda/compiler/base/lreference.cpp index bbd1d69bb6a81706815b77e78a6c6ff6c460ff62..95138f9fd2a7c40264692fac0f951e1b01a3dcb3 100644 --- a/ets2panda/compiler/base/lreference.cpp +++ b/ets2panda/compiler/base/lreference.cpp @@ -21,7 +21,9 @@ #include "compiler/core/function.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" +#include "checker/types/ets/etsFunctionType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsResizableArrayType.h" #include "ir/base/spreadElement.h" #include "ir/base/classProperty.h" #include "ir/base/classDefinition.h" diff --git a/ets2panda/compiler/core/ASTCompiler.h b/ets2panda/compiler/core/ASTCompiler.h index d7925c2f4429ed3b8775ea8fc5a2fb778b2330b6..dcc4b7d423276f25064911edf028fe43b6bbb6ed 100644 --- a/ets2panda/compiler/core/ASTCompiler.h +++ b/ets2panda/compiler/core/ASTCompiler.h @@ -60,6 +60,7 @@ #include "ir/expressions/classExpression.h" #include "ir/expressions/conditionalExpression.h" #include "ir/expressions/directEvalExpression.h" +#include "ir/expressions/dummyNode.h" #include "ir/expressions/functionExpression.h" #include "ir/expressions/identifier.h" #include "ir/expressions/importExpression.h" @@ -82,6 +83,7 @@ #include "ir/expressions/literals/numberLiteral.h" #include "ir/expressions/literals/regExpLiteral.h" #include "ir/expressions/literals/stringLiteral.h" +#include "ir/expressions/literals/undefinedLiteral.h" #include "ir/module/exportAllDeclaration.h" #include "ir/module/exportDefaultDeclaration.h" #include "ir/module/exportNamedDeclaration.h" diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 758d0da822c177409ececbccb60d5b0feb82d623..1d70c15a69ac76b2a862cc30aebc55e39c4831a3 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -23,12 +23,40 @@ #include "compiler/core/vReg.h" #include "compiler/function/functionBuilder.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/charType.h" +#include "checker/types/ets/doubleType.h" +#include "checker/types/ets/floatType.h" +#include "checker/types/ets/intType.h" +#include "checker/types/ets/longType.h" +#include "checker/types/ets/shortType.h" +#include "checker/types/ets/etsBooleanType.h" +#include "checker/types/ets/etsExtensionFuncHelperType.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsUnionType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsVoidType.h" +#include "checker/types/ets/etsStringType.h" +#include "checker/types/ets/etsBigIntType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsTypeAliasType.h" +#include "checker/types/ets/etsArrayType.h" +#include "checker/types/ets/wildcardType.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsNonNullishType.h" +#include "checker/types/ets/etsNullishTypes.h" +#include "checker/types/ets/etsReadonlyType.h" +#include "checker/types/ets/etsAnyType.h" +#include "checker/types/ets/etsNeverType.h" +#include "checker/types/ets/etsEnumType.h" + #include "ETSGen-inl.h" #include "generated/signatures.h" #include "util/es2pandaMacros.h" #include "varbinder/ETSBinder.h" +#include "ir/brokenTypeNode.h" + namespace ark::es2panda::compiler { ETSGen *ETSCompiler::GetETSGen() const @@ -1748,3 +1776,766 @@ void ETSCompiler::Compile(const ir::TSQualifiedName *expr) const } } // namespace ark::es2panda::compiler + +namespace ark::es2panda::ir { + +void PrefixAssertionExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void NamedType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSFunctionType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSPackageDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSNewClassInstanceExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSClassLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSTypeReferencePart::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSPrimitiveType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSTypeReference::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSNewMultiDimArrayInstanceExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSWildcardType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSNewArrayInstanceExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSUndefinedKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSBooleanKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSConditionalType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSExternalModuleReference::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSMappedType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypePredicate::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeAssertion::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSParenthesizedType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeParameter::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSEnumMember::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeParameterDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSStringKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeAliasDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSNonNullExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSInterfaceBody::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSThisType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSConstructorType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSIndexedAccessType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSEnumDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeOperator::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSParameterProperty::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSQualifiedName::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSInterfaceDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSInferType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeReference::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSAnyKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSBigintKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSModuleBlock::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSNullKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeParameterInstantiation::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTupleType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSVoidKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSLiteralType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSNamedTupleMember::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSAsExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSNeverKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSImportEqualsDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSInterfaceHeritage::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSTypeQuery::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSFunctionType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSIntersectionType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSNumberKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSModuleDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSClassImplements::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSUnionType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSUnknownKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSArrayType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSImportType::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ImportDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ExportSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ImportDefaultSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ExportAllDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ExportDefaultDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ExportNamedDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ImportSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ImportNamespaceSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ThisExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void AssignmentExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ObjectExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void FunctionExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BlockExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void OmittedExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ChainExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void MemberExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void UpdateExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void DirectEvalExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void DummyNode::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void YieldExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ClassExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void AwaitExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BinaryExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BinaryExpression::CompileOperands(compiler::ETSGen *etsg, compiler::VReg lhs) const +{ + left_->Compile(etsg); + + if (operator_ == lexer::TokenType::KEYW_INSTANCEOF) { + etsg->StoreAccumulator(left_, lhs); + } else { + etsg->ApplyConversionAndStoreAccumulator(left_, lhs, operationType_); + } + + right_->Compile(etsg); + etsg->ApplyConversion(right_, operationType_); +} + +void SuperExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ImportExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TaggedTemplateExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void Identifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void SequenceExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BooleanLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void UndefinedLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->LoadAccumulatorUndefined(this); +} + +void NumberLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void StringLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BigIntLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void NullLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void RegExpLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TypeofExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void NewExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void CallExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ArrowFunctionExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ConditionalExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void CatchClause::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ClassDefinition::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSSignatureDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSMethodSignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void Decorator::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void MetaProperty::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ClassStaticBlock::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ClassProperty::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void Property::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSPropertySignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSIndexSignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TemplateElement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void MethodDefinition::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ScriptFunction::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void FunctionDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void VariableDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void SwitchStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TryStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void AnnotationUsage::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void AnnotationDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ForUpdateStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void LabelledStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ExpressionStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void EmptyStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void DebuggerStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void IfStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ForOfStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ForInStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ContinueStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void SwitchCaseStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void VariableDeclarator::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void DoWhileStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ClassDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TSObjectKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BrokenTypeNode::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void TemplateLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void UnaryExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void CharLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void SpreadElement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ReturnStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void AssertStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void WhileStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BlockStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ThrowStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void BreakStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void OpaqueTypeNode::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ArrayExpression::Compile(compiler::ETSGen *const etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +void ETSParameterExpression::Compile(compiler::ETSGen *const etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +} // namespace ark::es2panda::ir diff --git a/ets2panda/compiler/core/ETSGen-inl.h b/ets2panda/compiler/core/ETSGen-inl.h index de548d52ede22fed2e87f790b77c79d1b212755d..b30f0bac3e43d397ce35ed3aa1f50fc0c5466bec 100644 --- a/ets2panda/compiler/core/ETSGen-inl.h +++ b/ets2panda/compiler/core/ETSGen-inl.h @@ -18,6 +18,14 @@ #include "ETSGen.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/charType.h" +#include "checker/types/ets/doubleType.h" +#include "checker/types/ets/floatType.h" +#include "checker/types/ets/intType.h" +#include "checker/types/ets/longType.h" +#include "checker/types/ets/shortType.h" + #include "checker/ETSchecker.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index a57b3008e1008d8123e14fbf635cf7f3a7f09885..4d3c406386ee40deda9332b4100799949bae1dc7 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -48,9 +48,27 @@ #include "checker/types/signature.h" #include "checker/checker.h" #include "checker/ETSchecker.h" -#include "checker/types/ets/etsObjectType.h" -#include "checker/types/ets/etsTupleType.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" +#include "checker/types/ets/etsBooleanType.h" +#include "checker/types/ets/etsExtensionFuncHelperType.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsVoidType.h" +#include "checker/types/ets/etsStringType.h" +#include "checker/types/ets/etsBigIntType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsTypeAliasType.h" +#include "checker/types/ets/etsArrayType.h" +#include "checker/types/ets/etsResizableArrayType.h" +#include "checker/types/ets/wildcardType.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsNonNullishType.h" +#include "checker/types/ets/etsNullishTypes.h" +#include "checker/types/ets/etsReadonlyType.h" +#include "checker/types/ets/etsAnyType.h" +#include "checker/types/ets/etsNeverType.h" +#include "checker/types/ets/etsEnumType.h" #include "parser/program/program.h" #include "checker/types/globalTypesHolder.h" #include "public/public.h" @@ -2975,4 +2993,5 @@ void ETSGen::LoadAccumulatorNumber(const ir::AstNode *node, T number, checker::T ApplyConversion(node, targetType_); } } + } // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 44062c41cc13294f29efe3e31854726d9f54fa0d..d5432d37868c0f14871a8d6fa40c8082cc392b06 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -27,6 +27,7 @@ #include "compiler/core/ETSfunction.h" #include "compiler/core/targetTypeContext.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "ir/expressions/identifier.h" #include "util/helpers.h" diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 69cac80ef67b34d00ffd74ca0d32bea6084cbfc5..ad1f2b024c5154c95723565c49ec80e2b64e4b7d 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -48,6 +48,7 @@ #include "checker/types/type.h" #include "checker/types/gradualType.h" #include "checker/types/ets/etsPartialTypeParameter.h" +#include "checker/types/ets/etsNonNullishType.h" #include "public/public.h" #include "util/nameMangler.h" diff --git a/ets2panda/compiler/core/ETSfunction.cpp b/ets2panda/compiler/core/ETSfunction.cpp index af91c7d094e4199a180f9de1fe3eb7c738dc8815..e53e58cc91b1c3be9e7a903bfc30245dbc28196f 100644 --- a/ets2panda/compiler/core/ETSfunction.cpp +++ b/ets2panda/compiler/core/ETSfunction.cpp @@ -34,6 +34,7 @@ #include "ir/ts/tsEnumMember.h" #include "checker/types/ets/types.h" #include "checker/types/gradualType.h" + namespace ark::es2panda::compiler { // #22952: this should have been done in lowering diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index f283dccf564d299d738c7f12bc33b745c5d6b5d4..c2bce6d536d05f5981af161a64316fee9165a787 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -1740,4 +1740,66 @@ void JSCompiler::Compile(const ir::WhileStatement *st) const PandaGen *pg = GetPandaGen(); CompileImpl(st, pg); } + } // namespace ark::es2panda::compiler + +namespace ark::es2panda::ir { + +void ChainExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg &objReg) const +{ + compiler::OptionalChain chain(pg, this); + + if (expression_->IsMemberExpression()) { + objReg = pg->AllocReg(); + expression_->AsMemberExpression()->CompileToReg(pg, objReg); + } else { + objReg = compiler::VReg::Invalid(); + expression_->Compile(pg); + } +} + +void MemberExpression::CompileToRegs(compiler::PandaGen *pg, compiler::VReg object, compiler::VReg property) const +{ + object_->Compile(pg); + pg->StoreAccumulator(this, object); + + pg->OptionalChainCheck(IsOptional(), object); + + if (!computed_) { + pg->LoadAccumulatorString(this, property_->AsIdentifier()->Name()); + } else { + property_->Compile(pg); + } + + pg->StoreAccumulator(this, property); +} + +void MemberExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg objReg) const +{ + object_->Compile(pg); + pg->StoreAccumulator(this, objReg); + pg->OptionalChainCheck(IsOptional(), objReg); + LoadRhs(pg); +} + +void MemberExpression::LoadRhs(compiler::PandaGen *pg) const +{ + compiler::RegScope rs(pg); + bool isSuper = object_->IsSuperExpression(); + compiler::Operand prop = pg->ToPropertyKey(property_, computed_, isSuper); + + if (isSuper) { + pg->LoadSuperProperty(this, prop); + } else if (IsPrivateReference()) { + const auto &name = property_->AsIdentifier()->Name(); + compiler::VReg objReg = pg->AllocReg(); + pg->StoreAccumulator(this, objReg); + compiler::VReg ctor = pg->AllocReg(); + compiler::Function::LoadClassContexts(this, pg, ctor, name); + pg->ClassPrivateFieldGet(this, ctor, objReg, name); + } else { + pg->LoadObjProperty(this, prop); + } +} + +} // namespace ark::es2panda::ir diff --git a/ets2panda/compiler/core/pandagen.cpp b/ets2panda/compiler/core/pandagen.cpp index d4602f2bea1f95b76eb8524b511ff0543b2329a4..8bf1b7940d7dd363e255d638f4c7be287e54e4be 100644 --- a/ets2panda/compiler/core/pandagen.cpp +++ b/ets2panda/compiler/core/pandagen.cpp @@ -37,9 +37,12 @@ #include "ir/base/scriptFunction.h" #include "ir/base/spreadElement.h" #include "ir/statement.h" +#include "ir/statements/annotationDeclaration.h" #include "ir/expressions/identifier.h" #include "ir/expressions/literals/numberLiteral.h" #include "ir/expressions/literals/stringLiteral.h" +#include "ir/ets/etsUnionType.h" +#include "ir/brokenTypeNode.h" namespace ark::es2panda::compiler { @@ -1833,3 +1836,785 @@ const checker::Type *PandaGen::GetVRegType(VReg vreg) const } } // namespace ark::es2panda::compiler + +namespace ark::es2panda::ir { + +void PrefixAssertionExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void NamedType::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSFunctionType::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSPackageDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSNewClassInstanceExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSClassLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSTypeReferencePart::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSPrimitiveType::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSTypeReference::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSNewMultiDimArrayInstanceExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSWildcardType::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSNewArrayInstanceExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSUndefinedKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSBooleanKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSExternalModuleReference::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSEnumMember::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSStringKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSEnumDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSAnyKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSVoidKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSNumberKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSUnknownKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ImportDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExportSpecifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ImportDefaultSpecifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExportAllDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExportDefaultDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ImportSpecifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ImportNamespaceSpecifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ThisExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void AssignmentExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void FunctionExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void OmittedExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ChainExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ArrayExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void MemberExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void UpdateExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void DirectEvalExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void DummyNode::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ClassExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void AwaitExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BinaryExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void SuperExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ImportExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TaggedTemplateExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void UnaryExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void Identifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void SequenceExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BooleanLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void UndefinedLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); +} + +void NumberLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void StringLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BigIntLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void NullLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void RegExpLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TypeofExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void NewExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void CallExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ArrowFunctionExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ConditionalExpression::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void CatchClause::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ClassDefinition::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSSignatureDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSMethodSignature::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void Decorator::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void MetaProperty::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ClassStaticBlock::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ClassProperty::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void Property::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSPropertySignature::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSIndexSignature::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TemplateElement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void MethodDefinition::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ScriptFunction::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void FunctionDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void VariableDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void SwitchStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void AnnotationUsage::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void AnnotationDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ForUpdateStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void LabelledStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExpressionStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ThrowStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void EmptyStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void DebuggerStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void IfStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ForOfStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ForInStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ContinueStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void SwitchCaseStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void DoWhileStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ClassDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSIntrinsicNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +void ETSUnionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +void ETSNeverType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + ES2PANDA_UNREACHABLE(); +} + +void ETSUndefinedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + ES2PANDA_UNREACHABLE(); +} + +void ETSNullType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + ES2PANDA_UNREACHABLE(); +} + +void ETSNonNullishTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + ES2PANDA_UNREACHABLE(); +} + +void ETSStringLiteralType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + ES2PANDA_UNREACHABLE(); +} + +void ETSKeyofType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +void TSConditionalType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSMappedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypePredicate::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeAssertion::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSParenthesizedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeParameter::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeParameterDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeAliasDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSNonNullExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSInterfaceBody::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSThisType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSConstructorType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSIndexedAccessType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeOperator::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSParameterProperty::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSQualifiedName::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSInterfaceDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSInferType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeReference::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSBigintKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSModuleBlock::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSNullKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeParameterInstantiation::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTupleType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSLiteralType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSNamedTupleMember::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSAsExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSNeverKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSObjectKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSImportEqualsDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSInterfaceHeritage::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSTypeQuery::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSFunctionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSIntersectionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSModuleDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSClassImplements::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSUnionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSArrayType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSImportType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BrokenTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ObjectExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BlockExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + ES2PANDA_UNREACHABLE(); +} + +void YieldExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TemplateLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void CharLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void SpreadElement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void OverloadDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +void ReturnStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void AssertStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TryStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void WhileStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BlockStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void VariableDeclarator::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void BreakStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void OpaqueTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ETSParameterExpression::Compile(compiler::PandaGen *const pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +} // namespace ark::es2panda::ir diff --git a/ets2panda/compiler/lowering/ets/boxingForLocals.cpp b/ets2panda/compiler/lowering/ets/boxingForLocals.cpp index 3c5f9f78520201beb779196e7c42151909f0d76e..8111c58d990cbbe12a5d1892a0522b36ceab2120 100644 --- a/ets2panda/compiler/lowering/ets/boxingForLocals.cpp +++ b/ets2panda/compiler/lowering/ets/boxingForLocals.cpp @@ -18,6 +18,7 @@ #include "compiler/lowering/util.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp b/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp index ad3cebeced6a13ed458e27f8656c5ab8b21e2295..cfec769c6837807ca579193421357986cff11990 100644 --- a/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp +++ b/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp @@ -14,6 +14,7 @@ */ #include "declareOverloadLowering.h" +#include "checker/types/ets/etsFunctionType.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" diff --git a/ets2panda/compiler/lowering/ets/dynamicImport.cpp b/ets2panda/compiler/lowering/ets/dynamicImport.cpp index 7d27f20b77c92701cf0412e84a5ef2419dec6516..a01b8eecbf131b0917a08c0f0a384276bbaae8ac 100644 --- a/ets2panda/compiler/lowering/ets/dynamicImport.cpp +++ b/ets2panda/compiler/lowering/ets/dynamicImport.cpp @@ -17,6 +17,7 @@ #include #include #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "ir/astNode.h" #include "compiler/lowering/util.h" diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index d935d7a4dc32347bd979a5f3bda886f69813bed1..9f29f4fad22dc36361bdcd89ddc83ff3810adad1 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -18,7 +18,6 @@ #include #include "checker/ETSchecker.h" -#include "checker/types/ets/etsEnumType.h" #include "checker/types/type.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" diff --git a/ets2panda/compiler/lowering/ets/enumLowering.h b/ets2panda/compiler/lowering/ets/enumLowering.h index f95443c8ce783deb8a2c3d27d974a2d4dcf85424..6b1f255be0b01141b58175e337ce1d21edb6f95b 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.h +++ b/ets2panda/compiler/lowering/ets/enumLowering.h @@ -20,6 +20,7 @@ #include #include "compiler/lowering/phase.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsEnumType.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp b/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp index e3527f11184dcca230d8c2cb870249787a7cf08e..d58ce57e14ebcb2664eae44d6945a023d3bc09c4 100644 --- a/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp @@ -19,6 +19,7 @@ #include "checker/ETSchecker.h" #include "checker/types/type.h" #include "checker/types/ets/etsEnumType.h" +#include "checker/types/ets/etsUnionType.h" #include "compiler/lowering/util.h" #include "ir/astNode.h" #include "ir/expressions/identifier.h" diff --git a/ets2panda/compiler/lowering/ets/expandBrackets.cpp b/ets2panda/compiler/lowering/ets/expandBrackets.cpp index 2f865dca1e7a3cf14adffe94625b949550eab0d7..bc7b60db5ce7af7059db68e483b20dd24abbd98d 100644 --- a/ets2panda/compiler/lowering/ets/expandBrackets.cpp +++ b/ets2panda/compiler/lowering/ets/expandBrackets.cpp @@ -16,6 +16,7 @@ #include "expandBrackets.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "compiler/lowering/util.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" diff --git a/ets2panda/compiler/lowering/ets/extensionAccessorLowering.cpp b/ets2panda/compiler/lowering/ets/extensionAccessorLowering.cpp index 0ec34677b128076d59b37fbe0d7286057cef08c1..097065dcc9c85da52ccd8193a7bbb3e65e502fcf 100644 --- a/ets2panda/compiler/lowering/ets/extensionAccessorLowering.cpp +++ b/ets2panda/compiler/lowering/ets/extensionAccessorLowering.cpp @@ -15,6 +15,7 @@ #include "extensionAccessorLowering.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" diff --git a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp index bc15ac423aa7c9cb1596bfa6ff5a5569d6f6155d..5b899f2ebe8f7a52a0a4bf8dc5ef62e5bcb79832 100644 --- a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp +++ b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp @@ -14,8 +14,12 @@ */ #include "genericBridgesLowering.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsTypeParameter.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" + #include "compiler/lowering/util.h" #include diff --git a/ets2panda/compiler/lowering/ets/gradualTypeNarrowing.cpp b/ets2panda/compiler/lowering/ets/gradualTypeNarrowing.cpp index edb6d6935041acddfd5e82b2dd2ab426f33d4a53..43fd205af5adf23026c63a8a8d32af833cd73aa0 100644 --- a/ets2panda/compiler/lowering/ets/gradualTypeNarrowing.cpp +++ b/ets2panda/compiler/lowering/ets/gradualTypeNarrowing.cpp @@ -16,7 +16,10 @@ #include "gradualTypeNarrowing.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsUnionType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsResizableArrayType.h" #include "checker/types/gradualType.h" #include "varbinder/ETSBinder.h" #include "es2panda.h" diff --git a/ets2panda/compiler/lowering/ets/interfaceObjectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/interfaceObjectLiteralLowering.cpp index 7a4a9db9dda99a3d44b33cfd1cd3a90203fe0ad6..e503cc012fc9e2d03071d94313f02615d1d82e97 100644 --- a/ets2panda/compiler/lowering/ets/interfaceObjectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/interfaceObjectLiteralLowering.cpp @@ -16,6 +16,7 @@ #include "interfaceObjectLiteralLowering.h" #include "checker/ETSchecker.h" #include "checker/ets/typeRelationContext.h" +#include "checker/types/ets/etsFunctionType.h" #include "compiler/lowering/util.h" #include "generated/signatures.h" #include "ir/expressions/assignmentExpression.h" diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index e3d748001cc78c774362bc78775c9807b715942d..5fa93d0db17a9f82aff53b12a1354566a6b58e20 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -17,6 +17,7 @@ #include "checker/ETSchecker.h" #include "checker/types/type.h" +#include "checker/types/ets/etsObjectType.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" #include "ir/astNode.h" diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index 1d45f1c3716b04eb2c97fd3c207e1a1601c32c91..80a2b064c13e9f781625ee501745805b0de88f09 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -19,6 +19,8 @@ #include "checker/types/ets/etsTupleType.h" #include "checker/ets/typeRelationContext.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsFunctionType.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" #include "ir/astNode.h" diff --git a/ets2panda/compiler/lowering/ets/objectIterator.cpp b/ets2panda/compiler/lowering/ets/objectIterator.cpp index 18a5c5c37345833e4a7af9494793c71439f7cb82..ff4577c7abad0b6f8d474fb91b56246b7c94fbc8 100644 --- a/ets2panda/compiler/lowering/ets/objectIterator.cpp +++ b/ets2panda/compiler/lowering/ets/objectIterator.cpp @@ -37,6 +37,9 @@ #include "compiler/lowering/util.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsUnionType.h" #include "util/options.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp index a899908b80b42d70310d2c1488be2cbfbd1340e8..362ccec9e76e116fdd000b32f784e9e433bd1554 100644 --- a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp @@ -15,6 +15,7 @@ #include "objectLiteralLowering.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 44b66ee3d2f22c0e38f59b168e86ef3e95d8f5ad..3343315af5b86498e0f2cb6d7b55a4e1bc1aefa9 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -26,6 +26,8 @@ #include "parser/ETSparser.h" #include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" #include "compiler/lowering/util.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "ir/opaqueTypeNode.h" diff --git a/ets2panda/compiler/lowering/ets/overloadMappingLowering.cpp b/ets2panda/compiler/lowering/ets/overloadMappingLowering.cpp index a72a5c6517090a6ecc5faa9b4871714b28856728..99c4fe14b28c043ed04baf1b76541bfaddedbfa7 100644 --- a/ets2panda/compiler/lowering/ets/overloadMappingLowering.cpp +++ b/ets2panda/compiler/lowering/ets/overloadMappingLowering.cpp @@ -15,6 +15,8 @@ #include "overloadMappingLowering.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsUnionType.h" #include "compiler/lowering/util.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp b/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp index 7a27a2001b37f02194a3290fb5dba83498a8cc9f..bce9887333ca53f4dc9b39a7108ddd5b8cd2e2bb 100644 --- a/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp +++ b/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp @@ -15,6 +15,7 @@ #include "compiler/lowering/util.h" #include "primitiveConversionPhase.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/primitiveConversionPhase.h b/ets2panda/compiler/lowering/ets/primitiveConversionPhase.h index 2fdd77510eb20489af22ff65be0ab25014774080..876e7341d93f8275976a049dd31e0f1c03302a3d 100644 --- a/ets2panda/compiler/lowering/ets/primitiveConversionPhase.h +++ b/ets2panda/compiler/lowering/ets/primitiveConversionPhase.h @@ -17,6 +17,7 @@ #define ES2PANDA_COMPILER_LOWERING_PRIMITIVE_CONVERSION_PHASE_H #include "compiler/lowering/phase.h" +#include "checker/types/ets/etsFunctionType.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/recordLowering.cpp b/ets2panda/compiler/lowering/ets/recordLowering.cpp index 8c13718bc00368c3864e7e2578a06a89c88f3fdd..b2de4d39f187ee11ced326451f22f01ca1bcc4ef 100644 --- a/ets2panda/compiler/lowering/ets/recordLowering.cpp +++ b/ets2panda/compiler/lowering/ets/recordLowering.cpp @@ -16,6 +16,16 @@ #include "recordLowering.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/charType.h" +#include "checker/types/ets/doubleType.h" +#include "checker/types/ets/floatType.h" +#include "checker/types/ets/intType.h" +#include "checker/types/ets/longType.h" +#include "checker/types/ets/shortType.h" +#include "checker/types/ets/etsStringType.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" diff --git a/ets2panda/compiler/lowering/ets/relaxedAnyLowering.cpp b/ets2panda/compiler/lowering/ets/relaxedAnyLowering.cpp index 78d661f3919288262311963853feb85035d9a3ff..9d4286f905c4fcaef6d019508043b10fc24fbe70 100644 --- a/ets2panda/compiler/lowering/ets/relaxedAnyLowering.cpp +++ b/ets2panda/compiler/lowering/ets/relaxedAnyLowering.cpp @@ -15,6 +15,7 @@ #include "relaxedAnyLowering.h" #include "ir/expressions/memberExpression.h" +#include "checker/types/ets/etsUnionType.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/spreadLowering.cpp b/ets2panda/compiler/lowering/ets/spreadLowering.cpp index 7bd611396699f242067a26056e9546a655949d82..849ec133155a8463e3cda49c06f4b912df6d1130 100644 --- a/ets2panda/compiler/lowering/ets/spreadLowering.cpp +++ b/ets2panda/compiler/lowering/ets/spreadLowering.cpp @@ -16,6 +16,8 @@ #include "spreadLowering.h" #include "checker/ETSchecker.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsResizableArrayType.h" #include "compiler/lowering/util.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/ets/stringComparison.cpp b/ets2panda/compiler/lowering/ets/stringComparison.cpp index 68d18c745e13857b8c481ae05cb54c014c1ffd4d..4274be1e2944576336f83074bfe73ab8fc2ce2c2 100644 --- a/ets2panda/compiler/lowering/ets/stringComparison.cpp +++ b/ets2panda/compiler/lowering/ets/stringComparison.cpp @@ -16,6 +16,7 @@ #include "varbinder/ETSBinder.h" #include "stringComparison.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "parser/parserImpl.h" #include "utils/arena_containers.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" diff --git a/ets2panda/compiler/lowering/ets/typeFromLowering.cpp b/ets2panda/compiler/lowering/ets/typeFromLowering.cpp index 31f98cba357c1ae0c9bba133238f47b42d9818f9..ca1492ac573110d0b8430aaafcfac8234d2e8f5e 100644 --- a/ets2panda/compiler/lowering/ets/typeFromLowering.cpp +++ b/ets2panda/compiler/lowering/ets/typeFromLowering.cpp @@ -16,6 +16,7 @@ #include "typeFromLowering.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsTupleType.h" #include "compiler/lowering/util.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" diff --git a/ets2panda/compiler/lowering/ets/unboxLowering.cpp b/ets2panda/compiler/lowering/ets/unboxLowering.cpp index b33a59d270584c698ec77ae62812a7015fb7b121..cd11cfac9e0369af14658f696cc9005f07422ed8 100644 --- a/ets2panda/compiler/lowering/ets/unboxLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unboxLowering.cpp @@ -19,7 +19,12 @@ #include "generated/tokenType.h" #include "ir/visitor/IterateAstVisitor.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsResizableArrayType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsTypeParameter.h" +#include "checker/types/ets/etsUnionType.h" #include "checker/types/typeFlag.h" #include "checker/types/globalTypesHolder.h" #include "compiler/lowering/util.h" diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index 2b2bc2713fdbed47e05eae8118dd52a10b1ab2ee..805b3b32d4642032b8cce7a217a010c3f36d8882 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -19,6 +19,8 @@ #include "compiler/lowering/util.h" #include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsFunctionType.h" #include "util/nameMangler.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 2e40ae01e8d4a566ed1d49f7b754521ebfe6709c..2700e10aa70be993ad41a19d6a3871fd619e5809 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -79,7 +79,6 @@ #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "generated/diagnostic.h" #include "lexer/token/sourceLocation.h" -#include "public/es2panda_lib.h" #include "util/options.h" namespace ark::es2panda::compiler { diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index 30b22ef0bee4629ad088cc018c71c143269f93e2..5d2fd08199d85de4c754fe8becd671169fea2dca 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -16,7 +16,10 @@ #include "declgenEts2Ts.h" #include "isolatedDeclgenChecker.h" +#include "checker/types/ets/etsFunctionType.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsObjectType.h" #include "compiler/lowering/phase.h" #include "generated/diagnostic.h" #include "ir/base/classProperty.h" diff --git a/ets2panda/ir/annotationAllowed.h b/ets2panda/ir/annotationAllowed.h index d75ec2f1261f30989ab5cab1e26dbd7aa2567dd3..393cfe8ecf194030fe28fd55bbb5aa749a012abc 100644 --- a/ets2panda/ir/annotationAllowed.h +++ b/ets2panda/ir/annotationAllowed.h @@ -80,17 +80,6 @@ public: } } - void DumpAnnotations(ir::SrcDumper *dumper) const - { - auto *node = AstNode::GetHistoryNodeAs>(); - if (node->annotations_ != nullptr && !node->annotations_->empty()) { - auto &annotations = *node->annotations_; - for (auto *anno : annotations) { - anno->Dump(dumper); - } - } - } - [[nodiscard]] ArenaVector &AnnotationsForUpdate() { auto *node = AstNode::GetOrCreateHistoryNodeAs>(); diff --git a/ets2panda/ir/as/namedType.cpp b/ets2panda/ir/as/namedType.cpp index 71eac941cf0e0ff15fc59e7907ec012ba8f81c87..81b7a6ec1085930282e6e66154c562207bb09ab1 100644 --- a/ets2panda/ir/as/namedType.cpp +++ b/ets2panda/ir/as/namedType.cpp @@ -15,13 +15,8 @@ #include "namedType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "ir/expressions/identifier.h" #include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" namespace ark::es2panda::ir { void NamedType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -63,39 +58,4 @@ void NamedType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void NamedType::Dump(AstDumper *dumper) const -{ - dumper->Add({{"type", "NamedType"}, - {"name", name_}, - {"typeParameters", AstDumper::Optional(typeParams_)}, - {"next", AstDumper::Optional(next_)}, - {"isNullable", nullable_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void NamedType::Dump(SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("NamedType"); -} - -void NamedType::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void NamedType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *NamedType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType NamedType::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/as/prefixAssertionExpression.cpp b/ets2panda/ir/as/prefixAssertionExpression.cpp index 544713d799e9cccf830668b77f6c40f31106075c..7e016f5805d68f41c6403f12d97bbf5cc4d52f8b 100644 --- a/ets2panda/ir/as/prefixAssertionExpression.cpp +++ b/ets2panda/ir/as/prefixAssertionExpression.cpp @@ -15,11 +15,6 @@ #include "prefixAssertionExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/typeNode.h" namespace ark::es2panda::ir { @@ -42,33 +37,4 @@ void PrefixAssertionExpression::Iterate(const NodeTraverser &cb) const cb(expr_); } -void PrefixAssertionExpression::Dump(AstDumper *dumper) const -{ - dumper->Add({{"type", "PrefixAssertionExpression"}, {"expression", expr_}, {"type", type_}}); -} - -void PrefixAssertionExpression::Dump(SrcDumper *dumper) const -{ - dumper->Add("PrefixAssertionExpression"); -} - -void PrefixAssertionExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void PrefixAssertionExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *PrefixAssertionExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType PrefixAssertionExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/astDump.cpp b/ets2panda/ir/astDump.cpp index 470679783384f4573d4802e218fb592468b63a60..8a9cfb6eb5a03826c42bbb4693d7ebfb38dac64e 100644 --- a/ets2panda/ir/astDump.cpp +++ b/ets2panda/ir/astDump.cpp @@ -15,7 +15,167 @@ #include "astDump.h" -#include "ir/astNode.h" +#include "ir/brokenTypeNode.h" +#include "ir/opaqueTypeNode.h" + +#include "ir/module/exportAllDeclaration.h" +#include "ir/module/exportDefaultDeclaration.h" +#include "ir/module/exportNamedDeclaration.h" +#include "ir/module/exportSpecifier.h" +#include "ir/module/importDefaultSpecifier.h" +#include "ir/module/importNamespaceSpecifier.h" + +#include "ir/ets/etsClassLiteral.h" +#include "ir/ets/etsStructDeclaration.h" +#include "ir/ets/etsIntrinsicNode.h" +#include "ir/ets/etsUnionType.h" +#include "ir/ets/etsStringLiteralType.h" +#include "ir/ets/etsTuple.h" +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" +#include "ir/ets/etsNeverType.h" +#include "ir/ets/etsNullishTypes.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "ir/ets/etsNewArrayInstanceExpression.h" +#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" +#include "ir/ets/etsNewClassInstanceExpression.h" +#include "ir/ets/etsFunctionType.h" +#include "ir/ets/etsNonNullishTypeNode.h" +#include "ir/ets/etsPackageDeclaration.h" +#include "ir/ets/etsPrimitiveType.h" +#include "ir/ets/etsWildcardType.h" +#include "ir/ets/etsKeyofType.h" +#include "ir/ets/etsModule.h" + +#include "ir/ts/tsAsExpression.h" +#include "ir/ts/tsEnumDeclaration.h" +#include "ir/ts/tsEnumMember.h" +#include "ir/ts/tsExternalModuleReference.h" +#include "ir/ts/tsNonNullExpression.h" +#include "ir/ts/tsTypeAssertion.h" +#include "ir/ts/tsAnyKeyword.h" +#include "ir/ts/tsArrayType.h" +#include "ir/ts/tsBigintKeyword.h" +#include "ir/ts/tsBooleanKeyword.h" +#include "ir/ts/tsLiteralType.h" +#include "ir/ts/tsNeverKeyword.h" +#include "ir/ts/tsNullKeyword.h" +#include "ir/ts/tsNumberKeyword.h" +#include "ir/ts/tsObjectKeyword.h" +#include "ir/ts/tsParenthesizedType.h" +#include "ir/ts/tsStringKeyword.h" +#include "ir/ts/tsTypeLiteral.h" +#include "ir/ts/tsUndefinedKeyword.h" +#include "ir/ts/tsUnionType.h" +#include "ir/ts/tsUnknownKeyword.h" +#include "ir/ts/tsVoidKeyword.h" +#include "ir/ts/tsConditionalType.h" +#include "ir/ts/tsConstructorType.h" +#include "ir/ts/tsFunctionType.h" +#include "ir/ts/tsImportEqualsDeclaration.h" +#include "ir/ts/tsImportType.h" +#include "ir/ts/tsInferType.h" +#include "ir/ts/tsIntersectionType.h" +#include "ir/ts/tsMappedType.h" +#include "ir/ts/tsModuleBlock.h" +#include "ir/ts/tsModuleDeclaration.h" +#include "ir/ts/tsParameterProperty.h" +#include "ir/ts/tsThisType.h" +#include "ir/ts/tsTypeAliasDeclaration.h" +#include "ir/ts/tsTypeOperator.h" +#include "ir/ts/tsTypeParameter.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/ts/tsTypeParameterInstantiation.h" +#include "ir/ts/tsTypePredicate.h" +#include "ir/ts/tsTypeReference.h" +#include "ir/ts/tsClassImplements.h" +#include "ir/ts/tsIndexedAccessType.h" +#include "ir/ts/tsInterfaceBody.h" +#include "ir/ts/tsInterfaceDeclaration.h" +#include "ir/ts/tsInterfaceHeritage.h" +#include "ir/ts/tsNamedTupleMember.h" +#include "ir/ts/tsQualifiedName.h" +#include "ir/ts/tsTupleType.h" +#include "ir/ts/tsTypeQuery.h" + +#include "ir/base/spreadElement.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/catchClause.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/decorator.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/metaProperty.h" +#include "ir/base/overloadDeclaration.h" +#include "ir/base/property.h" +#include "ir/base/tsMethodSignature.h" +#include "ir/base/tsPropertySignature.h" +#include "ir/base/tsSignatureDeclaration.h" +#include "ir/base/tsIndexSignature.h" + +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/taggedTemplateExpression.h" +#include "ir/expressions/typeofExpression.h" +#include "ir/expressions/unaryExpression.h" +#include "ir/expressions/updateExpression.h" +#include "ir/expressions/yieldExpression.h" + +#include "ir/expressions/arrowFunctionExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/templateLiteral.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/awaitExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/classExpression.h" +#include "ir/expressions/chainExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/importExpression.h" +#include "ir/expressions/dummyNode.h" +#include "ir/expressions/directEvalExpression.h" +#include "ir/expressions/blockExpression.h" +#include "ir/expressions/conditionalExpression.h" +#include "ir/expressions/thisExpression.h" +#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/expressions/literals/bigIntLiteral.h" +#include "ir/expressions/literals/booleanLiteral.h" +#include "ir/expressions/literals/charLiteral.h" +#include "ir/expressions/literals/nullLiteral.h" +#include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/regExpLiteral.h" +#include "ir/expressions/newExpression.h" +#include "ir/expressions/omittedExpression.h" +#include "ir/expressions/superExpression.h" + +#include "ir/statements/assertStatement.h" +#include "ir/statements/annotationDeclaration.h" +#include "ir/statements/breakStatement.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/continueStatement.h" +#include "ir/statements/debuggerStatement.h" +#include "ir/statements/doWhileStatement.h" +#include "ir/statements/emptyStatement.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/forInStatement.h" +#include "ir/statements/forOfStatement.h" +#include "ir/statements/forUpdateStatement.h" +#include "ir/statements/labelledStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/ifStatement.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" +#include "ir/statements/switchCaseStatement.h" +#include "ir/statements/switchStatement.h" +#include "ir/statements/tryStatement.h" +#include "ir/statements/throwStatement.h" +#include "ir/statements/whileStatement.h" + +#include "ir/as/namedType.h" +#include "ir/as/prefixAssertionExpression.h" + #include "util/helpers.h" #include "parser/program/program.h" @@ -23,6 +183,7 @@ #include namespace ark::es2panda::ir { + AstDumper::AstDumper(const ir::AstNode *node, util::StringView sourceCode) : index_(sourceCode) { isSrcEmpty_ = sourceCode.Empty(); @@ -278,4 +439,1042 @@ void AstDumper::Indent() ss_ << " "; } } + +void ETSStringLiteralType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "ETSStringLiteralType"}, {"value", value_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSNewArrayInstanceExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "ETSNewArrayInstanceExpression"}, {"typeReference", typeReference_}, {"dimension", dimension_}}); +} +void TSInferType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "TSInferType"}, {"typeParameter", typeParam_}, {"annotations", AstDumper::Optional(Annotations())}}); +} + +void TSTypeLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "TSTypeLiteral"}, {"members", members_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSLiteralType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "TSLiteralType"}, {"literal", literal_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSTypeQuery::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "TSTypeQuery"}, {"exprName", exprName_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSIntersectionType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "TSIntersectionType"}, {"types", types_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSModuleDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "TSModuleDeclaration"}, {"id", name_}, {"body", AstDumper::Optional(body_)}, {"global", global_}}); +} +void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", IsExportEquals() ? "TSExportAssignment" : "ExportDefaultDeclaration"}, {"declaration", decl_}}); +} +void ConditionalExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "ConditionalExpression"}, {"test", test_}, {"consequent", consequent_}, {"alternate", alternate_}}); +} + +void ETSTuple::Dump(ir::AstDumper *const dumper) const +{ + dumper->Add({{"type", "ETSTuple"}, + {"types", AstDumper::Optional(typeAnnotationList_)}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSNewMultiDimArrayInstanceExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSNewMultiDimArrayInstanceExpression"}, + {"typeReference", typeReference_}, + {"dimensions", dimensions_}}); +} +void TSParenthesizedType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSParenthesizedType"}, + {"typeAnnotation", type_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void TSTupleType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTupleType"}, + {"elementTypes", elementTypes_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSClassImplements::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSClassImplements"}, + {"expression", expression_}, + {"typeParameters", AstDumper::Optional(typeParameters_)}}); +} + +void ArrowFunctionExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ArrowFunctionExpression"}, + {"function", func_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void SpreadElement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", (type_ == AstNodeType::SPREAD_ELEMENT) ? "SpreadElement" : "RestElement"}, + {"argument", argument_}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}}); +} +void FunctionDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", Function()->IsOverload() ? "TSDeclareFunction" : "FunctionDeclaration"}, + {"annotations", AstDumper::Optional(Annotations())}, + {"function", Function()}}); +} + +void ETSTypeReferencePart::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSTypeReferencePart"}, + {"name", Name()}, + {"typeParams", AstDumper::Optional(TypeParams())}, + {"previous", AstDumper::Optional(Previous())}}); +} + +void TSIndexedAccessType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSIndexedAccessType"}, + {"objectType", objectType_}, + {"indexType", indexType_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSTypeOperator::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeOperator"}, + {"operator", AstDumper::TypeOperatorToString(operatorType_)}, + {"typeAnnotation", type_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSTypeReference::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeReference"}, + {"typeName", typeName_}, + {"typeParameters", AstDumper::Optional(typeParams_)}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSImportEqualsDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSImportEqualsDeclaration"}, + {"id", id_}, + {"moduleReference", moduleReference_}, + {"isExport", isExport_}}); +} +void TSInterfaceHeritage::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({ + {"type", "TSInterfaceHeritage"}, + {"expression", expr_}, + }); +} +void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ExportNamedDeclaration"}, + {"declaration", AstDumper::Nullish(decl_)}, + {"source", AstDumper::Nullish(source_)}, + {"specifiers", specifiers_}}); +} +void ObjectExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", (type_ == AstNodeType::OBJECT_EXPRESSION) ? "ObjectExpression" : "ObjectPattern"}, + {"properties", properties_}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, + {"optional", AstDumper::Optional(optional_)}}); +} +void ArrayExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", type_ == AstNodeType::ARRAY_EXPRESSION ? "ArrayExpression" : "ArrayPattern"}, + {"elements", elements_}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, + {"optional", AstDumper::Optional(optional_)}}); +} +void DummyNode::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "DummyNode"}, + {"name", name_}, + {"indexName", indexName_}, + {"returnType", AstDumper::Optional(GetReturnTypeLiteral())}}); +} + +void BinaryExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", IsLogical() ? "LogicalExpression" : "BinaryExpression"}, + {"operator", operator_}, + {"left", left_}, + {"right", right_}}); +} +void TaggedTemplateExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TaggedTemplateExpression"}, + {"tag", tag_}, + {"quasi", quasi_}, + {"typeParameters", AstDumper::Optional(typeParams_)}}); +} +void Identifier::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", IsPrivateIdent() ? "PrivateIdentifier" : "Identifier"}, + {"name", Name()}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, + {"optional", AstDumper::Optional(IsOptional())}}); +} +void TSIndexSignature::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSIndexSignature"}, + {"parameters", param_}, + {"typeAnnotation", typeAnnotation_}, + {"readonly", readonly_}}); +} +void TemplateElement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({ + {"type", "TemplateElement"}, + {"value", {{"raw", raw_}, {"cooked", cooked_}}}, + }); +} +void TryStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TryStatement"}, + {"block", block_}, + {"handler", catchClauses_}, + {"finalizer", AstDumper::Nullish(finalizer_)}}); +} +void IfStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "IfStatement"}, + {"test", test_}, + {"consequent", consequent_}, + {"alternate", AstDumper::Nullish(alternate_)}}); +} + +void ETSFunctionType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSFunctionType"}, + {"params", Params()}, + {"typeParameters", AstDumper::Optional(TypeParams())}, + {"returnType", ReturnType()}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void ETSWildcardType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSWildcardType"}, + {"typeReference", AstDumper::Optional(typeReference_)}, + {"in", AstDumper::Optional(IsIn())}, + {"out", AstDumper::Optional(IsOut())}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSTypePredicate::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypePredicate"}, + {"parameterName", parameterName_}, + {"typeAnnotation", AstDumper::Nullish(typeAnnotation_)}, + {"asserts", asserts_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSTypeAliasDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeAliasDeclaration"}, + {"annotations", AstDumper::Optional(Annotations())}, + {"id", Id()}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, + {"typeParameters", AstDumper::Optional(TypeParams())}}); +} +void TSEnumDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSEnumDeclaration"}, + {"id", Key()}, + {"members", Members()}, + {"const", IsConst()}, + {"declare", IsDeclare()}}); +} +void TSNamedTupleMember::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSNamedTupleMember"}, + {"elementType", elementType_}, + {"label", label_}, + {"optional", AstDumper::Optional(optional_)}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void AssignmentExpression::Dump(ir::AstDumper *dumper) const +{ + if (type_ == AstNodeType::ASSIGNMENT_EXPRESSION) { + dumper->Add({{"type", "AssignmentExpression"}, {"operator", operator_}, {"left", left_}, {"right", right_}}); + } else { + dumper->Add({{"type", "AssignmentPattern"}, {"left", left_}, {"right", right_}}); + } +} +void MemberExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "MemberExpression"}, + {"object", object_}, + {"property", property_}, + {"computed", computed_}, + {"optional", IsOptional()}}); +} +void OverloadDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "OverloadDeclaration"}, + {"key", key_}, + {"optional", AstDumper::Optional(AstDumper::ModifierToString(flags_))}, + {"static", IsStatic()}, + {"overloadedList", overloadedList_}}); +} + +void ForUpdateStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ForUpdateStatement"}, + {"init", AstDumper::Nullish(init_)}, + {"test", AstDumper::Nullish(test_)}, + {"update", AstDumper::Nullish(update_)}, + {"body", body_}}); +} + +void NamedType::Dump(AstDumper *dumper) const +{ + dumper->Add({{"type", "NamedType"}, + {"name", name_}, + {"typeParameters", AstDumper::Optional(typeParams_)}, + {"next", AstDumper::Optional(next_)}, + {"isNullable", nullable_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSConditionalType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSConditionalType"}, + {"checkType", checkType_}, + {"extendsType", extendsType_}, + {"trueType", trueType_}, + {"falseType", falseType_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void TSConstructorType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSConstructorType"}, + {"params", signature_.Params()}, + {"typeParameters", AstDumper::Optional(signature_.TypeParams())}, + {"returnType", signature_.ReturnType()}, + {"abstract", AstDumper::Optional(abstract_)}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSInterfaceDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSInterfaceDeclaration"}, + {"annotations", AstDumper::Optional(Annotations())}, + {"body", Body()}, + {"id", Id()}, + {"extends", Extends()}, + {"typeParameters", AstDumper::Optional(TypeParams())}}); +} +void TSFunctionType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSFunctionType"}, + {"params", signature_.Params()}, + {"typeParameters", AstDumper::Optional(signature_.TypeParams())}, + {"returnType", signature_.ReturnType()}, + {"isNullable", AstDumper::Optional(nullable_)}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSImportType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSImportType"}, + {"parameter", param_}, + {"qualifier", AstDumper::Optional(qualifier_)}, + {"typeParameters", AstDumper::Optional(typeParams_)}, + {"isTypeOf", isTypeof_}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void CallExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "CallExpression"}, + {"callee", callee_}, + {"arguments", arguments_}, + {"optional", IsOptional()}, + {"typeParameters", AstDumper::Optional(typeParams_)}}); + // #22953: trailing block is not handled +} +void TSSignatureDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", (kind_ == TSSignatureDeclaration::TSSignatureDeclarationKind::CALL_SIGNATURE) + ? "TSCallSignatureDeclaration" + : "TSConstructSignatureDeclaration"}, + {"params", Params()}, + {"typeParameters", AstDumper::Optional(TypeParams())}, + {"returnType", AstDumper::Optional(ReturnTypeAnnotation())}}); +} +void TSPropertySignature::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSPropertySignature"}, + {"computed", computed_}, + {"optional", optional_}, + {"readonly", readonly_}, + {"key", key_}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}}); +} + +void TSTypeParameter::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeParameter"}, + {"name", Name()}, + {"constraint", AstDumper::Optional(Constraint())}, + {"default", AstDumper::Optional(DefaultType())}, + {"in", AstDumper::Optional(IsIn())}, + {"out", AstDumper::Optional(IsOut())}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void TSParameterProperty::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSParameterProperty"}, + {"accessibility", accessibility_ == AccessibilityOption::PUBLIC ? "public" + : accessibility_ == AccessibilityOption::PRIVATE ? "private" + : accessibility_ == AccessibilityOption::PROTECTED ? "protected" + : "undefined"}, + {"readonly", readonly_}, + {"static", static_}, + {"export", export_}, + {"parameter", parameter_}}); +} +void TSMethodSignature::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSMethodSignature"}, + {"computed", computed_}, + {"optional", optional_}, + {"key", key_}, + {"params", Params()}, + {"typeParameters", AstDumper::Optional(TypeParams())}, + {"typeAnnotation", AstDumper::Optional(ReturnTypeAnnotation())}}); +} +void ETSParameterExpression::Dump(ir::AstDumper *const dumper) const +{ + if (!IsRestParameter()) { + dumper->Add({{"type", "ETSParameterExpression"}, + {"name", Ident()}, + {"initializer", AstDumper::Optional(Initializer())}, + {"annotations", AstDumper::Optional(Annotations())}}); + } else { + dumper->Add({{"type", "ETSParameterExpression"}, + {"rest parameter", Spread()}, + {"annotations", AstDumper::Optional(Annotations())}}); + } +} +void TSMappedType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSMappedType"}, + {"typeParameter", typeParameter_}, + {"typeAnnotation", AstDumper::Optional(typeAnnotation_)}, + {"readonly", readonly_ == MappedOption::NO_OPTS ? AstDumper::Optional(false) + : readonly_ == MappedOption::PLUS ? AstDumper::Optional("+") + : AstDumper::Optional("-")}, + {"optional", optional_ == MappedOption::NO_OPTS ? AstDumper::Optional(false) + : optional_ == MappedOption::PLUS ? AstDumper::Optional("+") + : AstDumper::Optional("-")}, + {"annotations", AstDumper::Optional(Annotations())}}); +} +void ScriptFunction::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ScriptFunction"}, + {"id", AstDumper::Nullish(Id())}, + {"generator", IsGenerator()}, + {"async", IsAsyncFunc()}, + {"expression", ((Flags() & ir::ScriptFunctionFlags::EXPRESSION) != 0)}, + {"params", Params()}, + {"returnType", AstDumper::Optional(ReturnTypeAnnotation())}, + {"typeParameters", AstDumper::Optional(TypeParams())}, + {"declare", AstDumper::Optional(IsDeclare())}, + {"body", AstDumper::Optional(Body())}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void ClassDefinition::Dump(ir::AstDumper *dumper) const +{ + auto propFilter = [](AstNode *prop) -> bool { + return !prop->IsClassStaticBlock() || !prop->AsClassStaticBlock()->Function()->IsHidden(); + }; + auto ctor = GetHistoryNodeAs()->ctor_; + dumper->Add({{"id", AstDumper::Nullish(Ident())}, + {"typeParameters", AstDumper::Optional(TypeParams())}, + {"superClass", AstDumper::Nullish(SuperClass())}, + {"superTypeParameters", AstDumper::Optional(SuperTypeParams())}, + {"implements", Implements()}, + {"annotations", AstDumper::Optional(Annotations())}, + {"constructor", AstDumper::Optional(ctor)}, + {"body", Body(), propFilter}}); +} + +void ClassProperty::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ClassProperty"}, + {"key", Key()}, + {"value", AstDumper::Optional(Value())}, + {"accessibility", AstDumper::Optional(AstDumper::ModifierToString(Modifiers()))}, + {"static", IsStatic()}, + {"readonly", IsReadonly()}, + {"declare", IsDeclare()}, + {"optional", IsOptionalDeclaration()}, + {"computed", IsComputed()}, + {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, + {"definite", IsDefinite()}, + {"annotations", AstDumper::Optional(Annotations())}}); +} + +void PrefixAssertionExpression::Dump(AstDumper *dumper) const +{ + dumper->Add({{"type", "PrefixAssertionExpression"}, {"expression", expr_}, {"type", type_}}); +} + +void ETSIntrinsicNode::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSIntrinsicNode"}, {"arguments", arguments_}}); +} +void ETSUnionType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSUnionType"}, {"types", Types()}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSPackageDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSPackageDeclaration"}, {"name", name_}}); +} +void ETSClassLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSClassLiteral"}}); +} +void ETSStructDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSStructDeclaration"}, {"definition", Definition()}}); +} +void ETSNeverType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSNeverType"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSUndefinedType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSUndefinedType"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSNullType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSNullType"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSReExportDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSReExportDeclaration"}, {"ets_import_declarations", GetETSImportDeclarations()}}); +} +void ETSPrimitiveType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSPrimitiveType"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSTypeReference::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSTypeReference"}, {"part", Part()}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void ETSNonNullishTypeNode::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSNonNullishType"}, {"typeNode", typeNode_}}); +} +void ETSKeyofType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSKeyofType"}, {"types", type_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSUndefinedKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSUndefinedKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSBooleanKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSBooleanKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSExternalModuleReference::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSExternalModuleReference"}, {"expression", expr_}}); +} + +void TSTypeAssertion::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeAssertion"}, {"typeAnnotation", TypeAnnotation()}, {"expression", expression_}}); +} + +void TSEnumMember::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSEnumMember"}, {"id", key_}, {"initializer", AstDumper::Optional(init_)}}); +} +void TSTypeParameterDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeParameterDeclaration"}, {"params", Params()}}); +} +void TSStringKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSStringKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSNonNullExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSNonNullExpression"}, {"expression", expr_}}); +} +void TSInterfaceBody::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSInterfaceBody"}, {"body", body_}}); +} +void TSThisType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSThisType"}}); +} + +void TSQualifiedName::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSQualifiedName"}, {"left", left_}, {"right", right_}}); +} +void TSAnyKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSAnyKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSBigintKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSBigIntKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSModuleBlock::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSModuleBlock"}, {"body", statements_}}); +} + +void TSNullKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSNullKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSTypeParameterInstantiation::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSTypeParameterInstantiation"}, {"params", params_}}); +} +void TSVoidKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSVoidKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSAsExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSAsExpression"}, {"expression", expression_}, {"typeAnnotation", TypeAnnotation()}}); +} +void TSNeverKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSNeverKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSObjectKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSObjectKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} + +void TSNumberKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSNumberKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} + +void TSUnionType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSUnionType"}, {"types", types_}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSUnknownKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSUnknownKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void TSArrayType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSArrayType"}, {"elementType", elementType_}, {"annotations", Annotations()}}); +} +void ImportDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ImportDeclaration"}, {"source", Source()}, {"specifiers", Specifiers()}}); +} +void ExportSpecifier::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ExportSpecifier"}, {"local", local_}, {"exported", exported_}}); +} +void ImportDefaultSpecifier::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ImportDefaultSpecifier"}, {"local", local_}}); +} + +void ExportAllDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ExportAllDeclaration"}, {"source", source_}, {"exported", AstDumper::Nullish(exported_)}}); +} + +void ImportSpecifier::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ImportSpecifier"}, {"local", ir::AstDumper::Optional(local_)}, {"imported", imported_}}); +} +void ImportNamespaceSpecifier::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ImportNamespaceSpecifier"}, {"local", local_}}); +} +void BrokenTypeNode::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ErrorType"}}); +} + +void ThisExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ThisExpression"}}); +} +void FunctionExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "FunctionExpression"}, {"function", func_}}); +} + +void ClassExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ClassExpression"}, {"definition", def_}}); +} +void YieldExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "YieldExpression"}, {"delegate", delegate_}, {"argument", AstDumper::Nullish(argument_)}}); +} +void ChainExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ChainExpression"}, {"expression", expression_}}); +} +void UpdateExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "UpdateExpression"}, {"operator", operator_}, {"prefix", prefix_}, {"argument", argument_}}); +} + +void BlockExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "BlockExpression"}, {"statements", statements_}}); +} +void OmittedExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "OmittedExpression"}}); +} +void TemplateLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TemplateLiteral"}, {"expressions", expressions_}, {"quasis", quasis_}}); +} +void AwaitExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "AwaitExpression"}, {"argument", AstDumper::Nullish(argument_)}}); +} +void SuperExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "Super"}}); +} +void ImportExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ImportExpression"}, {"source", source_}}); +} +void UnaryExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "UnaryExpression"}, {"operator", operator_}, {"prefix", true}, {"argument", argument_}}); +} +void SequenceExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "SequenceExpression"}, {"expressions", sequence_}}); +} +void BooleanLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "BooleanLiteral"}, {"value", boolean_}}); +} + +void UndefinedLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "UndefinedLiteral"}, {"value", AstDumper::Property::Constant::PROP_UNDEFINED}}); +} + +void NumberLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "NumberLiteral"}, {"value", number_}}); +} +void StringLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "StringLiteral"}, {"value", str_}}); +} + +void BigIntLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "BigIntLiteral"}, {"value", src_}}); +} + +void CharLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "CharLiteral"}, {"value", char_}}); +} + +void NullLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "NullLiteral"}, {"value", AstDumper::Property::Constant::PROP_NULL}}); +} + +void RegExpLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "RegExpLiteral"}, {"source", pattern_}, {"flags", flagsStr_}}); +} + +void TypeofExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TypeofExpression"}, {"argument", argument_}}); +} +void NewExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "NewExpression"}, {"callee", callee_}, {"arguments", arguments_}}); +} + +void CatchClause::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "CatchClause"}, {"body", body_}, {"param", AstDumper::Nullish(param_)}}); +} + +void Decorator::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "Decorator"}, {"expression", expr_}}); +} +void ClassStaticBlock::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ClassStaticBlock"}, {"value", Value()}}); +} +void ReturnStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ReturnStatement"}, {"argument", AstDumper::Nullish(argument_)}}); +} +void SwitchStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "SwitchStatement"}, {"discriminant", discriminant_}, {"cases", cases_}}); +} +void AssertStatement::Dump([[maybe_unused]] ir::AstDumper *dumper) const +{ + ES2PANDA_UNREACHABLE(); +} + +void AnnotationUsage::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"expr_", expr_}, {"properties", properties_}}); +} +void AnnotationDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"Expr", Expr()}, {"properties", Properties()}, {"annotations", AstDumper::Optional(Annotations())}}); +} +void LabelledStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "LabelledStatement"}, {"label", ident_}, {"body", body_}}); +} +void ExpressionStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ExpressionStatement"}, {"expression", expression_}}); +} +void WhileStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "WhileStatement"}, {"test", test_}, {"body", body_}}); +} +void BlockStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", IsProgram() ? "Program" : "BlockStatement"}, {"statements", Statements()}}); +} +void ThrowStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ThrowStatement"}, {"argument", argument_}}); +} +void EmptyStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "EmptyStatement"}}); +} + +void DebuggerStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "DebuggerStatement"}}); +} + +void ForOfStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ForOfStatement"}, {"await", isAwait_}, {"left", left_}, {"right", right_}, {"body", body_}}); +} +void ForInStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ForInStatement"}, {"left", left_}, {"right", right_}, {"body", body_}}); +} + +void ContinueStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullish(ident_)}}); +} +void SwitchCaseStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"consequent", consequent_}}); +} +void VariableDeclarator::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "VariableDeclarator"}, {"id", id_}, {"init", AstDumper::Nullish(init_)}}); +} +void DoWhileStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "DoWhileStatement"}, {"body", body_}, {"test", test_}}); +} +void ClassDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ClassDeclaration"}, {"definition", Definition()}}); +} +void BreakStatement::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "BreakStatement"}, {"label", AstDumper::Nullish(ident_)}}); +} +void OpaqueTypeNode::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "OpaqueType"}, {"annotations", AstDumper::Optional(Annotations())}}); +} + +void ETSNewClassInstanceExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add( + {{"type", "ETSNewClassInstanceExpression"}, {"typeReference", typeReference_}, {"arguments", arguments_}}); +} + +void MetaProperty::Dump(ir::AstDumper *dumper) const +{ + const char *kind = nullptr; + + switch (kind_) { + case MetaPropertyKind::NEW_TARGET: { + kind = "new.Target"; + break; + } + case MetaPropertyKind::IMPORT_META: { + kind = "import.Meta"; + break; + } + default: { + ES2PANDA_UNREACHABLE(); + } + } + + dumper->Add({{"type", "MetaProperty"}, {"kind", kind}}); +} + +void MethodDefinition::Dump(ir::AstDumper *dumper) const +{ + const char *kind = nullptr; + + switch (Kind()) { + case MethodDefinitionKind::CONSTRUCTOR: { + kind = "constructor"; + break; + } + case MethodDefinitionKind::METHOD: { + kind = "method"; + break; + } + case MethodDefinitionKind::EXTENSION_METHOD: { + kind = "extensionmethod"; + break; + } + case MethodDefinitionKind::GET: { + kind = "get"; + break; + } + case MethodDefinitionKind::SET: { + kind = "set"; + break; + } + case MethodDefinitionKind::EXTENSION_GET: { + kind = "extensionget"; + break; + } + case MethodDefinitionKind::EXTENSION_SET: { + kind = "extensionset"; + break; + } + default: { + ES2PANDA_UNREACHABLE(); + } + } + + dumper->Add({{"type", "MethodDefinition"}, + {"key", Key()}, + {"kind", kind}, + {"accessibility", AstDumper::Optional(AstDumper::ModifierToString(Modifiers()))}, + {"static", IsStatic()}, + {"optional", IsOptionalDeclaration()}, + {"computed", IsComputed()}, + {"value", Value()}, + {"overloads", Overloads()}}); +} + +void Property::Dump(ir::AstDumper *dumper) const +{ + const char *kind = nullptr; + + switch (kind_) { + case PropertyKind::INIT: { + kind = "init"; + break; + } + case PropertyKind::PROTO: { + kind = "proto"; + break; + } + case PropertyKind::GET: { + kind = "get"; + break; + } + case PropertyKind::SET: { + kind = "set"; + break; + } + default: { + ES2PANDA_UNREACHABLE(); + } + } + + dumper->Add({{"type", "Property"}, + {"method", isMethod_}, + {"shorthand", isShorthand_}, + {"computed", isComputed_}, + {"key", key_}, + {"value", value_}, + {"kind", kind}}); +} + +void VariableDeclaration::Dump(ir::AstDumper *dumper) const +{ + const char *kind = nullptr; + + switch (Kind()) { + case VariableDeclarationKind::CONST: { + kind = "const"; + break; + } + case VariableDeclarationKind::LET: { + kind = "let"; + break; + } + case VariableDeclarationKind::VAR: { + kind = "var"; + break; + } + default: { + ES2PANDA_UNREACHABLE(); + } + } + + dumper->Add({{"type", "VariableDeclaration"}, + {"declarations", Declarators()}, + {"kind", kind}, + {"annotations", AstDumper::Optional(Annotations())}, + {"declare", AstDumper::Optional(IsDeclare())}}); +} + } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/astDump.h b/ets2panda/ir/astDump.h index febaf9827013db6cf04b53c63a323ffb4bd72d9c..61c06f867a1ee8a98ef3a2b4401ac872ab743e12 100644 --- a/ets2panda/ir/astDump.h +++ b/ets2panda/ir/astDump.h @@ -16,7 +16,6 @@ #ifndef ES2PANDA_IR_AST_DUMP_H #define ES2PANDA_IR_AST_DUMP_H -#include "ir/astNode.h" #include "lexer/token/sourceLocation.h" #include "generated/tokenType.h" #include "lexer/token/number.h" @@ -26,6 +25,11 @@ #include namespace ark::es2panda::ir { + +enum class ModifierFlags : uint32_t; +enum class TSOperatorType; + +class AstNode; class AstDumper { public: class Nullish { @@ -44,7 +48,13 @@ public: class Optional { public: using Val = std::variant>; - explicit Optional(const ir::AstNode *node) : value_(node) {} + + // NOTE: the constructor is declared here with 'T' instead of 'AstNode' due to implicit 'ptr->bool' conversion, + // which allows overload resolution to select the bool-overload if the node class was declared but not defined. + template >> + explicit Optional(const T *node) : value_(node) + { + } explicit Optional(const char *string) : value_(const_cast(string)) {} explicit Optional(bool boolean) : value_(boolean) {} diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index 811496115396c1ea9419798713265ad6ff4134b0..52f15f42df6aef04a60dcad184ac0adf54823158 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -16,8 +16,8 @@ #include "astNode.h" #include "compiler/lowering/phase.h" #include "ir/astDump.h" -#include "ir/astNodeHistory.h" #include "ir/srcDump.h" +#include "ir/astNodeHistory.h" #include "ir/typed.h" namespace ark::es2panda::ir { diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index f6bbfea98758a81a1104bd283735a4943a17bcd0..6e157a1c4070b0c4dd4b8e4f3ad8324796febcc1 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -21,6 +21,7 @@ #include "astNodeMapping.h" #include "compiler/lowering/phase_id.h" #include "ir/visitor/AstVisitor.h" + #include "lexer/token/sourceLocation.h" #include "util/es2pandaMacros.h" @@ -113,8 +114,8 @@ inline std::string_view ToString(AstNodeType nodeType) // Forward declarations class AstNodeHistory; class AstDumper; -class Expression; class SrcDumper; +class Expression; class Statement; class ClassElement; template diff --git a/ets2panda/ir/base/catchClause.cpp b/ets2panda/ir/base/catchClause.cpp index c11433d958f4954e280b5d414698c2ff1e6ec797..ae7ab4480a49a8c03ba539efae54af25fa9a34ef 100644 --- a/ets2panda/ir/base/catchClause.cpp +++ b/ets2panda/ir/base/catchClause.cpp @@ -15,10 +15,9 @@ #include "catchClause.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" - +#include "ir/statements/blockStatement.h" +#include "ir/expressions/identifier.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void CatchClause::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -44,56 +43,11 @@ void CatchClause::Iterate(const NodeTraverser &cb) const cb(body_); } -void CatchClause::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "CatchClause"}, {"body", body_}, {"param", AstDumper::Nullish(param_)}}); -} - -void CatchClause::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(body_ != nullptr); - dumper->Add("("); - if (param_ != nullptr) { - param_->Dump(dumper); - if (param_->IsIdentifier() && param_->AsIdentifier()->TypeAnnotation() != nullptr) { - dumper->Add(": "); - param_->AsIdentifier()->TypeAnnotation()->Dump(dumper); - } - } - dumper->Add(") {"); - dumper->IncrIndent(); - dumper->Endl(); - body_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); -} - bool CatchClause::IsDefaultCatchClause() const { return param_ != nullptr && param_->AsIdentifier()->TypeAnnotation() == nullptr; } -void CatchClause::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void CatchClause::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *CatchClause::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType CatchClause::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - CatchClause::CatchClause(CatchClause const &other, ArenaAllocator *allocator) : TypedStatement(other) { param_ = nullptr; diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index 0c02f92ba392ebbec02db89591da9beaad8208a4..45568910dd5ac29e3b1ca5c1af05a58711f94c5d 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -15,17 +15,17 @@ #include "classDefinition.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/base/classStaticBlock.h" #include "ir/base/methodDefinition.h" #include "ir/base/scriptFunction.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/assignmentExpression.h" #include "ir/expressions/identifier.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/expressionStatement.h" #include "ir/ts/tsClassImplements.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/ts/tsTypeParameterInstantiation.h" namespace ark::es2panda::ir { @@ -297,199 +297,6 @@ void ClassDefinition::SetIdent(ir::Identifier *ident) noexcept } } -void ClassDefinition::Dump(ir::AstDumper *dumper) const -{ - auto propFilter = [](AstNode *prop) -> bool { - return !prop->IsClassStaticBlock() || !prop->AsClassStaticBlock()->Function()->IsHidden(); - }; - auto ctor = GetHistoryNodeAs()->ctor_; - dumper->Add({{"id", AstDumper::Nullish(Ident())}, - {"typeParameters", AstDumper::Optional(TypeParams())}, - {"superClass", AstDumper::Nullish(SuperClass())}, - {"superTypeParameters", AstDumper::Optional(SuperTypeParams())}, - {"implements", Implements()}, - {"annotations", AstDumper::Optional(Annotations())}, - {"constructor", AstDumper::Optional(ctor)}, - {"body", Body(), propFilter}}); -} - -void ClassDefinition::DumpGlobalClass(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(IsGlobal()); - ir::ClassStaticBlock *classStaticBlock = nullptr; - for (auto elem : Body()) { - if (elem->IsClassProperty()) { - elem->Dump(dumper); - dumper->Endl(); - } - - if (elem->IsClassStaticBlock()) { - classStaticBlock = elem->AsClassStaticBlock(); - } - } - for (auto elem : Body()) { - if (elem->IsMethodDefinition()) { - elem->Dump(dumper); - dumper->Endl(); - } - } - - if (classStaticBlock == nullptr) { - return; - } - - auto bodyStmts = - classStaticBlock->Value()->AsFunctionExpression()->Function()->Body()->AsBlockStatement()->Statements(); - for (auto statement : bodyStmts) { - if (statement->IsExpressionStatement() && - statement->AsExpressionStatement()->GetExpression()->IsAssignmentExpression() && - statement->AsExpressionStatement()->GetExpression()->AsAssignmentExpression()->IsIgnoreConstAssign()) { - // skip the dummy assignment expression created for const variable decl in the class static block. - continue; - } - statement->Dump(dumper); - if (statement != bodyStmts.back()) { - dumper->Endl(); - } - } -} - -// This method is needed by OHOS CI code checker -void ClassDefinition::DumpBody(ir::SrcDumper *dumper) const -{ - auto const body = Body(); - dumper->Add(" {"); - if (!body.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - for (auto elem : body) { - elem->Dump(dumper); - if (elem == body.back()) { - dumper->DecrIndent(); - } - dumper->Endl(); - } - } - dumper->Add("}"); -} - -void ClassDefinition::DumpPrefix(ir::SrcDumper *dumper) const -{ - if (IsExported()) { - dumper->Add("export "); - } else if (IsDefaultExported()) { - dumper->Add("export default "); - } - - if (dumper->IsDeclgen()) { - dumper->TryDeclareAmbientContext(); - } else if (IsDeclare()) { - dumper->Add("declare "); - } - - if (IsFinal()) { - dumper->Add("final "); - } - - if (IsAbstract() && !IsNamespaceTransformed()) { - dumper->Add("abstract "); - } - - if (parent_->IsETSStructDeclaration() || IsFromStruct()) { - dumper->Add("struct "); - } else if (IsNamespaceTransformed()) { - dumper->Add("namespace "); - } else { - dumper->Add("class "); - } -} - -bool ClassDefinition::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return false; - } - - if (dumper->IsIndirectDepPhase()) { - return false; - } - - if (IsExported() || IsDefaultExported()) { - return false; - } - - const auto className = ident_->Name().Mutf8(); - dumper->AddNode(className, this); - return true; -} - -void ClassDefinition::Dump(ir::SrcDumper *dumper) const -{ - auto guard = dumper->BuildAmbientContextGuard(); - // NOTE: plugin API fails - auto const ident = Ident(); - if ((ident->Name().StartsWith("$dynmodule")) || (ident->Name().StartsWith("$jscall"))) { - return; - } - - if (IsGlobal()) { - DumpGlobalClass(dumper); - return; - } - - ES2PANDA_ASSERT(ident_ != nullptr); - - if (RegisterUnexportedForDeclGen(dumper)) { - return; - } - - DumpAnnotations(dumper); - - DumpPrefix(dumper); - ident_->Dump(dumper); - - if (TypeParams() != nullptr) { - dumper->Add("<"); - TypeParams()->Dump(dumper); - dumper->Add("> "); - } - - if (SuperClass() != nullptr) { - dumper->Add(" extends "); - SuperClass()->Dump(dumper); - } - - DumpItems(dumper, " implements ", Implements()); - - if (!IsDeclare() || !Body().empty()) { - DumpBody(dumper); - } - if (IsLocal()) { - dumper->Add(";"); - } - dumper->Endl(); -} - -void ClassDefinition::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ClassDefinition::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ClassDefinition::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ClassDefinition::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ClassDefinition *ClassDefinition::Construct(ArenaAllocator *allocator) { ArenaVector body {allocator->Adapter()}; diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 4425052ca70bc3780384b940cd883d573490071d..a6b5fdad494ede78ba28396190038c04a0967c60 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -18,7 +18,7 @@ #include "varbinder/scope.h" #include "varbinder/variable.h" -#include "ir/srcDump.h" + #include "ir/annotationAllowed.h" #include "ir/astNode.h" #include "ir/astNodeHistory.h" @@ -479,21 +479,6 @@ public: v->Accept(this); } - template - static void DumpItems(ir::SrcDumper *dumper, const std::string &prefix, const ArenaVector &items) - { - if (items.empty()) { - return; - } - dumper->Add(prefix); - for (size_t i = 0; i < items.size(); ++i) { - items[i]->Dump(dumper); - if (i < items.size() - 1) { - dumper->Add(", "); - } - } - } - void CleanUp() override { AstNode::CleanUp(); diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index ae5a6082d5b71d2116974064d0fbd2a9a8741b96..372b6f85da875ca818d937fbfc1edcf8aab7f508 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -14,12 +14,7 @@ */ #include "classProperty.h" - -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "compiler/lowering/util.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { @@ -79,192 +74,6 @@ void ClassProperty::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ClassProperty::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ClassProperty"}, - {"key", Key()}, - {"value", AstDumper::Optional(Value())}, - {"accessibility", AstDumper::Optional(AstDumper::ModifierToString(Modifiers()))}, - {"static", IsStatic()}, - {"readonly", IsReadonly()}, - {"declare", IsDeclare()}, - {"optional", IsOptionalDeclaration()}, - {"computed", IsComputed()}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, - {"definite", IsDefinite()}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ClassProperty::DumpModifiers(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(key_); - - if (compiler::HasGlobalClassParent(this)) { - if (key_->Parent()->IsConst()) { - dumper->Add("const "); - } else { - dumper->Add("let "); - } - return; - } - - if (Parent() != nullptr && Parent()->IsClassDefinition() && !Parent()->AsClassDefinition()->IsLocal()) { - if (IsPrivate()) { - dumper->Add("private "); - } else if (IsProtected()) { - dumper->Add("protected "); - } else if (IsInternal()) { - dumper->Add("internal "); - } else { - dumper->Add("public "); - } - } - - if (IsStatic()) { - dumper->Add("static "); - } - - if (IsReadonly()) { - dumper->Add("readonly "); - } -} - -bool ClassProperty::DumpNamespaceForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return false; - } - - if (Parent() == nullptr) { - return false; - } - - bool isNamespaceTransformed = - Parent()->IsClassDefinition() && Parent()->AsClassDefinition()->IsNamespaceTransformed(); - if (isNamespaceTransformed) { - dumper->Add("let "); - return true; - } - return false; -} - -void ClassProperty::DumpPrefix(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - if (DumpNamespaceForDeclGen(dumper)) { - return; - } - DumpModifiers(dumper); -} - -void ClassProperty::DumpCheckerTypeForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return; - } - - if (TsType() == nullptr) { - return; - } - - auto typeStr = TsType()->ToString(); - dumper->Add(": "); - dumper->Add(typeStr); - - dumper->PushTask([dumper, typeStr] { dumper->DumpNode(typeStr); }); -} - -bool ClassProperty::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(key_); - if (!dumper->IsDeclgen()) { - return false; - } - - auto name = key_->AsIdentifier()->Name().Mutf8(); - if (name.rfind('#', 0) == 0) { - return true; - } - - if (IsPrivate()) { - return true; - } - - if (!compiler::HasGlobalClassParent(this)) { - return false; - } - - if (dumper->IsIndirectDepPhase()) { - return false; - } - - if (key_->Parent()->IsExported() || key_->Parent()->IsDefaultExported()) { - return false; - } - - dumper->AddNode(name, this); - return true; -} - -void ClassProperty::Dump(ir::SrcDumper *dumper) const -{ - if (dumper->IsDeclgen() && IsInternal()) { - return; - } - if (RegisterUnexportedForDeclGen(dumper)) { - return; - } - DumpPrefix(dumper); - - if (Key() != nullptr) { - Key()->Dump(dumper); - } - - if (IsOptionalDeclaration()) { - dumper->Add("?"); - } - - if (IsDefinite()) { - dumper->Add("!"); - } - - if (typeAnnotation_ != nullptr && !dumper->IsDeclgen()) { - dumper->Add(": "); - TypeAnnotation()->Dump(dumper); - } - - DumpCheckerTypeForDeclGen(dumper); - - if (value_ != nullptr) { - if (!dumper->IsDeclgen() || Parent()->IsAnnotationDeclaration()) { - dumper->Add(" = "); - Value()->Dump(dumper); - } - } - - dumper->Add(";"); -} - -void ClassProperty::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ClassProperty::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ClassProperty::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ClassProperty::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const key = Key()->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/base/classStaticBlock.cpp b/ets2panda/ir/base/classStaticBlock.cpp index dffca6bb9cb072b951909353fb8d20bbd3d09b82..11a863483107ead5d0f5acd4a9111430b07a3812 100644 --- a/ets2panda/ir/base/classStaticBlock.cpp +++ b/ets2panda/ir/base/classStaticBlock.cpp @@ -15,12 +15,6 @@ #include "classStaticBlock.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/base/decorator.h" #include "ir/base/scriptFunction.h" #include "ir/expression.h" @@ -43,51 +37,6 @@ void ClassStaticBlock::Iterate(const NodeTraverser &cb) const cb(value); } -void ClassStaticBlock::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ClassStaticBlock"}, {"value", Value()}}); -} - -void ClassStaticBlock::Dump(ir::SrcDumper *dumper) const -{ - if (dumper->IsDeclgen()) { - return; - } - - ES2PANDA_ASSERT(value_); - ES2PANDA_ASSERT(value_->IsFunctionExpression()); - ES2PANDA_ASSERT(value_->AsFunctionExpression()->Function()->IsScriptFunction()); - dumper->Add("static {"); - dumper->IncrIndent(); - dumper->Endl(); - const auto *scriptFunc = value_->AsFunctionExpression()->Function()->AsScriptFunction(); - ES2PANDA_ASSERT(scriptFunc->HasBody()); - scriptFunc->Body()->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); -} - -void ClassStaticBlock::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ClassStaticBlock::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ClassStaticBlock::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ClassStaticBlock::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ir::ScriptFunction *ClassStaticBlock::Function() { return Value()->AsFunctionExpression()->Function(); diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index 573093d668402ec608935c9a2a7036bbd6641010..755fabf6df1bf453c5c5ce2afd87f616963acc7e 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -15,10 +15,7 @@ #include "decorator.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/expression.h" namespace ark::es2panda::ir { void Decorator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -34,36 +31,6 @@ void Decorator::Iterate(const NodeTraverser &cb) const cb(expr_); } -void Decorator::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "Decorator"}, {"expression", expr_}}); -} - -void Decorator::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("Decorator"); -} - -void Decorator::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void Decorator::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *Decorator::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType Decorator::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index 38bed829d844a75ec6bdcebd8f8d767128a9876a..227597488392a1d4f137424f586b5a4f6c08e13e 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -15,10 +15,6 @@ #include "metaProperty.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void MetaProperty::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -27,52 +23,6 @@ void MetaProperty::TransformChildren([[maybe_unused]] const NodeTransformer &cb, void MetaProperty::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void MetaProperty::Dump(ir::AstDumper *dumper) const -{ - const char *kind = nullptr; - - switch (kind_) { - case MetaPropertyKind::NEW_TARGET: { - kind = "new.Target"; - break; - } - case MetaPropertyKind::IMPORT_META: { - kind = "import.Meta"; - break; - } - default: { - ES2PANDA_UNREACHABLE(); - } - } - - dumper->Add({{"type", "MetaProperty"}, {"kind", kind}}); -} - -void MetaProperty::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void MetaProperty::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("MetaProperty"); -} - -void MetaProperty::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *MetaProperty::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType MetaProperty::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(kind_); diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index 4cfd0e42840ba1fd8b77db4e83be1aff58cf333a..c324e8fd11063b073a7e510719e0dd345598e90e 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -15,12 +15,9 @@ #include "methodDefinition.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "classDefinition.h" #include "ir/ts/tsInterfaceBody.h" -#include "compiler/lowering/util.h" +#include "ir/expressions/functionExpression.h" namespace ark::es2panda::ir { @@ -118,234 +115,6 @@ void MethodDefinition::TransformChildren(const NodeTransformer &cb, std::string_ } } -void MethodDefinition::Dump(ir::AstDumper *dumper) const -{ - const char *kind = nullptr; - - switch (Kind()) { - case MethodDefinitionKind::CONSTRUCTOR: { - kind = "constructor"; - break; - } - case MethodDefinitionKind::METHOD: { - kind = "method"; - break; - } - case MethodDefinitionKind::EXTENSION_METHOD: { - kind = "extensionmethod"; - break; - } - case MethodDefinitionKind::GET: { - kind = "get"; - break; - } - case MethodDefinitionKind::SET: { - kind = "set"; - break; - } - case MethodDefinitionKind::EXTENSION_GET: { - kind = "extensionget"; - break; - } - case MethodDefinitionKind::EXTENSION_SET: { - kind = "extensionset"; - break; - } - default: { - ES2PANDA_UNREACHABLE(); - } - } - - dumper->Add({{"type", "MethodDefinition"}, - {"key", Key()}, - {"kind", kind}, - {"accessibility", AstDumper::Optional(AstDumper::ModifierToString(Modifiers()))}, - {"static", IsStatic()}, - {"optional", IsOptionalDeclaration()}, - {"computed", IsComputed()}, - {"value", Value()}, - {"overloads", Overloads()}}); -} - -void MethodDefinition::DumpModifierPrefix(ir::SrcDumper *dumper) const -{ - if (compiler::HasGlobalClassParent(this)) { - return; - } - if (IsStatic()) { - dumper->Add("static "); - } - - if (IsAbstract() && !(Parent()->IsTSInterfaceBody() || - (BaseOverloadMethod() != nullptr && BaseOverloadMethod()->Parent()->IsTSInterfaceBody()))) { - dumper->Add("abstract "); - } - if (IsFinal()) { - dumper->Add("final "); - } - if (IsNative()) { - dumper->Add("native "); - } - if (IsAsync() && !dumper->IsDeclgen()) { - dumper->Add("async "); - } - if (IsOverride()) { - dumper->Add("override "); - } - - if (IsGetter()) { - dumper->Add("get "); - } else if (IsSetter()) { - dumper->Add("set "); - } -} - -static bool IsNamespaceTransformed(const MethodDefinition *method) -{ - auto *parent = method->Parent(); - if (parent->IsMethodDefinition()) { - // handle overloads - parent = parent->Parent(); - } - if (parent->IsClassDefinition() && parent->AsClassDefinition()->IsNamespaceTransformed()) { - return true; - } - return false; -} - -void MethodDefinition::DumpPrefix(ir::SrcDumper *dumper) const -{ - bool global = compiler::HasGlobalClassParent(this); - if (global || IsNamespaceTransformed(this)) { - if (IsExported()) { - dumper->Add("export "); - } - if (IsDefaultExported()) { - dumper->Add("export default "); - } - if (dumper->IsDeclgen()) { - if (global) { - dumper->Add("declare "); - } else { - dumper->TryDeclareAmbientContext(); - } - } - dumper->Add("function "); - return; - } - - if (Parent() != nullptr && Parent()->IsClassDefinition() && !Parent()->AsClassDefinition()->IsLocal()) { - if (IsPrivate()) { - dumper->Add("private "); - } else if (IsProtected()) { - dumper->Add("protected "); - } else if (IsInternal()) { - dumper->Add("internal "); - } else { - dumper->Add("public "); - } - } - DumpModifierPrefix(dumper); -} - -bool MethodDefinition::FilterForDeclGen() const -{ - if (key_ == nullptr) { - return false; - } - - if (compiler::HasGlobalClassParent(this) && !key_->Parent()->IsExported() && !key_->Parent()->IsDefaultExported()) { - return true; - } - - ES2PANDA_ASSERT(Id() != nullptr); - auto name = Id()->Name().Mutf8(); - if (name.find("%%async") != std::string::npos || name == compiler::Signatures::INITIALIZER_BLOCK_INIT || - name == compiler::Signatures::INIT_METHOD) { - return true; - } - - if (name.rfind('#', 0) == 0) { - return true; - } - - if (name == compiler::Signatures::CCTOR) { - return true; - } - - if (name == compiler::Signatures::GET_INDEX_METHOD || name == compiler::Signatures::SET_INDEX_METHOD) { - return true; - } - - if (IsPrivate() || IsInternal()) { - return true; - } - - return false; -} - -void MethodDefinition::Dump(ir::SrcDumper *dumper) const -{ - if (dumper->IsDeclgen() && FilterForDeclGen()) { - return; - } - - if (compiler::HasGlobalClassParent(this) && Id() != nullptr && Id()->Name().Is(compiler::Signatures::INIT_METHOD)) { - Function()->Body()->Dump(dumper); - return; - } - - auto value = Value(); - if (value->AsFunctionExpression()->Function()->HasAnnotations()) { - for (auto *anno : value->AsFunctionExpression()->Function()->Annotations()) { - // NOTE(zhelyapov): workaround, see #26031 - if (anno->GetBaseName()->Name() != compiler::Signatures::DEFAULT_ANNO_FOR_FUNC) { - anno->Dump(dumper); - } - } - } - - DumpPrefix(dumper); - - if (IsConstructor() && - !(Key()->IsIdentifier() && Key()->AsIdentifier()->Name().Is(compiler::Signatures::CONSTRUCTOR_NAME))) { - dumper->Add(std::string(compiler::Signatures::CONSTRUCTOR_NAME) + " "); - } - - auto key = Key(); - if (key != nullptr) { - key->Dump(dumper); - } - - if (value != nullptr) { - value->Dump(dumper); - } - - for (auto method : Overloads()) { - method->Dump(dumper); - } -} - -void MethodDefinition::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void MethodDefinition::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *MethodDefinition::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType MethodDefinition::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const key = Key()->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/base/overloadDeclaration.cpp b/ets2panda/ir/base/overloadDeclaration.cpp index 7af8f592ff7f7d3ece7a2d44b487e374152dae84..b630f692fec6eef5d668a56edb64d5c0191c0d30 100644 --- a/ets2panda/ir/base/overloadDeclaration.cpp +++ b/ets2panda/ir/base/overloadDeclaration.cpp @@ -14,8 +14,6 @@ */ #include "overloadDeclaration.h" -#include "checker/ETSchecker.h" -#include "compiler/lowering/util.h" namespace ark::es2panda::ir { PrivateFieldKind OverloadDeclaration::ToPrivateFieldKind(bool const isStatic) const @@ -51,72 +49,6 @@ void OverloadDeclaration::Iterate(const NodeTraverser &cb) const } } -void OverloadDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "OverloadDeclaration"}, - {"key", key_}, - {"optional", AstDumper::Optional(AstDumper::ModifierToString(flags_))}, - {"static", IsStatic()}, - {"overloadedList", overloadedList_}}); -} - -void OverloadDeclaration::DumpModifier(ir::SrcDumper *dumper) const -{ - if (compiler::HasGlobalClassParent(this) && !dumper->IsDeclgen()) { - if (IsExported()) { - dumper->Add("export "); - } - } - - if (Parent() != nullptr && Parent()->IsClassDefinition() && !Parent()->AsClassDefinition()->IsLocal() && - !compiler::HasGlobalClassParent(this)) { - if (IsPrivate()) { - dumper->Add("private "); - } else if (IsProtected()) { - dumper->Add("protected "); - } else if (IsInternal()) { - dumper->Add("internal "); - } else { - dumper->Add("public "); - } - - if (IsStatic()) { - dumper->Add("static "); - } - } - - if (IsAsync()) { - dumper->Add("async "); - } -} - -void OverloadDeclaration::Dump(ir::SrcDumper *dumper) const -{ - DumpModifier(dumper); - dumper->Add("overload "); - dumper->Add(IsConstructor() ? "constructor " : key_->AsIdentifier()->Name().Mutf8()); - dumper->Add("{"); - for (size_t i = 0; i < overloadedList_.size(); i++) { - if (i != 0) { - dumper->Add(", "); - } - overloadedList_[i]->Dump(dumper); - } - dumper->Add("};"); -} - -void OverloadDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *OverloadDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType OverloadDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - OverloadDeclaration *OverloadDeclaration::Construct(ArenaAllocator *allocator) { return allocator->New(nullptr, ModifierFlags::NONE, allocator); diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index 531954ca21084242c387790f7cfda39607dacd2e..6aff6a035ba76539b1e1ad94a6e612d52e2c2b6c 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -15,9 +15,11 @@ #include "property.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/literals/stringLiteral.h" namespace ark::es2panda::ir { Property::Property([[maybe_unused]] Tag const tag, Property const &other, Expression *const key, @@ -135,67 +137,4 @@ void Property::Iterate(const NodeTraverser &cb) const cb(value_); } -void Property::Dump(ir::AstDumper *dumper) const -{ - const char *kind = nullptr; - - switch (kind_) { - case PropertyKind::INIT: { - kind = "init"; - break; - } - case PropertyKind::PROTO: { - kind = "proto"; - break; - } - case PropertyKind::GET: { - kind = "get"; - break; - } - case PropertyKind::SET: { - kind = "set"; - break; - } - default: { - ES2PANDA_UNREACHABLE(); - } - } - - dumper->Add({{"type", "Property"}, - {"method", isMethod_}, - {"shorthand", isShorthand_}, - {"computed", isComputed_}, - {"key", key_}, - {"value", value_}, - {"kind", kind}}); -} - -void Property::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void Property::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -void Property::Dump(ir::SrcDumper *dumper) const -{ - if (kind_ == PropertyKind::INIT) { - key_->Dump(dumper); - dumper->Add(": "); - value_->Dump(dumper); - } -} - -checker::Type *Property::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType Property::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index 0cd1d4a6cfade656886517f12a91fad8ffb2dc27..15de8699b4a933891e74908650454e4a56183913 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -15,14 +15,14 @@ #include "scriptFunction.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/typeNode.h" +#include "ir/expressions/identifier.h" +#include "ir/statements/blockStatement.h" +#include "ir/ts/tsTypeParameterDeclaration.h" + #include "mem/arena_allocator.h" #include "utils/arena_containers.h" - +#include "util/helpers.h" namespace ark::es2panda::ir { void ScriptFunction::SetBody(AstNode *body) @@ -271,129 +271,6 @@ void ScriptFunction::SetReturnTypeAnnotation(TypeNode *node) noexcept } } -void ScriptFunction::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ScriptFunction"}, - {"id", AstDumper::Nullish(Id())}, - {"generator", IsGenerator()}, - {"async", IsAsyncFunc()}, - {"expression", ((Flags() & ir::ScriptFunctionFlags::EXPRESSION) != 0)}, - {"params", Params()}, - {"returnType", AstDumper::Optional(ReturnTypeAnnotation())}, - {"typeParameters", AstDumper::Optional(TypeParams())}, - {"declare", AstDumper::Optional(IsDeclare())}, - {"body", AstDumper::Optional(Body())}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ScriptFunction::DumpCheckerTypeForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return; - } - - if (IsConstructor()) { - return; - } - - if (IsSetter()) { - return; - } - - if (Signature() == nullptr) { - return; - } - - if (Signature()->ReturnType() == nullptr) { - return; - } - - auto typeStr = Signature()->ReturnType()->ToString(); - dumper->Add(": "); - dumper->Add(typeStr); - - dumper->PushTask([dumper, typeStr] { dumper->DumpNode(typeStr); }); -} - -void ScriptFunction::Dump(ir::SrcDumper *dumper) const -{ - if (TypeParams() != nullptr) { - dumper->Add("<"); - TypeParams()->Dump(dumper); - dumper->Add(">"); - } - dumper->Add("("); - for (auto param : Params()) { - param->Dump(dumper); - if (param != Params().back()) { - dumper->Add(", "); - } - } - dumper->Add(")"); - if (ReturnTypeAnnotation() != nullptr && !dumper->IsDeclgen()) { - dumper->Add(": "); - ReturnTypeAnnotation()->Dump(dumper); - } - DumpCheckerTypeForDeclGen(dumper); - if (dumper->IsDeclgen()) { - dumper->Add(";"); - dumper->Endl(); - return; - } - DumpBody(dumper); -} - -void ScriptFunction::DumpBody(ir::SrcDumper *dumper) const -{ - if (!HasBody()) { - dumper->Endl(); - return; - } - - if (IsArrow()) { - dumper->Add(" =>"); - } - - if (body_->IsBlockStatement()) { - dumper->Add(" {"); - const auto &statements = body_->AsBlockStatement()->Statements(); - if (!statements.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - body_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); - } else { - dumper->Add(" "); - body_->Dump(dumper); - } - - if (!IsArrow()) { - dumper->Endl(); - } -} - -void ScriptFunction::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ScriptFunction::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ScriptFunction::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ScriptFunction::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ScriptFunction *ScriptFunction::Construct(ArenaAllocator *allocator) { auto adapter = allocator->Adapter(); diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index 9b504315154444509a9647ceb807d7c9d9109def..ea490d3780230ba40c6fa0fd0985324cd52634d3 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -15,9 +15,9 @@ #include "spreadElement.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const &other, @@ -116,43 +116,6 @@ void SpreadElement::Iterate(const NodeTraverser &cb) const } } -void SpreadElement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", (type_ == AstNodeType::SPREAD_ELEMENT) ? "SpreadElement" : "RestElement"}, - {"argument", argument_}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}}); -} - -void SpreadElement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("..."); - argument_->Dump(dumper); - auto type = TypeAnnotation(); - if (type != nullptr && type->IsValidInCurrentPhase()) { - dumper->Add(": "); - type->Dump(dumper); - } -} - -void SpreadElement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void SpreadElement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *SpreadElement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType SpreadElement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - std::string SpreadElement::ToString() const { auto str = Argument()->ToString(); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 4ba3be396ab3d805729e62709515a8c2a4673c42..f154c5da7db6f105cdad3f34db267daacd3ce93a 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -15,10 +15,6 @@ #include "templateElement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -27,39 +23,6 @@ void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer & void TemplateElement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void TemplateElement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({ - {"type", "TemplateElement"}, - {"value", {{"raw", raw_}, {"cooked", cooked_}}}, - }); -} - -void TemplateElement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(std::string(raw_)); -} - -void TemplateElement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TemplateElement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TemplateElement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TemplateElement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(raw_, cooked_); diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index 22d8a78b5655f40150fe944aa864d84c5cea1ccc..1695e64fc6479ec5a255f9b3758957cdbe771afc 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -15,9 +15,7 @@ #include "tsIndexSignature.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const noexcept @@ -45,39 +43,6 @@ void TSIndexSignature::Iterate(const NodeTraverser &cb) const cb(typeAnnotation_); } -void TSIndexSignature::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSIndexSignature"}, - {"parameters", param_}, - {"typeAnnotation", typeAnnotation_}, - {"readonly", readonly_}}); -} - -void TSIndexSignature::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSIndexSignature"); -} - -void TSIndexSignature::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSIndexSignature::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSIndexSignature::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSIndexSignature::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const param = param_ != nullptr ? param_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/base/tsMethodSignature.cpp b/ets2panda/ir/base/tsMethodSignature.cpp index de2b99a6a186fff17126ab382bfa9beff3108b51..355a45f6add8e4044027f9436fc0826e2154d075 100644 --- a/ets2panda/ir/base/tsMethodSignature.cpp +++ b/ets2panda/ir/base/tsMethodSignature.cpp @@ -14,11 +14,8 @@ */ #include "tsMethodSignature.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void TSMethodSignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -37,39 +34,4 @@ void TSMethodSignature::Iterate(const NodeTraverser &cb) const signature_.Iterate(cb); } -void TSMethodSignature::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSMethodSignature"}, - {"computed", computed_}, - {"optional", optional_}, - {"key", key_}, - {"params", Params()}, - {"typeParameters", AstDumper::Optional(TypeParams())}, - {"typeAnnotation", AstDumper::Optional(ReturnTypeAnnotation())}}); -} - -void TSMethodSignature::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSMethodSignature"); -} - -void TSMethodSignature::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSMethodSignature::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSMethodSignature::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSMethodSignature::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index d1a2bb2ee1c3215b5dc81ee10c79a5a0bd480132..76f7690f683272184a6eec13b44402e680c8a440 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -15,9 +15,7 @@ #include "tsPropertySignature.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void TSPropertySignature::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -44,41 +42,6 @@ void TSPropertySignature::Iterate(const NodeTraverser &cb) const } } -void TSPropertySignature::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSPropertySignature"}, - {"computed", computed_}, - {"optional", optional_}, - {"readonly", readonly_}, - {"key", key_}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}}); -} - -void TSPropertySignature::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSPropertySignature"); -} - -void TSPropertySignature::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSPropertySignature::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSPropertySignature::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSPropertySignature::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/base/tsSignatureDeclaration.cpp b/ets2panda/ir/base/tsSignatureDeclaration.cpp index 141398e53ad54809bf782bb61ef90385914112fb..038c5af3b3d85e3de0a58e7faf5df2cb0a7e1a96 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.cpp +++ b/ets2panda/ir/base/tsSignatureDeclaration.cpp @@ -15,12 +15,8 @@ #include "tsSignatureDeclaration.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void TSSignatureDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -33,38 +29,4 @@ void TSSignatureDeclaration::Iterate(const NodeTraverser &cb) const signature_.Iterate(cb); } -void TSSignatureDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", (kind_ == TSSignatureDeclaration::TSSignatureDeclarationKind::CALL_SIGNATURE) - ? "TSCallSignatureDeclaration" - : "TSConstructSignatureDeclaration"}, - {"params", Params()}, - {"typeParameters", AstDumper::Optional(TypeParams())}, - {"returnType", AstDumper::Optional(ReturnTypeAnnotation())}}); -} - -void TSSignatureDeclaration::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSSignatureDeclaration"); -} - -void TSSignatureDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSSignatureDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSSignatureDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSSignatureDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/brokenTypeNode.cpp b/ets2panda/ir/brokenTypeNode.cpp index 05ef63679f55f15117eaf0cf22f9f0ef00f2546b..fbdf699f9b69034a4248e5522ae06edea5b59d3c 100644 --- a/ets2panda/ir/brokenTypeNode.cpp +++ b/ets2panda/ir/brokenTypeNode.cpp @@ -14,11 +14,8 @@ */ #include "brokenTypeNode.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "checker/ETSchecker.h" namespace ark::es2panda::ir { @@ -26,49 +23,9 @@ void BrokenTypeNode::TransformChildren([[maybe_unused]] const NodeTransformer &c [[maybe_unused]] std::string_view transformationName) { } - + void BrokenTypeNode::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void BrokenTypeNode::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ErrorType"}}); -} - -void BrokenTypeNode::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(ERROR_TYPE); -} - -void BrokenTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void BrokenTypeNode::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *BrokenTypeNode::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *BrokenTypeNode::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::Type *BrokenTypeNode::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - return checker->GlobalTypeError(); -} - -checker::VerifiedType BrokenTypeNode::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - BrokenTypeNode *BrokenTypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(allocator); diff --git a/ets2panda/ir/brokenTypeNode.h b/ets2panda/ir/brokenTypeNode.h index f4143f6adf0f015b3d33d9b611771d1a789b8dd9..f38e5912894491f4cc30d711a3401a3c158a3e5a 100644 --- a/ets2panda/ir/brokenTypeNode.h +++ b/ets2panda/ir/brokenTypeNode.h @@ -39,7 +39,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index ba0830fb309dc14f1c0c19e9dd964bb7b1c1fccd..afe940e1e36a66244480d088d91f77fbe664ace3 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -15,9 +15,7 @@ #include "etsClassLiteral.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void ETSClassLiteral::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -33,36 +31,6 @@ void ETSClassLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const cb(expr_); } -void ETSClassLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSClassLiteral"}}); -} - -void ETSClassLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("ETSClassLiteral"); -} - -void ETSClassLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ETSClassLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSClassLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSClassLiteral::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index 73b0c3bc03ac022d736bf1d97c9b8c89d712ffd6..9c30f7321af365e8b9d728e5eb7fe16e511cb2a9 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -15,10 +15,7 @@ #include "etsFunctionType.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/ts/tsTypeParameterDeclaration.h" namespace ark::es2panda::ir { void ETSFunctionType::SetParams(ArenaVector &¶msList) @@ -43,69 +40,6 @@ void ETSFunctionType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSFunctionType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSFunctionType"}, - {"params", Params()}, - {"typeParameters", AstDumper::Optional(TypeParams())}, - {"returnType", ReturnType()}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSFunctionType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("(("); - for (auto *param : Params()) { - param->Dump(dumper); - if (param != Params().back()) { - dumper->Add(", "); - } - } - dumper->Add(")"); - - if (TypeParams() != nullptr) { - TypeParams()->Dump(dumper); - } - - if (ReturnType() != nullptr) { - dumper->Add("=> "); - ReturnType()->Dump(dumper); - } - - dumper->Add(")"); -} - -void ETSFunctionType::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ETSFunctionType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSFunctionType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *ETSFunctionType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType ETSFunctionType::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSFunctionType::GetType(checker::ETSChecker *checker) -{ - return Check(checker); -} - ETSFunctionType *ETSFunctionType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ArenaVector paramsClone(allocator->Adapter()); diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 3a1554983583ab8557076efaa4bad337f77da467..cd439123fa397e06405e66dfc2927099183c9b7a 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -124,7 +124,6 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check(checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsIntrinsicNode.cpp b/ets2panda/ir/ets/etsIntrinsicNode.cpp index 9024106ab3d9fe693127fbfa675a62341b23a60b..69334fb49178366bbf44558e2609d7b0f0f5f8a2 100644 --- a/ets2panda/ir/ets/etsIntrinsicNode.cpp +++ b/ets2panda/ir/ets/etsIntrinsicNode.cpp @@ -14,8 +14,7 @@ */ #include "etsIntrinsicNode.h" - -#include "checker/ETSchecker.h" +#include "ir/typeNode.h" #include "compiler/core/ETSGen.h" namespace ark::es2panda::ir { @@ -27,25 +26,6 @@ void ETSIntrinsicNode::Iterate(const NodeTraverser &cb) const } } -void ETSIntrinsicNode::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSIntrinsicNode"}, {"arguments", arguments_}}); -} - -void ETSIntrinsicNode::Dump([[maybe_unused]] ir::SrcDumper *dumper) const -{ - dumper->Add("%%intrin%%"); - dumper->Add(Id().Mutf8()); - dumper->Add("("); - for (auto arg : arguments_) { - arg->Dump(dumper); - if (arg != arguments_.back()) { - dumper->Add(", "); - } - } - dumper->Add(")"); -} - EtsIntrinsicInfo const *GetIntrinsicInfoFor(ETSIntrinsicNode const *node) { return node->info_; @@ -119,8 +99,6 @@ private: static const InfosMap infos_; }; -void ETSIntrinsicNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - void ETSIntrinsicNode::Compile(compiler::ETSGen *etsg) const { if (auto info = GetIntrinsicInfoFor(this); LIKELY(info != nullptr)) { @@ -167,11 +145,6 @@ checker::Type *ETSIntrinsicNode::ExpectedTypeAt(checker::ETSChecker *checker, si return nullptr; } -checker::Type *ETSIntrinsicNode::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - checker::VerifiedType ETSIntrinsicNode::Check([[maybe_unused]] checker::ETSChecker *checker) { if (auto info = GetIntrinsicInfoFor(this); LIKELY(info != nullptr)) { diff --git a/ets2panda/ir/ets/etsKeyofType.cpp b/ets2panda/ir/ets/etsKeyofType.cpp index 6a319bcadcb7fec3aa25566e740ef8724154fc73..0ae99bbd04986e0ea89a1e53ec6298177b9d9182 100644 --- a/ets2panda/ir/ets/etsKeyofType.cpp +++ b/ets2panda/ir/ets/etsKeyofType.cpp @@ -15,8 +15,6 @@ #include "etsKeyofType.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void ETSKeyofType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { @@ -31,58 +29,6 @@ void ETSKeyofType::Iterate(const NodeTraverser &cb) const cb(type_); } -void ETSKeyofType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSKeyofType"}, {"types", type_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSKeyofType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("keyof "); - type_->Dump(dumper); -} - -void ETSKeyofType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *ETSKeyofType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType ETSKeyofType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSKeyofType::GetType(checker::ETSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - auto *typeReference = type_->GetType(checker); - ES2PANDA_ASSERT(typeReference); - - if (typeReference->IsETSPrimitiveType()) { - typeReference = checker->MaybeBoxType(typeReference); - } - - if (!typeReference->IsETSObjectType()) { - checker->LogError(diagnostic::KEYOF_REFERENCE_TYPE, {}, Start()); - SetTsType(checker->GlobalTypeError()); - return checker->GlobalTypeError(); - } - - checker::TypeStackElement tse(checker, GetHistoryNode(), {{diagnostic::CYCLIC_TYPE_OF, {}}}, Start()); - if (tse.HasTypeError()) { - return checker->GlobalTypeError(); - } - - SetTsType(checker->CreateUnionFromKeyofType(typeReference->AsETSObjectType())); - return TsType(); -} - ETSKeyofType *ETSKeyofType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { TypeNode *type = type_->Clone(allocator, nullptr); diff --git a/ets2panda/ir/ets/etsModule.cpp b/ets2panda/ir/ets/etsModule.cpp index 16a9a05cf0f4874b0d203f683931f5171b19bf3d..f9f16b315209a2d25dfd6ed1185952715f633bb2 100644 --- a/ets2panda/ir/ets/etsModule.cpp +++ b/ets2panda/ir/ets/etsModule.cpp @@ -18,45 +18,6 @@ namespace ark::es2panda::ir { -void ETSModule::Dump(ir::SrcDumper *dumper) const -{ - if (IsNamespace()) { - if (IsExported()) { - dumper->Add("export "); - } - - if (IsDefaultExported()) { - dumper->Add("export default "); - } - - if (IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) { - dumper->Add("declare "); - } - - dumper->Add("namespace "); - Ident()->Dump(dumper); - dumper->Add(" {"); - dumper->IncrIndent(); - } - - if (!Statements().empty()) { - dumper->Endl(); - for (auto elem : Statements()) { - elem->Dump(dumper); - if (elem != Statements().back()) { - dumper->Endl(); - } - } - } - if (IsNamespace()) { - dumper->DecrIndent(); - } - dumper->Endl(); - if (IsNamespace()) { - dumper->Add("}"); - } -} - ETSModule *ETSModule::Construct(ArenaAllocator *allocator) { ArenaVector statementList(allocator->Adapter()); diff --git a/ets2panda/ir/ets/etsModule.h b/ets2panda/ir/ets/etsModule.h index abc2a5eca1b40aa271e3706b1834926fbc9fe88c..a67a558b92645699e350387158a6749279c9fd8a 100644 --- a/ets2panda/ir/ets/etsModule.h +++ b/ets2panda/ir/ets/etsModule.h @@ -19,7 +19,6 @@ #include "ir/statements/blockStatement.h" #include "ir/annotationAllowed.h" #include "ir/expressions/identifier.h" -#include "ir/srcDump.h" namespace ark::es2panda::parser { class Program; diff --git a/ets2panda/ir/ets/etsNeverType.cpp b/ets2panda/ir/ets/etsNeverType.cpp index 527b3d7b35022282a8a9d0deb98ad8317deb7a69..9618d42ce7b668e28826153bfa4426e57fcc8798 100644 --- a/ets2panda/ir/ets/etsNeverType.cpp +++ b/ets2panda/ir/ets/etsNeverType.cpp @@ -15,8 +15,6 @@ #include "etsNeverType.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void ETSNeverType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -29,38 +27,6 @@ void ETSNeverType::Iterate([[maybe_unused]] const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSNeverType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSNeverType"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSNeverType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("never"); -} - -void ETSNeverType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - ES2PANDA_UNREACHABLE(); -} - -checker::Type *ETSNeverType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType ETSNeverType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSNeverType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - SetTsType(checker->GlobalETSNeverType()); - return TsType(); -} - ETSNeverType *ETSNeverType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *const clone = allocator->New(allocator); diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index 6031857627b31719e2fbf5ad4b3cab3c215a10e5..edf3779c7248a36351fd7ea47c9c484c8b23a46d 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -15,11 +15,7 @@ #include "etsNewArrayInstanceExpression.h" -#include "checker/ETSchecker.h" #include "checker/ets/typeRelationContext.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" namespace ark::es2panda::ir { void ETSNewArrayInstanceExpression::TransformChildren(const NodeTransformer &cb, @@ -42,42 +38,6 @@ void ETSNewArrayInstanceExpression::Iterate(const NodeTraverser &cb) const cb(dimension_); } -void ETSNewArrayInstanceExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "ETSNewArrayInstanceExpression"}, {"typeReference", typeReference_}, {"dimension", dimension_}}); -} - -void ETSNewArrayInstanceExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("new "); - ES2PANDA_ASSERT(typeReference_); - typeReference_->Dump(dumper); - ES2PANDA_ASSERT(dimension_); - dumper->Add("["); - dimension_->Dump(dumper); - dumper->Add("]"); -} - -void ETSNewArrayInstanceExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSNewArrayInstanceExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSNewArrayInstanceExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSNewArrayInstanceExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index 7c0b525c0e0a81f81125ffd054e34218f715914f..c304f244db98a67bfdfd0ab5ac7dd993cd18cb7d 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -15,10 +15,6 @@ #include "etsNewClassInstanceExpression.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void ETSNewClassInstanceExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -44,55 +40,6 @@ void ETSNewClassInstanceExpression::Iterate([[maybe_unused]] const NodeTraverser } } -void ETSNewClassInstanceExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "ETSNewClassInstanceExpression"}, {"typeReference", typeReference_}, {"arguments", arguments_}}); -} - -void ETSNewClassInstanceExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("new "); - if (typeReference_ != nullptr) { - if (typeReference_->IsETSUnionType()) { - dumper->Add("("); - } - typeReference_->Dump(dumper); - if (typeReference_->IsETSUnionType()) { - dumper->Add(")"); - } - } - - dumper->Add("("); - for (auto argument : arguments_) { - argument->Dump(dumper); - if (argument != arguments_.back()) { - dumper->Add(", "); - } - } - dumper->Add(")"); -} - -void ETSNewClassInstanceExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ETSNewClassInstanceExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSNewClassInstanceExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSNewClassInstanceExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, ArenaAllocator *const allocator) : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) @@ -116,9 +63,4 @@ ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocat return clone; } -bool ETSNewClassInstanceExpression::TypeIsAllowedForInstantiation(checker::Type *type) -{ - return !(type->IsETSNullType() || type->IsETSUndefinedType() || type->IsETSNeverType() || type->IsETSVoidType()); -} - } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index c8c614ddc86b574ffac581011d9ba0393d6d93a1..66ddf250c17d5c40bf74c0112b4a1a68c4698081 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -99,7 +99,6 @@ public: void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; checker::VerifiedType Check(checker::ETSChecker *checker) override; - static bool TypeIsAllowedForInstantiation(checker::Type *type); void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 08ff84bcf44bb3e2a1467e8b3333535c251ea215..7b63ffdf32fa4de9498cecc9d5686c47a9cd1b34 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -16,9 +16,6 @@ #include "etsNewMultiDimArrayInstanceExpression.h" #include "checker/ets/typeRelationContext.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" namespace ark::es2panda::ir { void ETSNewMultiDimArrayInstanceExpression::TransformChildren(const NodeTransformer &cb, @@ -45,44 +42,6 @@ void ETSNewMultiDimArrayInstanceExpression::Iterate(const NodeTraverser &cb) con } } -void ETSNewMultiDimArrayInstanceExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSNewMultiDimArrayInstanceExpression"}, - {"typeReference", typeReference_}, - {"dimensions", dimensions_}}); -} - -void ETSNewMultiDimArrayInstanceExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("new "); - ES2PANDA_ASSERT(typeReference_); - typeReference_->Dump(dumper); - for (auto dim : dimensions_) { - dumper->Add("["); - dim->Dump(dumper); - dumper->Add("]"); - } -} - -void ETSNewMultiDimArrayInstanceExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSNewMultiDimArrayInstanceExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSNewMultiDimArrayInstanceExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSNewMultiDimArrayInstanceExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - void ETSNewMultiDimArrayInstanceExpression::ClearPreferredType() { SetPreferredType(nullptr); diff --git a/ets2panda/ir/ets/etsNonNullishTypeNode.cpp b/ets2panda/ir/ets/etsNonNullishTypeNode.cpp index ba8b6151771babfd04900a5cb947f214d97d6e1a..aab4820b8b65fb55499de50f90fe8481387f22a3 100644 --- a/ets2panda/ir/ets/etsNonNullishTypeNode.cpp +++ b/ets2panda/ir/ets/etsNonNullishTypeNode.cpp @@ -14,7 +14,6 @@ */ #include "etsNonNullishTypeNode.h" -#include "checker/ETSchecker.h" namespace ark::es2panda::ir { void ETSNonNullishTypeNode::TransformChildren([[maybe_unused]] const NodeTransformer &cb, @@ -31,39 +30,6 @@ void ETSNonNullishTypeNode::Iterate([[maybe_unused]] const NodeTraverser &cb) co cb(typeNode_); } -void ETSNonNullishTypeNode::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSNonNullishType"}, {"typeNode", typeNode_}}); -} - -void ETSNonNullishTypeNode::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("NonNullable<"); - typeNode_->Dump(dumper); - dumper->Add(">"); -} - -void ETSNonNullishTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - ES2PANDA_UNREACHABLE(); -} - -checker::Type *ETSNonNullishTypeNode::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType ETSNonNullishTypeNode::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSNonNullishTypeNode::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - return TsType() != nullptr ? TsType() : Check(checker); -} - ETSNonNullishTypeNode *ETSNonNullishTypeNode::Clone(ArenaAllocator *allocator, AstNode *parent) { TypeNode *typeNode = typeNode_->Clone(allocator, nullptr); diff --git a/ets2panda/ir/ets/etsNullishTypes.cpp b/ets2panda/ir/ets/etsNullishTypes.cpp index a0ebf975b71ebdf75fbdf6c88fcb8231f7622fbe..9418c2b6e29942df2f34a19476dad8cf04ea7e18 100644 --- a/ets2panda/ir/ets/etsNullishTypes.cpp +++ b/ets2panda/ir/ets/etsNullishTypes.cpp @@ -15,8 +15,6 @@ #include "etsNullishTypes.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void ETSUndefinedType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -29,38 +27,6 @@ void ETSUndefinedType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSUndefinedType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSUndefinedType"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSUndefinedType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("undefined"); -} - -void ETSUndefinedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - ES2PANDA_UNREACHABLE(); -} - -checker::Type *ETSUndefinedType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType ETSUndefinedType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSUndefinedType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - SetTsType(checker->GlobalETSUndefinedType()); - return TsType(); -} - ETSUndefinedType *ETSUndefinedType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *const clone = allocator->New(allocator); @@ -88,38 +54,6 @@ void ETSNullType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSNullType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSNullType"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSNullType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("null"); -} - -void ETSNullType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - ES2PANDA_UNREACHABLE(); -} - -checker::Type *ETSNullType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType ETSNullType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSNullType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - SetTsType(checker->GlobalETSNullType()); - return TsType(); -} - ETSNullType *ETSNullType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *const clone = allocator->New(allocator); diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index fb8fec13f688de7823ffae75086a6d5510008dcc..01df78251e270e3daf72a0ee8a3178a0653a2cfa 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -15,9 +15,7 @@ #include "etsPackageDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/expression.h" namespace ark::es2panda::ir { void ETSPackageDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -33,41 +31,6 @@ void ETSPackageDeclaration::Iterate([[maybe_unused]] const NodeTraverser &cb) co cb(name_); } -void ETSPackageDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSPackageDeclaration"}, {"name", name_}}); -} - -void ETSPackageDeclaration::Dump(ir::SrcDumper *dumper) const -{ - if (dumper->IsDeclgen()) { - return; - } - dumper->Add("package "); - name_->Dump(dumper); - dumper->Add(";"); - dumper->Endl(); -} - -void ETSPackageDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSPackageDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSPackageDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSPackageDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto const name = name_ != nullptr ? name_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 2dbccd6b9f9b116a96a841649a08325ce8533095..0c2a12d684aed6bd086f23a439c29f727354b99e 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -15,10 +15,8 @@ #include "etsParameterExpression.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/typeNode.h" +#include "ir/base/spreadElement.h" namespace ark::es2panda::ir { @@ -203,68 +201,6 @@ void ETSParameterExpression::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSParameterExpression::Dump(ir::AstDumper *const dumper) const -{ - if (!IsRestParameter()) { - dumper->Add({{"type", "ETSParameterExpression"}, - {"name", Ident()}, - {"initializer", AstDumper::Optional(Initializer())}, - {"annotations", AstDumper::Optional(Annotations())}}); - } else { - dumper->Add({{"type", "ETSParameterExpression"}, - {"rest parameter", Spread()}, - {"annotations", AstDumper::Optional(Annotations())}}); - } -} - -void ETSParameterExpression::Dump(ir::SrcDumper *const dumper) const -{ - DumpAnnotations(dumper); - - if (IsRestParameter()) { - Spread()->Dump(dumper); - } else { - auto const ident = Ident(); - auto const initializer = Initializer(); - if (ident != nullptr) { - ES2PANDA_ASSERT(ident_->IsAnnotatedExpression()); - ident->Dump(dumper); - if (IsOptional() && initializer == nullptr) { - dumper->Add("?"); - } - auto typeAnnotation = ident->AsAnnotatedExpression()->TypeAnnotation(); - if (typeAnnotation != nullptr) { - dumper->Add(": "); - typeAnnotation->Dump(dumper); - } - } - if (initializer != nullptr) { - dumper->Add(" = "); - initializer->Dump(dumper); - } - } -} - -void ETSParameterExpression::Compile(compiler::PandaGen *const pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ETSParameterExpression::Compile(compiler::ETSGen *const etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSParameterExpression::Check(checker::TSChecker *const checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSParameterExpression::Check(checker::ETSChecker *const checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { AnnotatedExpression *identOrSpread = nullptr; diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index 69661b129d8fecc36258d0614b23772f7162ed7e..9266451a89a7a4a70dfe26fe3002d050166e0fa2 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -15,11 +15,6 @@ #include "etsPrimitiveType.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void ETSPrimitiveType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -32,122 +27,6 @@ void ETSPrimitiveType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSPrimitiveType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSPrimitiveType"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSPrimitiveType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - - switch (GetPrimitiveType()) { - case PrimitiveType::BYTE: - dumper->Add("byte"); - break; - case PrimitiveType::INT: - dumper->Add("int"); - break; - case PrimitiveType::LONG: - dumper->Add("long"); - break; - case PrimitiveType::SHORT: - dumper->Add("short"); - break; - case PrimitiveType::FLOAT: - dumper->Add("float"); - break; - case PrimitiveType::DOUBLE: - dumper->Add("double"); - break; - case PrimitiveType::BOOLEAN: - dumper->Add("boolean"); - break; - case PrimitiveType::CHAR: - dumper->Add("char"); - break; - case PrimitiveType::VOID: - dumper->Add("void"); - break; - default: - ES2PANDA_UNREACHABLE(); - } -} - -void ETSPrimitiveType::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ETSPrimitiveType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSPrimitiveType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalAnyType(); -} - -checker::VerifiedType ETSPrimitiveType::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - switch (GetPrimitiveType()) { - case PrimitiveType::BYTE: { - SetTsType(checker->GlobalByteBuiltinType()); - return TsType(); - } - case PrimitiveType::SHORT: { - SetTsType(checker->GlobalShortBuiltinType()); - return TsType(); - } - case PrimitiveType::INT: { - SetTsType(checker->GlobalIntBuiltinType()); - return TsType(); - } - case PrimitiveType::LONG: { - SetTsType(checker->GlobalLongBuiltinType()); - return TsType(); - } - case PrimitiveType::FLOAT: { - SetTsType(checker->GlobalFloatBuiltinType()); - return TsType(); - } - case PrimitiveType::DOUBLE: { - SetTsType(checker->GlobalDoubleBuiltinType()); - return TsType(); - } - case PrimitiveType::BOOLEAN: { - SetTsType(checker->GlobalETSBooleanBuiltinType()); - return TsType(); - } - case PrimitiveType::CHAR: { - SetTsType(checker->GlobalCharBuiltinType()); - return TsType(); - } - case PrimitiveType::VOID: { - if (LIKELY(checker->CheckVoidAnnotation(this))) { - SetTsType(checker->GlobalVoidType()); - return TsType(); - } - - return checker->InvalidateType(this); - } - default: { - ES2PANDA_UNREACHABLE(); - } - } -} - ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(GetPrimitiveType(), allocator); diff --git a/ets2panda/ir/ets/etsReExportDeclaration.cpp b/ets2panda/ir/ets/etsReExportDeclaration.cpp index 4475c8b08ca38e60ee149065501f58154901a988..e09d64139771cf7140771d05d0c039dc1a143567 100644 --- a/ets2panda/ir/ets/etsReExportDeclaration.cpp +++ b/ets2panda/ir/ets/etsReExportDeclaration.cpp @@ -14,7 +14,7 @@ */ #include "ir/ets/etsReExportDeclaration.h" -#include "ir/astDump.h" + #include "checker/checker.h" namespace ark::es2panda::ir { @@ -55,36 +55,6 @@ void ETSReExportDeclaration::Iterate(const NodeTraverser &cb) const GetETSImportDeclarations()->Iterate(cb); } -void ETSReExportDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSReExportDeclaration"}, {"ets_import_declarations", GetETSImportDeclarations()}}); -} - -void ETSReExportDeclaration::Dump([[maybe_unused]] ir::SrcDumper *dumper) const -{ - auto importDeclaration = GetETSImportDeclarations(); - const auto &specifiers = importDeclaration->Specifiers(); - dumper->Add("export "); - if (specifiers.size() == 1 && - (specifiers[0]->IsImportNamespaceSpecifier() || specifiers[0]->IsImportDefaultSpecifier())) { - specifiers[0]->Dump(dumper); - } else { - dumper->Add("{ "); - for (auto specifier : specifiers) { - specifier->Dump(dumper); - if (specifier != specifiers.back()) { - dumper->Add(", "); - } - } - dumper->Add(" }"); - } - - dumper->Add(" from "); - importDeclaration->Source()->Dump(dumper); - dumper->Add(";"); - dumper->Endl(); -} - checker::VerifiedType ETSReExportDeclaration::Check(checker::ETSChecker * /*checker*/) { return {this, nullptr}; diff --git a/ets2panda/ir/ets/etsStringLiteralType.cpp b/ets2panda/ir/ets/etsStringLiteralType.cpp index cff8978020f823e0bf68623c60a29ffd726471bc..edf5e5b5171aaf6b9f74ad69991a2932dba5abc8 100644 --- a/ets2panda/ir/ets/etsStringLiteralType.cpp +++ b/ets2panda/ir/ets/etsStringLiteralType.cpp @@ -15,7 +15,7 @@ #include "etsStringLiteralType.h" -#include "checker/ETSchecker.h" +#include "checker/types/ets/etsStringType.h" namespace ark::es2panda::ir { void ETSStringLiteralType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, @@ -29,39 +29,6 @@ void ETSStringLiteralType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSStringLiteralType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "ETSStringLiteralType"}, {"value", value_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSStringLiteralType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("\"" + value_.Mutf8() + "\""); -} - -void ETSStringLiteralType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - ES2PANDA_UNREACHABLE(); -} - -checker::Type *ETSStringLiteralType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType ETSStringLiteralType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSStringLiteralType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - SetTsType(checker->CreateETSStringLiteralType(value_)); - return TsType(); -} - ETSStringLiteralType *ETSStringLiteralType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *const clone = allocator->New(value_, allocator); diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index efad97ab17ae51df4b10c55a2ff703452519015a..eeae40eefc361e548f7a7d6130e622b1cc3656fd 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -15,31 +15,8 @@ #include "etsStructDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" +#include "ir/base/classDefinition.h" namespace ark::es2panda::ir { -void ETSStructDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSStructDeclaration"}, {"definition", Definition()}}); -} -void ETSStructDeclaration::Dump(ir::SrcDumper *dumper) const -{ - if (Definition() != nullptr) { - Definition()->Dump(dumper); - } -} - -checker::Type *ETSStructDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType ETSStructDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - ES2PANDA_ASSERT(checker->IsAnyError()); - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index 3012e89b118d2c08d04028b9c9ba06f00ce84d7d..45b89da743441f93521bba1f2362e2ea755a472a 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -15,8 +15,8 @@ #include "etsTuple.h" -#include "checker/ETSchecker.h" #include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::ir { @@ -41,26 +41,6 @@ void ETSTuple::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSTuple::Dump(ir::AstDumper *const dumper) const -{ - dumper->Add({{"type", "ETSTuple"}, - {"types", AstDumper::Optional(typeAnnotationList_)}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSTuple::Dump(ir::SrcDumper *const dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("["); - for (const auto *const typeAnnot : typeAnnotationList_) { - typeAnnot->Dump(dumper); - if (typeAnnot != typeAnnotationList_.back()) { - dumper->Add(", "); - } - } - dumper->Add("]"); -} - void ETSTuple::Compile([[maybe_unused]] compiler::PandaGen *const pg) const {} void ETSTuple::Compile([[maybe_unused]] compiler::ETSGen *const etsg) const {} diff --git a/ets2panda/ir/ets/etsTuple.h b/ets2panda/ir/ets/etsTuple.h index 6039a546e5eaea6cefb1fdb7ebbe710ce2f24c40..a84b34be6bda58293c90c86c1dec85717fb91b92 100644 --- a/ets2panda/ir/ets/etsTuple.h +++ b/ets2panda/ir/ets/etsTuple.h @@ -16,7 +16,6 @@ #ifndef ES2PANDA_IR_ETS_TUPLE_H #define ES2PANDA_IR_ETS_TUPLE_H -#include "checker/ETSchecker.h" #include "ir/typeNode.h" namespace ark::es2panda::ir { diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index dc213924fba70e2a3af09fa5a49baae1f6fbc510..3f591548293a2227e3f3db2dcf35e83040b5cb56 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -15,10 +15,7 @@ #include "etsTypeReference.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::ir { @@ -99,48 +96,6 @@ ir::Identifier *ETSTypeReference::BaseName() const return nullptr; } -void ETSTypeReference::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSTypeReference"}, {"part", Part()}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSTypeReference::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - ES2PANDA_ASSERT(Part() != nullptr); - Part()->Dump(dumper); -} - -void ETSTypeReference::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSTypeReference::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSTypeReference::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSTypeReference::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} -checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - auto *type = Part()->GetType(checker); - if (IsReadonlyType()) { - type = checker->GetReadonlyType(type); - } - return SetTsType(type); -} - ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ETSTypeReferencePart *partClone = nullptr; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index fb40b130edcf5cd68f3a806b2dda6263a7aed827..9a9320f038c717d47e1aa56f75262b1455ebf70d 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -15,11 +15,7 @@ #include "etsTypeReferencePart.h" -#include "checker/ETSchecker.h" #include "checker/ets/typeRelationContext.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" namespace ark::es2panda::ir { @@ -81,42 +77,6 @@ void ETSTypeReferencePart::Iterate(const NodeTraverser &cb) const } } -void ETSTypeReferencePart::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSTypeReferencePart"}, - {"name", Name()}, - {"typeParams", AstDumper::Optional(TypeParams())}, - {"previous", AstDumper::Optional(Previous())}}); -} - -void ETSTypeReferencePart::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(Name() != nullptr); - Name()->Dump(dumper); - if (TypeParams() != nullptr) { - TypeParams()->Dump(dumper); - } -} - -void ETSTypeReferencePart::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ETSTypeReferencePart::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSTypeReferencePart::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ETSTypeReferencePart::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - static checker::Type *HandleFixedArrayType(checker::ETSChecker *const checker, ETSTypeReferencePart *ref) { auto typeParams = ref->TypeParams(); diff --git a/ets2panda/ir/ets/etsUnionType.cpp b/ets2panda/ir/ets/etsUnionType.cpp index 95f556c907df88cfa9b063707c7bbe3c9c27747d..072040bfff43e28848f1c0116d81ca9fd9358f25 100644 --- a/ets2panda/ir/ets/etsUnionType.cpp +++ b/ets2panda/ir/ets/etsUnionType.cpp @@ -15,7 +15,7 @@ #include "etsUnionType.h" -#include "checker/ETSchecker.h" +#include "checker/types/ets/etsTypeParameter.h" namespace ark::es2panda::ir { void ETSUnionType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -40,73 +40,6 @@ void ETSUnionType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ETSUnionType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSUnionType"}, {"types", Types()}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSUnionType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("("); - for (auto type : Types()) { - type->Dump(dumper); - if (type != Types().back()) { - dumper->Add(" | "); - } - } - dumper->Add(")"); -} - -void ETSUnionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *ETSUnionType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType ETSUnionType::Check(checker::ETSChecker *checker) -{ - for (auto *it : Types()) { - it->Check(checker); - } - - return {this, GetType(checker)}; -} - -static bool CheckConstituentTypesValid(ArenaVector const &constituentTypes) -{ - for (auto &it : constituentTypes) { - if (it->IsTypeError()) { - return false; - } - } - return true; -} - -checker::Type *ETSUnionType::GetType(checker::ETSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - checker->CheckAnnotations(this); - - ArenaVector types(checker->Allocator()->Adapter()); - - for (auto *it : Types()) { - types.push_back(it->GetType(checker)); - } - - checker->Relation()->SetNode(this); - if (!CheckConstituentTypesValid(types)) { - SetTsType(checker->GlobalTypeError()); - } else { - SetTsType(checker->CreateETSUnionType(std::move(types))); - } - checker->Relation()->SetNode(nullptr); - return TsType(); -} - ETSUnionType *ETSUnionType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ArenaVector types(allocator->Adapter()); diff --git a/ets2panda/ir/ets/etsWildcardType.cpp b/ets2panda/ir/ets/etsWildcardType.cpp index e021bd39b40d02bd0780a6f1e295d33cd9c56af3..17601b6b30d9448c757a8b092a7c36a029cfd9fa 100644 --- a/ets2panda/ir/ets/etsWildcardType.cpp +++ b/ets2panda/ir/ets/etsWildcardType.cpp @@ -15,12 +15,6 @@ #include "etsWildcardType.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/ets/etsTypeReference.h" namespace ark::es2panda::ir { @@ -43,48 +37,4 @@ void ETSWildcardType::Iterate(const NodeTraverser &cb) const } } -void ETSWildcardType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ETSWildcardType"}, - {"typeReference", AstDumper::Optional(typeReference_)}, - {"in", AstDumper::Optional(IsIn())}, - {"out", AstDumper::Optional(IsOut())}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ETSWildcardType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("ETSWildcardType"); -} - -void ETSWildcardType::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ETSWildcardType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ETSWildcardType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *ETSWildcardType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType ETSWildcardType::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *ETSWildcardType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - return checker->GlobalWildcardType(); -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ets/etsWildcardType.h b/ets2panda/ir/ets/etsWildcardType.h index d97e155308457adae50a52caf60d728b24a3e15d..f026b00158ac4c1c1748e940367df27d4a13196d 100644 --- a/ets2panda/ir/ets/etsWildcardType.h +++ b/ets2panda/ir/ets/etsWildcardType.h @@ -46,7 +46,6 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check(checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index b74e9c4d71a55b9a9f7974a728e5d1c04f6d2abd..34bd288ce47745c5493b82dfadd4cd351fe34a94 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -16,13 +16,11 @@ #include "arrayExpression.h" #include -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" #include "checker/ets/typeRelationContext.h" #include "checker/ts/destructuringContext.h" #include "checker/types/ets/etsTupleType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsResizableArrayType.h" namespace ark::es2panda::ir { ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression const &other, @@ -179,41 +177,6 @@ void ArrayExpression::Iterate(const NodeTraverser &cb) const } } -void ArrayExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", type_ == AstNodeType::ARRAY_EXPRESSION ? "ArrayExpression" : "ArrayPattern"}, - {"elements", elements_}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, - {"optional", AstDumper::Optional(optional_)}}); -} - -void ArrayExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("["); - for (auto element : elements_) { - element->Dump(dumper); - if (element != elements_.back()) { - dumper->Add(", "); - } - } - dumper->Add("]"); -} - -void ArrayExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ArrayExpression::Compile(compiler::ETSGen *const etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ArrayExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - checker::Type *CheckAssignmentPattern(Expression *it, checker::TSChecker *checker, checker::Type *elementType, bool &addOptional, checker::ElementFlags &memberFlag) { @@ -399,11 +362,6 @@ bool ArrayExpression::TrySetPreferredTypeForNestedArrayExpr(checker::ETSChecker return true; } -checker::VerifiedType ArrayExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - std::optional ArrayExpression::ExtractPossiblePreferredType(checker::Type *type) { ES2PANDA_ASSERT(type); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 6a735503ace505d16ebbe7342418210e63642f67..f8c7708fe6fd18906fd077564cca6dc61e14d87d 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -15,10 +15,8 @@ #include "arrowFunctionExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" +#include "ir/base/scriptFunction.h" +#include "ir/expressions/functionExpression.h" namespace ark::es2panda::ir { void ArrowFunctionExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -38,44 +36,6 @@ void ArrowFunctionExpression::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void ArrowFunctionExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ArrowFunctionExpression"}, - {"function", func_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void ArrowFunctionExpression::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("("); - if (func_->IsScriptFunction() && func_->AsScriptFunction()->IsAsyncFunc()) { - dumper->Add("async "); - } - func_->Dump(dumper); - dumper->Add(")"); -} - -void ArrowFunctionExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ArrowFunctionExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ArrowFunctionExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ArrowFunctionExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *const allocator) : AnnotationAllowed(static_cast(other), allocator) { @@ -100,54 +60,6 @@ ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const al return clone; } -ir::TypeNode *ArrowFunctionExpression::CreateReturnNodeFromType(checker::ETSChecker *checker, checker::Type *returnType) -{ - /* - Construct a synthetic Node with the correct ts_type_. - */ - ES2PANDA_ASSERT(returnType != nullptr); - auto *ident = checker->AllocNode(util::StringView(""), checker->Allocator()); - auto *const part = checker->AllocNode(ident, checker->Allocator()); - auto *returnNode = checker->AllocNode(part, checker->Allocator()); - ES2PANDA_ASSERT(returnNode); - returnNode->SetTsType(returnType); - return returnNode; -} - -ir::TypeNode *ArrowFunctionExpression::CreateTypeAnnotation(checker::ETSChecker *checker) -{ - ir::TypeNode *returnNode = nullptr; - /* - There are two scenarios for lambda type inference: defined or undefined return type. - example code: - ``` - enum Color { Red, Blue} - // has Return Type Color - let x = () : Color => {return Color.Red} - // No Return Type Color - let y = () => {return Color.Red} - ``` - */ - if (Function()->ReturnTypeAnnotation() == nullptr) { - /* - When lambda expression does not declare a return type, we need to construct the - declaration node of lambda according to the Function()->Signature()->ReturnType(). - */ - returnNode = CreateReturnNodeFromType(checker, Function()->Signature()->ReturnType()); - } else { - returnNode = Function()->ReturnTypeAnnotation()->Clone(checker->Allocator(), nullptr); - returnNode->SetTsType(Function()->ReturnTypeAnnotation()->TsType()); - } - - ArenaVector params {checker->Allocator()->Adapter()}; - checker->CopyParams(Function()->Params(), params, nullptr); - - auto signature = ir::FunctionSignature(nullptr, std::move(params), returnNode); - auto *funcType = checker->AllocNode(std::move(signature), ir::ScriptFunctionFlags::NONE, - checker->Allocator()); - return funcType; -} - bool ArrowFunctionExpression::IsVarFromSubscope(const varbinder::Variable *var) const { // The parameter scope's and the function scope's common ancestor lives outside the function, so we have to check diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index 2550cc7e0dac82d24970f05ef9e826aaa79a199a..19a01d50e4778f125a131885f81a45a2e841f13d 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -71,8 +71,7 @@ public: void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; checker::VerifiedType Check(checker::ETSChecker *checker) override; - ir::TypeNode *CreateTypeAnnotation(checker::ETSChecker *checker); - ir::TypeNode *CreateReturnNodeFromType(checker::ETSChecker *checker, checker::Type *returnType); + bool IsVarFromSubscope(const varbinder::Variable *var) const; void Accept(ASTVisitorT *v) override @@ -80,6 +79,16 @@ public: v->Accept(this); } + ir::TypeNode *CreateTypeAnnotation([[maybe_unused]] checker::ETSChecker *checker) + { + // Unused function, to be removed after the bindings problem solved. + ES2PANDA_UNREACHABLE(); + } + ir::TypeNode *CreateReturnNodeFromType([[maybe_unused]] checker::ETSChecker *checker, [[maybe_unused]] checker::Type *returnType) + { + // Unused function, to be removed after the bindings problem solved. + ES2PANDA_UNREACHABLE(); + } private: ScriptFunction *func_; checker::Type *preferredType_ {}; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index 2505910c5f663426231c9b860261e1ff6eb67cf2..2c6124e2d9cb4e4124e01184253f8aebd93bce72 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -16,9 +16,10 @@ #include "assignmentExpression.h" #include "compiler/base/lreference.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" + +#include "ir/base/spreadElement.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/arrayExpression.h" namespace ark::es2panda::ir { @@ -101,54 +102,6 @@ void AssignmentExpression::Iterate(const NodeTraverser &cb) const cb(right_); } -void AssignmentExpression::Dump(ir::AstDumper *dumper) const -{ - if (type_ == AstNodeType::ASSIGNMENT_EXPRESSION) { - dumper->Add({{"type", "AssignmentExpression"}, {"operator", operator_}, {"left", left_}, {"right", right_}}); - } else { - dumper->Add({{"type", "AssignmentPattern"}, {"left", left_}, {"right", right_}}); - } -} - -void AssignmentExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(left_); - left_->Dump(dumper); - dumper->Add(" "); - dumper->Add(TokenToString(operator_)); - dumper->Add(" "); - ES2PANDA_ASSERT(right_); - right_->Dump(dumper); -} - -void AssignmentExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void AssignmentExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -void AssignmentExpression::CompilePattern(compiler::PandaGen *pg) const -{ - compiler::RegScope rs(pg); - auto lref = compiler::JSLReference::Create(pg, left_, false); - right_->Compile(pg); - lref.SetValue(); -} - -checker::Type *AssignmentExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType AssignmentExpression::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, AssignmentExpression const &other, Expression *const left, Expression *const right) : AssignmentExpression(other) diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index 614ea5d8f69b5df148d1176441b08b01ba409655..df565b8a6a3723b18f6c163622488b8fe1bfe9cb 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -154,7 +154,6 @@ public: void Dump(ir::SrcDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; - void CompilePattern(compiler::PandaGen *pg) const; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index d9e6b54668008d143b2a88f3adfde348c52e06dd..419db2492c336d610a81c2a5329d94de1060597a 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -15,10 +15,6 @@ #include "awaitExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" - namespace ark::es2panda::ir { void AwaitExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -37,39 +33,6 @@ void AwaitExpression::Iterate(const NodeTraverser &cb) const } } -void AwaitExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "AwaitExpression"}, {"argument", AstDumper::Nullish(argument_)}}); -} - -void AwaitExpression::Dump(ir::SrcDumper *dumper) const -{ - if (argument_ != nullptr) { - dumper->Add("await "); - argument_->Dump(dumper); - } -} - -void AwaitExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void AwaitExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *AwaitExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType AwaitExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index b7de84484e0bdec1096887ee85f98a272f731918..9074020e198950207b454e8997833c324e89bd15 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -15,10 +15,6 @@ #include "binaryExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void BinaryExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { @@ -39,61 +35,6 @@ void BinaryExpression::Iterate(const NodeTraverser &cb) const cb(right_); } -void BinaryExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", IsLogical() ? "LogicalExpression" : "BinaryExpression"}, - {"operator", operator_}, - {"left", left_}, - {"right", right_}}); -} - -void BinaryExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(left_ != nullptr); - ES2PANDA_ASSERT(right_ != nullptr); - dumper->Add("(("); - left_->Dump(dumper); - dumper->Add(") "); - dumper->Add(TokenToString(operator_)); - dumper->Add(" ("); - right_->Dump(dumper); - dumper->Add("))"); -} - -void BinaryExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void BinaryExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -void BinaryExpression::CompileOperands(compiler::ETSGen *etsg, compiler::VReg lhs) const -{ - left_->Compile(etsg); - - if (operator_ == lexer::TokenType::KEYW_INSTANCEOF) { - etsg->StoreAccumulator(left_, lhs); - } else { - etsg->ApplyConversionAndStoreAccumulator(left_, lhs, operationType_); - } - - right_->Compile(etsg); - etsg->ApplyConversion(right_, operationType_); -} - -checker::Type *BinaryExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType BinaryExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp index 853f4973fc05b72ead4e21d302bcbce5a85f5bc8..7d511f7e6eaf9dc4d0d4635835c312248263adea 100644 --- a/ets2panda/ir/expressions/blockExpression.cpp +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -15,9 +15,6 @@ #include "blockExpression.h" -#include "compiler/core/ETSGen.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { BlockExpression::BlockExpression(ArenaVector &&statements) @@ -65,40 +62,4 @@ void BlockExpression::Iterate(const NodeTraverser &cb) const } } -void BlockExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "BlockExpression"}, {"statements", statements_}}); -} - -void BlockExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("({"); - for (auto *statement : statements_) { - statement->Dump(dumper); - if (statement != statements_.back()) { - dumper->Endl(); - } - } - dumper->Add("})"); -} - -void BlockExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - ES2PANDA_UNREACHABLE(); -} - -void BlockExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *BlockExpression::Check([[maybe_unused]] checker::TSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); -} - -checker::VerifiedType BlockExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 4be13e81f78eadcac19dd71382540f7e53d3a6fb..314c6aac2cc08796d0b71242897521b4bb0d1e8d 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -15,9 +15,11 @@ #include "callExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/expressions/memberExpression.h" +#include "ir/expressions/functionExpression.h" +#include "ir/statements/blockStatement.h" + +#include "ir/ts/tsTypeParameterInstantiation.h" namespace ark::es2panda::ir { void CallExpression::SetArguments(ArenaVector &&argumentsList) @@ -76,64 +78,6 @@ void CallExpression::Iterate(const NodeTraverser &cb) const } } -void CallExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "CallExpression"}, - {"callee", callee_}, - {"arguments", arguments_}, - {"optional", IsOptional()}, - {"typeParameters", AstDumper::Optional(typeParams_)}}); - // #22953: trailing block is not handled -} - -void CallExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(callee_); - callee_->Dump(dumper); - if (IsOptional()) { - dumper->Add("?."); - } - - if (typeParams_ != nullptr) { - typeParams_->Dump(dumper); - } - - dumper->Add("("); - for (auto arg : arguments_) { - arg->Dump(dumper); - if (arg != arguments_.back()) { - dumper->Add(", "); - } - } - dumper->Add(")"); - if (trailingLambdaInfo_.block != nullptr) { - if (trailingLambdaInfo_.isBlockInNewLine) { - dumper->Endl(); - } - trailingLambdaInfo_.block->Dump(dumper); - } -} - -void CallExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void CallExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *CallExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType CallExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *const allocator) : MaybeOptionalExpression(static_cast(other)), arguments_(allocator->Adapter()), diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index 8407013cb3c357ce210e68af58575ea182e3d04b..486890ebd7a26bd86d2011b881e8d402fd32fcae 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -15,10 +15,6 @@ #include "chainExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void ChainExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -33,51 +29,6 @@ void ChainExpression::Iterate(const NodeTraverser &cb) const cb(expression_); } -void ChainExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ChainExpression"}, {"expression", expression_}}); -} - -void ChainExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("("); // affects precedence - expression_->Dump(dumper); - dumper->Add(")"); -} - -void ChainExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ChainExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg &objReg) const -{ - compiler::OptionalChain chain(pg, this); - - if (expression_->IsMemberExpression()) { - objReg = pg->AllocReg(); - expression_->AsMemberExpression()->CompileToReg(pg, objReg); - } else { - objReg = compiler::VReg::Invalid(); - expression_->Compile(pg); - } -} - -void ChainExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ChainExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ChainExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expression = expression_ != nullptr ? expression_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 4e2ba3bd8834461ee529b4546c8b84fc15e1507e..3f1951d02e7446b8af8a1bb5155052c8e2b94199 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -16,7 +16,8 @@ #ifndef ES2PANDA_IR_EXPRESSION_CHAIN_EXPRESSION_H #define ES2PANDA_IR_EXPRESSION_CHAIN_EXPRESSION_H -#include "ir/expression.h" +#include "compiler/base/optionalChain.h" +#include "ir/expressions/memberExpression.h" #include "ir/irnode.h" namespace ark::es2panda::checker { diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index 36a0f7fa2e70328bc8cb9955ecf1459440b5b35b..6e6d17a2f4f9de455a64b6265e934d5421e4a3a7 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -15,9 +15,7 @@ #include "classExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/base/classDefinition.h" namespace ark::es2panda::ir { void ClassExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -33,36 +31,6 @@ void ClassExpression::Iterate(const NodeTraverser &cb) const cb(def_); } -void ClassExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ClassExpression"}, {"definition", def_}}); -} - -void ClassExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("ClassExpression"); -} - -void ClassExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ClassExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ClassExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ClassExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const def = def_ != nullptr ? def_->Clone(allocator, nullptr)->AsClassDefinition() : nullptr; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index e0db6c2ec31acc059641e691bf94534f20e10b32..4aac2d045c51490f071313fdf6eeea8278832e6d 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -15,10 +15,6 @@ #include "conditionalExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" - namespace ark::es2panda::ir { void ConditionalExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -45,52 +41,6 @@ void ConditionalExpression::Iterate(const NodeTraverser &cb) const cb(alternate_); } -void ConditionalExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "ConditionalExpression"}, {"test", test_}, {"consequent", consequent_}, {"alternate", alternate_}}); -} - -void ConditionalExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(test_ != nullptr); - dumper->Add("("); - test_->Dump(dumper); - dumper->Add(" ? "); - if (consequent_ != nullptr) { - consequent_->Dump(dumper); - } - dumper->Add(" : "); - if (alternate_ != nullptr) { - alternate_->Dump(dumper); - } - dumper->Add(")"); - if ((parent_ != nullptr) && (parent_->IsBlockStatement() || parent_->IsBlockExpression())) { - dumper->Add(";"); - dumper->Endl(); - } -} - -void ConditionalExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ConditionalExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ConditionalExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ConditionalExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/expressions/directEvalExpression.cpp b/ets2panda/ir/expressions/directEvalExpression.cpp index d5a7fdb9684013575053cf065d87526927e64bfb..2d402e602a34fe89e2e142c3f7b04738e6c4c419 100644 --- a/ets2panda/ir/expressions/directEvalExpression.cpp +++ b/ets2panda/ir/expressions/directEvalExpression.cpp @@ -17,29 +17,6 @@ #include "directEvalExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { -void DirectEvalExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void DirectEvalExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *DirectEvalExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType DirectEvalExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/expressions/dummyNode.cpp b/ets2panda/ir/expressions/dummyNode.cpp index bf4b171b8f3b7acb2549a0dd8e722d4bfcdc2d9d..f3753291f1070ce561f2e7e2187d9ad27865c2d9 100644 --- a/ets2panda/ir/expressions/dummyNode.cpp +++ b/ets2panda/ir/expressions/dummyNode.cpp @@ -15,12 +15,7 @@ #include "dummyNode.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void DummyNode::TransformChildren([[maybe_unused]] const NodeTransformer &cb, @@ -30,36 +25,4 @@ void DummyNode::TransformChildren([[maybe_unused]] const NodeTransformer &cb, void DummyNode::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void DummyNode::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "DummyNode"}, - {"name", name_}, - {"indexName", indexName_}, - {"returnType", AstDumper::Optional(GetReturnTypeLiteral())}}); -} - -void DummyNode::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(std::string(name_)); -} - -void DummyNode::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void DummyNode::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *DummyNode::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType DummyNode::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index b5096815fca802dd2449b17f1a44ef188c86fee4..879880ae693c71d47f23119ae0df79f087e040d4 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -15,9 +15,7 @@ #include "functionExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/base/scriptFunction.h" namespace ark::es2panda::ir { void FunctionExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -33,36 +31,6 @@ void FunctionExpression::Iterate(const NodeTraverser &cb) const cb(func_); } -void FunctionExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "FunctionExpression"}, {"function", func_}}); -} - -void FunctionExpression::Dump(ir::SrcDumper *dumper) const -{ - func_->Dump(dumper); -} - -void FunctionExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void FunctionExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *FunctionExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ES2PANDA_ASSERT(func_->Clone(allocator, nullptr) != nullptr); diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 050fd78b378553fa2a3a49ef2c12fb4a4d7d29ee..78ccac3ccfd580d63f21e7fecbca68a58246accd 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -15,10 +15,13 @@ #include "identifier.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" +#include "ir/base/classDefinition.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/tsPropertySignature.h" +#include "ir/base/classProperty.h" +#include "ir/statements/variableDeclarator.h" +#include "ir/ts/tsEnumMember.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, ArenaAllocator *const allocator) @@ -115,58 +118,6 @@ ValidationInfo Identifier::ValidateExpression() return info; } -void Identifier::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", IsPrivateIdent() ? "PrivateIdentifier" : "Identifier"}, - {"name", Name()}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, - {"optional", AstDumper::Optional(IsOptional())}}); -} - -void Identifier::Dump(ir::SrcDumper *dumper) const -{ - if (IsReceiver()) { - dumper->Add("this"); - return; - } - - if (IsPrivateIdent()) { - dumper->Add("private "); - } - - auto name = std::string(Name()); - std::string propertyStr = compiler::Signatures::PROPERTY.data(); - if (UNLIKELY(name.find(propertyStr) != std::string::npos)) { - name.replace(name.find(propertyStr), propertyStr.length(), "_$property$_"); - } - dumper->Add(name); - if (IsOptional()) { - dumper->Add("?"); - } - - dumper->PushTask([dumper, name = std::string(name_)] { dumper->DumpNode(name); }); -} - -void Identifier::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void Identifier::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *Identifier::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType Identifier::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - bool Identifier::IsDeclaration(ScriptExtension ext) const { // We can determine reference status from parent node diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index fc1c140d4daf9a13d8f7be40e2e5e14bba1c1ac4..c444cbc5b3c3319ffbfe746e10f8d46cbfdaa81e 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -15,10 +15,6 @@ #include "importExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void ImportExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { @@ -33,35 +29,6 @@ void ImportExpression::Iterate(const NodeTraverser &cb) const cb(source_); } -void ImportExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ImportExpression"}, {"source", source_}}); -} - -void ImportExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("ImportExpression"); -} - -void ImportExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ImportExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} -checker::Type *ImportExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ImportExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const source = source_ != nullptr ? source_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index 95cc4f3eaa7531ac60a58ef1d9a3955e2ed62d9a..4ee580d535a150c11588c5da1d68685db39da030 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -15,11 +15,6 @@ #include "bigIntLiteral.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void BigIntLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -28,36 +23,6 @@ void BigIntLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb void BigIntLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void BigIntLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "BigIntLiteral"}, {"value", src_}}); -} - -void BigIntLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(std::string(src_) + "n"); -} - -void BigIntLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void BigIntLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *BigIntLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(src_); diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index 8e34cbf5381edca76a5ae956ab31b01e0ff2354e..c6c20e6f8ce8916a83b1cfc5d53fb9b78d00abfc 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_IR_EXPRESSION_LITERAL_BIGINT_LITERAL_H #define ES2PANDA_IR_EXPRESSION_LITERAL_BIGINT_LITERAL_H +#include "ir/typeNode.h" #include "ir/expressions/literal.h" #include "util/ustring.h" diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 01025493fbe35c3d4eebd448b98b6d6fa83a4b28..763f3b94139ab8299f6202b0f9a3cbdb31cc44f1 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -15,11 +15,6 @@ #include "booleanLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void BooleanLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -28,36 +23,6 @@ void BooleanLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &c void BooleanLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void BooleanLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "BooleanLiteral"}, {"value", boolean_}}); -} - -void BooleanLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(boolean_ ? "true" : "false"); -} - -void BooleanLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void BooleanLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *BooleanLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(boolean_); diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index 3dcd401f22f96dc2f48f27692e4be373ba887452..c3f8b2fa9a3d9b8114b02e8a8996d0bbe03b59fe 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -15,10 +15,7 @@ #include "charLiteral.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/ETSchecker.h" +#include "util/helpers.h" namespace ark::es2panda::ir { void CharLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, @@ -28,36 +25,6 @@ void CharLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, void CharLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void CharLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "CharLiteral"}, {"value", char_}}); -} - -void CharLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("c\'" + ToString() + "\'"); -} - -void CharLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void CharLiteral::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *CharLiteral::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(char_); diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index f88e2e85329bb9c8538bd775e9b70ad52b5a185e..7b60c6b48b615fba2606b8b8ce200c96ac491eb3 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -15,10 +15,6 @@ #include "nullLiteral.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void NullLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -27,36 +23,6 @@ void NullLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, void NullLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void NullLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "NullLiteral"}, {"value", AstDumper::Property::Constant::PROP_NULL}}); -} - -void NullLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("null"); -} - -void NullLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void NullLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *NullLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType NullLiteral::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(); diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index d3cf60f0268eb3424cf9edc204521889eb91fdbd..b2d326283cba9fd86ec9032c8aa2cc7400bff876 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -15,10 +15,8 @@ #include "numberLiteral.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "util/dtoa_helper.h" +#include "libpandabase/utils/bit_helpers.h" namespace ark::es2panda::ir { @@ -35,67 +33,6 @@ void NumberLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb void NumberLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void NumberLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "NumberLiteral"}, {"value", number_}}); -} - -void NumberLiteral::Dump(ir::SrcDumper *dumper) const -{ - if (std::string(number_.Str()).empty() || (parent_ != nullptr && parent_->IsTSEnumMember())) { - if (number_.IsInt()) { - dumper->Add(number_.GetInt()); - return; - } - - if (number_.IsLong()) { - dumper->Add(number_.GetLong()); - return; - } - - if (number_.IsFloat()) { - dumper->Add(number_.GetFloat()); - return; - } - - if (number_.IsDouble()) { - dumper->Add(number_.GetDouble()); - return; - } - - if (number_.IsShort()) { - dumper->Add(number_.GetShort()); - return; - } - - if (number_.IsByte()) { - dumper->Add(number_.GetByte()); - return; - } - } - dumper->Add(std::string(number_.Str())); -} - -void NumberLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void NumberLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *NumberLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType NumberLiteral::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(number_); diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index 71b31dc0c9a39839b7b32cef49a5dd86d057f559..e741143bd5099a0bec04939483c7de17f107e05c 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -15,10 +15,7 @@ #include "regExpLiteral.h" -#include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" namespace ark::es2panda::ir { void RegExpLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, @@ -28,36 +25,6 @@ void RegExpLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb void RegExpLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void RegExpLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "RegExpLiteral"}, {"source", pattern_}, {"flags", flagsStr_}}); -} - -void RegExpLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(std::string(pattern_)); -} - -void RegExpLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void RegExpLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *RegExpLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType RegExpLiteral::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(pattern_, flags_, flagsStr_); diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index c0345f6b612da3d585639e0a251eeeee2469f269..c0a66b866a4f87735db611ce71d77268a2af5cd7 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -15,10 +15,6 @@ #include "stringLiteral.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void StringLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -27,36 +23,6 @@ void StringLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb void StringLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void StringLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "StringLiteral"}, {"value", str_}}); -} - -void StringLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("\"" + util::Helpers::CreateEscapedString(std::string(str_)) + "\""); -} - -void StringLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void StringLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *StringLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType StringLiteral::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(str_); diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index 0023873e05bc04836829d705d43efdcda2ca5d2a..e8e0dc7bba60f967a2d6de31bc92249f1ef1c147 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -18,6 +18,7 @@ #include "ir/expressions/literal.h" #include "util/es2pandaMacros.h" +#include "util/helpers.h" #include "util/ustring.h" namespace ark::es2panda::ir { diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp index d30067ede8bb0a29ec113eaba38c6f2567dd3418..c96f7d029d91944686858b6493f5f8fdb1376768 100644 --- a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp @@ -15,13 +15,6 @@ #include "undefinedLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void UndefinedLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -30,37 +23,6 @@ void UndefinedLiteral::TransformChildren([[maybe_unused]] const NodeTransformer void UndefinedLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void UndefinedLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "UndefinedLiteral"}, {"value", AstDumper::Property::Constant::PROP_UNDEFINED}}); -} - -void UndefinedLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("undefined"); -} - -void UndefinedLiteral::Compile(compiler::PandaGen *pg) const -{ - pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); -} - -void UndefinedLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->LoadAccumulatorUndefined(this); -} - -checker::Type *UndefinedLiteral::Check(checker::TSChecker *checker) -{ - return checker->GlobalUndefinedType(); -} - -checker::VerifiedType UndefinedLiteral::Check(checker::ETSChecker *checker) -{ - SetTsType(checker->GlobalETSUndefinedType()); - return {this, TsType()}; -} - UndefinedLiteral *UndefinedLiteral::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *const clone = allocator->New(); diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 984599ecf5cd79eae996eb6d9ff3e15e95d1a98a..3163218c3fec6a4b386fce0022e9bc6b04fbfcea 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -15,11 +15,13 @@ #include "memberExpression.h" -#include "checker/TSchecker.h" #include "checker/ets/castingContext.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsTupleType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsExtensionFuncHelperType.h" + #include "util/diagnostic.h" #include "util/es2pandaMacros.h" @@ -56,100 +58,6 @@ void MemberExpression::Iterate(const NodeTraverser &cb) const cb(property_); } -void MemberExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "MemberExpression"}, - {"object", object_}, - {"property", property_}, - {"computed", computed_}, - {"optional", IsOptional()}}); -} - -void MemberExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(object_ != nullptr); - ES2PANDA_ASSERT(property_ != nullptr); - - object_->Dump(dumper); - if (IsOptional()) { - dumper->Add("?"); - if ((MemberExpressionKind::ELEMENT_ACCESS & kind_) != 0U) { - dumper->Add("."); - } - } - if ((MemberExpressionKind::ELEMENT_ACCESS & kind_) != 0U) { - dumper->Add("["); - property_->Dump(dumper); - dumper->Add("]"); - } else { - dumper->Add("."); - property_->Dump(dumper); - } - if ((parent_ != nullptr) && (parent_->IsBlockStatement() || parent_->IsBlockExpression())) { - dumper->Add(";"); - dumper->Endl(); - } -} - -void MemberExpression::LoadRhs(compiler::PandaGen *pg) const -{ - compiler::RegScope rs(pg); - bool isSuper = object_->IsSuperExpression(); - compiler::Operand prop = pg->ToPropertyKey(property_, computed_, isSuper); - - if (isSuper) { - pg->LoadSuperProperty(this, prop); - } else if (IsPrivateReference()) { - const auto &name = property_->AsIdentifier()->Name(); - compiler::VReg objReg = pg->AllocReg(); - pg->StoreAccumulator(this, objReg); - compiler::VReg ctor = pg->AllocReg(); - compiler::Function::LoadClassContexts(this, pg, ctor, name); - pg->ClassPrivateFieldGet(this, ctor, objReg, name); - } else { - pg->LoadObjProperty(this, prop); - } -} - -void MemberExpression::CompileToRegs(compiler::PandaGen *pg, compiler::VReg object, compiler::VReg property) const -{ - object_->Compile(pg); - pg->StoreAccumulator(this, object); - - pg->OptionalChainCheck(IsOptional(), object); - - if (!computed_) { - pg->LoadAccumulatorString(this, property_->AsIdentifier()->Name()); - } else { - property_->Compile(pg); - } - - pg->StoreAccumulator(this, property); -} - -void MemberExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void MemberExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg objReg) const -{ - object_->Compile(pg); - pg->StoreAccumulator(this, objReg); - pg->OptionalChainCheck(IsOptional(), objReg); - LoadRhs(pg); -} - -void MemberExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *MemberExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - std::pair MemberExpression::ResolveObjectMember( checker::ETSChecker *checker) const { @@ -566,11 +474,6 @@ checker::Type *MemberExpression::CheckComputed(checker::ETSChecker *checker, che return nullptr; } -checker::VerifiedType MemberExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(Tag {}, *this, allocator); diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 4c72e652feabf12e3d22dd1f36bbfe9ed09b86f7..6f42c5f78a164133864722a1f4202d7b5285d6de 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -17,17 +17,18 @@ #define ES2PANDA_IR_EXPRESSION_MEMBER_EXPRESSION_H #include "checker/checkerContext.h" -#include "checker/types/ets/etsObjectType.h" #include "ir/expression.h" - +#include "varbinder/variable.h" namespace ark::es2panda::compiler { class JSCompiler; class ETSCompiler; } // namespace ark::es2panda::compiler namespace ark::es2panda::checker { -class ETSObjectType; class ETSAnalyzer; +class ETSFunctionType; +class ETSObjectType; +class ETSUnionType; } // namespace ark::es2panda::checker namespace ark::es2panda::ir { diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index 121a9871a1b0a46a0d51d39afa5f7e509dce4f5d..6c486105eb7bec765f82ebd792d748182e391405 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -15,10 +15,6 @@ #include "newExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const &other, ArenaAllocator *const allocator) @@ -68,33 +64,4 @@ void NewExpression::Iterate(const NodeTraverser &cb) const } } -void NewExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "NewExpression"}, {"callee", callee_}, {"arguments", arguments_}}); -} - -void NewExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("NewExpression"); -} - -void NewExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void NewExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *NewExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType NewExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index 36bc52d2fffd16d886d8fed240cafe2d8e6163e8..4fd2c42ccd0406980685a6a9ee794d45b8019cec 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -15,8 +15,6 @@ #include "objectExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/ts/destructuringContext.h" namespace ark::es2panda::ir { @@ -196,37 +194,6 @@ void ObjectExpression::Iterate(const NodeTraverser &cb) const } } -void ObjectExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", (type_ == AstNodeType::OBJECT_EXPRESSION) ? "ObjectExpression" : "ObjectPattern"}, - {"properties", properties_}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, - {"optional", AstDumper::Optional(optional_)}}); -} - -void ObjectExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("{"); - if (!properties_.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - for (auto property : properties_) { - property->Dump(dumper); - dumper->Add(","); - if (property == properties_.back()) { - dumper->DecrIndent(); - } - dumper->Endl(); - } - } - dumper->Add("}"); -} - -void ObjectExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - // CC-OFFNXT(G.FMT.10-CPP) project code style std::tuple ObjectExpression::CheckPatternIsShorthand(CheckPatternIsShorthandArgs *args) @@ -376,21 +343,6 @@ bool ObjectExpression::CheckAssignmentPattern(Property *prop, varbinder::Variabl return true; } -checker::Type *ObjectExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -void ObjectExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::VerifiedType ObjectExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - void ObjectExpression::CleanCheckInformation() { SetPreferredType(nullptr); diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index a804144ab34d4a4b8447ef825aa6af03d1d88f1e..676e962ba0838847868093760c81998dedf70e32 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -15,10 +15,6 @@ #include "omittedExpression.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void OmittedExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -27,36 +23,6 @@ void OmittedExpression::TransformChildren([[maybe_unused]] const NodeTransformer void OmittedExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void OmittedExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "OmittedExpression"}}); -} - -void OmittedExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("OmittedExpression"); -} - -void OmittedExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void OmittedExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *OmittedExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType OmittedExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(); diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index f84e542b58ff162ce0752e4b420009f38714304e..0a881de9d56cf5a0d7bea8ecda8dfd520ada46c0 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -15,11 +15,6 @@ #include "sequenceExpression.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceExpression const &other, ArenaAllocator *const allocator) @@ -58,38 +53,4 @@ void SequenceExpression::Iterate(const NodeTraverser &cb) const } } -void SequenceExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "SequenceExpression"}, {"expressions", sequence_}}); -} - -void SequenceExpression::Dump(ir::SrcDumper *dumper) const -{ - for (auto *expr : sequence_) { - expr->Dump(dumper); - if (expr != sequence_.back()) { - dumper->Add(", "); - } - } -} - -void SequenceExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void SequenceExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *SequenceExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType SequenceExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 027182de8aeb3ebdff9368cd606216e8e6d01e06..131d2d9c40fa97c2e438ed2afed27df74a49ff1c 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -15,11 +15,6 @@ #include "superExpression.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void SuperExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -28,36 +23,6 @@ void SuperExpression::TransformChildren([[maybe_unused]] const NodeTransformer & void SuperExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void SuperExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "Super"}}); -} - -void SuperExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("super"); -} - -void SuperExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void SuperExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *SuperExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType SuperExpression::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(); diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 069005b5537a41162c7cb76f4876520a4370e90d..e7e9d3ad9cbffdbc5ec85e3997162dbe519dcae4 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -15,9 +15,9 @@ #include "taggedTemplateExpression.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "checker/TSchecker.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/templateLiteral.h" +#include "ir/ts/tsTypeParameterInstantiation.h" namespace ark::es2panda::ir { void TaggedTemplateExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -50,39 +50,6 @@ void TaggedTemplateExpression::Iterate(const NodeTraverser &cb) const cb(quasi_); } -void TaggedTemplateExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TaggedTemplateExpression"}, - {"tag", tag_}, - {"quasi", quasi_}, - {"typeParameters", AstDumper::Optional(typeParams_)}}); -} - -void TaggedTemplateExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TaggedTemplateExpression"); -} - -void TaggedTemplateExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TaggedTemplateExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TaggedTemplateExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const tag = tag_ != nullptr ? tag_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 4275fe126a9e65b20a52a4a6d2b8353cfcd72a21..1dcf2c871a1848944a893121fbfef3f69efeabff 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -15,11 +15,6 @@ #include "templateLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral const &other, ArenaAllocator *const allocator) @@ -77,50 +72,6 @@ void TemplateLiteral::Iterate(const NodeTraverser &cb) const } } -void TemplateLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TemplateLiteral"}, {"expressions", expressions_}, {"quasis", quasis_}}); -} - -void TemplateLiteral::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("`"); - auto const num = std::max(expressions_.size(), quasis_.size()); - - for (std::size_t i = 0U; i < num; i++) { - if (i < quasis_.size()) { - quasis_[i]->Dump(dumper); - } - if (i < expressions_.size()) { - dumper->Add("${"); - expressions_[i]->Dump(dumper); - dumper->Add("}"); - } - } - dumper->Add("`"); -} - -void TemplateLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -checker::Type *TemplateLiteral::Check([[maybe_unused]] checker::TSChecker *checker) -{ - // NOTE: aszilagyi. - return checker->GlobalAnyType(); -} - -void TemplateLiteral::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::VerifiedType TemplateLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - util::StringView TemplateLiteral::GetMultilineString() const { return multilineString_; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 269fb8a2224280b46fc9bb42fa48a49c38d08ba3..c4b3fda05b4e67020c44b796e549a4fb79640732 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -15,11 +15,6 @@ #include "thisExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void ThisExpression::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -28,36 +23,6 @@ void ThisExpression::TransformChildren([[maybe_unused]] const NodeTransformer &c void ThisExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void ThisExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ThisExpression"}}); -} - -void ThisExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("this"); -} - -void ThisExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ThisExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ThisExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ThisExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(); diff --git a/ets2panda/ir/expressions/typeofExpression.cpp b/ets2panda/ir/expressions/typeofExpression.cpp index c5d2b5e4d7c87f965a40bd143aa2bb65161f4c78..fb4aec11b8039c4afcfb2925db1c6c18f167fb46 100644 --- a/ets2panda/ir/expressions/typeofExpression.cpp +++ b/ets2panda/ir/expressions/typeofExpression.cpp @@ -15,11 +15,6 @@ #include "typeofExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void TypeofExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { @@ -34,38 +29,6 @@ void TypeofExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const cb(argument_); } -void TypeofExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TypeofExpression"}, {"argument", argument_}}); -} - -void TypeofExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("(typeof "); - argument_->Dump(dumper); - dumper->Add(")"); -} - -void TypeofExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TypeofExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TypeofExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TypeofExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TypeofExpression *TypeofExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const argument = argument_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 1208f24c21eb357c8c8bab271a1090ca384979a9..f779cf4e8d24ceaca515a57b07696959d8daa277 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -15,11 +15,6 @@ #include "unaryExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void UnaryExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -34,43 +29,6 @@ void UnaryExpression::Iterate(const NodeTraverser &cb) const cb(argument_); } -void UnaryExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "UnaryExpression"}, {"operator", operator_}, {"prefix", true}, {"argument", argument_}}); -} - -void UnaryExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(TokenToString(operator_)); - if (!argument_->IsIdentifier()) { - dumper->Add("("); - argument_->Dump(dumper); - dumper->Add(")"); - } else { - argument_->Dump(dumper); - } -} - -void UnaryExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void UnaryExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *UnaryExpression::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType UnaryExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 4d8f148bf22d29bfa829adc6495ea60956d674fa..6507384f61a8e9c8c7e13368c6b212c362a1796d 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -15,11 +15,6 @@ #include "updateExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void UpdateExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -34,45 +29,6 @@ void UpdateExpression::Iterate(const NodeTraverser &cb) const cb(argument_); } -void UpdateExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "UpdateExpression"}, {"operator", operator_}, {"prefix", prefix_}, {"argument", argument_}}); -} - -void UpdateExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(argument_); - dumper->Add("("); - if (prefix_) { - dumper->Add(TokenToString(operator_)); - argument_->Dump(dumper); - } else { - argument_->Dump(dumper); - dumper->Add(TokenToString(operator_)); - } - dumper->Add(")"); -} - -void UpdateExpression::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void UpdateExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *UpdateExpression::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType UpdateExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 23e17be10d567ea75d108469b465f571206048d0..2250a44582b68ced7c3ee09ed8236f239ebc8f4c 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -15,10 +15,7 @@ #include "yieldExpression.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "compiler/function/generatorFunctionBuilder.h" -#include "checker/TSchecker.h" namespace ark::es2panda::ir { void YieldExpression::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -38,36 +35,6 @@ void YieldExpression::Iterate(const NodeTraverser &cb) const } } -void YieldExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "YieldExpression"}, {"delegate", delegate_}, {"argument", AstDumper::Nullish(argument_)}}); -} - -void YieldExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("YieldExpression"); -} - -void YieldExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void YieldExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *YieldExpression::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType YieldExpression::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/module/exportAllDeclaration.cpp b/ets2panda/ir/module/exportAllDeclaration.cpp index b61b9dd17c3ba42ff5145da53355b414374ab52a..e40c3904dc2b97a0301316c7cf4684b2333a03b1 100644 --- a/ets2panda/ir/module/exportAllDeclaration.cpp +++ b/ets2panda/ir/module/exportAllDeclaration.cpp @@ -15,11 +15,8 @@ #include "exportAllDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/literals/stringLiteral.h" namespace ark::es2panda::ir { void ExportAllDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -46,33 +43,4 @@ void ExportAllDeclaration::Iterate(const NodeTraverser &cb) const } } -void ExportAllDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ExportAllDeclaration"}, {"source", source_}, {"exported", AstDumper::Nullish(exported_)}}); -} - -void ExportAllDeclaration::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("ExportAllDeclaration"); -} - -void ExportAllDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ExportAllDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ExportAllDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ExportAllDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/module/exportDefaultDeclaration.cpp b/ets2panda/ir/module/exportDefaultDeclaration.cpp index 5d96ad38e2c22aeedb7017a324ab44ce33b8c0fb..043f156bde840aeda486260aad5b59a2f6c71882 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.cpp +++ b/ets2panda/ir/module/exportDefaultDeclaration.cpp @@ -15,12 +15,6 @@ #include "exportDefaultDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void ExportDefaultDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { @@ -35,34 +29,4 @@ void ExportDefaultDeclaration::Iterate(const NodeTraverser &cb) const cb(decl_); } -void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", IsExportEquals() ? "TSExportAssignment" : "ExportDefaultDeclaration"}, {"declaration", decl_}}); -} - -void ExportDefaultDeclaration::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("ExportDefaultDeclaration"); -} - -void ExportDefaultDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ExportDefaultDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ExportDefaultDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ExportDefaultDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/module/exportNamedDeclaration.cpp b/ets2panda/ir/module/exportNamedDeclaration.cpp index e351e25179d431290a36ab8f13c8b4fe39f05faa..b6a5c5e14b2bcddca8d281c9a6a47687fb4b911f 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.cpp +++ b/ets2panda/ir/module/exportNamedDeclaration.cpp @@ -15,11 +15,8 @@ #include "exportNamedDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/literals/stringLiteral.h" +#include "ir/module/exportSpecifier.h" namespace ark::es2panda::ir { void ExportNamedDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -61,44 +58,4 @@ void ExportNamedDeclaration::Iterate(const NodeTraverser &cb) const } } -void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ExportNamedDeclaration"}, - {"declaration", AstDumper::Nullish(decl_)}, - {"source", AstDumper::Nullish(source_)}, - {"specifiers", specifiers_}}); -} - -void ExportNamedDeclaration::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("export { "); - for (const auto *spec : specifiers_) { - spec->Dump(dumper); - - if (spec != specifiers_.back()) { - dumper->Add(", "); - } - } - dumper->Add(" }"); -} - -void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ExportNamedDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ExportNamedDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ExportNamedDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/module/exportSpecifier.cpp b/ets2panda/ir/module/exportSpecifier.cpp index 1c28d57fe53a0f57a6606771288018944388a220..dea756ba1619c2f23acfad62efcf387e49bc3e99 100644 --- a/ets2panda/ir/module/exportSpecifier.cpp +++ b/ets2panda/ir/module/exportSpecifier.cpp @@ -15,11 +15,7 @@ #include "exportSpecifier.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { void ExportSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -41,44 +37,4 @@ void ExportSpecifier::Iterate(const NodeTraverser &cb) const cb(exported_); } -void ExportSpecifier::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ExportSpecifier"}, {"local", local_}, {"exported", exported_}}); -} - -void ExportSpecifier::Dump(ir::SrcDumper *dumper) const -{ - if (GetConstantExpression() != nullptr) { - GetConstantExpression()->Dump(dumper); - dumper->Add("as default"); - return; - } - - exported_->Dump(dumper); - - if (local_ != nullptr) { - dumper->Add(" as "); - local_->Dump(dumper); - } -} - -void ExportSpecifier::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ExportSpecifier::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ExportSpecifier::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ExportSpecifier::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index f35446002cb806df1cc5498b0a9b154a99822d80..eb545c8de75404806b9506d473acb2eea2917c5e 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -15,11 +15,8 @@ #include "importDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/literals/stringLiteral.h" + #include "utils/arena_containers.h" namespace ark::es2panda::ir { @@ -56,58 +53,6 @@ void ImportDeclaration::Iterate(const NodeTraverser &cb) const } } -void ImportDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ImportDeclaration"}, {"source", Source()}, {"specifiers", Specifiers()}}); -} - -void ImportDeclaration::Dump(ir::SrcDumper *dumper) const -{ - if (dumper->IsDeclgen()) { - return; - } - dumper->Add("import "); - auto const &specifiers = Specifiers(); - if (specifiers.size() == 1 && - (specifiers[0]->IsImportNamespaceSpecifier() || specifiers[0]->IsImportDefaultSpecifier())) { - specifiers[0]->Dump(dumper); - } else { - dumper->Add("{ "); - for (auto specifier : specifiers) { - specifier->Dump(dumper); - if (specifier != specifiers.back()) { - dumper->Add(", "); - } - } - dumper->Add(" }"); - } - - dumper->Add(" from "); - Source()->Dump(dumper); - dumper->Add(";"); - dumper->Endl(); -} - -void ImportDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ImportDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ImportDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ImportDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ImportDeclaration *ImportDeclaration::Construct(ArenaAllocator *allocator) { ArenaVector specifiers(allocator->Adapter()); diff --git a/ets2panda/ir/module/importDefaultSpecifier.cpp b/ets2panda/ir/module/importDefaultSpecifier.cpp index cd2c11fd56249dc4548f194c0bf11933f8a8dc92..b8102869c5179125fd3a39f46372a2642276690b 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.cpp +++ b/ets2panda/ir/module/importDefaultSpecifier.cpp @@ -15,11 +15,7 @@ #include "importDefaultSpecifier.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { void ImportDefaultSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -35,33 +31,4 @@ void ImportDefaultSpecifier::Iterate(const NodeTraverser &cb) const cb(local_); } -void ImportDefaultSpecifier::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ImportDefaultSpecifier"}, {"local", local_}}); -} - -void ImportDefaultSpecifier::Dump(ir::SrcDumper *dumper) const -{ - local_->Dump(dumper); -} - -void ImportDefaultSpecifier::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ImportDefaultSpecifier::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ImportDefaultSpecifier::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ImportDefaultSpecifier::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/module/importNamespaceSpecifier.cpp b/ets2panda/ir/module/importNamespaceSpecifier.cpp index 4425928858b387f96985ba07c33c545128d87639..8a8ccb394c17946aa92739fc467d8ac79f4a1a87 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.cpp +++ b/ets2panda/ir/module/importNamespaceSpecifier.cpp @@ -15,11 +15,7 @@ #include "importNamespaceSpecifier.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { void ImportNamespaceSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -35,37 +31,4 @@ void ImportNamespaceSpecifier::Iterate(const NodeTraverser &cb) const cb(local_); } -void ImportNamespaceSpecifier::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ImportNamespaceSpecifier"}, {"local", local_}}); -} - -void ImportNamespaceSpecifier::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("* "); - if (!local_->Name().Empty()) { - dumper->Add("as "); - } - local_->Dump(dumper); -} - -void ImportNamespaceSpecifier::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ImportNamespaceSpecifier::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ImportNamespaceSpecifier::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ImportNamespaceSpecifier::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/module/importSpecifier.cpp b/ets2panda/ir/module/importSpecifier.cpp index fd7908212057486147a975439f1721bc1e394c3c..dbe10f96267a53cda205300380af3928d9851400 100644 --- a/ets2panda/ir/module/importSpecifier.cpp +++ b/ets2panda/ir/module/importSpecifier.cpp @@ -15,11 +15,7 @@ #include "importSpecifier.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { void ImportSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -45,36 +41,4 @@ void ImportSpecifier::Iterate(const NodeTraverser &cb) const cb(imported_); } -void ImportSpecifier::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ImportSpecifier"}, {"local", ir::AstDumper::Optional(local_)}, {"imported", imported_}}); -} - -void ImportSpecifier::Dump(ir::SrcDumper *dumper) const -{ - imported_->Dump(dumper); - if (local_ != nullptr) { - dumper->Add(" as "); - local_->Dump(dumper); - } -} - -void ImportSpecifier::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void ImportSpecifier::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ImportSpecifier::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ImportSpecifier::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/opaqueTypeNode.cpp b/ets2panda/ir/opaqueTypeNode.cpp index 0c4ebd8d9cfa46717ada4c45a829ed457798cd06..d1e99ffb1cc34f64d55e9840abbb85486f0135cf 100644 --- a/ets2panda/ir/opaqueTypeNode.cpp +++ b/ets2panda/ir/opaqueTypeNode.cpp @@ -14,11 +14,8 @@ */ #include "opaqueTypeNode.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "checker/types/type.h" namespace ark::es2panda::ir { @@ -33,47 +30,6 @@ void OpaqueTypeNode::Iterate([[maybe_unused]] const NodeTraverser &cb) const IterateAnnotations(cb); } -void OpaqueTypeNode::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "OpaqueType"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void OpaqueTypeNode::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add(TsType()->ToString()); -} - -void OpaqueTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void OpaqueTypeNode::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *OpaqueTypeNode::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *OpaqueTypeNode::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::Type *OpaqueTypeNode::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - return TsType(); -} - -checker::VerifiedType OpaqueTypeNode::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - void OpaqueTypeNode::CleanCheckInformation() {} void OpaqueTypeNode::CleanUp() {} diff --git a/ets2panda/ir/opaqueTypeNode.h b/ets2panda/ir/opaqueTypeNode.h index a5948b290df4d957553d02dc3a509fb0ff5f9ae9..490be304d9accec67f2f01182e9a0a75e33e0fcc 100644 --- a/ets2panda/ir/opaqueTypeNode.h +++ b/ets2panda/ir/opaqueTypeNode.h @@ -45,7 +45,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; void CleanCheckInformation() override; diff --git a/ets2panda/ir/srcDump.cpp b/ets2panda/ir/srcDump.cpp index d87e3dd148314dc62b95c3f1a29d533f2b6e49cd..873743398e5f73dd224d7716649e66285f7ef20b 100644 --- a/ets2panda/ir/srcDump.cpp +++ b/ets2panda/ir/srcDump.cpp @@ -15,12 +15,170 @@ #include "srcDump.h" -#include -#include -#include -#include -#include -#include +#include "ir/brokenTypeNode.h" +#include "ir/opaqueTypeNode.h" +#include "ir/annotationAllowed.h" + +#include "ir/module/exportAllDeclaration.h" +#include "ir/module/exportDefaultDeclaration.h" +#include "ir/module/exportNamedDeclaration.h" +#include "ir/module/exportSpecifier.h" +#include "ir/module/importDefaultSpecifier.h" +#include "ir/module/importNamespaceSpecifier.h" + +#include "ir/ets/etsClassLiteral.h" +#include "ir/ets/etsStructDeclaration.h" +#include "ir/ets/etsIntrinsicNode.h" +#include "ir/ets/etsUnionType.h" +#include "ir/ets/etsStringLiteralType.h" +#include "ir/ets/etsTuple.h" +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" +#include "ir/ets/etsNeverType.h" +#include "ir/ets/etsNullishTypes.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "ir/ets/etsNewArrayInstanceExpression.h" +#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" +#include "ir/ets/etsNewClassInstanceExpression.h" +#include "ir/ets/etsFunctionType.h" +#include "ir/ets/etsNonNullishTypeNode.h" +#include "ir/ets/etsPackageDeclaration.h" +#include "ir/ets/etsPrimitiveType.h" +#include "ir/ets/etsWildcardType.h" +#include "ir/ets/etsKeyofType.h" +#include "ir/ets/etsModule.h" + +#include "ir/ts/tsAsExpression.h" +#include "ir/ts/tsEnumDeclaration.h" +#include "ir/ts/tsEnumMember.h" +#include "ir/ts/tsExternalModuleReference.h" +#include "ir/ts/tsNonNullExpression.h" +#include "ir/ts/tsTypeAssertion.h" +#include "ir/ts/tsAnyKeyword.h" +#include "ir/ts/tsArrayType.h" +#include "ir/ts/tsBigintKeyword.h" +#include "ir/ts/tsBooleanKeyword.h" +#include "ir/ts/tsLiteralType.h" +#include "ir/ts/tsNeverKeyword.h" +#include "ir/ts/tsNullKeyword.h" +#include "ir/ts/tsNumberKeyword.h" +#include "ir/ts/tsObjectKeyword.h" +#include "ir/ts/tsParenthesizedType.h" +#include "ir/ts/tsStringKeyword.h" +#include "ir/ts/tsTypeLiteral.h" +#include "ir/ts/tsUndefinedKeyword.h" +#include "ir/ts/tsUnionType.h" +#include "ir/ts/tsUnknownKeyword.h" +#include "ir/ts/tsVoidKeyword.h" +#include "ir/ts/tsConditionalType.h" +#include "ir/ts/tsConstructorType.h" +#include "ir/ts/tsFunctionType.h" +#include "ir/ts/tsImportEqualsDeclaration.h" +#include "ir/ts/tsImportType.h" +#include "ir/ts/tsInferType.h" +#include "ir/ts/tsIntersectionType.h" +#include "ir/ts/tsMappedType.h" +#include "ir/ts/tsModuleBlock.h" +#include "ir/ts/tsModuleDeclaration.h" +#include "ir/ts/tsParameterProperty.h" +#include "ir/ts/tsThisType.h" +#include "ir/ts/tsTypeAliasDeclaration.h" +#include "ir/ts/tsTypeOperator.h" +#include "ir/ts/tsTypeParameter.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/ts/tsTypeParameterInstantiation.h" +#include "ir/ts/tsTypePredicate.h" +#include "ir/ts/tsTypeReference.h" +#include "ir/ts/tsClassImplements.h" +#include "ir/ts/tsIndexedAccessType.h" +#include "ir/ts/tsInterfaceBody.h" +#include "ir/ts/tsInterfaceDeclaration.h" +#include "ir/ts/tsInterfaceHeritage.h" +#include "ir/ts/tsNamedTupleMember.h" +#include "ir/ts/tsQualifiedName.h" +#include "ir/ts/tsTupleType.h" +#include "ir/ts/tsTypeQuery.h" + +#include "ir/base/spreadElement.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/catchClause.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/decorator.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/metaProperty.h" +#include "ir/base/overloadDeclaration.h" +#include "ir/base/property.h" +#include "ir/base/tsMethodSignature.h" +#include "ir/base/tsPropertySignature.h" +#include "ir/base/tsSignatureDeclaration.h" +#include "ir/base/tsIndexSignature.h" + +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/taggedTemplateExpression.h" +#include "ir/expressions/typeofExpression.h" +#include "ir/expressions/unaryExpression.h" +#include "ir/expressions/updateExpression.h" +#include "ir/expressions/yieldExpression.h" + +#include "ir/expressions/arrowFunctionExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/templateLiteral.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/awaitExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/classExpression.h" +#include "ir/expressions/chainExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/importExpression.h" +#include "ir/expressions/dummyNode.h" +#include "ir/expressions/directEvalExpression.h" +#include "ir/expressions/blockExpression.h" +#include "ir/expressions/conditionalExpression.h" +#include "ir/expressions/thisExpression.h" +#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/expressions/literals/bigIntLiteral.h" +#include "ir/expressions/literals/booleanLiteral.h" +#include "ir/expressions/literals/charLiteral.h" +#include "ir/expressions/literals/nullLiteral.h" +#include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/regExpLiteral.h" +#include "ir/expressions/newExpression.h" +#include "ir/expressions/omittedExpression.h" +#include "ir/expressions/superExpression.h" + +#include "ir/statements/assertStatement.h" +#include "ir/statements/annotationDeclaration.h" +#include "ir/statements/breakStatement.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/continueStatement.h" +#include "ir/statements/debuggerStatement.h" +#include "ir/statements/doWhileStatement.h" +#include "ir/statements/emptyStatement.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/forInStatement.h" +#include "ir/statements/forOfStatement.h" +#include "ir/statements/forUpdateStatement.h" +#include "ir/statements/labelledStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/ifStatement.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" +#include "ir/statements/switchCaseStatement.h" +#include "ir/statements/switchStatement.h" +#include "ir/statements/tryStatement.h" +#include "ir/statements/throwStatement.h" +#include "ir/statements/whileStatement.h" + +#include "ir/as/namedType.h" +#include "ir/as/prefixAssertionExpression.h" + +#include "compiler/lowering/util.h" + #include #include @@ -182,4 +340,2362 @@ void SrcDumper::Run() } } +void ImportDefaultSpecifier::Dump(ir::SrcDumper *dumper) const +{ + local_->Dump(dumper); +} +void TSTypeAssertion::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSTypeAssertion"); +} +void TSThisType::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("this"); +} +void TSIndexedAccessType::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSIndexedAccessType"); +} +void TSParameterProperty::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSParameterProperty"); +} +void TSModuleBlock::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSModuleBlock"); +} +void TSImportEqualsDeclaration::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSImportEqualsDeclaration"); +} +void TSModuleDeclaration::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSModuleDeclaration"); +} +void ExportAllDeclaration::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("ExportAllDeclaration"); +} +void ExportDefaultDeclaration::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("ExportDefaultDeclaration"); +} +void BrokenTypeNode::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(ERROR_TYPE); +} +void ThisExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("this"); +} +void FunctionExpression::Dump(ir::SrcDumper *dumper) const +{ + func_->Dump(dumper); +} + +void OmittedExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("OmittedExpression"); +} + +void DummyNode::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(std::string(name_)); +} + +void YieldExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("YieldExpression"); +} + +void ClassExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("ClassExpression"); +} + +void SuperExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("super"); +} + +void ImportExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("ImportExpression"); +} +void TaggedTemplateExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TaggedTemplateExpression"); +} +void BooleanLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(boolean_ ? "true" : "false"); +} +void UndefinedLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("undefined"); +} +void StringLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("\"" + util::Helpers::CreateEscapedString(std::string(str_)) + "\""); +} +void BigIntLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(std::string(src_) + "n"); +} +void CharLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("c\'" + ToString() + "\'"); +} + +void RegExpLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(std::string(pattern_)); +} +void NullLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("null"); +} +void NewExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("NewExpression"); +} +void TSSignatureDeclaration::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSSignatureDeclaration"); +} +void TSMethodSignature::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSMethodSignature"); +} + +void Decorator::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("Decorator"); +} +void MetaProperty::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("MetaProperty"); +} + +void TSPropertySignature::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSPropertySignature"); +} +void TSIndexSignature::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSIndexSignature"); +} +void TemplateElement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(std::string(raw_)); +} +void AssertStatement::Dump([[maybe_unused]] ir::SrcDumper *dumper) const +{ + ES2PANDA_UNREACHABLE(); +} +void EmptyStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(""); +} +void DebuggerStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("DebuggerStatement"); +} + +void ForInStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("ForInStatement"); +} + +template +void DumpAnnotations(const AnnotationAllowed *node, ir::SrcDumper *dumper) +{ + node->IterateAnnotations([dumper](auto *anno) { anno->Dump(dumper); }); +} + +void NamedType::Dump(SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("NamedType"); +} + +void ETSNeverType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("never"); +} +void ETSUndefinedType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("undefined"); +} +void ETSNullType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("null"); +} +void ETSWildcardType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("ETSWildcardType"); +} + +void ETSStringLiteralType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("\"" + value_.Mutf8() + "\""); +} + +void TSUndefinedKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSUndefinedKeyword"); +} +void TSBooleanKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSBooleanKeyword"); +} +void TSConditionalType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSConditionalType"); +} +void TSMappedType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSMappedType"); +} +void TSTypePredicate::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSTypePredicate"); +} +void TSParenthesizedType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSParenthesizedType"); +} +void TSStringKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSStringKeyword"); +} +void TSConstructorType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSConstructorType"); +} +void TSTypeOperator::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSTypeOperator"); +} + +void TSInferType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSInferType"); +} +void TSTypeLiteral::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSTypeLiteral"); +} +void TSTypeReference::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + BaseName()->Dump(dumper); +} +void TSAnyKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSAnyKeyword"); +} +void TSBigintKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSBigintKeyword"); +} +void TSNullKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSNullKeyword"); +} +void TSTupleType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSTupleType"); +} +void TSVoidKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSVoidKeyword"); +} + +void TSLiteralType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSLiteralType"); +} +void TSNamedTupleMember::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSNamedTupleMember"); +} +void TSNeverKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSNeverKeyword"); +} +void TSObjectKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSObjectKeyword"); +} +void TSInterfaceHeritage::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(expr_ != nullptr); + expr_->Dump(dumper); +} + +void TSTypeQuery::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSTypeQuery"); +} +void TSFunctionType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSFunctionType"); +} + +void TSIntersectionType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSIntersectionType"); +} +void TSNumberKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSNumberKeyword"); +} + +void TSClassImplements::Dump(ir::SrcDumper *dumper) const +{ + expression_->Dump(dumper); + ES2PANDA_ASSERT(typeParameters_ == nullptr); +} +void TSUnionType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSUnionType"); +} +void TSUnknownKeyword::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSUnknownKeyword"); +} +void TSImportType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("TSImportType"); +} + +void OpaqueTypeNode::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add(TsType()->ToString()); +} + +void ETSStructDeclaration::Dump(ir::SrcDumper *dumper) const +{ + if (Definition() != nullptr) { + Definition()->Dump(dumper); + } +} +void ETSTypeReference::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + ES2PANDA_ASSERT(Part() != nullptr); + Part()->Dump(dumper); +} + +void ETSKeyofType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("keyof "); + type_->Dump(dumper); +} +void TSNonNullExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(expr_ != nullptr); + expr_->Dump(dumper); + dumper->Add("!"); +} +void TSInterfaceBody::Dump(ir::SrcDumper *dumper) const +{ + for (auto b : body_) { + b->Dump(dumper); + } +} +void TSQualifiedName::Dump(ir::SrcDumper *dumper) const +{ + left_->Dump(dumper); + dumper->Add("."); + right_->Dump(dumper); +} +void ChainExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("("); // affects precedence + expression_->Dump(dumper); + dumper->Add(")"); +} +void TypeofExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("(typeof "); + argument_->Dump(dumper); + dumper->Add(")"); +} + +void ThrowStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(Argument() != nullptr); + dumper->Add("throw "); + Argument()->Dump(dumper); + dumper->Add(";"); +} + +void ETSTypeReferencePart::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(Name() != nullptr); + Name()->Dump(dumper); + if (TypeParams() != nullptr) { + TypeParams()->Dump(dumper); + } +} + +void AwaitExpression::Dump(ir::SrcDumper *dumper) const +{ + if (argument_ != nullptr) { + dumper->Add("await "); + argument_->Dump(dumper); + } +} +void ClassDeclaration::Dump(ir::SrcDumper *dumper) const +{ + if (Definition() != nullptr) { + Definition()->Dump(dumper); + } +} + +void ETSPackageDeclaration::Dump(ir::SrcDumper *dumper) const +{ + if (dumper->IsDeclgen()) { + return; + } + dumper->Add("package "); + name_->Dump(dumper); + dumper->Add(";"); + dumper->Endl(); +} + +void ETSNonNullishTypeNode::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("NonNullable<"); + typeNode_->Dump(dumper); + dumper->Add(">"); +} +void TSAsExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("("); + expression_->Dump(dumper); + dumper->Add(" as "); + TypeAnnotation()->Dump(dumper); + dumper->Add(")"); +} +void ImportSpecifier::Dump(ir::SrcDumper *dumper) const +{ + imported_->Dump(dumper); + if (local_ != nullptr) { + dumper->Add(" as "); + local_->Dump(dumper); + } +} +void ImportNamespaceSpecifier::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("* "); + if (!local_->Name().Empty()) { + dumper->Add("as "); + } + local_->Dump(dumper); +} +void Property::Dump(ir::SrcDumper *dumper) const +{ + if (kind_ == PropertyKind::INIT) { + key_->Dump(dumper); + dumper->Add(": "); + value_->Dump(dumper); + } +} +void LabelledStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(ident_ != nullptr); + ident_->Dump(dumper); + dumper->Add(":"); + dumper->Endl(); + body_->Dump(dumper); +} +void ExpressionStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(expression_ != nullptr); + expression_->Dump(dumper); + if ((parent_ != nullptr) && (parent_->IsBlockStatement() || parent_->IsSwitchCaseStatement())) { + dumper->Add(";"); + } +} + +void TSEnumMember::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(key_ != nullptr); + key_->Dump(dumper); + if (init_ != nullptr) { + dumper->Add(" = "); + init_->Dump(dumper); + } +} +void TSTypeParameterDeclaration::Dump(ir::SrcDumper *dumper) const +{ + for (auto param : Params()) { + param->Dump(dumper); + if (param != Params().back()) { + dumper->Add(", "); + } + } +} +void SequenceExpression::Dump(ir::SrcDumper *dumper) const +{ + for (auto *expr : sequence_) { + expr->Dump(dumper); + if (expr != sequence_.back()) { + dumper->Add(", "); + } + } +} + +void ReturnStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("return"); + if (argument_ != nullptr) { + dumper->Add(" "); + argument_->Dump(dumper); + } + dumper->Add(";"); +} +void ContinueStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("continue"); + if (Ident() != nullptr) { + dumper->Add(" "); + Ident()->Dump(dumper); + } + dumper->Add(";"); +} +void BreakStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("break"); + if (ident_ != nullptr) { + dumper->Add(" "); + ident_->Dump(dumper); + } + dumper->Add(";"); +} + +void ETSNewArrayInstanceExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("new "); + ES2PANDA_ASSERT(typeReference_); + typeReference_->Dump(dumper); + ES2PANDA_ASSERT(dimension_); + dumper->Add("["); + dimension_->Dump(dumper); + dumper->Add("]"); +} +void AssignmentExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(left_); + left_->Dump(dumper); + dumper->Add(" "); + dumper->Add(TokenToString(operator_)); + dumper->Add(" "); + ES2PANDA_ASSERT(right_); + right_->Dump(dumper); +} +void ArrowFunctionExpression::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("("); + if (func_->IsScriptFunction() && func_->AsScriptFunction()->IsAsyncFunc()) { + dumper->Add("async "); + } + func_->Dump(dumper); + dumper->Add(")"); +} + +void SpreadElement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("..."); + argument_->Dump(dumper); + auto type = TypeAnnotation(); + if (type != nullptr && type->IsValidInCurrentPhase()) { + dumper->Add(": "); + type->Dump(dumper); + } +} + +void ETSNewMultiDimArrayInstanceExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("new "); + ES2PANDA_ASSERT(typeReference_); + typeReference_->Dump(dumper); + for (auto dim : dimensions_) { + dumper->Add("["); + dim->Dump(dumper); + dumper->Add("]"); + } +} +void TSTypeParameterInstantiation::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("<"); + for (auto param : params_) { + param->Dump(dumper); + if (param != params_.back()) { + dumper->Add(", "); + } + } + dumper->Add(">"); +} +void BlockExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("({"); + for (auto *statement : statements_) { + statement->Dump(dumper); + if (statement != statements_.back()) { + dumper->Endl(); + } + } + dumper->Add("})"); +} +void ArrayExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("["); + for (auto element : elements_) { + element->Dump(dumper); + if (element != elements_.back()) { + dumper->Add(", "); + } + } + dumper->Add("]"); +} +void UnaryExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add(TokenToString(operator_)); + if (!argument_->IsIdentifier()) { + dumper->Add("("); + argument_->Dump(dumper); + dumper->Add(")"); + } else { + argument_->Dump(dumper); + } +} + +// 11 + +void ETSUnionType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("("); + for (auto type : Types()) { + type->Dump(dumper); + if (type != Types().back()) { + dumper->Add(" | "); + } + } + dumper->Add(")"); +} +void ETSTuple::Dump(ir::SrcDumper *const dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("["); + for (const auto *const typeAnnot : typeAnnotationList_) { + typeAnnot->Dump(dumper); + if (typeAnnot != typeAnnotationList_.back()) { + dumper->Add(", "); + } + } + dumper->Add("]"); +} + +void BinaryExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(left_ != nullptr); + ES2PANDA_ASSERT(right_ != nullptr); + dumper->Add("(("); + left_->Dump(dumper); + dumper->Add(") "); + dumper->Add(TokenToString(operator_)); + dumper->Add(" ("); + right_->Dump(dumper); + dumper->Add("))"); +} + +void ETSIntrinsicNode::Dump([[maybe_unused]] ir::SrcDumper *dumper) const +{ + dumper->Add("%%intrin%%"); + dumper->Add(Id().Mutf8()); + dumper->Add("("); + for (auto arg : arguments_) { + arg->Dump(dumper); + if (arg != arguments_.back()) { + dumper->Add(", "); + } + } + dumper->Add(")"); +} + +void UpdateExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(argument_); + dumper->Add("("); + if (prefix_) { + dumper->Add(TokenToString(operator_)); + argument_->Dump(dumper); + } else { + argument_->Dump(dumper); + dumper->Add(TokenToString(operator_)); + } + dumper->Add(")"); +} + +void OverloadDeclaration::DumpModifier(ir::SrcDumper *dumper) const +{ + if (compiler::HasGlobalClassParent(this) && !dumper->IsDeclgen()) { + if (IsExported()) { + dumper->Add("export "); + } + } + + if (Parent() != nullptr && Parent()->IsClassDefinition() && !Parent()->AsClassDefinition()->IsLocal() && + !compiler::HasGlobalClassParent(this)) { + if (IsPrivate()) { + dumper->Add("private "); + } else if (IsProtected()) { + dumper->Add("protected "); + } else if (IsInternal()) { + dumper->Add("internal "); + } else { + dumper->Add("public "); + } + + if (IsStatic()) { + dumper->Add("static "); + } + } + + if (IsAsync()) { + dumper->Add("async "); + } +} + +void OverloadDeclaration::Dump(ir::SrcDumper *dumper) const +{ + DumpModifier(dumper); + dumper->Add("overload "); + dumper->Add(IsConstructor() ? "constructor " : key_->AsIdentifier()->Name().Mutf8()); + dumper->Add("{"); + for (size_t i = 0; i < overloadedList_.size(); i++) { + if (i != 0) { + dumper->Add(", "); + } + overloadedList_[i]->Dump(dumper); + } + dumper->Add("};"); +} + +void ClassStaticBlock::Dump(ir::SrcDumper *dumper) const +{ + if (dumper->IsDeclgen()) { + return; + } + + ES2PANDA_ASSERT(value_); + ES2PANDA_ASSERT(value_->IsFunctionExpression()); + ES2PANDA_ASSERT(value_->AsFunctionExpression()->Function()->IsScriptFunction()); + dumper->Add("static {"); + dumper->IncrIndent(); + dumper->Endl(); + const auto *scriptFunc = value_->AsFunctionExpression()->Function()->AsScriptFunction(); + ES2PANDA_ASSERT(scriptFunc->HasBody()); + scriptFunc->Body()->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); +} + +void WhileStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("while ("); + if (test_ != nullptr) { + test_->Dump(dumper); + } + dumper->Add(") {"); + if (body_ != nullptr) { + dumper->IncrIndent(); + dumper->Endl(); + body_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); +} +bool TSEnumDeclaration::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return false; + } + + if (dumper->IsIndirectDepPhase()) { + return false; + } + + if (key_->Parent()->IsDefaultExported() || key_->Parent()->IsExported()) { + return false; + } + + auto name = key_->AsIdentifier()->Name().Mutf8(); + dumper->AddNode(name, this); + return true; +} + +void TSEnumDeclaration::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(isConst_ == false); + ES2PANDA_ASSERT(key_ != nullptr); + if (RegisterUnexportedForDeclGen(dumper)) { + return; + } + if (key_->Parent()->IsExported() && dumper->IsDeclgen()) { + dumper->Add("export "); + } else if (key_->Parent()->IsDefaultExported() && dumper->IsDeclgen()) { + dumper->Add("export default "); + } + if (dumper->IsDeclgen()) { + dumper->TryDeclareAmbientContext(); + } else if (IsDeclare()) { + dumper->Add("declare "); + } + dumper->Add("enum "); + Key()->Dump(dumper); + dumper->Add(" {"); + auto const members = Members(); + if (!members.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + for (auto member : members) { + member->Dump(dumper); + if (member != members.back()) { + dumper->Add(","); + dumper->Endl(); + } + } + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); + dumper->Endl(); +} + +bool TSTypeAliasDeclaration::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return false; + } + + if (dumper->IsIndirectDepPhase()) { + return false; + } + + if (id_->Parent()->IsExported() || id_->Parent()->IsDefaultExported()) { + return false; + } + + auto name = id_->Name().Mutf8(); + dumper->AddNode(name, this); + return true; +} + +void TSTypeAliasDeclaration::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(id_); + if (RegisterUnexportedForDeclGen(dumper)) { + return; + } + DumpAnnotations(this, dumper); + if (id_->Parent()->IsExported()) { + dumper->Add("export "); + } + dumper->Add("type "); + Id()->Dump(dumper); + auto const typeParams = TypeParams(); + if (typeParams != nullptr) { + dumper->Add("<"); + typeParams->Dump(dumper); + dumper->Add(">"); + } + dumper->Add(" = "); + if (Id()->IsAnnotatedExpression()) { + auto type = TypeAnnotation(); + ES2PANDA_ASSERT(type); + type->Dump(dumper); + } + dumper->Add(";"); + dumper->Endl(); +} + +void ScriptFunction::DumpCheckerTypeForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return; + } + + if (IsConstructor()) { + return; + } + + if (IsSetter()) { + return; + } + + if (Signature() == nullptr) { + return; + } + + if (Signature()->ReturnType() == nullptr) { + return; + } + + auto typeStr = Signature()->ReturnType()->ToString(); + dumper->Add(": "); + dumper->Add(typeStr); + + dumper->PushTask([dumper, typeStr] { dumper->DumpNode(typeStr); }); +} + +void ScriptFunction::DumpBody(ir::SrcDumper *dumper) const +{ + if (!HasBody()) { + dumper->Endl(); + return; + } + + if (IsArrow()) { + dumper->Add(" =>"); + } + + if (body_->IsBlockStatement()) { + dumper->Add(" {"); + const auto &statements = body_->AsBlockStatement()->Statements(); + if (!statements.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + body_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); + } else { + dumper->Add(" "); + body_->Dump(dumper); + } + + if (!IsArrow()) { + dumper->Endl(); + } +} + +void ScriptFunction::Dump(ir::SrcDumper *dumper) const +{ + if (TypeParams() != nullptr) { + dumper->Add("<"); + TypeParams()->Dump(dumper); + dumper->Add(">"); + } + dumper->Add("("); + for (auto param : Params()) { + param->Dump(dumper); + if (param != Params().back()) { + dumper->Add(", "); + } + } + dumper->Add(")"); + if (ReturnTypeAnnotation() != nullptr && !dumper->IsDeclgen()) { + dumper->Add(": "); + ReturnTypeAnnotation()->Dump(dumper); + } + DumpCheckerTypeForDeclGen(dumper); + if (dumper->IsDeclgen()) { + dumper->Add(";"); + dumper->Endl(); + return; + } + DumpBody(dumper); +} + +void ForUpdateStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("for "); + dumper->Add("("); + if (init_ != nullptr) { + init_->Dump(dumper); + } + dumper->Add(";"); + if (test_ != nullptr) { + test_->Dump(dumper); + } + dumper->Add(";"); + if (update_ != nullptr) { + update_->Dump(dumper); + } + dumper->Add(") "); + dumper->Add("{"); + if (body_ != nullptr) { + dumper->IncrIndent(); + dumper->Endl(); + body_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); +} + +void BlockStatement::Dump(ir::SrcDumper *dumper) const +{ + auto const &statements = Statements(); + // NOTE(nsizov): trailing blocks + if (Parent() != nullptr && (Parent()->IsBlockStatement() || Parent()->IsCallExpression())) { + dumper->Add("{"); + if (!statements.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + } + } + for (auto statement : statements) { + statement->Dump(dumper); + if (statement != statements.back()) { + dumper->Endl(); + } + } + if (Parent() != nullptr && (Parent()->IsBlockStatement() || Parent()->IsCallExpression())) { + if (!statements.empty()) { + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); + } +} + +void TryStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(block_ != nullptr); + dumper->Add("try {"); + dumper->IncrIndent(); + dumper->Endl(); + block_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); + for (auto clause : catchClauses_) { + dumper->Add(" catch "); + clause->Dump(dumper); + } + if (finalizer_ != nullptr) { + dumper->Add(" finally {"); + dumper->IncrIndent(); + dumper->Endl(); + finalizer_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); + } +} +void SwitchCaseStatement::Dump(ir::SrcDumper *dumper) const +{ + if (test_ != nullptr) { + dumper->Add("case "); + test_->Dump(dumper); + dumper->Add(":"); + } else { + dumper->Add("default:"); + } + if (!consequent_.empty()) { + dumper->Add(" {"); + dumper->IncrIndent(); + dumper->Endl(); + for (auto cs : consequent_) { + cs->Dump(dumper); + if (!cs->IsBlockStatement() && cs != consequent_.back()) { + dumper->Endl(); + } + } + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); + } +} + +void IfStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(test_); + ES2PANDA_ASSERT(consequent_ != nullptr); + dumper->Add("if ("); + test_->Dump(dumper); + dumper->Add(") {"); + dumper->IncrIndent(); + dumper->Endl(); + consequent_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); + if (alternate_ != nullptr) { + dumper->Add(" else {"); + dumper->IncrIndent(); + dumper->Endl(); + alternate_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); + } +} + +void ForOfStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(left_ != nullptr); + ES2PANDA_ASSERT(right_ != nullptr); + dumper->Add("for "); + if (isAwait_) { + dumper->Add("await "); + } + dumper->Add("("); + left_->Dump(dumper); + dumper->Add(" of "); + right_->Dump(dumper); + dumper->Add(") {"); + if (body_ != nullptr) { + dumper->IncrIndent(); + dumper->Endl(); + body_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); +} + +void VariableDeclarator::Dump(ir::SrcDumper *dumper) const +{ + if (id_ != nullptr) { + id_->Dump(dumper); + if (id_->IsOptionalDeclaration()) { + dumper->Add("?"); + } + if (id_->IsAnnotatedExpression()) { + auto *type = id_->AsAnnotatedExpression()->TypeAnnotation(); + if (type != nullptr) { + dumper->Add(": "); + type->Dump(dumper); + } + } + } + if (init_ != nullptr) { + dumper->Add(" = "); + init_->Dump(dumper); + } +} + +void ConditionalExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(test_ != nullptr); + dumper->Add("("); + test_->Dump(dumper); + dumper->Add(" ? "); + if (consequent_ != nullptr) { + consequent_->Dump(dumper); + } + dumper->Add(" : "); + if (alternate_ != nullptr) { + alternate_->Dump(dumper); + } + dumper->Add(")"); + if ((parent_ != nullptr) && (parent_->IsBlockStatement() || parent_->IsBlockExpression())) { + dumper->Add(";"); + dumper->Endl(); + } +} +void CatchClause::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(body_ != nullptr); + dumper->Add("("); + if (param_ != nullptr) { + param_->Dump(dumper); + if (param_->IsIdentifier() && param_->AsIdentifier()->TypeAnnotation() != nullptr) { + dumper->Add(": "); + param_->AsIdentifier()->TypeAnnotation()->Dump(dumper); + } + } + dumper->Add(") {"); + dumper->IncrIndent(); + dumper->Endl(); + body_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + dumper->Add("}"); +} +void SwitchStatement::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(discriminant_); + dumper->Add("switch ("); + discriminant_->Dump(dumper); + dumper->Add(") {"); + if (!cases_.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + for (auto cs : cases_) { + cs->Dump(dumper); + if (cs == cases_.back()) { + dumper->DecrIndent(); + } + dumper->Endl(); + } + } + dumper->Add("}"); +} + +void ObjectExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("{"); + if (!properties_.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + for (auto property : properties_) { + property->Dump(dumper); + dumper->Add(","); + if (property == properties_.back()) { + dumper->DecrIndent(); + } + dumper->Endl(); + } + } + dumper->Add("}"); +} +void DoWhileStatement::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("do {"); + if (body_ != nullptr) { + dumper->IncrIndent(); + dumper->Endl(); + body_->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("} while"); + dumper->Add("("); + if (test_ != nullptr) { + test_->Dump(dumper); + } + dumper->Add(")"); +} + +void TSExternalModuleReference::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("TSExternalModuleReference"); +} + +void PrefixAssertionExpression::Dump(SrcDumper *dumper) const +{ + dumper->Add("PrefixAssertionExpression"); +} + +void ETSClassLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("ETSClassLiteral"); +} + +template +void DumpItems(ir::SrcDumper *dumper, const std::string &prefix, const ArenaVector &items) +{ + if (items.empty()) { + return; + } + dumper->Add(prefix); + for (size_t i = 0; i < items.size(); ++i) { + items[i]->Dump(dumper); + if (i < items.size() - 1) { + dumper->Add(", "); + } + } +} +void ClassDefinition::DumpGlobalClass(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(IsGlobal()); + ir::ClassStaticBlock *classStaticBlock = nullptr; + for (auto elem : Body()) { + if (elem->IsClassProperty()) { + elem->Dump(dumper); + dumper->Endl(); + } + + if (elem->IsClassStaticBlock()) { + classStaticBlock = elem->AsClassStaticBlock(); + } + } + for (auto elem : Body()) { + if (elem->IsMethodDefinition()) { + elem->Dump(dumper); + dumper->Endl(); + } + } + + if (classStaticBlock == nullptr) { + return; + } + + auto bodyStmts = + classStaticBlock->Value()->AsFunctionExpression()->Function()->Body()->AsBlockStatement()->Statements(); + for (auto statement : bodyStmts) { + if (statement->IsExpressionStatement() && + statement->AsExpressionStatement()->GetExpression()->IsAssignmentExpression() && + statement->AsExpressionStatement()->GetExpression()->AsAssignmentExpression()->IsIgnoreConstAssign()) { + // skip the dummy assignment expression created for const variable decl in the class static block. + continue; + } + statement->Dump(dumper); + if (statement != bodyStmts.back()) { + dumper->Endl(); + } + } +} + +// This method is needed by OHOS CI code checker +void ClassDefinition::DumpBody(ir::SrcDumper *dumper) const +{ + auto const body = Body(); + dumper->Add(" {"); + if (!body.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + for (auto elem : body) { + elem->Dump(dumper); + if (elem == body.back()) { + dumper->DecrIndent(); + } + dumper->Endl(); + } + } + dumper->Add("}"); +} + +void ClassDefinition::DumpPrefix(ir::SrcDumper *dumper) const +{ + if (IsExported()) { + dumper->Add("export "); + } else if (IsDefaultExported()) { + dumper->Add("export default "); + } + + if (dumper->IsDeclgen()) { + dumper->TryDeclareAmbientContext(); + } else if (IsDeclare()) { + dumper->Add("declare "); + } + + if (IsFinal()) { + dumper->Add("final "); + } + + if (IsAbstract() && !IsNamespaceTransformed()) { + dumper->Add("abstract "); + } + + if (parent_->IsETSStructDeclaration() || IsFromStruct()) { + dumper->Add("struct "); + } else if (IsNamespaceTransformed()) { + dumper->Add("namespace "); + } else { + dumper->Add("class "); + } +} + +bool ClassDefinition::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return false; + } + + if (dumper->IsIndirectDepPhase()) { + return false; + } + + if (IsExported() || IsDefaultExported()) { + return false; + } + + const auto className = ident_->Name().Mutf8(); + dumper->AddNode(className, this); + return true; +} + +void ClassDefinition::Dump(ir::SrcDumper *dumper) const +{ + auto guard = dumper->BuildAmbientContextGuard(); + // NOTE: plugin API fails + auto const ident = Ident(); + if ((ident->Name().StartsWith("$dynmodule")) || (ident->Name().StartsWith("$jscall"))) { + return; + } + + if (IsGlobal()) { + DumpGlobalClass(dumper); + return; + } + + ES2PANDA_ASSERT(ident_ != nullptr); + + if (RegisterUnexportedForDeclGen(dumper)) { + return; + } + + DumpAnnotations(this, dumper); + + DumpPrefix(dumper); + ident_->Dump(dumper); + + if (TypeParams() != nullptr) { + dumper->Add("<"); + TypeParams()->Dump(dumper); + dumper->Add("> "); + } + + if (SuperClass() != nullptr) { + dumper->Add(" extends "); + SuperClass()->Dump(dumper); + } + + DumpItems(dumper, " implements ", Implements()); + + if (!IsDeclare() || !Body().empty()) { + DumpBody(dumper); + } + if (IsLocal()) { + dumper->Add(";"); + } + dumper->Endl(); +} + +void AnnotationDeclaration::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + ES2PANDA_ASSERT(Expr() != nullptr); + if (IsExported()) { + dumper->Add("export "); + } + if (IsDeclare() || dumper->IsDeclgen()) { + dumper->Add("declare "); + } + dumper->Add("@interface "); + Expr()->Dump(dumper); + dumper->Add(" {"); + + auto const properties = Properties(); + if (!properties.empty()) { + dumper->IncrIndent(); + dumper->Endl(); + for (auto elem : properties) { + elem->Dump(dumper); + if (elem != properties.back()) { + dumper->Endl(); + } + } + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); +} + +void ClassProperty::DumpModifiers(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(key_); + + if (compiler::HasGlobalClassParent(this)) { + if (key_->Parent()->IsConst()) { + dumper->Add("const "); + } else { + dumper->Add("let "); + } + return; + } + + if (Parent() != nullptr && Parent()->IsClassDefinition() && !Parent()->AsClassDefinition()->IsLocal()) { + if (IsPrivate()) { + dumper->Add("private "); + } else if (IsProtected()) { + dumper->Add("protected "); + } else if (IsInternal()) { + dumper->Add("internal "); + } else { + dumper->Add("public "); + } + } + + if (IsStatic()) { + dumper->Add("static "); + } + + if (IsReadonly()) { + dumper->Add("readonly "); + } +} + +bool ClassProperty::DumpNamespaceForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return false; + } + + if (Parent() == nullptr) { + return false; + } + + bool isNamespaceTransformed = + Parent()->IsClassDefinition() && Parent()->AsClassDefinition()->IsNamespaceTransformed(); + if (isNamespaceTransformed) { + dumper->Add("let "); + return true; + } + return false; +} + +void ClassProperty::DumpPrefix(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + if (DumpNamespaceForDeclGen(dumper)) { + return; + } + DumpModifiers(dumper); +} + +void ClassProperty::DumpCheckerTypeForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return; + } + + if (TsType() == nullptr) { + return; + } + + auto typeStr = TsType()->ToString(); + dumper->Add(": "); + dumper->Add(typeStr); + + dumper->PushTask([dumper, typeStr] { dumper->DumpNode(typeStr); }); +} + +bool ClassProperty::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(key_); + if (!dumper->IsDeclgen()) { + return false; + } + + auto name = key_->AsIdentifier()->Name().Mutf8(); + if (name.rfind('#', 0) == 0) { + return true; + } + + if (IsPrivate()) { + return true; + } + + if (!compiler::HasGlobalClassParent(this)) { + return false; + } + + if (dumper->IsIndirectDepPhase()) { + return false; + } + + if (key_->Parent()->IsExported() || key_->Parent()->IsDefaultExported()) { + return false; + } + + dumper->AddNode(name, this); + return true; +} + +void ClassProperty::Dump(ir::SrcDumper *dumper) const +{ + if (dumper->IsDeclgen() && IsInternal()) { + return; + } + if (RegisterUnexportedForDeclGen(dumper)) { + return; + } + DumpPrefix(dumper); + + if (Key() != nullptr) { + Key()->Dump(dumper); + } + + if (IsOptionalDeclaration()) { + dumper->Add("?"); + } + + if (IsDefinite()) { + dumper->Add("!"); + } + + if (typeAnnotation_ != nullptr && !dumper->IsDeclgen()) { + dumper->Add(": "); + TypeAnnotation()->Dump(dumper); + } + + DumpCheckerTypeForDeclGen(dumper); + + if (value_ != nullptr) { + if (!dumper->IsDeclgen() || Parent()->IsAnnotationDeclaration()) { + dumper->Add(" = "); + Value()->Dump(dumper); + } + } + + dumper->Add(";"); +} + +void MethodDefinition::DumpModifierPrefix(ir::SrcDumper *dumper) const +{ + if (compiler::HasGlobalClassParent(this)) { + return; + } + if (IsStatic()) { + dumper->Add("static "); + } + + if (IsAbstract() && !(Parent()->IsTSInterfaceBody() || + (BaseOverloadMethod() != nullptr && BaseOverloadMethod()->Parent()->IsTSInterfaceBody()))) { + dumper->Add("abstract "); + } + if (IsFinal()) { + dumper->Add("final "); + } + if (IsNative()) { + dumper->Add("native "); + } + if (IsAsync() && !dumper->IsDeclgen()) { + dumper->Add("async "); + } + if (IsOverride()) { + dumper->Add("override "); + } + + if (IsGetter()) { + dumper->Add("get "); + } else if (IsSetter()) { + dumper->Add("set "); + } +} + +static bool IsNamespaceTransformed(const MethodDefinition *method) +{ + auto *parent = method->Parent(); + if (parent->IsMethodDefinition()) { + // handle overloads + parent = parent->Parent(); + } + if (parent->IsClassDefinition() && parent->AsClassDefinition()->IsNamespaceTransformed()) { + return true; + } + return false; +} + +void MethodDefinition::DumpPrefix(ir::SrcDumper *dumper) const +{ + bool global = compiler::HasGlobalClassParent(this); + if (global || IsNamespaceTransformed(this)) { + if (IsExported()) { + dumper->Add("export "); + } + if (IsDefaultExported()) { + dumper->Add("export default "); + } + if (dumper->IsDeclgen()) { + if (global) { + dumper->Add("declare "); + } else { + dumper->TryDeclareAmbientContext(); + } + } + dumper->Add("function "); + return; + } + + if (Parent() != nullptr && Parent()->IsClassDefinition() && !Parent()->AsClassDefinition()->IsLocal()) { + if (IsPrivate()) { + dumper->Add("private "); + } else if (IsProtected()) { + dumper->Add("protected "); + } else if (IsInternal()) { + dumper->Add("internal "); + } else { + dumper->Add("public "); + } + } + DumpModifierPrefix(dumper); +} + +bool MethodDefinition::FilterForDeclGen() const +{ + if (key_ == nullptr) { + return false; + } + + if (compiler::HasGlobalClassParent(this) && !key_->Parent()->IsExported() && !key_->Parent()->IsDefaultExported()) { + return true; + } + + ES2PANDA_ASSERT(Id() != nullptr); + auto name = Id()->Name().Mutf8(); + if (name.find("%%async") != std::string::npos || name == compiler::Signatures::INITIALIZER_BLOCK_INIT || + name == compiler::Signatures::INIT_METHOD) { + return true; + } + + if (name.rfind('#', 0) == 0) { + return true; + } + + if (name == compiler::Signatures::CCTOR) { + return true; + } + + if (name == compiler::Signatures::GET_INDEX_METHOD || name == compiler::Signatures::SET_INDEX_METHOD) { + return true; + } + + if (IsPrivate() || IsInternal()) { + return true; + } + + return false; +} + +void MethodDefinition::Dump(ir::SrcDumper *dumper) const +{ + if (dumper->IsDeclgen() && FilterForDeclGen()) { + return; + } + + if (compiler::HasGlobalClassParent(this) && Id() != nullptr && Id()->Name().Is(compiler::Signatures::INIT_METHOD)) { + Function()->Body()->Dump(dumper); + return; + } + + auto value = Value(); + if (value->AsFunctionExpression()->Function()->HasAnnotations()) { + for (auto *anno : value->AsFunctionExpression()->Function()->Annotations()) { + // NOTE(zhelyapov): workaround, see #26031 + if (anno->GetBaseName()->Name() != compiler::Signatures::DEFAULT_ANNO_FOR_FUNC) { + anno->Dump(dumper); + } + } + } + + DumpPrefix(dumper); + + if (IsConstructor() && + !(Key()->IsIdentifier() && Key()->AsIdentifier()->Name().Is(compiler::Signatures::CONSTRUCTOR_NAME))) { + dumper->Add(std::string(compiler::Signatures::CONSTRUCTOR_NAME) + " "); + } + + auto key = Key(); + if (key != nullptr) { + key->Dump(dumper); + } + + if (value != nullptr) { + value->Dump(dumper); + } + + for (auto method : Overloads()) { + method->Dump(dumper); + } +} + +void ETSFunctionType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + dumper->Add("(("); + for (auto *param : Params()) { + param->Dump(dumper); + if (param != Params().back()) { + dumper->Add(", "); + } + } + dumper->Add(")"); + + if (TypeParams() != nullptr) { + TypeParams()->Dump(dumper); + } + + if (ReturnType() != nullptr) { + dumper->Add("=> "); + ReturnType()->Dump(dumper); + } + + dumper->Add(")"); +} + +void ETSModule::Dump(ir::SrcDumper *dumper) const +{ + if (IsNamespace()) { + if (IsExported()) { + dumper->Add("export "); + } + + if (IsDefaultExported()) { + dumper->Add("export default "); + } + + if (IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) { + dumper->Add("declare "); + } + + dumper->Add("namespace "); + Ident()->Dump(dumper); + dumper->Add(" {"); + dumper->IncrIndent(); + } + + if (!Statements().empty()) { + dumper->Endl(); + for (auto elem : Statements()) { + elem->Dump(dumper); + if (elem != Statements().back()) { + dumper->Endl(); + } + } + } + if (IsNamespace()) { + dumper->DecrIndent(); + } + dumper->Endl(); + if (IsNamespace()) { + dumper->Add("}"); + } +} + +void ETSNewClassInstanceExpression::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("new "); + if (typeReference_ != nullptr) { + if (typeReference_->IsETSUnionType()) { + dumper->Add("("); + } + typeReference_->Dump(dumper); + if (typeReference_->IsETSUnionType()) { + dumper->Add(")"); + } + } + + dumper->Add("("); + for (auto argument : arguments_) { + argument->Dump(dumper); + if (argument != arguments_.back()) { + dumper->Add(", "); + } + } + dumper->Add(")"); +} + +void ETSParameterExpression::Dump(ir::SrcDumper *const dumper) const +{ + DumpAnnotations(this, dumper); + + if (IsRestParameter()) { + Spread()->Dump(dumper); + } else { + auto const ident = Ident(); + auto const initializer = Initializer(); + if (ident != nullptr) { + ES2PANDA_ASSERT(ident_->IsAnnotatedExpression()); + ident->Dump(dumper); + if (IsOptional() && initializer == nullptr) { + dumper->Add("?"); + } + auto typeAnnotation = ident->AsAnnotatedExpression()->TypeAnnotation(); + if (typeAnnotation != nullptr) { + dumper->Add(": "); + typeAnnotation->Dump(dumper); + } + } + if (initializer != nullptr) { + dumper->Add(" = "); + initializer->Dump(dumper); + } + } +} + +void ETSPrimitiveType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + + switch (GetPrimitiveType()) { + case PrimitiveType::BYTE: + dumper->Add("byte"); + break; + case PrimitiveType::INT: + dumper->Add("int"); + break; + case PrimitiveType::LONG: + dumper->Add("long"); + break; + case PrimitiveType::SHORT: + dumper->Add("short"); + break; + case PrimitiveType::FLOAT: + dumper->Add("float"); + break; + case PrimitiveType::DOUBLE: + dumper->Add("double"); + break; + case PrimitiveType::BOOLEAN: + dumper->Add("boolean"); + break; + case PrimitiveType::CHAR: + dumper->Add("char"); + break; + case PrimitiveType::VOID: + dumper->Add("void"); + break; + default: + ES2PANDA_UNREACHABLE(); + } +} + +void CallExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(callee_); + callee_->Dump(dumper); + if (IsOptional()) { + dumper->Add("?."); + } + + if (typeParams_ != nullptr) { + typeParams_->Dump(dumper); + } + + dumper->Add("("); + for (auto arg : arguments_) { + arg->Dump(dumper); + if (arg != arguments_.back()) { + dumper->Add(", "); + } + } + dumper->Add(")"); + if (trailingLambdaInfo_.block != nullptr) { + if (trailingLambdaInfo_.isBlockInNewLine) { + dumper->Endl(); + } + trailingLambdaInfo_.block->Dump(dumper); + } +} + +void Identifier::Dump(ir::SrcDumper *dumper) const +{ + if (IsReceiver()) { + dumper->Add("this"); + return; + } + + if (IsPrivateIdent()) { + dumper->Add("private "); + } + + auto name = std::string(Name()); + std::string propertyStr = compiler::Signatures::PROPERTY.data(); + if (UNLIKELY(name.find(propertyStr) != std::string::npos)) { + name.replace(name.find(propertyStr), propertyStr.length(), "_$property$_"); + } + dumper->Add(name); + if (IsOptional()) { + dumper->Add("?"); + } + + dumper->PushTask([dumper, name = std::string(name_)] { dumper->DumpNode(name); }); +} + +void MemberExpression::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(object_ != nullptr); + ES2PANDA_ASSERT(property_ != nullptr); + + object_->Dump(dumper); + if (IsOptional()) { + dumper->Add("?"); + if ((MemberExpressionKind::ELEMENT_ACCESS & kind_) != 0U) { + dumper->Add("."); + } + } + if ((MemberExpressionKind::ELEMENT_ACCESS & kind_) != 0U) { + dumper->Add("["); + property_->Dump(dumper); + dumper->Add("]"); + } else { + dumper->Add("."); + property_->Dump(dumper); + } + if ((parent_ != nullptr) && (parent_->IsBlockStatement() || parent_->IsBlockExpression())) { + dumper->Add(";"); + dumper->Endl(); + } +} + +void TemplateLiteral::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("`"); + auto const num = std::max(expressions_.size(), quasis_.size()); + + for (std::size_t i = 0U; i < num; i++) { + if (i < quasis_.size()) { + quasis_[i]->Dump(dumper); + } + if (i < expressions_.size()) { + dumper->Add("${"); + expressions_[i]->Dump(dumper); + dumper->Add("}"); + } + } + dumper->Add("`"); +} + +void NumberLiteral::Dump(ir::SrcDumper *dumper) const +{ + if (std::string(number_.Str()).empty() || (parent_ != nullptr && parent_->IsTSEnumMember())) { + if (number_.IsInt()) { + dumper->Add(number_.GetInt()); + return; + } + + if (number_.IsLong()) { + dumper->Add(number_.GetLong()); + return; + } + + if (number_.IsFloat()) { + dumper->Add(number_.GetFloat()); + return; + } + + if (number_.IsDouble()) { + dumper->Add(number_.GetDouble()); + return; + } + + if (number_.IsShort()) { + dumper->Add(number_.GetShort()); + return; + } + + if (number_.IsByte()) { + dumper->Add(number_.GetByte()); + return; + } + } + dumper->Add(std::string(number_.Str())); +} + +void ExportNamedDeclaration::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("export { "); + for (const auto *spec : specifiers_) { + spec->Dump(dumper); + + if (spec != specifiers_.back()) { + dumper->Add(", "); + } + } + dumper->Add(" }"); +} + +void ExportSpecifier::Dump(ir::SrcDumper *dumper) const +{ + if (GetConstantExpression() != nullptr) { + GetConstantExpression()->Dump(dumper); + dumper->Add("as default"); + return; + } + + exported_->Dump(dumper); + + if (local_ != nullptr) { + dumper->Add(" as "); + local_->Dump(dumper); + } +} + +void ImportDeclaration::Dump(ir::SrcDumper *dumper) const +{ + if (dumper->IsDeclgen()) { + return; + } + dumper->Add("import "); + auto const &specifiers = Specifiers(); + if (specifiers.size() == 1 && + (specifiers[0]->IsImportNamespaceSpecifier() || specifiers[0]->IsImportDefaultSpecifier())) { + specifiers[0]->Dump(dumper); + } else { + dumper->Add("{ "); + for (auto specifier : specifiers) { + specifier->Dump(dumper); + if (specifier != specifiers.back()) { + dumper->Add(", "); + } + } + dumper->Add(" }"); + } + + dumper->Add(" from "); + Source()->Dump(dumper); + dumper->Add(";"); + dumper->Endl(); +} + +void AnnotationUsage::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(expr_ != nullptr); + dumper->Add("@"); + expr_->Dump(dumper); + dumper->Add("("); + + if (!properties_.empty()) { + dumper->Add("{"); + for (auto elem : properties_) { + ES2PANDA_ASSERT(elem->AsClassProperty()->Id() != nullptr); + dumper->Add(elem->AsClassProperty()->Id()->Name().Mutf8()); + dumper->Add(":"); + elem->AsClassProperty()->Value()->Dump(dumper); + if (elem != properties_.back()) { + dumper->Add(","); + } + } + dumper->Add("}"); + } + dumper->Add(") "); +} + +void FunctionDeclaration::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + auto func = Function(); + if (func->IsNative()) { + dumper->Add("native "); + } + if (IsExported()) { + dumper->Add("export "); + } else if (IsDefaultExported()) { + dumper->Add("export default "); + } + if (func->IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) { + dumper->Add("declare "); + } + if (func->IsAsyncFunc()) { + dumper->Add("async "); + } + dumper->Add("function "); + + func->Id()->Dump(dumper); + func->Dump(dumper); +} + +void VariableDeclaration::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + + if (IsDeclare()) { + dumper->Add("declare "); + } + + switch (Kind()) { + case VariableDeclarationKind::CONST: + dumper->Add("const "); + break; + case VariableDeclarationKind::LET: + dumper->Add("let "); + break; + case VariableDeclarationKind::VAR: + dumper->Add("var "); + break; + default: + ES2PANDA_UNREACHABLE(); + } + + for (auto declarator : Declarators()) { + declarator->Dump(dumper); + if (declarator != Declarators().back()) { + dumper->Add(", "); + } + } + + auto const parent = Parent(); + if ((parent != nullptr) && + (parent->IsBlockStatement() || parent->IsBlockExpression() || parent->IsSwitchCaseStatement())) { + dumper->Add(";"); + } +} + +void TSArrayType::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + ES2PANDA_ASSERT(elementType_); + if (elementType_->IsETSUnionType()) { + dumper->Add("("); + } + + elementType_->Dump(dumper); + + if (elementType_->IsETSUnionType()) { + dumper->Add(")"); + } + dumper->Add("[]"); +} + +bool TSInterfaceDeclaration::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const +{ + if (!dumper->IsDeclgen()) { + return false; + } + + if (dumper->IsIndirectDepPhase()) { + return false; + } + + if (id_->Parent()->IsDefaultExported() || id_->Parent()->IsExported()) { + return false; + } + + auto name = id_->Name().Mutf8(); + dumper->AddNode(name, this); + return true; +} + +void TSInterfaceDeclaration::Dump(ir::SrcDumper *dumper) const +{ + ES2PANDA_ASSERT(id_); + if (!id_->Parent()->IsDefaultExported() && !id_->Parent()->IsExported() && dumper->IsDeclgen() && + !dumper->IsIndirectDepPhase()) { + auto name = id_->Name().Mutf8(); + dumper->AddNode(name, this); + return; + } + DumpAnnotations(this, dumper); + if (id_->Parent()->IsExported()) { + dumper->Add("export "); + } else if (id_->Parent()->IsDefaultExported()) { + dumper->Add("export default "); + } + if (dumper->IsDeclgen()) { + dumper->TryDeclareAmbientContext(); + } else if (IsDeclare()) { + dumper->Add("declare "); + } + dumper->Add("interface "); + Id()->Dump(dumper); + + auto const typeParams = TypeParams(); + if (typeParams != nullptr) { + dumper->Add("<"); + typeParams->Dump(dumper); + dumper->Add(">"); + } + + auto const extends = Extends(); + if (!extends.empty()) { + dumper->Add(" extends "); + for (auto ext : extends) { + ext->Dump(dumper); + if (ext != extends.back()) { + dumper->Add(", "); + } + } + } + + auto body = Body(); + dumper->Add(" {"); + if (body != nullptr) { + dumper->IncrIndent(); + dumper->Endl(); + body->Dump(dumper); + dumper->DecrIndent(); + dumper->Endl(); + } + dumper->Add("}"); + dumper->Endl(); +} + +void TSTypeParameter::Dump(ir::SrcDumper *dumper) const +{ + DumpAnnotations(this, dumper); + if (IsIn()) { + dumper->Add("in "); + } + if (IsOut()) { + dumper->Add("out "); + } + + Name()->Dump(dumper); + + if (DefaultType() != nullptr) { + dumper->Add(" = "); + DefaultType()->Dump(dumper); + } + if (Constraint() != nullptr) { + dumper->Add(" extends "); + Constraint()->Dump(dumper); + } +} + +void ETSReExportDeclaration::Dump([[maybe_unused]] ir::SrcDumper *dumper) const +{ + auto importDeclaration = GetETSImportDeclarations(); + const auto &specifiers = importDeclaration->Specifiers(); + dumper->Add("export "); + if (specifiers.size() == 1 && + (specifiers[0]->IsImportNamespaceSpecifier() || specifiers[0]->IsImportDefaultSpecifier())) { + specifiers[0]->Dump(dumper); + } else { + dumper->Add("{ "); + for (auto specifier : specifiers) { + specifier->Dump(dumper); + if (specifier != specifiers.back()) { + dumper->Add(", "); + } + } + dumper->Add(" }"); + } + + dumper->Add(" from "); + importDeclaration->Source()->Dump(dumper); + dumper->Add(";"); + dumper->Endl(); +} + } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/srcDump.h b/ets2panda/ir/srcDump.h index 59bbf15500fd443e843347fe6960dc6f5916a9c5..ac27b3f8cec022b10237b414eefc954bf2daaec7 100644 --- a/ets2panda/ir/srcDump.h +++ b/ets2panda/ir/srcDump.h @@ -16,7 +16,6 @@ #ifndef ES2PANDA_IR_SRCDUMP_H #define ES2PANDA_IR_SRCDUMP_H -#include #include #include "generated/tokenType.h" #include @@ -27,6 +26,8 @@ namespace ark::es2panda::ir { +class AstNode; + // Forward declarations class ClassDefinition; class TSTypeAliasDeclaration; diff --git a/ets2panda/ir/statements/annotationDeclaration.cpp b/ets2panda/ir/statements/annotationDeclaration.cpp index ef585a3083f9345910b0a4cf4add426b94a45760..d68297641af31d0859c24243605580294e60af78 100644 --- a/ets2panda/ir/statements/annotationDeclaration.cpp +++ b/ets2panda/ir/statements/annotationDeclaration.cpp @@ -14,11 +14,11 @@ */ #include "annotationDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" + +#include "ir/ts/tsClassImplements.h" namespace ark::es2panda::ir { @@ -98,60 +98,6 @@ void AnnotationDeclaration::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void AnnotationDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"Expr", Expr()}, {"properties", Properties()}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void AnnotationDeclaration::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - ES2PANDA_ASSERT(Expr() != nullptr); - if (IsExported()) { - dumper->Add("export "); - } - if (IsDeclare() || dumper->IsDeclgen()) { - dumper->Add("declare "); - } - dumper->Add("@interface "); - Expr()->Dump(dumper); - dumper->Add(" {"); - - auto const properties = Properties(); - if (!properties.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - for (auto elem : properties) { - elem->Dump(dumper); - if (elem != properties.back()) { - dumper->Endl(); - } - } - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); -} -void AnnotationDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void AnnotationDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *AnnotationDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType AnnotationDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - Identifier *AnnotationDeclaration::GetBaseName() const { if (Expr()->IsIdentifier()) { diff --git a/ets2panda/ir/statements/annotationUsage.cpp b/ets2panda/ir/statements/annotationUsage.cpp index 2d22aed190e78bad6be6a27631fd2357ed62daaf..424521992e3710c74be9161a7578eab6455282d9 100644 --- a/ets2panda/ir/statements/annotationUsage.cpp +++ b/ets2panda/ir/statements/annotationUsage.cpp @@ -14,9 +14,11 @@ */ #include "annotationUsage.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" + +#include "ir/base/classProperty.h" +#include "ir/expressions/identifier.h" +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" namespace ark::es2panda::ir { void AnnotationUsage::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -44,33 +46,6 @@ void AnnotationUsage::Iterate(const NodeTraverser &cb) const } } -void AnnotationUsage::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"expr_", expr_}, {"properties", properties_}}); -} -void AnnotationUsage::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(expr_ != nullptr); - dumper->Add("@"); - expr_->Dump(dumper); - dumper->Add("("); - - if (!properties_.empty()) { - dumper->Add("{"); - for (auto elem : properties_) { - ES2PANDA_ASSERT(elem->AsClassProperty()->Id() != nullptr); - dumper->Add(elem->AsClassProperty()->Id()->Name().Mutf8()); - dumper->Add(":"); - elem->AsClassProperty()->Value()->Dump(dumper); - if (elem != properties_.back()) { - dumper->Add(","); - } - } - dumper->Add("}"); - } - dumper->Add(") "); -} - AnnotationUsage *AnnotationUsage::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr)->AsExpression() : nullptr; @@ -95,26 +70,6 @@ AnnotationUsage *AnnotationUsage::Clone(ArenaAllocator *const allocator, AstNode return clone; } -void AnnotationUsage::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void AnnotationUsage::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *AnnotationUsage::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType AnnotationUsage::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - Identifier *AnnotationUsage::GetBaseName() const { if (expr_->IsIdentifier()) { diff --git a/ets2panda/ir/statements/assertStatement.cpp b/ets2panda/ir/statements/assertStatement.cpp index dce93e657056b3f381b883d7a8905537143edcf9..8dabb1abc5cc625c7bbc340736084782c2e84c5f 100644 --- a/ets2panda/ir/statements/assertStatement.cpp +++ b/ets2panda/ir/statements/assertStatement.cpp @@ -17,12 +17,7 @@ #include "varbinder/ETSBinder.h" #include "compiler/base/condition.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + #include "ir/expression.h" namespace ark::es2panda::ir { @@ -37,36 +32,6 @@ void AssertStatement::Iterate([[maybe_unused]] const NodeTraverser &cb) const ES2PANDA_UNREACHABLE(); } -void AssertStatement::Dump([[maybe_unused]] ir::AstDumper *dumper) const -{ - ES2PANDA_UNREACHABLE(); -} - -void AssertStatement::Dump([[maybe_unused]] ir::SrcDumper *dumper) const -{ - ES2PANDA_UNREACHABLE(); -} - -void AssertStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void AssertStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *AssertStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType AssertStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - AssertStatement *AssertStatement::Clone([[maybe_unused]] ArenaAllocator *const allocator, [[maybe_unused]] AstNode *const parent) { diff --git a/ets2panda/ir/statements/blockStatement.cpp b/ets2panda/ir/statements/blockStatement.cpp index 63f18d40c1fb67c9337b4669f71f123050166870..395928f029ac98710d5d76d0991841055e4f92a6 100644 --- a/ets2panda/ir/statements/blockStatement.cpp +++ b/ets2panda/ir/statements/blockStatement.cpp @@ -15,14 +15,10 @@ #include "blockStatement.h" -#include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + #include "utils/arena_containers.h" +#include "util/helpers.h" namespace ark::es2panda::ir { void BlockStatement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -64,57 +60,6 @@ void BlockStatement::Iterate(const NodeTraverser &cb) const } } -void BlockStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", IsProgram() ? "Program" : "BlockStatement"}, {"statements", Statements()}}); -} - -void BlockStatement::Dump(ir::SrcDumper *dumper) const -{ - auto const &statements = Statements(); - // NOTE(nsizov): trailing blocks - if (Parent() != nullptr && (Parent()->IsBlockStatement() || Parent()->IsCallExpression())) { - dumper->Add("{"); - if (!statements.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - } - } - for (auto statement : statements) { - statement->Dump(dumper); - if (statement != statements.back()) { - dumper->Endl(); - } - } - if (Parent() != nullptr && (Parent()->IsBlockStatement() || Parent()->IsCallExpression())) { - if (!statements.empty()) { - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); - } -} - -void BlockStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void BlockStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *BlockStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType BlockStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - BlockStatement *BlockStatement::Construct(ArenaAllocator *allocator) { ArenaVector statementList(allocator->Adapter()); diff --git a/ets2panda/ir/statements/breakStatement.cpp b/ets2panda/ir/statements/breakStatement.cpp index afbca163d33206566e70d0df4763dd4b46b38e35..947905a64c58c341f29d7e8a81cb7d8ca0a6ef54 100644 --- a/ets2panda/ir/statements/breakStatement.cpp +++ b/ets2panda/ir/statements/breakStatement.cpp @@ -15,12 +15,9 @@ #include "breakStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/ETSchecker.h" +#include "ir/expressions/identifier.h" + +#include "util/helpers.h" namespace ark::es2panda::ir { void BreakStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -40,41 +37,6 @@ void BreakStatement::Iterate(const NodeTraverser &cb) const } } -void BreakStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "BreakStatement"}, {"label", AstDumper::Nullish(ident_)}}); -} - -void BreakStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("break"); - if (ident_ != nullptr) { - dumper->Add(" "); - ident_->Dump(dumper); - } - dumper->Add(";"); -} - -void BreakStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void BreakStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *BreakStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType BreakStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - BreakStatement *BreakStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const ident = ident_ != nullptr ? ident_->Clone(allocator, nullptr) : nullptr; diff --git a/ets2panda/ir/statements/classDeclaration.cpp b/ets2panda/ir/statements/classDeclaration.cpp index 2eb415d04b30694f9532d025ee3cc46a6dba2942..7d3d3d75206e8d80886328cf3009bb149c37ef63 100644 --- a/ets2panda/ir/statements/classDeclaration.cpp +++ b/ets2panda/ir/statements/classDeclaration.cpp @@ -15,11 +15,8 @@ #include "classDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/base/classDefinition.h" + #include namespace ark::es2panda::ir { @@ -58,35 +55,4 @@ void ClassDeclaration::Iterate(const NodeTraverser &cb) const cb(def); } -void ClassDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ClassDeclaration"}, {"definition", Definition()}}); -} - -void ClassDeclaration::Dump(ir::SrcDumper *dumper) const -{ - if (Definition() != nullptr) { - Definition()->Dump(dumper); - } -} - -void ClassDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ClassDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ClassDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ClassDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/continueStatement.cpp b/ets2panda/ir/statements/continueStatement.cpp index ab35d97e73d831665c191f4fa47d44d332fa3222..b860800ebcbe1c8296d9c399f79954c25c6110aa 100644 --- a/ets2panda/ir/statements/continueStatement.cpp +++ b/ets2panda/ir/statements/continueStatement.cpp @@ -15,11 +15,7 @@ #include "continueStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "util/helpers.h" namespace ark::es2panda::ir { void ContinueStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -39,41 +35,6 @@ void ContinueStatement::Iterate(const NodeTraverser &cb) const } } -void ContinueStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullish(ident_)}}); -} - -void ContinueStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("continue"); - if (Ident() != nullptr) { - dumper->Add(" "); - Ident()->Dump(dumper); - } - dumper->Add(";"); -} - -void ContinueStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ContinueStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ContinueStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ContinueStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ContinueStatement *ContinueStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const ident = ident_ != nullptr ? ident_->Clone(allocator, nullptr) : nullptr; diff --git a/ets2panda/ir/statements/debuggerStatement.cpp b/ets2panda/ir/statements/debuggerStatement.cpp index fa84ad325d541455339e0c7b004ab7ee40919f14..56a8094f2bc78fff646f4dd4c1704cef433490d2 100644 --- a/ets2panda/ir/statements/debuggerStatement.cpp +++ b/ets2panda/ir/statements/debuggerStatement.cpp @@ -15,12 +15,6 @@ #include "debuggerStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void DebuggerStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -29,33 +23,4 @@ void DebuggerStatement::TransformChildren([[maybe_unused]] const NodeTransformer void DebuggerStatement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void DebuggerStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "DebuggerStatement"}}); -} - -void DebuggerStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("DebuggerStatement"); -} - -void DebuggerStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void DebuggerStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *DebuggerStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType DebuggerStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/doWhileStatement.cpp b/ets2panda/ir/statements/doWhileStatement.cpp index 58e70f28f5e02b7c4451ebc2e36d8f0c09376e1c..bd4968a135fb95bcd62a4cd8d156ff032ef00519 100644 --- a/ets2panda/ir/statements/doWhileStatement.cpp +++ b/ets2panda/ir/statements/doWhileStatement.cpp @@ -19,11 +19,8 @@ #include "varbinder/scope.h" #include "compiler/base/condition.h" #include "compiler/core/labelTarget.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "util/helpers.h" namespace ark::es2panda::ir { void DoWhileStatement::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -45,49 +42,6 @@ void DoWhileStatement::Iterate(const NodeTraverser &cb) const cb(test_); } -void DoWhileStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "DoWhileStatement"}, {"body", body_}, {"test", test_}}); -} - -void DoWhileStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("do {"); - if (body_ != nullptr) { - dumper->IncrIndent(); - dumper->Endl(); - body_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("} while"); - dumper->Add("("); - if (test_ != nullptr) { - test_->Dump(dumper); - } - dumper->Add(")"); -} - -void DoWhileStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void DoWhileStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *DoWhileStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType DoWhileStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - DoWhileStatement *DoWhileStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const body = body_->Clone(allocator, nullptr)->AsStatement(); diff --git a/ets2panda/ir/statements/emptyStatement.cpp b/ets2panda/ir/statements/emptyStatement.cpp index e7e6c976b12d586f428dc8c548537b5bfa2ee57b..42abcedf17a8a8fcc01f55e1ee6b6cb936f2ed73 100644 --- a/ets2panda/ir/statements/emptyStatement.cpp +++ b/ets2panda/ir/statements/emptyStatement.cpp @@ -15,12 +15,6 @@ #include "emptyStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void EmptyStatement::TransformChildren([[maybe_unused]] const NodeTransformer &c, [[maybe_unused]] std::string_view const transformationName) @@ -29,41 +23,11 @@ void EmptyStatement::TransformChildren([[maybe_unused]] const NodeTransformer &c void EmptyStatement::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} -void EmptyStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "EmptyStatement"}}); -} - -void EmptyStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add(""); -} - -void EmptyStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void EmptyStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - bool EmptyStatement::IsBrokenStatement() { return isBrokenStatement_; } -checker::Type *EmptyStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType EmptyStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - [[nodiscard]] EmptyStatement *EmptyStatement::Clone(ArenaAllocator *allocator, AstNode *parent) { EmptyStatement *stmt = allocator->New(IsBrokenStatement()); diff --git a/ets2panda/ir/statements/expressionStatement.cpp b/ets2panda/ir/statements/expressionStatement.cpp index 58cbd0e3d196802c536110aac8c7b3630436d38a..a1ba61883fef6f4ea14c7e5998425c681378dbf1 100644 --- a/ets2panda/ir/statements/expressionStatement.cpp +++ b/ets2panda/ir/statements/expressionStatement.cpp @@ -15,10 +15,6 @@ #include "expressionStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void ExpressionStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -33,20 +29,6 @@ void ExpressionStatement::Iterate(const NodeTraverser &cb) const cb(expression_); } -void ExpressionStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ExpressionStatement"}, {"expression", expression_}}); -} - -void ExpressionStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(expression_ != nullptr); - expression_->Dump(dumper); - if ((parent_ != nullptr) && (parent_->IsBlockStatement() || parent_->IsSwitchCaseStatement())) { - dumper->Add(";"); - } -} - ExpressionStatement *ExpressionStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expression = expression_->Clone(allocator, nullptr)->AsExpression(); @@ -59,23 +41,4 @@ ExpressionStatement *ExpressionStatement::Clone(ArenaAllocator *const allocator, return clone; } -void ExpressionStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ExpressionStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ExpressionStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ExpressionStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/forInStatement.cpp b/ets2panda/ir/statements/forInStatement.cpp index 9436f75696f297a3a274ff248d40a1d1eaefdadc..0f6c55365f04b6a0c1d36d58e29be5cd433f84b7 100644 --- a/ets2panda/ir/statements/forInStatement.cpp +++ b/ets2panda/ir/statements/forInStatement.cpp @@ -18,11 +18,8 @@ #include "varbinder/scope.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" -#include "compiler/core/pandagen.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "util/helpers.h" namespace ark::es2panda::ir { void ForInStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -50,36 +47,6 @@ void ForInStatement::Iterate(const NodeTraverser &cb) const cb(body_); } -void ForInStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ForInStatement"}, {"left", left_}, {"right", right_}, {"body", body_}}); -} - -void ForInStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("ForInStatement"); -} - -void ForInStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ForInStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ForInStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ForInStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ForInStatement *ForInStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const left = left_->Clone(allocator, nullptr); diff --git a/ets2panda/ir/statements/forOfStatement.cpp b/ets2panda/ir/statements/forOfStatement.cpp index 62926980918b34847ac6a00cbb06d82a2c11a60a..c4e70f63bebbec38fdc767b3aaf311e4545ff652 100644 --- a/ets2panda/ir/statements/forOfStatement.cpp +++ b/ets2panda/ir/statements/forOfStatement.cpp @@ -15,9 +15,10 @@ #include "forOfStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" +#include "checker/ETSchecker.h" +#include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsUnionType.h" namespace ark::es2panda::ir { @@ -66,54 +67,6 @@ void ForOfStatement::Iterate(const NodeTraverser &cb) const cb(body_); } -void ForOfStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ForOfStatement"}, {"await", isAwait_}, {"left", left_}, {"right", right_}, {"body", body_}}); -} - -void ForOfStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(left_ != nullptr); - ES2PANDA_ASSERT(right_ != nullptr); - dumper->Add("for "); - if (isAwait_) { - dumper->Add("await "); - } - dumper->Add("("); - left_->Dump(dumper); - dumper->Add(" of "); - right_->Dump(dumper); - dumper->Add(") {"); - if (body_ != nullptr) { - dumper->IncrIndent(); - dumper->Endl(); - body_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); -} - -void ForOfStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ForOfStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ForOfStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ForOfStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ForOfStatement *ForOfStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr) : nullptr; diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index cd0d2d53170af2dffb4c3e54d27d413d90e2b4de..cdb1d75d31a02d770e07c141057a17df6a4b2bf5 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -18,11 +18,8 @@ #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "util/helpers.h" namespace ark::es2panda::ir { void ForUpdateStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -69,62 +66,6 @@ void ForUpdateStatement::Iterate(const NodeTraverser &cb) const cb(body_); } -void ForUpdateStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ForUpdateStatement"}, - {"init", AstDumper::Nullish(init_)}, - {"test", AstDumper::Nullish(test_)}, - {"update", AstDumper::Nullish(update_)}, - {"body", body_}}); -} - -void ForUpdateStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("for "); - dumper->Add("("); - if (init_ != nullptr) { - init_->Dump(dumper); - } - dumper->Add(";"); - if (test_ != nullptr) { - test_->Dump(dumper); - } - dumper->Add(";"); - if (update_ != nullptr) { - update_->Dump(dumper); - } - dumper->Add(") "); - dumper->Add("{"); - if (body_ != nullptr) { - dumper->IncrIndent(); - dumper->Endl(); - body_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); -} - -void ForUpdateStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ForUpdateStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ForUpdateStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ForUpdateStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ForUpdateStatement *ForUpdateStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ir::AstNode *init = nullptr; diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index a677ab50352d15278caa0e5fe02b578eca1a56cb..1bc214ea0f63b971740ea602eab8092b3c8b1775 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -16,11 +16,6 @@ #include "functionDeclaration.h" #include "varbinder/variable.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "compiler/core/pandagen.h" namespace ark::es2panda::ir { @@ -48,57 +43,6 @@ void FunctionDeclaration::Iterate(const NodeTraverser &cb) const cb(func); } -void FunctionDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", Function()->IsOverload() ? "TSDeclareFunction" : "FunctionDeclaration"}, - {"annotations", AstDumper::Optional(Annotations())}, - {"function", Function()}}); -} - -void FunctionDeclaration::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - auto func = Function(); - if (func->IsNative()) { - dumper->Add("native "); - } - if (IsExported()) { - dumper->Add("export "); - } else if (IsDefaultExported()) { - dumper->Add("export default "); - } - if (func->IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) { - dumper->Add("declare "); - } - if (func->IsAsyncFunc()) { - dumper->Add("async "); - } - dumper->Add("function "); - - func->Id()->Dump(dumper); - func->Dump(dumper); -} - -void FunctionDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void FunctionDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *FunctionDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType FunctionDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - FunctionDeclaration *FunctionDeclaration::Construct(ArenaAllocator *allocator) { return allocator->New(allocator, nullptr); diff --git a/ets2panda/ir/statements/ifStatement.cpp b/ets2panda/ir/statements/ifStatement.cpp index 9b50804416cb282c0d6936ae812cba59b0a9ac60..5c3a2404ce3b19a4c91d3e1381fc9a9d79dd36f3 100644 --- a/ets2panda/ir/statements/ifStatement.cpp +++ b/ets2panda/ir/statements/ifStatement.cpp @@ -15,11 +15,11 @@ #include "ifStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "util/helpers.h" +#include "ir/expression.h" namespace ark::es2panda::ir { + void IfStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (auto *transformedNode = cb(test_); test_ != transformedNode) { @@ -50,58 +50,6 @@ void IfStatement::Iterate(const NodeTraverser &cb) const } } -void IfStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "IfStatement"}, - {"test", test_}, - {"consequent", consequent_}, - {"alternate", AstDumper::Nullish(alternate_)}}); -} - -void IfStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(test_); - ES2PANDA_ASSERT(consequent_ != nullptr); - dumper->Add("if ("); - test_->Dump(dumper); - dumper->Add(") {"); - dumper->IncrIndent(); - dumper->Endl(); - consequent_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); - if (alternate_ != nullptr) { - dumper->Add(" else {"); - dumper->IncrIndent(); - dumper->Endl(); - alternate_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); - } -} - -void IfStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void IfStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *IfStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType IfStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - IfStatement *IfStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/statements/labelledStatement.cpp b/ets2panda/ir/statements/labelledStatement.cpp index 0a4f1c2b7fe207b863aa7751fe1b0261b23a880a..8191dc3a5dc85c8cd2d901fb641dab06660fafd3 100644 --- a/ets2panda/ir/statements/labelledStatement.cpp +++ b/ets2panda/ir/statements/labelledStatement.cpp @@ -15,11 +15,9 @@ #include "labelledStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" + +#include "util/helpers.h" namespace ark::es2panda::ir { void LabelledStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -41,20 +39,6 @@ void LabelledStatement::Iterate(const NodeTraverser &cb) const cb(body_); } -void LabelledStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "LabelledStatement"}, {"label", ident_}, {"body", body_}}); -} - -void LabelledStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(ident_ != nullptr); - ident_->Dump(dumper); - dumper->Add(":"); - dumper->Endl(); - body_->Dump(dumper); -} - const ir::AstNode *LabelledStatement::GetReferencedStatement() const { const auto *iter = body_; @@ -76,26 +60,6 @@ const ir::AstNode *LabelledStatement::GetReferencedStatement() const } } -void LabelledStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void LabelledStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *LabelledStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType LabelledStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - LabelledStatement *LabelledStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const ident = ident_->Clone(allocator, nullptr); diff --git a/ets2panda/ir/statements/loopStatement.cpp b/ets2panda/ir/statements/loopStatement.cpp index 1396aa3bec52ebda32d2c9fb22fb1b7673634b10..31db45e258f7252dc2fc0fd3f517e7fa68c71b0b 100644 --- a/ets2panda/ir/statements/loopStatement.cpp +++ b/ets2panda/ir/statements/loopStatement.cpp @@ -19,9 +19,4 @@ #include "checker/checker.h" namespace ark::es2panda::ir { -checker::VerifiedType LoopStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - ES2PANDA_UNREACHABLE(); - return {this, nullptr}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/returnStatement.cpp b/ets2panda/ir/statements/returnStatement.cpp index a14d55209022265152bc5a14a5507f8b11834a97..872a20d6c5e86a6b5b86c63bc598789dd5bd24fd 100644 --- a/ets2panda/ir/statements/returnStatement.cpp +++ b/ets2panda/ir/statements/returnStatement.cpp @@ -15,11 +15,9 @@ #include "returnStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "checker/ETSchecker.h" + +#include "ir/base/scriptFunction.h" namespace ark::es2panda::ir { void ReturnStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -39,41 +37,6 @@ void ReturnStatement::Iterate(const NodeTraverser &cb) const } } -void ReturnStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ReturnStatement"}, {"argument", AstDumper::Nullish(argument_)}}); -} - -void ReturnStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("return"); - if (argument_ != nullptr) { - dumper->Add(" "); - argument_->Dump(dumper); - } - dumper->Add(";"); -} - -void ReturnStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ReturnStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ReturnStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ReturnStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - void ReturnStatement::SetReturnType(checker::ETSChecker *checker, checker::Type *type) { returnType_ = type; diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index 07d1b0d3af4807667dd2e7a6ddbb09ea57b7d4c6..b6c607e477893170f143209347b7a62d6a899aff 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -15,12 +15,7 @@ #include "switchCaseStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "checker/ets/typeRelationContext.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" namespace ark::es2panda::ir { void SwitchCaseStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -51,56 +46,6 @@ void SwitchCaseStatement::Iterate(const NodeTraverser &cb) const } } -void SwitchCaseStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"consequent", consequent_}}); -} - -void SwitchCaseStatement::Dump(ir::SrcDumper *dumper) const -{ - if (test_ != nullptr) { - dumper->Add("case "); - test_->Dump(dumper); - dumper->Add(":"); - } else { - dumper->Add("default:"); - } - if (!consequent_.empty()) { - dumper->Add(" {"); - dumper->IncrIndent(); - dumper->Endl(); - for (auto cs : consequent_) { - cs->Dump(dumper); - if (!cs->IsBlockStatement() && cs != consequent_.back()) { - dumper->Endl(); - } - } - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); - } -} - -void SwitchCaseStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void SwitchCaseStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *SwitchCaseStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType SwitchCaseStatement::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - // Auxilary function extracted from the 'Check' method for 'SwitchStatement' to reduce function's size. void SwitchCaseStatement::CheckAndTestCase(checker::ETSChecker *checker, checker::Type *comparedExprType, checker::Type *unboxedDiscType, ir::Expression *node, bool &isDefaultCase) diff --git a/ets2panda/ir/statements/switchStatement.cpp b/ets2panda/ir/statements/switchStatement.cpp index c9bc019eaa8c7d9dbc23c9bbe73a1b066254c22e..f52c41119c263f4b8b15b848149beb9f4701dfae 100644 --- a/ets2panda/ir/statements/switchStatement.cpp +++ b/ets2panda/ir/statements/switchStatement.cpp @@ -14,12 +14,9 @@ */ #include "switchStatement.h" +#include "ir/statements/switchCaseStatement.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "util/helpers.h" namespace ark::es2panda::ir { void SwitchStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -46,51 +43,6 @@ void SwitchStatement::Iterate(const NodeTraverser &cb) const } } -void SwitchStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "SwitchStatement"}, {"discriminant", discriminant_}, {"cases", cases_}}); -} - -void SwitchStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(discriminant_); - dumper->Add("switch ("); - discriminant_->Dump(dumper); - dumper->Add(") {"); - if (!cases_.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - for (auto cs : cases_) { - cs->Dump(dumper); - if (cs == cases_.back()) { - dumper->DecrIndent(); - } - dumper->Endl(); - } - } - dumper->Add("}"); -} - -void SwitchStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void SwitchStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *SwitchStatement::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType SwitchStatement::Check(checker::ETSChecker *const checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - SwitchStatement *SwitchStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const discriminant = discriminant_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/statements/throwStatement.cpp b/ets2panda/ir/statements/throwStatement.cpp index ee2f446c43799716cd4b22ec33d4e5abe8fd90c4..5a7554ea7fd8827b906f1b52b9616e44bf62d122 100644 --- a/ets2panda/ir/statements/throwStatement.cpp +++ b/ets2panda/ir/statements/throwStatement.cpp @@ -15,9 +15,7 @@ #include "throwStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" +#include "ir/expression.h" namespace ark::es2panda::ir { void ThrowStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -33,39 +31,6 @@ void ThrowStatement::Iterate(const NodeTraverser &cb) const cb(argument_); } -void ThrowStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "ThrowStatement"}, {"argument", argument_}}); -} - -void ThrowStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(Argument() != nullptr); - dumper->Add("throw "); - Argument()->Dump(dumper); - dumper->Add(";"); -} - -void ThrowStatement::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void ThrowStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *ThrowStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType ThrowStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - ThrowStatement *ThrowStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expression = argument_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/statements/tryStatement.cpp b/ets2panda/ir/statements/tryStatement.cpp index acc5b4d085afe04bd1a49cb404958b038ad7b90d..d4ee0622cce751d373ce3ab758592fc411f97826 100644 --- a/ets2panda/ir/statements/tryStatement.cpp +++ b/ets2panda/ir/statements/tryStatement.cpp @@ -15,13 +15,9 @@ #include "tryStatement.h" -#include "checker/TSchecker.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "compiler/core/dynamicContext.h" #include "compiler/base/catchTable.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + #include "ir/base/catchClause.h" #include "ir/statements/blockStatement.h" @@ -61,64 +57,11 @@ void TryStatement::Iterate(const NodeTraverser &cb) const } } -void TryStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TryStatement"}, - {"block", block_}, - {"handler", catchClauses_}, - {"finalizer", AstDumper::Nullish(finalizer_)}}); -} - -void TryStatement::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(block_ != nullptr); - dumper->Add("try {"); - dumper->IncrIndent(); - dumper->Endl(); - block_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); - for (auto clause : catchClauses_) { - dumper->Add(" catch "); - clause->Dump(dumper); - } - if (finalizer_ != nullptr) { - dumper->Add(" finally {"); - dumper->IncrIndent(); - dumper->Endl(); - finalizer_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - dumper->Add("}"); - } -} - bool TryStatement::HasDefaultCatchClause() const { return (!catchClauses_.empty() && catchClauses_.back()->IsDefaultCatchClause()); } -void TryStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TryStatement::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TryStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TryStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TryStatement::TryStatement(TryStatement const &other, ArenaAllocator *allocator) : Statement(other), catchClauses_(allocator->Adapter()), diff --git a/ets2panda/ir/statements/variableDeclaration.cpp b/ets2panda/ir/statements/variableDeclaration.cpp index ad2bc7f2e98675139f9b8dd8ddb0eff7684cbf0b..eef103056280e772a415c1ed014570e6bd7d9a28 100644 --- a/ets2panda/ir/statements/variableDeclaration.cpp +++ b/ets2panda/ir/statements/variableDeclaration.cpp @@ -15,10 +15,6 @@ #include "variableDeclaration.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "utils/arena_containers.h" namespace ark::es2panda::ir { @@ -77,71 +73,6 @@ void VariableDeclaration::Iterate(const NodeTraverser &cb) const } } -void VariableDeclaration::Dump(ir::AstDumper *dumper) const -{ - const char *kind = nullptr; - - switch (Kind()) { - case VariableDeclarationKind::CONST: { - kind = "const"; - break; - } - case VariableDeclarationKind::LET: { - kind = "let"; - break; - } - case VariableDeclarationKind::VAR: { - kind = "var"; - break; - } - default: { - ES2PANDA_UNREACHABLE(); - } - } - - dumper->Add({{"type", "VariableDeclaration"}, - {"declarations", Declarators()}, - {"kind", kind}, - {"annotations", AstDumper::Optional(Annotations())}, - {"declare", AstDumper::Optional(IsDeclare())}}); -} - -void VariableDeclaration::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - - if (IsDeclare()) { - dumper->Add("declare "); - } - - switch (Kind()) { - case VariableDeclarationKind::CONST: - dumper->Add("const "); - break; - case VariableDeclarationKind::LET: - dumper->Add("let "); - break; - case VariableDeclarationKind::VAR: - dumper->Add("var "); - break; - default: - ES2PANDA_UNREACHABLE(); - } - - for (auto declarator : Declarators()) { - declarator->Dump(dumper); - if (declarator != Declarators().back()) { - dumper->Add(", "); - } - } - - auto const parent = Parent(); - if ((parent != nullptr) && - (parent->IsBlockStatement() || parent->IsBlockExpression() || parent->IsSwitchCaseStatement())) { - dumper->Add(";"); - } -} - VariableDeclaration::VariableDeclaration([[maybe_unused]] Tag const tag, VariableDeclaration const &other, ArenaAllocator *const allocator) : AnnotationAllowed(static_cast const &>(other)), @@ -193,26 +124,6 @@ VariableDeclaration *VariableDeclaration::Clone(ArenaAllocator *const allocator, return clone; } -void VariableDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void VariableDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *VariableDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType VariableDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - VariableDeclaration *VariableDeclaration::Construct(ArenaAllocator *allocator) { ArenaVector declarators(allocator->Adapter()); diff --git a/ets2panda/ir/statements/variableDeclarator.cpp b/ets2panda/ir/statements/variableDeclarator.cpp index 621d394dbddd3a6456ace50782677fe4aeaa4011..19a7a6b59c5d9bc12b35bcf32cb63622b88ae393 100644 --- a/ets2panda/ir/statements/variableDeclarator.cpp +++ b/ets2panda/ir/statements/variableDeclarator.cpp @@ -15,10 +15,7 @@ #include "variableDeclarator.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void VariableDeclarator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -45,32 +42,6 @@ void VariableDeclarator::Iterate(const NodeTraverser &cb) const } } -void VariableDeclarator::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "VariableDeclarator"}, {"id", id_}, {"init", AstDumper::Nullish(init_)}}); -} - -void VariableDeclarator::Dump(ir::SrcDumper *dumper) const -{ - if (id_ != nullptr) { - id_->Dump(dumper); - if (id_->IsOptionalDeclaration()) { - dumper->Add("?"); - } - if (id_->IsAnnotatedExpression()) { - auto *type = id_->AsAnnotatedExpression()->TypeAnnotation(); - if (type != nullptr) { - dumper->Add(": "); - type->Dump(dumper); - } - } - } - if (init_ != nullptr) { - dumper->Add(" = "); - init_->Dump(dumper); - } -} - VariableDeclarator *VariableDeclarator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const id = id_ != nullptr ? id_->Clone(allocator, nullptr)->AsExpression() : nullptr; @@ -94,23 +65,4 @@ VariableDeclarator *VariableDeclarator::Clone(ArenaAllocator *const allocator, A return clone; } -void VariableDeclarator::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void VariableDeclarator::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *VariableDeclarator::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType VariableDeclarator::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/statements/whileStatement.cpp b/ets2panda/ir/statements/whileStatement.cpp index 5bdc886393ced88805b5fd6d7e863bba745f40a8..fa630082f38d820b9cca075365b9041bbca082c4 100644 --- a/ets2panda/ir/statements/whileStatement.cpp +++ b/ets2panda/ir/statements/whileStatement.cpp @@ -17,14 +17,13 @@ #include "compiler/base/condition.h" #include "compiler/core/labelTarget.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" + #include "compiler/core/regScope.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + #include "ir/expression.h" +#include "util/helpers.h" + namespace ark::es2panda::ir { void WhileStatement::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -45,48 +44,6 @@ void WhileStatement::Iterate(const NodeTraverser &cb) const cb(body_); } -void WhileStatement::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "WhileStatement"}, {"test", test_}, {"body", body_}}); -} - -void WhileStatement::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("while ("); - if (test_ != nullptr) { - test_->Dump(dumper); - } - dumper->Add(") {"); - if (body_ != nullptr) { - dumper->IncrIndent(); - dumper->Endl(); - body_->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); -} - -void WhileStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void WhileStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *WhileStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType WhileStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - WhileStatement *WhileStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/ts/tsAnyKeyword.cpp b/ets2panda/ir/ts/tsAnyKeyword.cpp index d2e6f0505768208bc9363d79ce3b6581c1c4f9d5..4c85c469cf7e25ce7d459c3dbf4910f45eb0b3dc 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.cpp +++ b/ets2panda/ir/ts/tsAnyKeyword.cpp @@ -15,12 +15,6 @@ #include "tsAnyKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSAnyKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,39 +27,4 @@ void TSAnyKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSAnyKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSAnyKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSAnyKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSAnyKeyword"); -} - -void TSAnyKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSAnyKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSAnyKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSAnyKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalAnyType(); -} - -checker::VerifiedType TSAnyKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsArrayType.cpp b/ets2panda/ir/ts/tsArrayType.cpp index 970e2762306f8b11ff8a5db72ff2fd899a8a96d8..ba261fac4c23055a82c0246fd7dc4a63f3cf273f 100644 --- a/ets2panda/ir/ts/tsArrayType.cpp +++ b/ets2panda/ir/ts/tsArrayType.cpp @@ -15,11 +15,6 @@ #include "tsArrayType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" - namespace ark::es2panda::ir { void TSArrayType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -37,62 +32,6 @@ void TSArrayType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSArrayType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSArrayType"}, {"elementType", elementType_}, {"annotations", Annotations()}}); -} - -void TSArrayType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - ES2PANDA_ASSERT(elementType_); - if (elementType_->IsETSUnionType()) { - dumper->Add("("); - } - - elementType_->Dump(dumper); - - if (elementType_->IsETSUnionType()) { - dumper->Add(")"); - } - dumper->Add("[]"); -} - -void TSArrayType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSArrayType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSArrayType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSArrayType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->Allocator()->New(elementType_->GetType(checker)); -} - -checker::VerifiedType TSArrayType::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *TSArrayType::GetType(checker::ETSChecker *checker) -{ - checker::Type *type = checker->CreateETSArrayType(elementType_->GetType(checker), IsReadonlyType()); - if (IsReadonlyType()) { - type = checker->GetReadonlyType(type); - } - SetTsType(type); - return type; -} - TSArrayType *TSArrayType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator, nullptr) : nullptr; diff --git a/ets2panda/ir/ts/tsAsExpression.cpp b/ets2panda/ir/ts/tsAsExpression.cpp index 90f1c4efca62ac78f03fd0faadde2c6154d6b020..fa7c9cbe826ce18a14a858d9cc6a77bd019e2884 100644 --- a/ets2panda/ir/ts/tsAsExpression.cpp +++ b/ets2panda/ir/ts/tsAsExpression.cpp @@ -15,10 +15,9 @@ #include "tsAsExpression.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/typeNode.h" + +#include "parser/program/program.h" namespace ark::es2panda::ir { Expression *TSAsExpression::Expr() noexcept @@ -56,40 +55,6 @@ void TSAsExpression::Iterate(const NodeTraverser &cb) const cb(TypeAnnotation()); } -void TSAsExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSAsExpression"}, {"expression", expression_}, {"typeAnnotation", TypeAnnotation()}}); -} - -void TSAsExpression::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("("); - expression_->Dump(dumper); - dumper->Add(" as "); - TypeAnnotation()->Dump(dumper); - dumper->Add(")"); -} - -void TSAsExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSAsExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSAsExpression::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSAsExpression::Check(checker::ETSChecker *const checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSAsExpression *TSAsExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expression = expression_ != nullptr ? expression_->Clone(allocator, nullptr)->AsExpression() : nullptr; diff --git a/ets2panda/ir/ts/tsAsExpression.h b/ets2panda/ir/ts/tsAsExpression.h index fe62b1594e6f713724bc0b49a24270b0070dc7cd..15c38f4e5ad577672dbfb70f21f9d66246dad82e 100644 --- a/ets2panda/ir/ts/tsAsExpression.h +++ b/ets2panda/ir/ts/tsAsExpression.h @@ -16,8 +16,6 @@ #ifndef ES2PANDA_IR_TS_AS_EXPRESSION_H #define ES2PANDA_IR_TS_AS_EXPRESSION_H -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/expression.h" namespace ark::es2panda::checker { class ETSAnalyzer; diff --git a/ets2panda/ir/ts/tsBigintKeyword.cpp b/ets2panda/ir/ts/tsBigintKeyword.cpp index ce2950480b50f8ec8641043b293d2b4902890b00..f2b29dd423ac3a8969267f07d171bd81c3178ebf 100644 --- a/ets2panda/ir/ts/tsBigintKeyword.cpp +++ b/ets2panda/ir/ts/tsBigintKeyword.cpp @@ -15,13 +15,6 @@ #include "tsBigintKeyword.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSBigintKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -34,38 +27,4 @@ void TSBigintKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSBigintKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSBigIntKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSBigintKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSBigintKeyword"); -} - -void TSBigintKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSBigintKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSBigintKeyword::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSBigintKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalBigintType(); -} - -checker::VerifiedType TSBigintKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsBooleanKeyword.cpp b/ets2panda/ir/ts/tsBooleanKeyword.cpp index 62244a79bb2ae5e4108c434048849279cffb2a6f..22359c71bca376d746f35e7fe11c3cf638808b62 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.cpp +++ b/ets2panda/ir/ts/tsBooleanKeyword.cpp @@ -15,12 +15,6 @@ #include "tsBooleanKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSBooleanKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,42 +27,6 @@ void TSBooleanKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSBooleanKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSBooleanKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSBooleanKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSBooleanKeyword"); -} - -void TSBooleanKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSBooleanKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSBooleanKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSBooleanKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalBooleanType(); -} - -checker::VerifiedType TSBooleanKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSBooleanKeyword *TSBooleanKeyword::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clone = allocator->New(allocator); diff --git a/ets2panda/ir/ts/tsClassImplements.cpp b/ets2panda/ir/ts/tsClassImplements.cpp index dfe2da11dfcbe9f307f31a704ca4c1adc08c5277..5a87db0c15ccc310d4def251796e13352ac64576 100644 --- a/ets2panda/ir/ts/tsClassImplements.cpp +++ b/ets2panda/ir/ts/tsClassImplements.cpp @@ -15,11 +15,6 @@ #include "tsClassImplements.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/ts/tsTypeParameter.h" #include "ir/ts/tsTypeParameterInstantiation.h" @@ -41,36 +36,4 @@ void TSClassImplements::Iterate(const NodeTraverser &cb) const } } -void TSClassImplements::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSClassImplements"}, - {"expression", expression_}, - {"typeParameters", AstDumper::Optional(typeParameters_)}}); -} - -void TSClassImplements::Dump(ir::SrcDumper *dumper) const -{ - expression_->Dump(dumper); - ES2PANDA_ASSERT(typeParameters_ == nullptr); -} - -void TSClassImplements::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSClassImplements::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSClassImplements::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSClassImplements::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsConditionalType.cpp b/ets2panda/ir/ts/tsConditionalType.cpp index 4e5e61df5205f7cf4bd5083d3c4325caff33a468..c7344ede6813af1be50785d58f733a5f157a5a21 100644 --- a/ets2panda/ir/ts/tsConditionalType.cpp +++ b/ets2panda/ir/ts/tsConditionalType.cpp @@ -15,12 +15,6 @@ #include "tsConditionalType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSConditionalType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -56,43 +50,4 @@ void TSConditionalType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSConditionalType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSConditionalType"}, - {"checkType", checkType_}, - {"extendsType", extendsType_}, - {"trueType", trueType_}, - {"falseType", falseType_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSConditionalType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSConditionalType"); -} - -void TSConditionalType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSConditionalType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSConditionalType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSConditionalType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSConditionalType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsConditionalType.h b/ets2panda/ir/ts/tsConditionalType.h index 0750383584e62b122b019ba08474b4f3e94321d7..aee95878e4a67de88cad4cc7f633f1025b94ab5f 100644 --- a/ets2panda/ir/ts/tsConditionalType.h +++ b/ets2panda/ir/ts/tsConditionalType.h @@ -58,7 +58,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; void Accept(ASTVisitorT *v) override diff --git a/ets2panda/ir/ts/tsConstructorType.cpp b/ets2panda/ir/ts/tsConstructorType.cpp index 0320d2f8c87a28c3f10d8ab16002b42717bde9a5..203c8c786631167f73d7651a125543e3a23293aa 100644 --- a/ets2panda/ir/ts/tsConstructorType.cpp +++ b/ets2panda/ir/ts/tsConstructorType.cpp @@ -15,12 +15,7 @@ #include "tsConstructorType.h" -#include "checker/TSchecker.h" #include "checker/types/signature.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" namespace ark::es2panda::ir { void TSConstructorType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -35,43 +30,4 @@ void TSConstructorType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSConstructorType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSConstructorType"}, - {"params", signature_.Params()}, - {"typeParameters", AstDumper::Optional(signature_.TypeParams())}, - {"returnType", signature_.ReturnType()}, - {"abstract", AstDumper::Optional(abstract_)}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSConstructorType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSConstructorType"); -} - -void TSConstructorType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSConstructorType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSConstructorType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSConstructorType::GetType(checker::TSChecker *checker) -{ - return checker->CheckTypeCached(this); -} - -checker::VerifiedType TSConstructorType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index 453a98a8b3de645d64d9a26c9b093bf4943381dc..04ebb5ba4323ce73d54ecae529d95eb7e9d07d2c 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -16,12 +16,11 @@ #include "tsEnumDeclaration.h" #include -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "util/helpers.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/memberExpression.h" +#include "ir/expressions/literals/stringLiteral.h" + #include "utils/arena_containers.h" namespace ark::es2panda::ir { @@ -68,114 +67,6 @@ void TSEnumDeclaration::Iterate(const NodeTraverser &cb) const } } -void TSEnumDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSEnumDeclaration"}, - {"id", Key()}, - {"members", Members()}, - {"const", IsConst()}, - {"declare", IsDeclare()}}); -} - -bool TSEnumDeclaration::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return false; - } - - if (dumper->IsIndirectDepPhase()) { - return false; - } - - if (key_->Parent()->IsDefaultExported() || key_->Parent()->IsExported()) { - return false; - } - - auto name = key_->AsIdentifier()->Name().Mutf8(); - dumper->AddNode(name, this); - return true; -} - -void TSEnumDeclaration::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(isConst_ == false); - ES2PANDA_ASSERT(key_ != nullptr); - if (RegisterUnexportedForDeclGen(dumper)) { - return; - } - if (key_->Parent()->IsExported() && dumper->IsDeclgen()) { - dumper->Add("export "); - } else if (key_->Parent()->IsDefaultExported() && dumper->IsDeclgen()) { - dumper->Add("export default "); - } - if (dumper->IsDeclgen()) { - dumper->TryDeclareAmbientContext(); - } else if (IsDeclare()) { - dumper->Add("declare "); - } - dumper->Add("enum "); - Key()->Dump(dumper); - dumper->Add(" {"); - auto const members = Members(); - if (!members.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - for (auto member : members) { - member->Dump(dumper); - if (member != members.back()) { - dumper->Add(","); - dumper->Endl(); - } - } - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); - dumper->Endl(); -} - -// NOTE (csabahurton): this method has not been moved to TSAnalyizer.cpp, because it is not used. -varbinder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker, - [[maybe_unused]] varbinder::EnumVariable *enumVar, - ir::MemberExpression *expr) -{ - if (checker::TSChecker::IsConstantMemberAccess(expr->AsExpression())) { - if (expr->Check(checker)->TypeFlags() == checker::TypeFlag::ENUM) { - util::StringView name; - if (!expr->IsComputed()) { - name = expr->Property()->AsIdentifier()->Name(); - } else { - ES2PANDA_ASSERT(checker::TSChecker::IsStringLike(expr->Property())); - name = reinterpret_cast(expr->Property())->Str(); - } - - // NOTE: aszilagyi. - } - } - - return false; -} - -void TSEnumDeclaration::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSEnumDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSEnumDeclaration::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSEnumDeclaration::Check(checker::ETSChecker *const checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSEnumDeclaration *TSEnumDeclaration::Construct(ArenaAllocator *allocator) { ArenaVector members(allocator->Adapter()); diff --git a/ets2panda/ir/ts/tsEnumMember.cpp b/ets2panda/ir/ts/tsEnumMember.cpp index f4f126095afdeed1b303c2dfceb7b419125489c3..2471c0a1a653e8b2fcc11d2ed346d860013a72b0 100644 --- a/ets2panda/ir/ts/tsEnumMember.cpp +++ b/ets2panda/ir/ts/tsEnumMember.cpp @@ -15,11 +15,8 @@ #include "tsEnumMember.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/expression.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { void TSEnumMember::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -46,44 +43,10 @@ void TSEnumMember::Iterate(const NodeTraverser &cb) const } } -void TSEnumMember::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSEnumMember"}, {"id", key_}, {"initializer", AstDumper::Optional(init_)}}); -} - -void TSEnumMember::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(key_ != nullptr); - key_->Dump(dumper); - if (init_ != nullptr) { - dumper->Add(" = "); - init_->Dump(dumper); - } -} - util::StringView TSEnumMember::Name() const { ES2PANDA_ASSERT(key_->IsIdentifier()); return key_->AsIdentifier()->Name(); } -void TSEnumMember::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSEnumMember::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSEnumMember::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSEnumMember::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsExternalModuleReference.cpp b/ets2panda/ir/ts/tsExternalModuleReference.cpp index 12207c3d4f1c83ee5d547b41505baaa37d5e4100..398ffb5f0350ecea0108cb9b07ef534bd387287c 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.cpp +++ b/ets2panda/ir/ts/tsExternalModuleReference.cpp @@ -15,12 +15,6 @@ #include "tsExternalModuleReference.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSExternalModuleReference::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -35,33 +29,4 @@ void TSExternalModuleReference::Iterate(const NodeTraverser &cb) const cb(expr_); } -void TSExternalModuleReference::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSExternalModuleReference"}, {"expression", expr_}}); -} - -void TSExternalModuleReference::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSExternalModuleReference"); -} - -void TSExternalModuleReference::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSExternalModuleReference::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSExternalModuleReference::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSExternalModuleReference::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsFunctionType.cpp b/ets2panda/ir/ts/tsFunctionType.cpp index e12589bd31cf2b2adebb5f2848da38ab4939c0d8..a4ee8683e93a66d93714b2596b47fcb835b5e0db 100644 --- a/ets2panda/ir/ts/tsFunctionType.cpp +++ b/ets2panda/ir/ts/tsFunctionType.cpp @@ -15,13 +15,9 @@ #include "tsFunctionType.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" #include "checker/types/signature.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + +#include "ir/ts/tsTypeParameterDeclaration.h" namespace ark::es2panda::ir { void TSFunctionType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -35,51 +31,6 @@ void TSFunctionType::Iterate(const NodeTraverser &cb) const signature_.Iterate(cb); } -void TSFunctionType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSFunctionType"}, - {"params", signature_.Params()}, - {"typeParameters", AstDumper::Optional(signature_.TypeParams())}, - {"returnType", signature_.ReturnType()}, - {"isNullable", AstDumper::Optional(nullable_)}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSFunctionType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSFunctionType"); -} - -void TSFunctionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSFunctionType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSFunctionType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSFunctionType::GetType(checker::TSChecker *checker) -{ - return checker->CheckTypeCached(this); -} - -checker::VerifiedType TSFunctionType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *TSFunctionType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - return nullptr; -} - TSFunctionType *TSFunctionType::Clone(ArenaAllocator *allocator, AstNode *parent) { // Clone the function signature diff --git a/ets2panda/ir/ts/tsFunctionType.h b/ets2panda/ir/ts/tsFunctionType.h index dcf8375b4c4f1e44f637e203fd3e7da0fb00d4be..33363543a870668faa9e4ede24423df748c3f861 100644 --- a/ets2panda/ir/ts/tsFunctionType.h +++ b/ets2panda/ir/ts/tsFunctionType.h @@ -93,7 +93,6 @@ public: checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; TSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp b/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp index efaa3883806d54e1b86ff8aa8bf051597ef6a363..54a76a7d302a76f21914f3ad9197159772a730f9 100644 --- a/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp +++ b/ets2panda/ir/ts/tsImportEqualsDeclaration.cpp @@ -15,11 +15,6 @@ #include "tsImportEqualsDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/expression.h" #include "ir/expressions/identifier.h" @@ -43,35 +38,4 @@ void TSImportEqualsDeclaration::Iterate(const NodeTraverser &cb) const cb(moduleReference_); } -void TSImportEqualsDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSImportEqualsDeclaration"}, - {"id", id_}, - {"moduleReference", moduleReference_}, - {"isExport", isExport_}}); -} - -void TSImportEqualsDeclaration::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSImportEqualsDeclaration"); -} - -void TSImportEqualsDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSImportEqualsDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSImportEqualsDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSImportEqualsDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsImportType.cpp b/ets2panda/ir/ts/tsImportType.cpp index 5762b63a592e4c3600a3281991b13981fa20b2fe..00731a74cc08d2df5406738fc0d551f11925ac3d 100644 --- a/ets2panda/ir/ts/tsImportType.cpp +++ b/ets2panda/ir/ts/tsImportType.cpp @@ -15,11 +15,6 @@ #include "tsImportType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/ts/tsTypeParameter.h" #include "ir/ts/tsTypeParameterInstantiation.h" @@ -63,44 +58,4 @@ void TSImportType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSImportType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSImportType"}, - {"parameter", param_}, - {"qualifier", AstDumper::Optional(qualifier_)}, - {"typeParameters", AstDumper::Optional(typeParams_)}, - {"isTypeOf", isTypeof_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSImportType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSImportType"); -} - -void TSImportType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSImportType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSImportType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSImportType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSImportType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsImportType.h b/ets2panda/ir/ts/tsImportType.h index f57b659efda5a54a7ccbaf4c81e9745691d62320..fdd2966d800fc820ec198784655e84fc199b84b2 100644 --- a/ets2panda/ir/ts/tsImportType.h +++ b/ets2panda/ir/ts/tsImportType.h @@ -60,7 +60,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; void Accept(ASTVisitorT *v) override diff --git a/ets2panda/ir/ts/tsIndexedAccessType.cpp b/ets2panda/ir/ts/tsIndexedAccessType.cpp index 73270348c9381dcadef467f29937043152d61334..746ff32fefa1a58033c41dd2990770e4f260320f 100644 --- a/ets2panda/ir/ts/tsIndexedAccessType.cpp +++ b/ets2panda/ir/ts/tsIndexedAccessType.cpp @@ -15,13 +15,6 @@ #include "tsIndexedAccessType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSIndexedAccessType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -45,52 +38,6 @@ void TSIndexedAccessType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSIndexedAccessType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSIndexedAccessType"}, - {"objectType", objectType_}, - {"indexType", indexType_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSIndexedAccessType::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSIndexedAccessType"); -} - -void TSIndexedAccessType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSIndexedAccessType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSIndexedAccessType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSIndexedAccessType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - checker::Type *baseType = objectType_->GetType(checker); - checker::Type *indexType = indexType_->GetType(checker); - checker::Type *resolved = checker->GetPropertyTypeForIndexType(baseType, indexType); - - SetTsType(resolved); - return TsType(); -} - -checker::VerifiedType TSIndexedAccessType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSIndexedAccessType *TSIndexedAccessType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clonedObjectType = objectType_->Clone(allocator, nullptr)->AsTypeNode(); diff --git a/ets2panda/ir/ts/tsInferType.cpp b/ets2panda/ir/ts/tsInferType.cpp index 98d102636eb732ddaf609ae0118548aca8ba274f..92795cc6f07451e1aabd11a2855bd1d521db2369 100644 --- a/ets2panda/ir/ts/tsInferType.cpp +++ b/ets2panda/ir/ts/tsInferType.cpp @@ -15,11 +15,6 @@ #include "tsInferType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/ts/tsTypeParameter.h" namespace ark::es2panda::ir { @@ -39,39 +34,4 @@ void TSInferType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSInferType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "TSInferType"}, {"typeParameter", typeParam_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSInferType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSInferType"); -} - -void TSInferType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSInferType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSInferType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSInferType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSInferType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsInferType.h b/ets2panda/ir/ts/tsInferType.h index 64057b5ae8a4d67845ac792cbb6ebfd3f4b30c17..8081d597fe41b896998214a6e843ef5843778dc8 100644 --- a/ets2panda/ir/ts/tsInferType.h +++ b/ets2panda/ir/ts/tsInferType.h @@ -40,7 +40,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; void Accept(ASTVisitorT *v) override diff --git a/ets2panda/ir/ts/tsInterfaceBody.cpp b/ets2panda/ir/ts/tsInterfaceBody.cpp index 94c56deddb610c93475c945c57739196999bba2b..202e11b0a841f61335edf48db510dd8c9ce4eafb 100644 --- a/ets2panda/ir/ts/tsInterfaceBody.cpp +++ b/ets2panda/ir/ts/tsInterfaceBody.cpp @@ -15,12 +15,6 @@ #include "tsInterfaceBody.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSInterfaceBody::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -40,35 +34,4 @@ void TSInterfaceBody::Iterate(const NodeTraverser &cb) const } } -void TSInterfaceBody::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSInterfaceBody"}, {"body", body_}}); -} - -void TSInterfaceBody::Dump(ir::SrcDumper *dumper) const -{ - for (auto b : body_) { - b->Dump(dumper); - } -} - -void TSInterfaceBody::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSInterfaceBody::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSInterfaceBody::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSInterfaceBody::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp index fdc64a468576f0ed1b90c12f58dc2b70f7247ff3..6bf4003e54a7d3570bcb1d75694fa1989ff24061 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.cpp +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.cpp @@ -19,12 +19,6 @@ #include "utils/arena_containers.h" #include "varbinder/declaration.h" #include "varbinder/variable.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/expressions/identifier.h" #include "ir/ts/tsInterfaceBody.h" @@ -144,109 +138,6 @@ void TSInterfaceDeclaration::Iterate(const NodeTraverser &cb) const cb(body); } -void TSInterfaceDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSInterfaceDeclaration"}, - {"annotations", AstDumper::Optional(Annotations())}, - {"body", Body()}, - {"id", Id()}, - {"extends", Extends()}, - {"typeParameters", AstDumper::Optional(TypeParams())}}); -} - -bool TSInterfaceDeclaration::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return false; - } - - if (dumper->IsIndirectDepPhase()) { - return false; - } - - if (id_->Parent()->IsDefaultExported() || id_->Parent()->IsExported()) { - return false; - } - - auto name = id_->Name().Mutf8(); - dumper->AddNode(name, this); - return true; -} - -void TSInterfaceDeclaration::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(id_); - if (!id_->Parent()->IsDefaultExported() && !id_->Parent()->IsExported() && dumper->IsDeclgen() && - !dumper->IsIndirectDepPhase()) { - auto name = id_->Name().Mutf8(); - dumper->AddNode(name, this); - return; - } - DumpAnnotations(dumper); - if (id_->Parent()->IsExported()) { - dumper->Add("export "); - } else if (id_->Parent()->IsDefaultExported()) { - dumper->Add("export default "); - } - if (dumper->IsDeclgen()) { - dumper->TryDeclareAmbientContext(); - } else if (IsDeclare()) { - dumper->Add("declare "); - } - dumper->Add("interface "); - Id()->Dump(dumper); - - auto const typeParams = TypeParams(); - if (typeParams != nullptr) { - dumper->Add("<"); - typeParams->Dump(dumper); - dumper->Add(">"); - } - - auto const extends = Extends(); - if (!extends.empty()) { - dumper->Add(" extends "); - for (auto ext : extends) { - ext->Dump(dumper); - if (ext != extends.back()) { - dumper->Add(", "); - } - } - } - - auto body = Body(); - dumper->Add(" {"); - if (body != nullptr) { - dumper->IncrIndent(); - dumper->Endl(); - body->Dump(dumper); - dumper->DecrIndent(); - dumper->Endl(); - } - dumper->Add("}"); - dumper->Endl(); -} - -void TSInterfaceDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSInterfaceDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSInterfaceDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSInterfaceDeclaration::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSInterfaceDeclaration *TSInterfaceDeclaration::Construct(ArenaAllocator *allocator) { ArenaVector extends(allocator->Adapter()); diff --git a/ets2panda/ir/ts/tsInterfaceHeritage.cpp b/ets2panda/ir/ts/tsInterfaceHeritage.cpp index c87aff667f9ba184f0436224eaa38ecae4d0a08a..64f3ff2743214fb02018bba89df4880dec77a8b6 100644 --- a/ets2panda/ir/ts/tsInterfaceHeritage.cpp +++ b/ets2panda/ir/ts/tsInterfaceHeritage.cpp @@ -15,11 +15,7 @@ #include "tsInterfaceHeritage.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" +#include "ir/typeNode.h" namespace ark::es2panda::ir { void TSInterfaceHeritage::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) @@ -35,37 +31,4 @@ void TSInterfaceHeritage::Iterate(const NodeTraverser &cb) const cb(expr_); } -void TSInterfaceHeritage::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({ - {"type", "TSInterfaceHeritage"}, - {"expression", expr_}, - }); -} - -void TSInterfaceHeritage::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(expr_ != nullptr); - expr_->Dump(dumper); -} - -void TSInterfaceHeritage::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSInterfaceHeritage::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSInterfaceHeritage::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSInterfaceHeritage::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsIntersectionType.cpp b/ets2panda/ir/ts/tsIntersectionType.cpp index 8305344470be121a34397f060e02bcab791398d8..4f50b8740a11a4f4cd0df9225ddfdaeba632dee3 100644 --- a/ets2panda/ir/ts/tsIntersectionType.cpp +++ b/ets2panda/ir/ts/tsIntersectionType.cpp @@ -15,12 +15,7 @@ #include "tsIntersectionType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/ETSchecker.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::ir { void TSIntersectionType::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) @@ -44,45 +39,4 @@ void TSIntersectionType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSIntersectionType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "TSIntersectionType"}, {"types", types_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSIntersectionType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSIntersectionType"); -} - -void TSIntersectionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSIntersectionType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSIntersectionType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - // NOTE: validate - return checker->GlobalETSObjectType(); -} - -checker::VerifiedType TSIntersectionType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsIntersectionType.h b/ets2panda/ir/ts/tsIntersectionType.h index 11abbca84815504ce0132c45d77edb91bf6c69b0..9ab16d37aa2cf17684d249b1f694bc89b2e1b28e 100644 --- a/ets2panda/ir/ts/tsIntersectionType.h +++ b/ets2panda/ir/ts/tsIntersectionType.h @@ -38,7 +38,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/ts/tsLiteralType.cpp b/ets2panda/ir/ts/tsLiteralType.cpp index 5ea315e81b81d71dfb0cc126f2521a57a65433ad..fa9481f7de8168ee24cdd22b237e36f7541179f1 100644 --- a/ets2panda/ir/ts/tsLiteralType.cpp +++ b/ets2panda/ir/ts/tsLiteralType.cpp @@ -15,12 +15,6 @@ #include "tsLiteralType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSLiteralType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -38,48 +32,6 @@ void TSLiteralType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSLiteralType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "TSLiteralType"}, {"literal", literal_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSLiteralType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSLiteralType"); -} - -void TSLiteralType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSLiteralType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSLiteralType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSLiteralType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - SetTsType(literal_->Check(checker)); - return TsType(); -} - -checker::VerifiedType TSLiteralType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSLiteralType *TSLiteralType::Clone(ArenaAllocator *allocator, AstNode *parent) { // Clone the literal expression diff --git a/ets2panda/ir/ts/tsMappedType.cpp b/ets2panda/ir/ts/tsMappedType.cpp index 393e8ec921d9ec0b31a214feab072c30f6cf0ca0..3b88a78f8e68b2a24b83f97d45c611ea481969cc 100644 --- a/ets2panda/ir/ts/tsMappedType.cpp +++ b/ets2panda/ir/ts/tsMappedType.cpp @@ -15,11 +15,6 @@ #include "tsMappedType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/typeNode.h" #include "ir/ts/tsTypeParameter.h" @@ -51,50 +46,6 @@ void TSMappedType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSMappedType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSMappedType"}, - {"typeParameter", typeParameter_}, - {"typeAnnotation", AstDumper::Optional(typeAnnotation_)}, - {"readonly", readonly_ == MappedOption::NO_OPTS ? AstDumper::Optional(false) - : readonly_ == MappedOption::PLUS ? AstDumper::Optional("+") - : AstDumper::Optional("-")}, - {"optional", optional_ == MappedOption::NO_OPTS ? AstDumper::Optional(false) - : optional_ == MappedOption::PLUS ? AstDumper::Optional("+") - : AstDumper::Optional("-")}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSMappedType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSMappedType"); -} - -void TSMappedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSMappedType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSMappedType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSMappedType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSMappedType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSMappedType *TSMappedType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clonedTypeParameter = typeParameter_->Clone(allocator, nullptr)->AsTSTypeParameter(); diff --git a/ets2panda/ir/ts/tsMappedType.h b/ets2panda/ir/ts/tsMappedType.h index 0b2faa31d02b5d3e9f608668b7f1c70785e7b45f..e8fbbcf82551594b4b1a7e56f684b8ceb370eef6 100644 --- a/ets2panda/ir/ts/tsMappedType.h +++ b/ets2panda/ir/ts/tsMappedType.h @@ -59,7 +59,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; TSMappedType *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/ts/tsModuleBlock.cpp b/ets2panda/ir/ts/tsModuleBlock.cpp index db77f5dee40dcd1a0f1810561f10faa36c5f6a97..2098feb04e8857a632ea7830ac08b784a73f6086 100644 --- a/ets2panda/ir/ts/tsModuleBlock.cpp +++ b/ets2panda/ir/ts/tsModuleBlock.cpp @@ -15,12 +15,6 @@ #include "tsModuleBlock.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSModuleBlock::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -39,32 +33,4 @@ void TSModuleBlock::Iterate(const NodeTraverser &cb) const } } -void TSModuleBlock::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSModuleBlock"}, {"body", statements_}}); -} - -void TSModuleBlock::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSModuleBlock"); -} - -void TSModuleBlock::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSModuleBlock::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSModuleBlock::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSModuleBlock::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsModuleDeclaration.cpp b/ets2panda/ir/ts/tsModuleDeclaration.cpp index 0f90e8f8e0270ba69bcccf0ab06c0d760487241d..4a4c730b175e5850a5c6bbe8b6813c845281a802 100644 --- a/ets2panda/ir/ts/tsModuleDeclaration.cpp +++ b/ets2panda/ir/ts/tsModuleDeclaration.cpp @@ -15,12 +15,6 @@ #include "tsModuleDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSModuleDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -46,34 +40,4 @@ void TSModuleDeclaration::Iterate(const NodeTraverser &cb) const } } -void TSModuleDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "TSModuleDeclaration"}, {"id", name_}, {"body", AstDumper::Optional(body_)}, {"global", global_}}); -} - -void TSModuleDeclaration::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSModuleDeclaration"); -} - -void TSModuleDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSModuleDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSModuleDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsNamedTupleMember.cpp b/ets2panda/ir/ts/tsNamedTupleMember.cpp index 26a2ad54af2fea954d164214821c2a52650d5398..ec5f94f8838790679acaa4925503cf07fb57872e 100644 --- a/ets2panda/ir/ts/tsNamedTupleMember.cpp +++ b/ets2panda/ir/ts/tsNamedTupleMember.cpp @@ -15,13 +15,6 @@ #include "tsNamedTupleMember.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSNamedTupleMember::TransformChildren(const NodeTransformer &cb, std::string_view const transformationName) { @@ -45,38 +38,4 @@ void TSNamedTupleMember::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSNamedTupleMember::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSNamedTupleMember"}, - {"elementType", elementType_}, - {"label", label_}, - {"optional", AstDumper::Optional(optional_)}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSNamedTupleMember::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSNamedTupleMember"); -} - -void TSNamedTupleMember::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSNamedTupleMember::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSNamedTupleMember::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSNamedTupleMember::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsNeverKeyword.cpp b/ets2panda/ir/ts/tsNeverKeyword.cpp index cca589761049e33c38c419f7aaac3f36115671bc..6446955acebb5aa62be0f8b43686bd5bd273230e 100644 --- a/ets2panda/ir/ts/tsNeverKeyword.cpp +++ b/ets2panda/ir/ts/tsNeverKeyword.cpp @@ -15,12 +15,6 @@ #include "tsNeverKeyword.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSNeverKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,39 +27,4 @@ void TSNeverKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSNeverKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSNeverKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSNeverKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSNeverKeyword"); -} - -void TSNeverKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSNeverKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSNeverKeyword::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSNeverKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalNeverType(); -} - -checker::VerifiedType TSNeverKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsNonNullExpression.cpp b/ets2panda/ir/ts/tsNonNullExpression.cpp index 61768c5e4cbb21d7e62d5dbb357a3c48cd9d1add..487122eb67449bc90c5e208bdb79f3e03e344a14 100644 --- a/ets2panda/ir/ts/tsNonNullExpression.cpp +++ b/ets2panda/ir/ts/tsNonNullExpression.cpp @@ -15,11 +15,6 @@ #include "tsNonNullExpression.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { void TSNonNullExpression::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -34,38 +29,6 @@ void TSNonNullExpression::Iterate(const NodeTraverser &cb) const cb(expr_); } -void TSNonNullExpression::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSNonNullExpression"}, {"expression", expr_}}); -} - -void TSNonNullExpression::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(expr_ != nullptr); - expr_->Dump(dumper); - dumper->Add("!"); -} - -void TSNonNullExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSNonNullExpression::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSNonNullExpression::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSNonNullExpression::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSNonNullExpression *TSNonNullExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const expr = expr_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/ts/tsNullKeyword.cpp b/ets2panda/ir/ts/tsNullKeyword.cpp index c8789804e572facb3f2b49989e7bcd51f099a0b0..6ad1bb0c90b1aa97d7f7ad70ef81dee7cbea2ba6 100644 --- a/ets2panda/ir/ts/tsNullKeyword.cpp +++ b/ets2panda/ir/ts/tsNullKeyword.cpp @@ -15,12 +15,6 @@ #include "tsNullKeyword.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSNullKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,38 +27,4 @@ void TSNullKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSNullKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSNullKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSNullKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSNullKeyword"); -} - -void TSNullKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSNullKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSNullKeyword::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSNullKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalNullType(); -} - -checker::VerifiedType TSNullKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsNumberKeyword.cpp b/ets2panda/ir/ts/tsNumberKeyword.cpp index c6752bc8accf7a1b7460f975519ca98c9731633f..89319d941075dea5a65244e8c5c09ad8a0ff9660 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.cpp +++ b/ets2panda/ir/ts/tsNumberKeyword.cpp @@ -15,12 +15,6 @@ #include "tsNumberKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSNumberKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,42 +27,6 @@ void TSNumberKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSNumberKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSNumberKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSNumberKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSNumberKeyword"); -} - -void TSNumberKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSNumberKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSNumberKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSNumberKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalNumberType(); -} - -checker::VerifiedType TSNumberKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSNumberKeyword *TSNumberKeyword::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clone = allocator->New(allocator); diff --git a/ets2panda/ir/ts/tsObjectKeyword.cpp b/ets2panda/ir/ts/tsObjectKeyword.cpp index 5eacf644625e1a94d6ef014c367282954c197d73..3d6abbdcf8e5ac9c76a27f431dac0d447a490862 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.cpp +++ b/ets2panda/ir/ts/tsObjectKeyword.cpp @@ -15,12 +15,6 @@ #include "tsObjectKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSObjectKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,39 +27,4 @@ void TSObjectKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSObjectKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSObjectKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSObjectKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSObjectKeyword"); -} - -void TSObjectKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSObjectKeyword::Compile([[maybe_unused]] compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSObjectKeyword::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSObjectKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalNonPrimitiveType(); -} - -checker::VerifiedType TSObjectKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsParameterProperty.cpp b/ets2panda/ir/ts/tsParameterProperty.cpp index 047484053faa822cf6aa5dcee3ec6ea0264975b4..cd6322db2928e34f97ff3a5d0d9af70fd8344193 100644 --- a/ets2panda/ir/ts/tsParameterProperty.cpp +++ b/ets2panda/ir/ts/tsParameterProperty.cpp @@ -15,11 +15,6 @@ #include "tsParameterProperty.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/expression.h" namespace ark::es2panda::ir { @@ -36,40 +31,4 @@ void TSParameterProperty::Iterate(const NodeTraverser &cb) const cb(parameter_); } -void TSParameterProperty::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSParameterProperty"}, - {"accessibility", accessibility_ == AccessibilityOption::PUBLIC ? "public" - : accessibility_ == AccessibilityOption::PRIVATE ? "private" - : accessibility_ == AccessibilityOption::PROTECTED ? "protected" - : "undefined"}, - {"readonly", readonly_}, - {"static", static_}, - {"export", export_}, - {"parameter", parameter_}}); -} - -void TSParameterProperty::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSParameterProperty"); -} - -void TSParameterProperty::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSParameterProperty::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSParameterProperty::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSParameterProperty::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsParenthesizedType.cpp b/ets2panda/ir/ts/tsParenthesizedType.cpp index 5e2ed2f554b5a588b70e1d3069dd7faee4120248..957c4639068b41c4eed375b2508720e5fa3e2091 100644 --- a/ets2panda/ir/ts/tsParenthesizedType.cpp +++ b/ets2panda/ir/ts/tsParenthesizedType.cpp @@ -15,12 +15,6 @@ #include "tsParenthesizedType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSParenthesizedType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -38,46 +32,4 @@ void TSParenthesizedType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSParenthesizedType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSParenthesizedType"}, - {"typeAnnotation", type_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSParenthesizedType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSParenthesizedType"); -} - -void TSParenthesizedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSParenthesizedType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSParenthesizedType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSParenthesizedType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - SetTsType(type_->GetType(checker)); - return TsType(); -} - -checker::VerifiedType TSParenthesizedType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsQualifiedName.cpp b/ets2panda/ir/ts/tsQualifiedName.cpp index f47595f293ee6feb981882c74488d81fe8f534a2..b2771c6b993d629f44f735bba45a8d804c7b5672 100644 --- a/ets2panda/ir/ts/tsQualifiedName.cpp +++ b/ets2panda/ir/ts/tsQualifiedName.cpp @@ -15,10 +15,7 @@ #include "tsQualifiedName.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "ir/expressions/identifier.h" namespace ark::es2panda::ir { TSQualifiedName::TSQualifiedName(Expression *left, Identifier *right, ArenaAllocator *allocator) @@ -55,37 +52,6 @@ void TSQualifiedName::TransformChildren(const NodeTransformer &cb, std::string_v } } -void TSQualifiedName::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSQualifiedName"}, {"left", left_}, {"right", right_}}); -} - -void TSQualifiedName::Dump(ir::SrcDumper *dumper) const -{ - left_->Dump(dumper); - dumper->Add("."); - right_->Dump(dumper); -} - -void TSQualifiedName::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSQualifiedName::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSQualifiedName::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSQualifiedName::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - util::StringView TSQualifiedName::Name() const { util::UString packageName(allocator_); diff --git a/ets2panda/ir/ts/tsStringKeyword.cpp b/ets2panda/ir/ts/tsStringKeyword.cpp index aa9f5fc9f808b55c3a2937e25bec9ad64f775fab..de3eec5570d2900db5848bec3a6dd4b221c552a9 100644 --- a/ets2panda/ir/ts/tsStringKeyword.cpp +++ b/ets2panda/ir/ts/tsStringKeyword.cpp @@ -15,12 +15,6 @@ #include "tsStringKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSStringKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,42 +27,6 @@ void TSStringKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSStringKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSStringKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSStringKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSStringKeyword"); -} - -void TSStringKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSStringKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSStringKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSStringKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalStringType(); -} - -checker::VerifiedType TSStringKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSStringKeyword *TSStringKeyword::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clone = allocator->New(allocator); diff --git a/ets2panda/ir/ts/tsThisType.cpp b/ets2panda/ir/ts/tsThisType.cpp index ded68e430bc7b7e22b12c7d1f917edb8233bf47d..0a9a5a6ed5019b2d5a06b5b1ba6f8494f36d8bfc 100644 --- a/ets2panda/ir/ts/tsThisType.cpp +++ b/ets2panda/ir/ts/tsThisType.cpp @@ -15,10 +15,7 @@ #include "tsThisType.h" -#include "checker/ETSchecker.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" +#include "checker/types/ets/etsObjectType.h" namespace ark::es2panda::ir { void TSThisType::TransformChildren([[maybe_unused]] const NodeTransformer &cb, @@ -32,49 +29,6 @@ void TSThisType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSThisType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSThisType"}}); -} - -void TSThisType::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("this"); -} - -void TSThisType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSThisType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSThisType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSThisType::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSThisType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *TSThisType::GetType([[maybe_unused]] checker::ETSChecker *checker) -{ - auto *containingClass = checker->Context().ContainingClass(); - if (containingClass == nullptr) { - return checker->GlobalTypeError(); - } - return containingClass; -} - TSThisType *TSThisType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(allocator); diff --git a/ets2panda/ir/ts/tsThisType.h b/ets2panda/ir/ts/tsThisType.h index e5367ce02ff527dec0cfc5903812dfc081c23eef..43e88d8450ee8f16913460d1c166e39f34de105b 100644 --- a/ets2panda/ir/ts/tsThisType.h +++ b/ets2panda/ir/ts/tsThisType.h @@ -30,7 +30,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; TSThisType *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/ts/tsTupleType.cpp b/ets2panda/ir/ts/tsTupleType.cpp index 26691a49deb047d007af98d71920d5232cc18fad..c23274b7f6ce2ec8310b07fb1a01c1e086e889cb 100644 --- a/ets2panda/ir/ts/tsTupleType.cpp +++ b/ets2panda/ir/ts/tsTupleType.cpp @@ -15,14 +15,12 @@ #include "tsTupleType.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" #include "util/helpers.h" #include "varbinder/scope.h" + #include "checker/TSchecker.h" #include "checker/types/ts/indexInfo.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + #include "ir/expressions/identifier.h" #include "ir/ts/tsNamedTupleMember.h" @@ -48,29 +46,6 @@ void TSTupleType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTupleType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTupleType"}, - {"elementTypes", elementTypes_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSTupleType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSTupleType"); -} - -void TSTupleType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSTupleType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - checker::Type *GetNumberIndexType(ArenaVector numberIndexTypes, checker::TSChecker *checker) { checker::Type *numberIndexType = nullptr; @@ -152,16 +127,6 @@ checker::Type *TSTupleType::GetType(checker::TSChecker *checker) return TsType(); } -checker::Type *TSTupleType::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTupleType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTupleType *TSTupleType::Clone(ArenaAllocator *allocator, AstNode *parent) { ArenaVector clonedElementTypes(allocator->Adapter()); diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp index d19433ee842fc84703ecc01460eb4a0347d1f644..76aaf07b6d4c06e9f0e32636b53c3d3dc7bf1048 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.cpp @@ -15,11 +15,6 @@ #include "tsTypeAliasDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/typeNode.h" #include "ir/expressions/identifier.h" @@ -81,82 +76,6 @@ void TSTypeAliasDeclaration::Iterate(const NodeTraverser &cb) const } } -void TSTypeAliasDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeAliasDeclaration"}, - {"annotations", AstDumper::Optional(Annotations())}, - {"id", Id()}, - {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}, - {"typeParameters", AstDumper::Optional(TypeParams())}}); -} - -bool TSTypeAliasDeclaration::RegisterUnexportedForDeclGen(ir::SrcDumper *dumper) const -{ - if (!dumper->IsDeclgen()) { - return false; - } - - if (dumper->IsIndirectDepPhase()) { - return false; - } - - if (id_->Parent()->IsExported() || id_->Parent()->IsDefaultExported()) { - return false; - } - - auto name = id_->Name().Mutf8(); - dumper->AddNode(name, this); - return true; -} - -void TSTypeAliasDeclaration::Dump(ir::SrcDumper *dumper) const -{ - ES2PANDA_ASSERT(id_); - if (RegisterUnexportedForDeclGen(dumper)) { - return; - } - DumpAnnotations(dumper); - if (id_->Parent()->IsExported()) { - dumper->Add("export "); - } - dumper->Add("type "); - Id()->Dump(dumper); - auto const typeParams = TypeParams(); - if (typeParams != nullptr) { - dumper->Add("<"); - typeParams->Dump(dumper); - dumper->Add(">"); - } - dumper->Add(" = "); - if (Id()->IsAnnotatedExpression()) { - auto type = TypeAnnotation(); - ES2PANDA_ASSERT(type); - type->Dump(dumper); - } - dumper->Add(";"); - dumper->Endl(); -} - -void TSTypeAliasDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSTypeAliasDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeAliasDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTypeAliasDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTypeAliasDeclaration *TSTypeAliasDeclaration::Construct(ArenaAllocator *allocator) { return allocator->New(allocator, nullptr, nullptr, nullptr); diff --git a/ets2panda/ir/ts/tsTypeAssertion.cpp b/ets2panda/ir/ts/tsTypeAssertion.cpp index 64ecd8063413a9b2c65b41d495d41c8125f0a543..ae206cdfbcf2ebaa3b97907792a329a12487ab9c 100644 --- a/ets2panda/ir/ts/tsTypeAssertion.cpp +++ b/ets2panda/ir/ts/tsTypeAssertion.cpp @@ -15,11 +15,6 @@ #include "tsTypeAssertion.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/typeNode.h" namespace ark::es2panda::ir { @@ -44,33 +39,4 @@ void TSTypeAssertion::Iterate(const NodeTraverser &cb) const cb(expression_); } -void TSTypeAssertion::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeAssertion"}, {"typeAnnotation", TypeAnnotation()}, {"expression", expression_}}); -} - -void TSTypeAssertion::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("TSTypeAssertion"); -} - -void TSTypeAssertion::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSTypeAssertion::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeAssertion::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTypeAssertion::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypeLiteral.cpp b/ets2panda/ir/ts/tsTypeLiteral.cpp index f79e4e20c3bfc19bfabe29590f3cd0e635c58635..06a84bca95054daf8c1b755dfcce372fed00f3ba 100644 --- a/ets2panda/ir/ts/tsTypeLiteral.cpp +++ b/ets2panda/ir/ts/tsTypeLiteral.cpp @@ -15,14 +15,9 @@ #include "tsTypeLiteral.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - #include "varbinder/variable.h" #include "varbinder/declaration.h" -#include "checker/TSchecker.h" + #include "checker/types/signature.h" namespace ark::es2panda::ir { @@ -47,53 +42,6 @@ void TSTypeLiteral::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTypeLiteral::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "TSTypeLiteral"}, {"members", members_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSTypeLiteral::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSTypeLiteral"); -} - -void TSTypeLiteral::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSTypeLiteral::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeLiteral::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSTypeLiteral::GetType(checker::TSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - checker::ObjectDescriptor *desc = checker->Allocator()->New(checker->Allocator()); - checker::Type *type = checker->Allocator()->New(desc); - ES2PANDA_ASSERT(type != nullptr); - type->SetVariable(Variable()); - - SetTsType(type); - return TsType(); -} - -checker::VerifiedType TSTypeLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTypeLiteral *TSTypeLiteral::Clone(ArenaAllocator *allocator, AstNode *parent) { ArenaVector clonedMembers(allocator->Adapter()); diff --git a/ets2panda/ir/ts/tsTypeOperator.cpp b/ets2panda/ir/ts/tsTypeOperator.cpp index 345217052f048fbf5e51563d741cb02b3bd1c59d..b0fec26af56d2b4cfb83117b1821b473779a121f 100644 --- a/ets2panda/ir/ts/tsTypeOperator.cpp +++ b/ets2panda/ir/ts/tsTypeOperator.cpp @@ -15,12 +15,6 @@ #include "tsTypeOperator.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSTypeOperator::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -39,44 +33,6 @@ void TSTypeOperator::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTypeOperator::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeOperator"}, - {"operator", AstDumper::TypeOperatorToString(operatorType_)}, - {"typeAnnotation", type_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSTypeOperator::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSTypeOperator"); -} - -void TSTypeOperator::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSTypeOperator::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeOperator::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSTypeOperator::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSTypeOperator::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTypeOperator *TSTypeOperator::Clone(ArenaAllocator *allocator, AstNode *parent) { // Clone the type annotation diff --git a/ets2panda/ir/ts/tsTypeOperator.h b/ets2panda/ir/ts/tsTypeOperator.h index 1c8e52791c9003e0a7e0c674b73c172806c55430..61d2996d6406c3621ce0052328fedf740006a7c0 100644 --- a/ets2panda/ir/ts/tsTypeOperator.h +++ b/ets2panda/ir/ts/tsTypeOperator.h @@ -53,7 +53,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; TSTypeOperator *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/ts/tsTypeParameter.cpp b/ets2panda/ir/ts/tsTypeParameter.cpp index 5e997562f4bfcccbc0a32f4216f4893292e57402..437accb0c024e490142a9143920303ecc453e308 100644 --- a/ets2panda/ir/ts/tsTypeParameter.cpp +++ b/ets2panda/ir/ts/tsTypeParameter.cpp @@ -15,11 +15,6 @@ #include "tsTypeParameter.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/typeNode.h" #include "ir/expressions/identifier.h" #include "utils/arena_containers.h" @@ -86,58 +81,6 @@ void TSTypeParameter::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTypeParameter::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeParameter"}, - {"name", Name()}, - {"constraint", AstDumper::Optional(Constraint())}, - {"default", AstDumper::Optional(DefaultType())}, - {"in", AstDumper::Optional(IsIn())}, - {"out", AstDumper::Optional(IsOut())}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSTypeParameter::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - if (IsIn()) { - dumper->Add("in "); - } - if (IsOut()) { - dumper->Add("out "); - } - - Name()->Dump(dumper); - - if (DefaultType() != nullptr) { - dumper->Add(" = "); - DefaultType()->Dump(dumper); - } - if (Constraint() != nullptr) { - dumper->Add(" extends "); - Constraint()->Dump(dumper); - } -} - -void TSTypeParameter::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSTypeParameter::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeParameter::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTypeParameter::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTypeParameter *TSTypeParameter::Construct(ArenaAllocator *allocator) { return allocator->New(nullptr, nullptr, nullptr, allocator); diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp index 1ae682e17f96f248d6503893e11c1186593749c5..5c71061db13ef361600bfdcbbec27037136e651d 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -15,11 +15,6 @@ #include "tsTypeParameterDeclaration.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/ts/tsTypeParameter.h" namespace ark::es2panda::ir { @@ -52,40 +47,6 @@ void TSTypeParameterDeclaration::Iterate(const NodeTraverser &cb) const } } -void TSTypeParameterDeclaration::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeParameterDeclaration"}, {"params", Params()}}); -} - -void TSTypeParameterDeclaration::Dump(ir::SrcDumper *dumper) const -{ - for (auto param : Params()) { - param->Dump(dumper); - if (param != Params().back()) { - dumper->Add(", "); - } - } -} - -void TSTypeParameterDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSTypeParameterDeclaration::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeParameterDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTypeParameterDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTypeParameterDeclaration *TSTypeParameterDeclaration::Construct(ArenaAllocator *allocator) { ArenaVector params(allocator->Adapter()); diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index 306816edeac35d1a3b64bd46f231479217d019da..6a9268a1c8370d086660eda6cf005f278d8e87c7 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -15,10 +15,6 @@ #include "tsTypeParameterInstantiation.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" - namespace ark::es2panda::ir { TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag const tag, TSTypeParameterInstantiation const &other, @@ -58,40 +54,4 @@ void TSTypeParameterInstantiation::Iterate(const NodeTraverser &cb) const } } -void TSTypeParameterInstantiation::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeParameterInstantiation"}, {"params", params_}}); -} - -void TSTypeParameterInstantiation::Dump(ir::SrcDumper *dumper) const -{ - dumper->Add("<"); - for (auto param : params_) { - param->Dump(dumper); - if (param != params_.back()) { - dumper->Add(", "); - } - } - dumper->Add(">"); -} - -void TSTypeParameterInstantiation::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSTypeParameterInstantiation::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeParameterInstantiation::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTypeParameterInstantiation::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypePredicate.cpp b/ets2panda/ir/ts/tsTypePredicate.cpp index 68f10c467bea286af7f5ee9edfd0d86266683d26..108184e6ce16228d77866498aef4de4cf78fb98a 100644 --- a/ets2panda/ir/ts/tsTypePredicate.cpp +++ b/ets2panda/ir/ts/tsTypePredicate.cpp @@ -15,11 +15,6 @@ #include "tsTypePredicate.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" #include "ir/typeNode.h" #include "ir/expression.h" @@ -51,41 +46,4 @@ void TSTypePredicate::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTypePredicate::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypePredicate"}, - {"parameterName", parameterName_}, - {"typeAnnotation", AstDumper::Nullish(typeAnnotation_)}, - {"asserts", asserts_}, - {"annotations", AstDumper::Optional(Annotations())}}); -} -void TSTypePredicate::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSTypePredicate"); -} - -void TSTypePredicate::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSTypePredicate::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypePredicate::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSTypePredicate::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return nullptr; -} - -checker::VerifiedType TSTypePredicate::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypePredicate.h b/ets2panda/ir/ts/tsTypePredicate.h index 47105611f7e56fd5477038067edd74aaf3ce6e8a..c8f66ffc6ad3ffd24b55cb8bbfdbfedfd7e163e2 100644 --- a/ets2panda/ir/ts/tsTypePredicate.h +++ b/ets2panda/ir/ts/tsTypePredicate.h @@ -52,7 +52,6 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; void Accept(ASTVisitorT *v) override diff --git a/ets2panda/ir/ts/tsTypeQuery.cpp b/ets2panda/ir/ts/tsTypeQuery.cpp index 8a0018cdc53af38b9ec1956b0f06fb43414cbc4e..4145cbb772e42d16f982c1de6d08d3f7972d36b0 100644 --- a/ets2panda/ir/ts/tsTypeQuery.cpp +++ b/ets2panda/ir/ts/tsTypeQuery.cpp @@ -15,13 +15,6 @@ #include "tsTypeQuery.h" -#include "checker/ETSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" -#include "checker/TSchecker.h" - namespace ark::es2panda::ir { void TSTypeQuery::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -39,40 +32,4 @@ void TSTypeQuery::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTypeQuery::Dump(ir::AstDumper *dumper) const -{ - dumper->Add( - {{"type", "TSTypeQuery"}, {"exprName", exprName_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSTypeQuery::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSTypeQuery"); -} - -void TSTypeQuery::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSTypeQuery::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSTypeQuery::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSTypeQuery::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSTypeQuery::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypeReference.cpp b/ets2panda/ir/ts/tsTypeReference.cpp index 1618aa19d5cd06dc3aa28d25d80c923f374ba1f0..f8e3e8c8ec691f68384d02a95f8650ee4866ffb1 100644 --- a/ets2panda/ir/ts/tsTypeReference.cpp +++ b/ets2panda/ir/ts/tsTypeReference.cpp @@ -18,12 +18,9 @@ #include "varbinder/declaration.h" #include "varbinder/scope.h" #include "varbinder/variable.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" + #include "ir/expressions/identifier.h" +#include "ir/expressions/memberExpression.h" #include "ir/ts/tsInterfaceDeclaration.h" #include "ir/ts/tsTypeAliasDeclaration.h" #include "ir/ts/tsTypeParameterInstantiation.h" @@ -59,29 +56,6 @@ void TSTypeReference::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSTypeReference::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSTypeReference"}, - {"typeName", typeName_}, - {"typeParameters", AstDumper::Optional(typeParams_)}, - {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSTypeReference::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - BaseName()->Dump(dumper); -} - -void TSTypeReference::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} -void TSTypeReference::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - ir::Identifier *TSTypeReference::BaseName() const { if (typeName_->IsIdentifier()) { @@ -103,37 +77,6 @@ ir::Identifier *TSTypeReference::BaseName() const return iter->Property()->AsIdentifier(); } -checker::Type *TSTypeReference::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSTypeReference::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - if (typeName_->IsTSQualifiedName()) { - return checker->GlobalAnyType(); - } - - ES2PANDA_ASSERT(typeName_->IsIdentifier()); - varbinder::Variable *var = typeName_->AsIdentifier()->Variable(); - - if (var == nullptr) { - checker->ThrowTypeError({"Cannot find name ", typeName_->AsIdentifier()->Name()}, Start()); - } - - SetTsType(checker->GetTypeReferenceType(this, var)); - return TsType(); -} - -checker::VerifiedType TSTypeReference::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSTypeReference *TSTypeReference::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clonedTypeName = typeName_->Clone(allocator, nullptr)->AsExpression(); diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.cpp b/ets2panda/ir/ts/tsUndefinedKeyword.cpp index fc10fda9073bc3d5e7c3d3989f4b3304200ef7cb..a00522f5b4b3b7c04445674dd34a536eb0aee9a3 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.cpp +++ b/ets2panda/ir/ts/tsUndefinedKeyword.cpp @@ -15,12 +15,6 @@ #include "tsUndefinedKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSUndefinedKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,39 +27,4 @@ void TSUndefinedKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSUndefinedKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSUndefinedKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSUndefinedKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSUndefinedKeyword"); -} - -void TSUndefinedKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSUndefinedKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSUndefinedKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalUndefinedType(); -} - -checker::VerifiedType TSUndefinedKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsUnionType.cpp b/ets2panda/ir/ts/tsUnionType.cpp index 97cc33ed09177412486d2d12cd0103d5817cc08c..270138e7025e0d2da245da360947877af371d5c9 100644 --- a/ets2panda/ir/ts/tsUnionType.cpp +++ b/ets2panda/ir/ts/tsUnionType.cpp @@ -15,12 +15,6 @@ #include "tsUnionType.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSUnionType::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { @@ -43,53 +37,6 @@ void TSUnionType::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSUnionType::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSUnionType"}, {"types", types_}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSUnionType::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSUnionType"); -} - -void TSUnionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSUnionType::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSUnionType::Check([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::VerifiedType TSUnionType::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - -checker::Type *TSUnionType::GetType(checker::TSChecker *checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - ArenaVector types(checker->Allocator()->Adapter()); - - for (auto *it : types_) { - types.push_back(it->GetType(checker)); - } - - SetTsType(checker->CreateUnionType(std::move(types))); - return TsType(); -} - TSUnionType *TSUnionType::Clone(ArenaAllocator *allocator, AstNode *parent) { // Clone all type nodes in the union diff --git a/ets2panda/ir/ts/tsUnknownKeyword.cpp b/ets2panda/ir/ts/tsUnknownKeyword.cpp index ebd721e2d63c459520f204fc8ca8ce7ab42b0074..54d61d266565b55c28f69f616e312893c853df53 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.cpp +++ b/ets2panda/ir/ts/tsUnknownKeyword.cpp @@ -15,12 +15,6 @@ #include "tsUnknownKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSUnknownKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,39 +27,4 @@ void TSUnknownKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSUnknownKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSUnknownKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSUnknownKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSUnknownKeyword"); -} - -void TSUnknownKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSUnknownKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSUnknownKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSUnknownKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalUnknownType(); -} - -checker::VerifiedType TSUnknownKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/ts/tsVoidKeyword.cpp b/ets2panda/ir/ts/tsVoidKeyword.cpp index e938461aa2738bbb5a79cbb291443d1719993eab..2f35e01fcf4799091ced7b8933dfc3f9ede472e1 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.cpp +++ b/ets2panda/ir/ts/tsVoidKeyword.cpp @@ -15,12 +15,6 @@ #include "tsVoidKeyword.h" -#include "checker/TSchecker.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/pandagen.h" -#include "ir/astDump.h" -#include "ir/srcDump.h" - namespace ark::es2panda::ir { void TSVoidKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb, [[maybe_unused]] std::string_view const transformationName) @@ -33,42 +27,6 @@ void TSVoidKeyword::Iterate(const NodeTraverser &cb) const IterateAnnotations(cb); } -void TSVoidKeyword::Dump(ir::AstDumper *dumper) const -{ - dumper->Add({{"type", "TSVoidKeyword"}, {"annotations", AstDumper::Optional(Annotations())}}); -} - -void TSVoidKeyword::Dump(ir::SrcDumper *dumper) const -{ - DumpAnnotations(dumper); - dumper->Add("TSVoidKeyword"); -} - -void TSVoidKeyword::Compile(compiler::PandaGen *pg) const -{ - pg->GetAstCompiler()->Compile(this); -} - -void TSVoidKeyword::Compile(compiler::ETSGen *etsg) const -{ - etsg->GetAstCompiler()->Compile(this); -} - -checker::Type *TSVoidKeyword::Check(checker::TSChecker *checker) -{ - return checker->GetAnalyzer()->Check(this); -} - -checker::Type *TSVoidKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) -{ - return checker->GlobalVoidType(); -} - -checker::VerifiedType TSVoidKeyword::Check(checker::ETSChecker *checker) -{ - return {this, checker->GetAnalyzer()->Check(this)}; -} - TSVoidKeyword *TSVoidKeyword::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *clone = allocator->New(allocator); diff --git a/ets2panda/ir/visitor/IterateAstVisitor.h b/ets2panda/ir/visitor/IterateAstVisitor.h index 79274780e6f1b6c15cf870658ff22aef2dad83fd..a5d7a357f65d5f8f6e53013ac55fc81870e09e1c 100644 --- a/ets2panda/ir/visitor/IterateAstVisitor.h +++ b/ets2panda/ir/visitor/IterateAstVisitor.h @@ -16,27 +16,168 @@ #ifndef ES2PANDA_COMPILER_CORE_ITERATE_AST_VISITOR_H #define ES2PANDA_COMPILER_CORE_ITERATE_AST_VISITOR_H -#include "AstVisitor.h" #include "ir/brokenTypeNode.h" -#include "ir/expressions/literals/undefinedLiteral.h" -#include "ir/expressions/blockExpression.h" +#include "ir/opaqueTypeNode.h" + +#include "ir/module/exportAllDeclaration.h" +#include "ir/module/exportDefaultDeclaration.h" +#include "ir/module/exportNamedDeclaration.h" +#include "ir/module/exportSpecifier.h" +#include "ir/module/importDefaultSpecifier.h" +#include "ir/module/importNamespaceSpecifier.h" + +#include "ir/ets/etsClassLiteral.h" +#include "ir/ets/etsStructDeclaration.h" #include "ir/ets/etsIntrinsicNode.h" #include "ir/ets/etsUnionType.h" #include "ir/ets/etsStringLiteralType.h" #include "ir/ets/etsTuple.h" +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" #include "ir/ets/etsNeverType.h" #include "ir/ets/etsNullishTypes.h" -#include "ir/statements/functionDeclaration.h" -#include "ir/expressions/functionExpression.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "ir/ets/etsNewArrayInstanceExpression.h" +#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" +#include "ir/ets/etsNewClassInstanceExpression.h" +#include "ir/ets/etsFunctionType.h" +#include "ir/ets/etsNonNullishTypeNode.h" +#include "ir/ets/etsPackageDeclaration.h" +#include "ir/ets/etsPrimitiveType.h" +#include "ir/ets/etsWildcardType.h" +#include "ir/ets/etsKeyofType.h" +#include "ir/ets/etsModule.h" + +#include "ir/ts/tsAsExpression.h" +#include "ir/ts/tsEnumDeclaration.h" +#include "ir/ts/tsEnumMember.h" +#include "ir/ts/tsExternalModuleReference.h" +#include "ir/ts/tsNonNullExpression.h" +#include "ir/ts/tsTypeAssertion.h" +#include "ir/ts/tsAnyKeyword.h" +#include "ir/ts/tsArrayType.h" +#include "ir/ts/tsBigintKeyword.h" +#include "ir/ts/tsBooleanKeyword.h" +#include "ir/ts/tsLiteralType.h" +#include "ir/ts/tsNeverKeyword.h" +#include "ir/ts/tsNullKeyword.h" +#include "ir/ts/tsNumberKeyword.h" +#include "ir/ts/tsObjectKeyword.h" +#include "ir/ts/tsParenthesizedType.h" +#include "ir/ts/tsStringKeyword.h" +#include "ir/ts/tsTypeLiteral.h" +#include "ir/ts/tsUndefinedKeyword.h" +#include "ir/ts/tsUnionType.h" +#include "ir/ts/tsUnknownKeyword.h" +#include "ir/ts/tsVoidKeyword.h" +#include "ir/ts/tsConditionalType.h" +#include "ir/ts/tsConstructorType.h" +#include "ir/ts/tsFunctionType.h" +#include "ir/ts/tsImportEqualsDeclaration.h" +#include "ir/ts/tsImportType.h" +#include "ir/ts/tsInferType.h" +#include "ir/ts/tsIntersectionType.h" +#include "ir/ts/tsMappedType.h" +#include "ir/ts/tsModuleBlock.h" +#include "ir/ts/tsModuleDeclaration.h" +#include "ir/ts/tsParameterProperty.h" +#include "ir/ts/tsThisType.h" +#include "ir/ts/tsTypeAliasDeclaration.h" +#include "ir/ts/tsTypeOperator.h" +#include "ir/ts/tsTypeParameter.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/ts/tsTypeParameterInstantiation.h" +#include "ir/ts/tsTypePredicate.h" +#include "ir/ts/tsTypeReference.h" +#include "ir/ts/tsClassImplements.h" +#include "ir/ts/tsIndexedAccessType.h" +#include "ir/ts/tsInterfaceBody.h" +#include "ir/ts/tsInterfaceDeclaration.h" +#include "ir/ts/tsInterfaceHeritage.h" +#include "ir/ts/tsNamedTupleMember.h" +#include "ir/ts/tsQualifiedName.h" +#include "ir/ts/tsTupleType.h" +#include "ir/ts/tsTypeQuery.h" + +#include "ir/base/spreadElement.h" #include "ir/base/scriptFunction.h" -#include "ir/base/methodDefinition.h" +#include "ir/base/catchClause.h" +#include "ir/base/classDefinition.h" #include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/decorator.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/metaProperty.h" +#include "ir/base/overloadDeclaration.h" +#include "ir/base/property.h" +#include "ir/base/tsMethodSignature.h" +#include "ir/base/tsPropertySignature.h" +#include "ir/base/tsSignatureDeclaration.h" +#include "ir/base/tsIndexSignature.h" + +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/taggedTemplateExpression.h" +#include "ir/expressions/typeofExpression.h" +#include "ir/expressions/unaryExpression.h" +#include "ir/expressions/updateExpression.h" +#include "ir/expressions/yieldExpression.h" + +#include "ir/expressions/arrowFunctionExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/templateLiteral.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/awaitExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/classExpression.h" +#include "ir/expressions/chainExpression.h" #include "ir/expressions/identifier.h" +#include "ir/expressions/importExpression.h" #include "ir/expressions/dummyNode.h" -#include "ir/ets/etsReExportDeclaration.h" +#include "ir/expressions/directEvalExpression.h" +#include "ir/expressions/blockExpression.h" +#include "ir/expressions/conditionalExpression.h" +#include "ir/expressions/thisExpression.h" +#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/expressions/literals/bigIntLiteral.h" +#include "ir/expressions/literals/booleanLiteral.h" +#include "ir/expressions/literals/charLiteral.h" +#include "ir/expressions/literals/nullLiteral.h" +#include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/regExpLiteral.h" +#include "ir/expressions/newExpression.h" +#include "ir/expressions/omittedExpression.h" +#include "ir/expressions/superExpression.h" + +#include "ir/statements/assertStatement.h" #include "ir/statements/annotationDeclaration.h" +#include "ir/statements/breakStatement.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/continueStatement.h" +#include "ir/statements/debuggerStatement.h" +#include "ir/statements/doWhileStatement.h" +#include "ir/statements/emptyStatement.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/forInStatement.h" +#include "ir/statements/forOfStatement.h" +#include "ir/statements/forUpdateStatement.h" +#include "ir/statements/labelledStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/ifStatement.h" #include "ir/statements/variableDeclaration.h" #include "ir/statements/variableDeclarator.h" +#include "ir/statements/switchCaseStatement.h" +#include "ir/statements/switchStatement.h" +#include "ir/statements/tryStatement.h" +#include "ir/statements/throwStatement.h" +#include "ir/statements/whileStatement.h" + +#include "ir/as/namedType.h" +#include "ir/as/prefixAssertionExpression.h" + +#include "AstVisitor.h" namespace ark::es2panda::ir::visitor { diff --git a/ets2panda/lsp/src/isolated_declaration.cpp b/ets2panda/lsp/src/isolated_declaration.cpp index 77f06d2da7ae35876a82c166d868c86a8942a97d..d78ca87e4a201be4cee9f333111cb0103218169a 100644 --- a/ets2panda/lsp/src/isolated_declaration.cpp +++ b/ets2panda/lsp/src/isolated_declaration.cpp @@ -15,6 +15,8 @@ #include "checker/ETSchecker.h" #include "checker/types/ets/etsFunctionType.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsUnionType.h" #include "isolated_declaration.h" #include "compiler/lowering/util.h" #include "ir/astNode.h" diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index e294a8573baf600112275eb0ac90ec63b0e3fa81..139827b44ccb9dc9b8ebe9269e427db55cc2463b 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -16,11 +16,34 @@ #include "ETSparser.h" #include "generated/diagnostic.h" #include "lexer/lexer.h" +#include "ir/base/classProperty.h" +#include "ir/base/methodDefinition.h" +#include "ir/ets/etsFunctionType.h" #include "ir/ets/etsTuple.h" #include "ir/ets/etsUnionType.h" +#include "ir/ets/etsStructDeclaration.h" +#include "ir/ets/etsStringLiteralType.h" +#include "ir/ets/etsNullishTypes.h" +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" +#include "ir/ets/etsModule.h" +#include "ir/ts/tsInterfaceDeclaration.h" +#include "ir/ts/tsTypeAliasDeclaration.h" +#include "ir/ts/tsArrayType.h" +#include "ir/ts/tsTypeParameter.h" + +#include "ir/expressions/identifier.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/arrowFunctionExpression.h" #include "ir/statements/annotationDeclaration.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" #include "ir/brokenTypeNode.h" +#include "generated/signatures.h" + namespace ark::es2panda::parser { ir::Statement *ETSParser::ParseTopLevelAnnotation(ir::ModifierFlags memberModifiers) diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index d7fc2578746f43ed9964f8e3b9647a50435c5a9d..499a507bf9df987f34504a8da6dca6efa71defe5 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -37,6 +37,7 @@ #include "ir/base/methodDefinition.h" #include "ir/base/classStaticBlock.h" #include "ir/base/spreadElement.h" +#include "ir/base/overloadDeclaration.h" #include "ir/expressions/identifier.h" #include "ir/expressions/functionExpression.h" #include "ir/expressions/dummyNode.h" diff --git a/ets2panda/parser/ETSparserEnums.cpp b/ets2panda/parser/ETSparserEnums.cpp index 44434862cb24624894067944521b420157710561..0127dea39d716edb84756da7eca742af5676998f 100644 --- a/ets2panda/parser/ETSparserEnums.cpp +++ b/ets2panda/parser/ETSparserEnums.cpp @@ -43,6 +43,7 @@ #include "ir/statements/classDeclaration.h" #include "ir/statements/variableDeclarator.h" #include "ir/statements/variableDeclaration.h" +#include "ir/expressions/binaryExpression.h" #include "ir/expressions/dummyNode.h" #include "ir/expressions/callExpression.h" #include "ir/expressions/thisExpression.h" diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 9b7dc49103daa67de0f5e3c03725d6d4bc6683ce..1fe58584606724f1d126681cb86d714aaeece293 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -16,8 +16,95 @@ #include "ETSparser.h" #include "lexer/lexer.h" -#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/brokenTypeNode.h" +#include "ir/ets/etsClassLiteral.h" +#include "ir/ets/etsStructDeclaration.h" +#include "ir/ets/etsIntrinsicNode.h" +#include "ir/ets/etsUnionType.h" +#include "ir/ets/etsStringLiteralType.h" #include "ir/ets/etsTuple.h" +#include "ir/ets/etsTypeReference.h" +#include "ir/ets/etsTypeReferencePart.h" +#include "ir/ets/etsNeverType.h" +#include "ir/ets/etsNullishTypes.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "ir/ets/etsNewArrayInstanceExpression.h" +#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" +#include "ir/ets/etsNewClassInstanceExpression.h" +#include "ir/ets/etsFunctionType.h" +#include "ir/ets/etsNonNullishTypeNode.h" +#include "ir/ets/etsPackageDeclaration.h" +#include "ir/ets/etsPrimitiveType.h" +#include "ir/ets/etsWildcardType.h" +#include "ir/ets/etsKeyofType.h" +#include "ir/ets/etsModule.h" + +#include "ir/ts/tsAsExpression.h" +#include "ir/ts/tsNonNullExpression.h" +#include "ir/ts/tsTypeAssertion.h" + +#include "ir/base/spreadElement.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/catchClause.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/decorator.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/metaProperty.h" +#include "ir/base/overloadDeclaration.h" +#include "ir/base/property.h" +#include "ir/base/tsMethodSignature.h" +#include "ir/base/tsPropertySignature.h" +#include "ir/base/tsSignatureDeclaration.h" +#include "ir/base/tsIndexSignature.h" + +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/taggedTemplateExpression.h" +#include "ir/expressions/typeofExpression.h" +#include "ir/expressions/unaryExpression.h" +#include "ir/expressions/updateExpression.h" +#include "ir/expressions/yieldExpression.h" +#include "ir/expressions/arrowFunctionExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/objectExpression.h" +#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/templateLiteral.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/awaitExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/classExpression.h" +#include "ir/expressions/chainExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/importExpression.h" +#include "ir/expressions/dummyNode.h" +#include "ir/expressions/directEvalExpression.h" +#include "ir/expressions/blockExpression.h" +#include "ir/expressions/conditionalExpression.h" +#include "ir/expressions/thisExpression.h" +#include "ir/expressions/literals/undefinedLiteral.h" +#include "ir/expressions/literals/bigIntLiteral.h" +#include "ir/expressions/literals/booleanLiteral.h" +#include "ir/expressions/literals/charLiteral.h" +#include "ir/expressions/literals/nullLiteral.h" +#include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/regExpLiteral.h" +#include "ir/expressions/newExpression.h" +#include "ir/expressions/omittedExpression.h" +#include "ir/expressions/superExpression.h" + +#include "ir/statements/assertStatement.h" +#include "ir/statements/annotationDeclaration.h" +#include "ir/statements/breakStatement.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/continueStatement.h" +#include "ir/statements/debuggerStatement.h" +#include "ir/statements/doWhileStatement.h" +#include "ir/statements/emptyStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" namespace ark::es2panda::parser { class FunctionContext; diff --git a/ets2panda/parser/ETSparserStatements.cpp b/ets2panda/parser/ETSparserStatements.cpp index bb7d3f6db0e6f009aa5414a9d115b164e3732e4d..7fbe2df6174657f21ec648a808f260ee1bf8b710 100644 --- a/ets2panda/parser/ETSparserStatements.cpp +++ b/ets2panda/parser/ETSparserStatements.cpp @@ -34,6 +34,7 @@ #include "ir/base/methodDefinition.h" #include "ir/base/classStaticBlock.h" #include "ir/base/spreadElement.h" +#include "ir/base/overloadDeclaration.h" #include "ir/expressions/identifier.h" #include "ir/expressions/functionExpression.h" #include "ir/statements/functionDeclaration.h" diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index b2da373d7fed73c1471bb15fa7fcc69bf92e8057..713c5a4fec8db8058951f17c210e90502558ed09 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -50,6 +50,7 @@ #include "ir/ets/etsStringLiteralType.h" #include "ir/ets/etsTypeReference.h" #include "ir/ets/etsTypeReferencePart.h" +#include "ir/ets/etsNonNullishTypeNode.h" #include "ir/ets/etsNullishTypes.h" #include "ir/ets/etsUnionType.h" #include "ir/ets/etsImportDeclaration.h" diff --git a/ets2panda/parser/JsdocHelper.cpp b/ets2panda/parser/JsdocHelper.cpp index f3e75ea9a63636b99be1890c64367b0846e9a36b..875bff08000c56933ded551e04960049db412da0 100644 --- a/ets2panda/parser/JsdocHelper.cpp +++ b/ets2panda/parser/JsdocHelper.cpp @@ -17,7 +17,19 @@ #include #include "lexer/lexer.h" #include "ir/ets/etsTuple.h" +#include "ir/ets/etsStructDeclaration.h" + +#include "ir/base/classProperty.h" +#include "ir/base/methodDefinition.h" + +#include "ir/expressions/arrowFunctionExpression.h" + #include "ir/statements/annotationDeclaration.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/variableDeclarator.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/ts/tsInterfaceDeclaration.h" +#include "ir/ts/tsTypeAliasDeclaration.h" namespace ark::es2panda::parser { static constexpr std::string_view JSDOC_END = "*/"; diff --git a/ets2panda/public/CMakeLists.txt b/ets2panda/public/CMakeLists.txt index 965ef9d300021cd9e2b19404ce342b52f5264a4c..132f57aa20efe511dfd11ed5996ef30dce2f03b6 100644 --- a/ets2panda/public/CMakeLists.txt +++ b/ets2panda/public/CMakeLists.txt @@ -632,6 +632,21 @@ add_custom_command( add_custom_target(gen_yamls DEPENDS es2panda_options_gen es2panda_keywords ${ES2PANDA_API_GENERATED} ${HEADERS_PARSER_SOURCES}) +# add check for PANDA_PRODUCT_BUILD after normal version tracking will be implemented +execute_process( + COMMAND date "+%Y-%m-%d_%H:%M:%S" + OUTPUT_VARIABLE CURRENT_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE LAST_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +add_definitions(-DES2PANDA_DATE="${CURRENT_DATE}") +add_definitions(-DES2PANDA_HASH="${LAST_COMMIT_HASH}") set(ES2PANDA_PUBLIC_SOURCES ${LIB_NAME}.cpp @@ -647,8 +662,7 @@ if (PANDA_TARGET_WINDOWS) endif() panda_frontend_add_library(es2panda-public ${PANDA_DEFAULT_LIB_TYPE} ${ES2PANDA_PUBLIC_SOURCES}) -add_dependencies(es2panda-lib gen_api) -add_dependencies(es2panda-public es2panda-lib) +add_dependencies(es2panda-public es2panda-lib gen_api) panda_target_include_directories(es2panda-public diff --git a/ets2panda/public/contextState.h b/ets2panda/public/contextState.h new file mode 100644 index 0000000000000000000000000000000000000000..3d79daff572ee2b542bb7e8696c26e07d1ac8b32 --- /dev/null +++ b/ets2panda/public/contextState.h @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_PUBLIC_CONTEXT_STATE +#define ES2PANDA_PUBLIC_CONTEXT_STATE + +// Switch off the linter for C header +// NOLINTBEGIN +// + +#ifdef __cplusplus +extern "C" { +#endif + +enum es2panda_ContextState { + ES2PANDA_STATE_NEW, + ES2PANDA_STATE_PARSED, + ES2PANDA_STATE_BOUND, + ES2PANDA_STATE_CHECKED, + ES2PANDA_STATE_LOWERED, + ES2PANDA_STATE_ASM_GENERATED, + ES2PANDA_STATE_BIN_GENERATED, + + ES2PANDA_STATE_ERROR +}; + +typedef enum es2panda_ContextState es2panda_ContextState; + +typedef struct es2panda_Context es2panda_Context; + +#ifdef __cplusplus +} +#endif + +// NOLINTEND + +#endif // ES2PANDA_PUBLIC_CONTEXT_STATE diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index a1562a4fd690c3c9a576037d2ff968a103a2f1f3..ba251b85afd853c7aae2e5bbe36960af0f0866fe 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -22,6 +22,7 @@ // NOLINTBEGIN // +#include "contextState.h" #include #include #include @@ -42,7 +43,6 @@ extern "C" { #endif typedef struct es2panda_Config es2panda_Config; -typedef struct es2panda_Context es2panda_Context; typedef struct es2panda_GlobalContext es2panda_GlobalContext; typedef struct es2panda_variantDoubleCharArrayBool { @@ -129,18 +129,6 @@ typedef struct es2panda_OverloadInfo { bool returnVoid; } es2panda_OverloadInfo; -enum es2panda_ContextState { - ES2PANDA_STATE_NEW, - ES2PANDA_STATE_PARSED, - ES2PANDA_STATE_BOUND, - ES2PANDA_STATE_CHECKED, - ES2PANDA_STATE_LOWERED, - ES2PANDA_STATE_ASM_GENERATED, - ES2PANDA_STATE_BIN_GENERATED, - - ES2PANDA_STATE_ERROR -}; - typedef struct es2panda_SuggestionInfo { const es2panda_DiagnosticKind *kind; const char **args; @@ -167,7 +155,6 @@ typedef enum Es2pandaLanguage { } Es2pandaLanguage; typedef enum es2panda_PluginDiagnosticType es2panda_PluginDiagnosticType; -typedef enum es2panda_ContextState es2panda_ContextState; // CC-OFFNXT(G.INC.08) project code style #include "generated/es2panda_lib/es2panda_lib_enums.inc" diff --git a/ets2panda/public/es2panda_lib_impl.inc.erb b/ets2panda/public/es2panda_lib_impl.inc.erb index 6e6468b21c7f6313f1bfdcd3b5c859facf9d3fb1..eb8e46658ac47aab8faa52c2fb92fca8e31cb1da 100644 --- a/ets2panda/public/es2panda_lib_impl.inc.erb +++ b/ets2panda/public/es2panda_lib_impl.inc.erb @@ -16,7 +16,7 @@ // Autogenerated file -- DO NOT EDIT! // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic, readability-non-const-parameter) // NOLINTBEGIN(readability-function-size, readability-magic-numbers) - + % Enums::enums&.each do |name, enum| % if enum.flags&.length > 0 extern "C" __attribute__((unused)) <%= enum.namespace %><%= if enum.parent_class_name then "::" + enum.parent_class_name diff --git a/ets2panda/public/headers_parser/cpp_parser.py b/ets2panda/public/headers_parser/cpp_parser.py index 7d33d64f9814056a0f12da273871a0831d4b31c2..ba673f7677ea25167536c81afbdff3039a4ea8e0 100644 --- a/ets2panda/public/headers_parser/cpp_parser.py +++ b/ets2panda/public/headers_parser/cpp_parser.py @@ -66,7 +66,7 @@ class CppParser: self.it.end, self.parsed = parse_namespace(self.it.data, self.it.start) self.res_update() - elif self.it.is_enum(): + elif self.it.is_enum_def(): self.it.end, self.parsed = parse_enum_class(self.it.data, self.it.start) self.res_append_namespace() diff --git a/ets2panda/public/headers_parser/line_iterator.py b/ets2panda/public/headers_parser/line_iterator.py index 734799fb449982aa0e43caf2d2d6d364bd371b27..9567a28d7c03cdd5b6253c97e8935008bd4d40c4 100644 --- a/ets2panda/public/headers_parser/line_iterator.py +++ b/ets2panda/public/headers_parser/line_iterator.py @@ -73,8 +73,8 @@ class LineIterator: # pylint: disable=C0115 def is_namespace(self) -> bool: return self.current_line.find("namespace") != -1 - def is_enum(self) -> bool: - return self.current_line.find("enum ") != -1 + def is_enum_def(self) -> bool: + return self.current_line.find("enum ") != -1 and self.current_line.find("{") != -1 def is_struct(self) -> bool: return self.current_line.find("struct ") != -1 diff --git a/ets2panda/public/public.h b/ets2panda/public/public.h index 72c7553a18454f2d47da38885160feb121da5090..a468ce232f2aa55ac3e2cd0433b23b2dda3f000c 100644 --- a/ets2panda/public/public.h +++ b/ets2panda/public/public.h @@ -17,7 +17,6 @@ #define ES2PANDA_PUBLIC_PUBLIC_H #include -#include "public/es2panda_lib.h" #include "assembler/assembly-program.h" #include "libpandabase/mem/arena_allocator.h" @@ -26,6 +25,7 @@ #include "parser/ETSparser.h" #include "checker/ETSchecker.h" #include "compiler/core/emitter.h" +#include "contextState.h" namespace ark::es2panda::util { class Options; diff --git a/ets2panda/test/unit/any_ins_test/any_ins_test.cpp b/ets2panda/test/unit/any_ins_test/any_ins_test.cpp index 357470258dbc0070928017a7bb44276e387ff7ef..7815f67f2c24d1a1a8f15a3e9c143e1d910fa20b 100644 --- a/ets2panda/test/unit/any_ins_test/any_ins_test.cpp +++ b/ets2panda/test/unit/any_ins_test/any_ins_test.cpp @@ -22,6 +22,8 @@ #include "assembly-parser.h" #include "assembly-program.h" #include "test/utils/checker_test.h" +#include "checker/types/ets/etsFunctionType.h" +#include "compiler/core/ETSGen.h" namespace ark::es2panda::compiler::test { diff --git a/ets2panda/test/unit/globalETSObjectType_test.cpp b/ets2panda/test/unit/globalETSObjectType_test.cpp index 9100fabbe57acc8e3f563cbbcea65f48b62343fb..38b595cfe4584c0c9f87e936950c30f36c36ceb7 100644 --- a/ets2panda/test/unit/globalETSObjectType_test.cpp +++ b/ets2panda/test/unit/globalETSObjectType_test.cpp @@ -19,7 +19,7 @@ #include "compiler/core/compilerImpl.h" #include "compiler/core/ETSCompiler.h" #include "compiler/core/ETSemitter.h" -#include "compiler/core/ETSGen.h" + #include "compiler/core/regSpiller.h" #include "compiler/lowering/phase.h" #include "es2panda.h" diff --git a/ets2panda/test/unit/public/ast_verifier_short_test.cpp b/ets2panda/test/unit/public/ast_verifier_short_test.cpp index 893f27a28d66caf20fdccd20223a968b6cbf820f..ea2787e16af60004eb67e9a1b5d9cf912d1a9cb2 100644 --- a/ets2panda/test/unit/public/ast_verifier_short_test.cpp +++ b/ets2panda/test/unit/public/ast_verifier_short_test.cpp @@ -15,6 +15,7 @@ #include "ast_verifier_test.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsBooleanType.h" #include "es2panda.h" #include "ir/expressions/literals/stringLiteral.h" #include "ir/expressions/identifier.h" diff --git a/ets2panda/test/unit/union_normalization_test_1.cpp b/ets2panda/test/unit/union_normalization_test_1.cpp index d4cbe2fb7d3e38397d63de770249ceec054843ad..0dd62bc8e562b2af1b1ccd14ca9c933aa8df4c7f 100644 --- a/ets2panda/test/unit/union_normalization_test_1.cpp +++ b/ets2panda/test/unit/union_normalization_test_1.cpp @@ -18,10 +18,11 @@ #include "checker/ETSAnalyzer.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsUnionType.h" #include "compiler/core/compilerImpl.h" #include "compiler/core/ETSCompiler.h" #include "compiler/core/ETSemitter.h" -#include "compiler/core/ETSGen.h" + #include "compiler/core/regSpiller.h" #include "compiler/lowering/phase.h" #include "es2panda.h" diff --git a/ets2panda/test/unit/union_normalization_test_2.cpp b/ets2panda/test/unit/union_normalization_test_2.cpp index 59715ca07ed513bca002240473d024897bbf922e..0561351c40c5bf1f2df7115898b321887afe9a64 100644 --- a/ets2panda/test/unit/union_normalization_test_2.cpp +++ b/ets2panda/test/unit/union_normalization_test_2.cpp @@ -18,10 +18,12 @@ #include "checker/ETSAnalyzer.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/etsStringType.h" #include "compiler/core/compilerImpl.h" #include "compiler/core/ETSCompiler.h" #include "compiler/core/ETSemitter.h" -#include "compiler/core/ETSGen.h" + #include "compiler/core/regSpiller.h" #include "compiler/lowering/phase.h" #include "es2panda.h" diff --git a/ets2panda/test/utils/ast_verifier_test.h b/ets2panda/test/utils/ast_verifier_test.h index 46d307067ab2ed5078bc40f39b0174be5b5c4acb..8e72b6d11b3933f1721812c54cbefc2b259c2da9 100644 --- a/ets2panda/test/utils/ast_verifier_test.h +++ b/ets2panda/test/utils/ast_verifier_test.h @@ -17,6 +17,7 @@ #define ES2PANDA_TEST_UTILS_AST_VERIFIER_TEST_H #include "ast_verifier/ASTVerifier.h" +#include "public/es2panda_lib.h" #include "panda_executable_path_getter.h" #include "compiler/lowering/phase.h" diff --git a/ets2panda/test/utils/checker_test.h b/ets2panda/test/utils/checker_test.h index de62d43764ef68294086a483ac35711d74580f04..a8348dcb8ad6767699ce077a11eac0631a8bb66b 100644 --- a/ets2panda/test/utils/checker_test.h +++ b/ets2panda/test/utils/checker_test.h @@ -22,7 +22,7 @@ #include "compiler/core/regSpiller.h" #include "compiler/core/ETSCompiler.h" #include "compiler/core/ETSemitter.h" -#include "compiler/core/ETSGen.h" + #include "checker/ETSAnalyzer.h" #include "ir/astNode.h" #include "util/options.h" diff --git a/ets2panda/util/plugin.h b/ets2panda/util/plugin.h index a09113ac0bba9e43c372ef2d764fbf14889fe7ac..fd1ee533e3a695240eec7cb26a6e2df7412b2747 100644 --- a/ets2panda/util/plugin.h +++ b/ets2panda/util/plugin.h @@ -17,9 +17,10 @@ #include "util/es2pandaMacros.h" #include "os/library_loader.h" -#include "public/es2panda_lib.h" #include "util/ustring.h" +extern "C" struct es2panda_Context; + namespace ark::es2panda::util { class Plugin { diff --git a/ets2panda/varbinder/TypedBinder.cpp b/ets2panda/varbinder/TypedBinder.cpp index 2cf8062201b8ba899049b8b3a0af4152b3cc220c..2b82cfaf2615985d8cbafc932eeee1da08ca82df 100644 --- a/ets2panda/varbinder/TypedBinder.cpp +++ b/ets2panda/varbinder/TypedBinder.cpp @@ -14,6 +14,7 @@ */ #include "TypedBinder.h" + #include "ir/base/tsSignatureDeclaration.h" #include "ir/base/tsMethodSignature.h" #include "ir/ts/tsFunctionType.h" diff --git a/ets2panda/varbinder/recordTable.cpp b/ets2panda/varbinder/recordTable.cpp index 6971fd4da368dda3a29bb2a6971890100d899887..df38c689e4889a0a716df46e1fb94b6322575c05 100644 --- a/ets2panda/varbinder/recordTable.cpp +++ b/ets2panda/varbinder/recordTable.cpp @@ -21,7 +21,6 @@ #include "ir/statements/annotationDeclaration.h" #include "ir/ts/tsEnumDeclaration.h" #include "ir/ts/tsInterfaceDeclaration.h" -#include "checker/types/ets/etsObjectType.h" #include "generated/signatures.h" namespace ark::es2panda::varbinder { diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 6798b4e03097de32a9409b3a4e30ceedb32a0b15..e9917a6938d377f11c509b7b8e4872c851f55038 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -19,6 +19,16 @@ #include "varbinder/tsBinding.h" #include "compiler/lowering/util.h" +#include "ir/base/classProperty.h" +#include "ir/base/classElement.h" + +#include "ir/module/exportAllDeclaration.h" +#include "ir/module/exportNamedDeclaration.h" + +#include "ir/ts/tsEnumDeclaration.h" +#include "ir/ts/tsTypeAliasDeclaration.h" +#include "ir/ts/tsInterfaceDeclaration.h" + namespace ark::es2panda::varbinder { VariableScope *Scope::EnclosingVariableScope() noexcept { diff --git a/ets2panda/varbinder/varbinder.cpp b/ets2panda/varbinder/varbinder.cpp index 73ef1c50e4f1131fe52bf38b672bf29a71ac825e..aa7faf36727f2db83fe5b5b8f952980a4f1725af 100644 --- a/ets2panda/varbinder/varbinder.cpp +++ b/ets2panda/varbinder/varbinder.cpp @@ -16,6 +16,18 @@ #include "varbinder.h" #include "public/public.h" +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/arrayExpression.h" +#include "ir/expressions/objectExpression.h" + +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" + +#include "ir/base/property.h" +#include "ir/base/spreadElement.h" +#include "ir/base/scriptFunction.h" + + namespace ark::es2panda::varbinder { void VarBinder::InitTopScope() {